Skip to content

Host reject to freeze? #20

Closed
Closed

Description

@Jack-Works

It might be possible there is a host API like this:

const process = new Process('./native.so')
process.memory instanceof ArrayBuffer
process.memory.transferToImmutable() // or .detach()

Is this a case we want the host to be able to reject the detached behavior? (This also affects other APIs like transfer actually).

Activity

  1. ljharb commented on Dec 24, 2024

    @ljharb
    Member

    I'm confused, how would this not work out of the box? If it's actually a proper instance of ArrayBuffer, then it'd be detachable; if it's not detachable, then it's not a proper instance of ArrayBuffer.

  2. Jack-Works commented on Dec 25, 2024

    @Jack-Works
    MemberAuthor

    I'm confused, how would this not work out of the box? If it's actually a proper instance of ArrayBuffer, then it'd be detachable; if it's not detachable, then it's not a proper instance of ArrayBuffer.

    I mean, if there is a case that the host wants to reject the AB being detachable. this is like HostEnsureCanAddPrivateElement that limits the ability of adding a private field to a host object.

  3. ljharb commented on Dec 25, 2024

    @ljharb
    Member

    Why would we want to consider a host hook when no use case for that has presented itself?

  4. Jamesernator commented on Dec 26, 2024

    @Jamesernator

    I'm confused, how would this not work out of the box? If it's actually a proper instance of ArrayBuffer, then it'd be detachable; if it's not detachable, then it's not a proper instance of ArrayBuffer.

    Why would we want to consider a host hook when no use case for that has presented itself?

    Host buffers can already be non-detachable/transferable via [[ArrayBufferDetachKey]], e.g. WebAssembly.Memory can't be transfered/detached (except via other WebAssembly methods, e.g. mem.grow does detach the previous buffer):

    const mem = new WebAssembly.Memory({ initial: 1 });
    // Throws a TypeError
    const newBuffer = mem.buffer.transfer();
    const oldBuffer = mem.buffer;
    mem.grow(1);
    // Now detached
    oldBuffer.detached; // true
    oldBuffer === mem.buffer; // false
    
    const mem = new WebAssembly.Memory({ initial: 1, maximum: 1 });
    // Not detachable by any means
    mem.buffer;

    I don't see that this proposal needs anything special, if a host buffer can't be transfered to an immutable buffer then they can just set [[ArrayBufferDetachKey]] and provide a separate API.

  5. Jack-Works commented on Dec 26, 2024

    @Jack-Works
    MemberAuthor

    Thank you! This is first time I learn ArrayBufferDetachKey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions