Repository navigation
[js-api] Set GC object prototype from descriptor - #140
Merged
Merged
Conversation
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.
Member
Author
|
cc @o- |
rmahdav
approved these changes
Nov 20, 2026
| 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, |
There was a problem hiding this comment.
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).
Member
Author
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
Could we also test prototype cycle rejection here?
Member
Author
|
Removed the cache collision fix, since that will be fixed separately (and in a different way) upstream in WebAssembly/spec#2327. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.