Skip to content

[js-api] Use OrdinaryObjectCreate for GC objects - #138

Merged
tlively merged 3 commits into
mainfrom
js-api-frozen-gc-objects
Nov 18, 2026
Merged

tlively merged 3 commits into
mainfrom
js-api-frozen-gc-objects

Conversation

@tlively

@tlively tlively commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Create Exported GC Objects using OrdinaryObjectCreate and SetIntegrityLevel("sealed") rather than defining custom exotic internal methods, and update JS API tests to cover ordinary empty, sealed object behavior.

Fixes #131.

Create Exported GC Objects using OrdinaryObjectCreate and SetIntegrityLevel("frozen") rather than defining custom exotic internal methods, and update JS API tests to cover ordinary frozen object behavior.
@tlively
tlively requested a review from rmahdav November 17, 2026 22:14
@tlively

tlively commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

@o-, can you take a look as well?

@tlively
tlively requested a review from rossberg November 17, 2026 22:15
@sjrd

sjrd commented Nov 17, 2026

Copy link
Copy Markdown

Now that I think more on it, shouldn't they be sealed rather than frozen? It doesn't really make a difference for now, since they have no own properties. But in a possible future with "own properties", it would matter.

Comment thread document/js-api/index.bs Outdated
@@ -1581,103 +1580,22 @@ The <dfn constructor for="Tag" lt="Tag(type)">new Tag(|type|)</dfn> constructor
<h3 id="gc-exotic-objects">Garbage Collected Objects</h3>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Optional nit: Shouldn't we update the id here to something like "gc-objects" 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.

Done. Gemini also added this oldids thing, which I hadn't known about, but apparently keeps old links working: https://speced.github.io/bikeshed/#id-gen.

Comment thread document/js-api/index.bs Outdated
1. Set |object|.\[[Set]] as specified in [=[[Set]] internal method of an Exported GC Object=].
1. Set |object|.\[[Delete]] as specified in [=[[Delete]] internal method of an Exported GC Object=].
1. Set |object|.\[[OwnPropertyKeys]] as specified in [=[[OwnPropertyKeys]] internal method of an Exported GC Object=].
1. Perform [=!=] [$SetIntegrityLevel$](|object|, "frozen").

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The second parameter here should be an enum constant ~frozen~ instead of a string "frozen". Since this file already defines <emu-const>, this should be <emu-const>frozen</emu-const>.

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.

Fixed.

Comment thread document/js-api/index.bs
1. Perform [=!=] [$SetIntegrityLevel$](|object|, "frozen").
1. [=map/Set=] |map|[|objectaddr|] to |object|.
1. Return |object|.
</div>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I saw your comment about tc39/proposal-nonextensible-applies-to-private in the test, but I think it is better to have a Note: here about it as well. This will prevent any confusion for readers.

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.

}
}
class StampField extends Base {
#field = 42;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we also add tests for private methods and private getter/setter 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.

Done.

@tlively

tlively commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

Now that I think more on it, shouldn't they be sealed rather than frozen? It doesn't really make a difference for now, since they have no own properties. But in a possible future with "own properties", it would matter.

Hmm, interesting question. I'm inclined to keep them frozen for now, since that communicates "maximally locked down." In a future where we allow configuring mutable own properties, we can make just the objects with such configuration sealed rather than frozen.

@rmahdav rmahdav left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, thanks!

@sjrd

sjrd commented Nov 18, 2026

Copy link
Copy Markdown

Hmm, interesting question. I'm inclined to keep them frozen for now, since that communicates "maximally locked down." In a future where we allow configuring mutable own properties, we can make just the objects with such configuration sealed rather than frozen.

"frozen" also suggests (shallow) immutability. Wasm structs are not shallow-immutable because we can mutate their Wasm fields.

Anyway, I don't feel strongly about it.

@tlively

tlively commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

Hmm, interesting question. I'm inclined to keep them frozen for now, since that communicates "maximally locked down." In a future where we allow configuring mutable own properties, we can make just the objects with such configuration sealed rather than frozen.

"frozen" also suggests (shallow) immutability. Wasm structs are not shallow-immutable because we can mutate their Wasm fields.

Anyway, I don't feel strongly about it.

That makes sense to me. I'll switch to using sealed. If someone wants to keep "frozen" enough to say something, we can always continue the discussion :)

@tlively
tlively merged commit 5fe5c84 into main Nov 18, 2026
11 checks passed
@tlively
tlively deleted the js-api-frozen-gc-objects branch November 18, 2026 21:23
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.

Make Wasm objects behave more normally in JS?

3 participants