WebAssembly / WebAssembly/spec

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

Open
#1,292 47 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
3.5k
Forks
539
Avg merge
2d 1h
Merged PRs (30d)
13

Description

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?)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked ResizableArrayBuffer and GrowableSharedArrayBuffer proposal and its referenced TC39 discussion, then compare the suggested behavior with the WebAssembly.Memory API specification. The issue needs an agreed normative plan for the new resizableBuffer behavior, detachment rules, and size validation, followed by the appropriate standards process.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.