From 668b11dbe49569aac979d893365cd6c3165e370d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 27 Jan 2024 17:43:56 +0000 Subject: [PATCH] Editorial: Return created EC from InitializeHostDefinedRealm 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]]. --- spec.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spec.html b/spec.html index b272c6b8ab..3d26d37f04 100644 --- a/spec.html +++ b/spec.html @@ -12080,7 +12080,7 @@

-

InitializeHostDefinedRealm ( ): either a normal completion containing ~unused~ or a throw completion

+

InitializeHostDefinedRealm ( ): either a normal completion containing an execution context or a throw completion

@@ -12094,9 +12094,14 @@

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_.