Skip to content

Commit

Permalink
Editorial: Return created EC from InitializeHostDefinedRealm
Browse files Browse the repository at this point in the history
This AO is not being used in ECMA-262 directly, but from real-world
experience implementing & using is as-is I can say that having to pull
the Realm out of the running execution context is somewhat awkward.

This change is not backwards compatible with how the HTML spec uses the
AO, but will allow simplifying the following:

1. Perform InitializeHostDefinedRealm() with the provided customizations
   for creating the global object and the global this binding.
2. Let realm execution context be the running JavaScript execution
   context.
3. Remove realm execution context from the JavaScript execution context
   stack.
4. Let realm be realm execution context's Realm component.

to

1. Let realm execution context be InitializeHostDefinedRealm() with the
   provided customizations for creating the global object and the global
   this binding.
2. Let realm be realm execution context's Realm component.

(https://html.spec.whatwg.org/#creating-a-new-javascript-realm)

For hosts that don't have HTML's requirement of removing the running
execution context, it becomes a simple:

1. Let executionContext be InitializeHostDefinedRealm().
2. Let realm be executionContext.[[Realm]].
  • Loading branch information
linusg committed Jan 28, 2024
1 parent 3290694 commit 4ed1126
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -12086,7 +12086,7 @@ <h1>
</emu-clause>

<emu-clause id="sec-initializehostdefinedrealm" type="abstract operation">
<h1>InitializeHostDefinedRealm ( ): either a normal completion containing ~unused~ or a throw completion</h1>
<h1>InitializeHostDefinedRealm ( ): either a normal completion containing an execution context or a throw completion</h1>
<dl class="header">
</dl>

Expand All @@ -12100,9 +12100,14 @@ <h1>InitializeHostDefinedRealm ( ): either a normal completion containing ~unuse
1. If the host requires use of an exotic object to serve as _realm_'s global object, let _global_ be such an object created in a host-defined manner. Otherwise, let _global_ be *undefined*, indicating that an ordinary object should be created as the global object.
1. If the host requires that the `this` binding in _realm_'s global scope return an object other than the global object, let _thisValue_ be such an object created in a host-defined manner. Otherwise, let _thisValue_ be *undefined*, indicating that _realm_'s global `this` binding should be the global object.
1. Perform SetRealmGlobalObject(_realm_, _global_, _thisValue_).
1. Let _globalObj_ be ? SetDefaultGlobalBindings(_realm_).
1. Let _result_ be Completion(SetDefaultGlobalBindings(_realm_)).
1. If _result_ is an abrupt completion, then
1. Remove _newContext_ from the execution context stack.
1. Return ? _result_.
1. Let _globalObj_ be ? _result_.
1. Create any host-defined global object properties on _globalObj_.
1. Return ~unused~.
1. Remove _newContext_ from the execution context stack.
1. Return _newContext_.
</emu-alg>
</emu-clause>

Expand Down

0 comments on commit 4ed1126

Please sign in to comment.