Re: [whatwg/webidl] When creating a global object the realm is not yet initialized (Issue #1547)

shannonbooth left a comment (whatwg/webidl#1547)

I've looked into this somewhat, and I think we can fix this using a slightly modified version of https://github.com/tc39/ecma262/pull/3728 in combination with some somewhat larger changes in the HTML spec where InitializeHostDefinedRealm / "create a realm" is used.

Instead of creating a global object and then the ESO, perhaps we can create the ESO first, _then_ the global object. This will allow the Exposed checks on creation of the global object to use the ESO.

To make this work, we will need to:
- Change algorithms used in "is exposed" to operate on the ESO, instead of global object. This means changing https://html.spec.whatwg.org/multipage/webappapis.html#secure-context so that owner set is stored on the worker ESO, instead of the worker global.
- Create ESOs inside of the "customisations" hook added https://github.com/tc39/ecma262/pull/3728, then create the global objects. One implication here is that creation of an ESO requires an execution context, so this is somewhat in conflict with https://github.com/tc39/ecma262/pull/3497 and the third commit of https://github.com/tc39/ecma262/pull/3728 as it requires the execution context to instead be passed through.

I haven't gotten all of the way through in terms of validating the above, but I've gotten far enough that I'm fairly confident that approach can work.

The only other way I can think of to fix this is to defer the full initialisation of globals until after the ESO is created, but this is quite a bit uglier (though this is the approach taken in ladybird implementation currently as a workaround).

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/issues/1547#issuecomment-4701438265
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/issues/1547/4701438265@github.com>

Received on Sunday, 14 June 2026 10:16:44 UTC