Skip to content

[js-api] Integration with the ResizableArrayBuffer and GrowableSharedArrayBuffer proposal #1292

@syg

Description

@syg

The ResizableArrayBuffer and GrowableSharedArrayBuffer proposal is a TC39 proposal that is currently stage 2.

There was some discussion of how the proposal might integrate with the Wasm/JS API. It seems better to move the discussion here to get a concrete plan and to get more Wasm eyes on the issue.

As a starting point, I suggest the following changes to the WebAssembly.Memory API:

  • Memory will have a new resizableBuffer attribute.
    • Returns a ResizableArrayBuffer or GrowableSharedArrayBuffer instance.
    • If an ArrayBuffer was vended by the buffer attribute on the same instance, that ArrayBuffer instance will be detached. SharedArrayBuffers and GrowableSharedArrayBuffer will alias the same memory.
    • If the Memory was created with a maximum size, that size will be reflected on the ResizableArrayBuffer or GrowableSharedArrayBuffer instance.
    • Otherwise, the maximum size is 2^32.
  • Memory's buffer attribute will detach any ResizableArrayBuffer buffers vended by the resizableBuffer attribute.
  • ResizableArrayBuffers gotten via Memory's resizableBuffer attribute will:
    • Throw on transfer(), since they can't be detached.
    • Throw on resize() calls that are shrinks.
    • Throw on resize() calls that are not in multiples of the wasm page size. (Thanks @conrad-watt)
  • GrowableArrayBuffers gotten via Memory's resizableBuffer attribute will:
    • Throw on grow() calls that are not in multiples of the wasm page size.

Thoughts welcome.

(Also, what is the process for bringing such a "normative PR" that's not a full proposal to the CG? Is it just an agenda item?)

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