Skip to content

[js-api] Set GC object prototype from descriptor - #140

Merged
tlively merged 3 commits into
mainfrom
js-api-descriptor-prototypes
Nov 20, 2026
Merged

tlively merged 3 commits into
mainfrom
js-api-descriptor-prototypes

Conversation

@tlively

@tlively tlively commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

When creating a new Exported GC Object for a WebAssembly struct, inspect its descriptor's first field and pass it to OrdinaryObjectCreate as the prototype if the field is immutable, matches externref, and converts to a JS Object. Add JS API tests for prototype delegation on sealed Wasm structs.

When creating a new Exported GC Object for a WebAssembly struct, inspect its descriptor's first field and pass it to OrdinaryObjectCreate as the prototype if the field is immutable, matches externref, and converts to a JS Object. Also key the Exported GC Object cache by (objectkind, objectaddr) tuples so struct and array addresses do not collide (fixing a pre-existing bug), and add JS API tests for prototype delegation on sealed Wasm structs.
@tlively
tlively requested review from eqrion and rmahdav November 19, 2026 02:26
@tlively

tlively commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

cc @o-

When the JS-side reflection of a Wasm struct is created,
if that struct has a descriptor,
the descriptor's first field is immutable with a type matching `externref`,
and that field contains a JS object,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If I understand correctly externref can hold Wasm objects (structs/arrays/functions) as well. If that is true, maybe say contains an object instead of contains a JS object (and in the line 600 as well).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point. I've made this more precise by saying "...and that field's value (converted to JS) is a JS object..." That covers Wasm objects as well, and better matches the formal spec.

assert_equals(obj[0], "zero");
}, "delete with prototype");

test(() => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also test prototype cycle rejection here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done.

@tlively

tlively commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Removed the cache collision fix, since that will be fixed separately (and in a different way) upstream in WebAssembly/spec#2327.

@tlively
tlively merged commit 6edc6cb into main Nov 20, 2026
12 checks passed
@tlively
tlively deleted the js-api-descriptor-prototypes branch November 20, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants