From 228026d4f307501244ffe8837ee29c6327385b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caridy=20Pati=C3=B1o?= Date: Thu, 25 Mar 2021 19:35:48 -0400 Subject: [PATCH 1/5] first draft for isolated realms --- README.md | 4 +- spec.html | 174 +++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 162 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4c13605c..e5583051 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ See more at the [explainer](explainer.md) document. ```ts declare class Realm { constructor(); - readonly globalThis: typeof globalThis; - import(specifier: string): Promise; + importBinding(specifier: string, bindingName: string): Promise; + evaluate(sourceText: string): PrimitiveValueOrCallable; } ``` diff --git a/spec.html b/spec.html index e65ad7e1..22b11f7d 100644 --- a/spec.html +++ b/spec.html @@ -32,8 +32,118 @@

Well-known intrinsic objects

+ +

Wrapped Function Exotic Objects

+

A wrapped function exotic object is an exotic object that wraps a callable object. A wrapped function exotic object is callable (it has a [[Call]] internal method). Calling a wrapped function exotic object generally results in a call of its wrapped function.

+ +

An object is a wrapped function exotic object if its [[Call]] internal method use the following implementations, and its other essential internal methods use the definitions found in . These methods are installed in WrappedFunctionCreate.

+ +

Wrapped function exotic objects do not have the internal slots of ECMAScript function objects listed in . Instead they have the internal slots listed in , in addition to [[Prototype]] and [[Extensible]].

+ + + + + + + + + + + + + + + + + + + +
+ Internal Slot + + Type + + Description +
+ [[WrappedTargetFunction]] + + Callable Object + + The wrapped function object. +
+ [[Realm]] + + Realm Record + + The realm in which the wrapped function object was created. +
+
+ + +

[[Call]] ( _thisArgument_, _argumentsList_ )

+

The [[Call]] internal method of a wrapped function exotic object _F_ takes arguments _thisArgument_ (an ECMAScript language value) and _argumentsList_ (a List of ECMAScript language values). It performs the following steps when called:

+ + 1. Let _target_ be _F_.[[WrappedTargetFunction]]. + 1. Assert: IsCallable(_target_) is *true*. + 1. Let _targetRealm_ be ? GetFunctionRealm(_target_). + 1. Let _callerRealm_ be ? GetFunctionRealm(_F_). + 1. For each element _key_ of _argumentsList_, do + 1. Let o be _argumentsList_[_key_]. + 1. Set _argumentsList_[_key_] to ? GetWrappedValue(_targetRealm_, _o_). + 1. Let _wrappedThisArgument_ to ? GetWrappedValue(_targetRealm_, _thisArgument_). + 1. Let _value_ be ? Call(_target_, _wrappedThisArgument_, _argumentsList_). + 1. Return ? GetWrappedValue(_callerRealm_, _value_). + +
+ + +

WrappedFunctionCreate ( _callerRealm_, _targetFunction_ )

+

The abstract operation WrappedFunctionCreate takes arguments _callerRealm_ and _targetFunction_. It is used to specify the creation of new wrapped function exotic objects. It performs the following steps when called:

+ + 1. Assert: _callerRealm_ is a Realm Record. + 1. Assert: IsCallable(_targetFunction_) is *true*. + 1. Let _internalSlotsList_ be the internal slots listed in , plus [[Prototype]] and [[Extensible]]. + 1. Let _obj_ be ! MakeBasicObject(_internalSlotsList_). + 1. Set _obj_.[[Prototype]] to %Function.prototype% from _callerRealm_. + 1. Set _obj_.[[Call]] as described in . + 1. Set _obj_.[[Realm]] to _callerRealm_. + 1. Set _obj_.[[WrappedTargetFunction]] to _targetFunction_. + 1. Return _obj_. + +
+
+

Realm Objects

+ +

Realm Abstract Operations

+ + +

PerformRealmEvaluation ( _x_, _evalRealm_ )

+ + 1. Assert: Type(_x_) is String. + 1. Assert: _evalRealm_ is a Realm Record. + 1. Let _hostDefined_ be _evalRealm_.[[HostDefined]]. + 1. Let _s_ be ParseScript(_x_, _evalRealm_, _hostDefined_). + 1. If _s_ is a List of errors, then + 1. Perform HostReportErrors(_s_). + 1. Return NormalCompletion(*undefined*). + 1. Return ? ScriptEvaluation(_s_). + +
+ + +

GetWrappedValue ( _callerRealm_, _value_ )

+ + 1. Assert: _callerRealm_ is a Realm Record. + 1. If Type(_value_) is Object, then + 1. If IsCallable(_value_) is *false*, throw a TypeError exception. + 1. Return ? WrappedFunctionCreate(_callerRealm_, _value_). + 1. Return _value_. + +
+ +

The Realm Constructor

@@ -92,19 +202,39 @@

Properties of the Realm Prototype Object

  • does not have a [[Realm]] or any other of the internal slots that are specific to _Realm_ instance objects.
  • - -

    Realm.prototype.import ( _specifier_ )

    + +

    Realm.prototype.evaluate ( _sourceText_ )

    + + Synchronously execute a top-level script. The _sourceText_ is interpreted as a Script and evaluated with this bound to the realm's global object. + + + 1. Let _O_ be *this* value. + 1. Perform ? RequireInternalSlot(_O_, [[Realm]]). + 1. If Type(_sourceText_) is not String, throw a *TypeError* exception. + 1. Let _realm_ be _O_.[[Realm]]. + 1. Let _value_ be ? PerformRealmEvaluation(_sourceText_, _realm_). + 1. Return ? GetWrappedValue(_realm_, _value_). + + + + Extensible web: This is the dynamic equivalent of a <script> in HTML. + +
    + + +

    Realm.prototype.importBinding ( _specifier_, _bindingName_ )

    The following steps are performed:

    1. Let _O_ be *this* value. 1. Perform ? ValidateRealmObject(_O_). 1. Let _referencingScriptOrModule_ be *null*. 1. Let _specifierString_ be ? ToString(_specifier_). + 1. Let __bindingNameString_ be ? ToString(_bindingName_). 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). 1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_). 1. Let _callerContext_ be the running execution context. 1. Push _O_.[[ExecutionContext]] onto the execution context stack; _O_.[[ExecutionContext]] is now the running execution context. - 1. Perform ! HostImportModuleDynamically(_referencingScriptOrModule_, _specifierString_, _promiseCapability_). + 1. Perform ! HostImportModuleBindingDynamically(_referencingScriptOrModule_, _specifierString_, __bindingNameString_, _promiseCapability_). 1. Remove _O_.[[ExecutionContext]] from the execution context stack and restore _callerContext_ as the running execution context. 1. Return _promiseCapability_.[[Promise]]. @@ -128,17 +258,6 @@

    ValidateRealmObject( _argument_ )

    - -

    get Realm.prototype.globalThis

    -

    Realm.prototype.globalThis is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps:

    - - - 1. Let _O_ be *this* value. - 1. Perform ? ValidateRealmObject(_O_). - 1. Return _O_.[[Realm]].[[GlobalEnv]].[[GlobalThisValue]]. - -
    -

    Realm.prototype [ @@toStringTag ]

    The initial value of the @@toStringTag property is the String value "Realm".

    @@ -187,6 +306,33 @@

    Runtime Semantics: HostInitializeSyntheticRealm ( _realm_ )

    global object.

    + + + +

    HostImportModuleBindingDynamically ( _referencingScriptOrModule_, _specifier_, _bindingName_, _promiseCapability_ )

    +

    The host-defined abstract operation HostImportModuleBindingDynamically takes arguments _referencingScriptOrModule_ (a Script Record or Module Record or *null*), _specifier_ (a |ModuleSpecifier| String), _bindingName_ (a |IdentifierName| String) and _promiseCapability_ (a PromiseCapability Record). It performs any necessary setup work in order to make available the module corresponding to _specifier_ occurring within the context of the script or module represented by _referencingScriptOrModule_. _referencingScriptOrModule_ is *null*. It then performs FinishDynamicImport to finish the dynamic import process.

    +

    The implementation of HostImportModuleBindingDynamically must conform with the implementation of HostImportModuleDynamically first and foremost, second, it should conform with the following:

    +
  • + The host environment must conform to one of the two following sets of requirements: +
    +
    Success path
    + +
    +
      +
    • The completion value must be the exported value for the _bindingName_ associated to the Module Namespace Object.
    • +
    +
    + +
    Failure path
    + +
    +
      +
    • At some future time, the Module Namespace Object does not contain the _bindingName_ as part of the ExportNames, with the abrupt completion representing the cause of failure.
    • +
    +
    +
    +
  • +
    From eef9071d98e34ab20612eca4652636343e000b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caridy=20Pati=C3=B1o?= Date: Fri, 26 Mar 2021 16:16:42 -0400 Subject: [PATCH 2/5] PR feedback --- spec.html | 165 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 107 insertions(+), 58 deletions(-) diff --git a/spec.html b/spec.html index 22b11f7d..11f3c7e9 100644 --- a/spec.html +++ b/spec.html @@ -80,36 +80,41 @@

    Wrapped Function Exotic Objects

    -

    [[Call]] ( _thisArgument_, _argumentsList_ )

    -

    The [[Call]] internal method of a wrapped function exotic object _F_ takes arguments _thisArgument_ (an ECMAScript language value) and _argumentsList_ (a List of ECMAScript language values). It performs the following steps when called:

    - - 1. Let _target_ be _F_.[[WrappedTargetFunction]]. - 1. Assert: IsCallable(_target_) is *true*. - 1. Let _targetRealm_ be ? GetFunctionRealm(_target_). - 1. Let _callerRealm_ be ? GetFunctionRealm(_F_). - 1. For each element _key_ of _argumentsList_, do - 1. Let o be _argumentsList_[_key_]. - 1. Set _argumentsList_[_key_] to ? GetWrappedValue(_targetRealm_, _o_). - 1. Let _wrappedThisArgument_ to ? GetWrappedValue(_targetRealm_, _thisArgument_). - 1. Let _value_ be ? Call(_target_, _wrappedThisArgument_, _argumentsList_). - 1. Return ? GetWrappedValue(_callerRealm_, _value_). - +

    [[Call]] ( _thisArgument_, _argumentsList_ )

    +

    The [[Call]] internal method of a wrapped function exotic object _F_ takes arguments _thisArgument_ (an ECMAScript language value) and _argumentsList_ (a List of ECMAScript language values). It performs the following steps when called:

    + + 1. Let _target_ be _F_.[[WrappedTargetFunction]]. + 1. Assert: IsCallable(_target_) is *true*. + 1. Let _targetRealm_ be ? GetFunctionRealm(_target_). + 1. Let _callerRealm_ be ? GetFunctionRealm(_F_). + 1. For each element _key_ of _argumentsList_, do + 1. Let o be _argumentsList_[_key_]. + 1. Set _argumentsList_[_key_] to ? GetWrappedValue(_targetRealm_, _o_). + 1. Let _wrappedThisArgument_ to ? GetWrappedValue(_targetRealm_, _thisArgument_). + 1. Let _result_ be the Completion Record of Call(_target_, _wrappedThisArgument_, _argumentsList_). + 1. If _result_ is an abrupt completion, throw a newly created TypeError object associate to the _callerRealm_. + 2. Else if _result_ is a Completion Record, set _value_ to _result_.[[Value]]. + 1. Return ? GetWrappedValue(_callerRealm_, _value_). + + + In the case of an abrupt completion, the type of error to be created should match the type of the abrupt completion record. This could be revisited when merging into the main specification. +
    -

    WrappedFunctionCreate ( _callerRealm_, _targetFunction_ )

    -

    The abstract operation WrappedFunctionCreate takes arguments _callerRealm_ and _targetFunction_. It is used to specify the creation of new wrapped function exotic objects. It performs the following steps when called:

    - - 1. Assert: _callerRealm_ is a Realm Record. - 1. Assert: IsCallable(_targetFunction_) is *true*. - 1. Let _internalSlotsList_ be the internal slots listed in , plus [[Prototype]] and [[Extensible]]. - 1. Let _obj_ be ! MakeBasicObject(_internalSlotsList_). - 1. Set _obj_.[[Prototype]] to %Function.prototype% from _callerRealm_. - 1. Set _obj_.[[Call]] as described in . - 1. Set _obj_.[[Realm]] to _callerRealm_. - 1. Set _obj_.[[WrappedTargetFunction]] to _targetFunction_. - 1. Return _obj_. - +

    WrappedFunctionCreate ( _callerRealm_, _targetFunction_ )

    +

    The abstract operation WrappedFunctionCreate takes arguments _callerRealm_ and _targetFunction_. It is used to specify the creation of new wrapped function exotic objects. It performs the following steps when called:

    + + 1. Assert: _callerRealm_ is a Realm Record. + 1. Assert: IsCallable(_targetFunction_) is *true*. + 1. Let _internalSlotsList_ be the internal slots listed in , plus [[Prototype]] and [[Extensible]]. + 1. Let _obj_ be ! MakeBasicObject(_internalSlotsList_). + 1. Set _obj_.[[Prototype]] to %Function.prototype% from _callerRealm_. + 1. Set _obj_.[[Call]] as described in . + 1. Set _obj_.[[Realm]] to _callerRealm_. + 1. Set _obj_.[[WrappedTargetFunction]] to _targetFunction_. + 1. Return _obj_. +
    @@ -118,20 +123,71 @@

    Realm Objects

    Realm Abstract Operations

    - -

    PerformRealmEvaluation ( _x_, _evalRealm_ )

    + +

    PerformRealmEval ( _sourceText_, _callerRealm_, _evalRealm_ )

    - 1. Assert: Type(_x_) is String. + 1. Assert: Type(_sourceText_) is String. + 1. Assert: _callerRealm_ is a Realm Record. 1. Assert: _evalRealm_ is a Realm Record. - 1. Let _hostDefined_ be _evalRealm_.[[HostDefined]]. - 1. Let _s_ be ParseScript(_x_, _evalRealm_, _hostDefined_). - 1. If _s_ is a List of errors, then - 1. Perform HostReportErrors(_s_). - 1. Return NormalCompletion(*undefined*). - 1. Return ? ScriptEvaluation(_s_). + 1. Perform ? HostEnsureCanCompileStrings(_callerRealm_, _evalRealm_). + 1. Let _inFunction_ be *false*. + 1. Let _inMethod_ be *false*. + 1. Let _inDerivedConstructor_ be *false*. + 1. Perform the following substeps in an implementation-defined order, possibly interleaving parsing and error detection: + 1. Let _script_ be ParseText(! StringToCodePoints(_sourceText_), |Script|). + 1. If _script_ is a List of errors, throw a *SyntaxError* exception. + 1. If _script_ Contains |ScriptBody| is *false*, return *undefined*. + 1. Let _body_ be the |ScriptBody| of _script_. + 1. If _inFunction_ is *false*, and _body_ Contains |NewTarget|, throw a *SyntaxError* exception. + 1. If _inMethod_ is *false*, and _body_ Contains |SuperProperty|, throw a *SyntaxError* exception. + 1. If _inDerivedConstructor_ is *false*, and _body_ Contains |SuperCall|, throw a *SyntaxError* exception. + 1. Let _strictEval_ be IsStrict of _script_. + 1. Let _runningContext_ be the running execution context. + 1. Let _lexEnv_ be NewDeclarativeEnvironment(_evalRealm_.[[GlobalEnv]]). + 1. Let _varEnv_ be _evalRealm_.[[GlobalEnv]]. + 1. If _strictEval_ is *true*, set _varEnv_ to _lexEnv_. + 1. If _runningContext_ is not already suspended, suspend _runningContext_. + 1. Let _evalContext_ be a new ECMAScript code execution context. + 1. Set _evalContext_'s Function to *null*. + 1. Set _evalContext_'s Realm to _evalRealm_. + 1. Set _evalContext_'s ScriptOrModule to *null*. + 1. Set _evalContext_'s VariableEnvironment to _varEnv_. + 1. Set _evalContext_'s LexicalEnvironment to _lexEnv_. + 1. Push _evalContext_ onto the execution context stack; _evalContext_ is now the running execution context. + 1. Let _result_ be EvalDeclarationInstantiation(_body_, _varEnv_, _lexEnv_, _strictEval_). + 1. If _result_.[[Type]] is ~normal~, then + 1. Set _result_ to the result of evaluating _body_. + 1. If _result_.[[Type]] is ~normal~ and _result_.[[Value]] is ~empty~, then + 1. Set _result_ to NormalCompletion(*undefined*). + 1. Suspend _evalContext_ and remove it from the execution context stack. + 1. Resume the context that is now on the top of the execution context stack as the running execution context. + 1. Return Completion(_result_).
    + +

    PerformRealmImportBinding ( _specifierString_, _exportNameString_, _callerRealm_, _evalRealm_, _evalContext_ )

    + + 1. Assert: Type(_specifierString_) is String. + 1. Assert: Type(_exportNameString_) is String. + 1. Assert: _callerRealm_ is a Realm Record. + 1. Assert: _evalRealm_ is a Realm Record. + 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). + 1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_). + 1. Let _runningContext_ be the running execution context. + 1. If _runningContext_ is not already suspended, suspend _runningContext_. + 1. Push _evalContext_ onto the execution context stack; _evalContext_ is now the running execution context. + 1. Perform ! HostImportModuleBindingDynamically(_callerRealm_, _evalRealm_, _specifierString_, _exportNameString_, _promiseCapability_). + 1. Suspend _evalContext_ and remove it from the execution context stack. + 1. Resume the context that is now on the top of the execution context stack as the running execution context. + 1. Return _promiseCapability_.[[Promise]]. + + + + The Realm's Execution Context is passed as a parameter _evalContext_. An alternative phrasing would be to create an extra execution context around the call to HostImportModuleBindingDynamically in order to execute within the appropriate Realm--the host can reference the current Realm to figure out how the import should work, similar to PerformRealmEval, which could be revisited when merging into the main specification. + +
    +

    GetWrappedValue ( _callerRealm_, _value_ )

    @@ -209,11 +265,12 @@

    Realm.prototype.evaluate ( _sourceText_ )

    1. Let _O_ be *this* value. - 1. Perform ? RequireInternalSlot(_O_, [[Realm]]). + 1. Perform ? ValidateRealmObject(_O_). 1. If Type(_sourceText_) is not String, throw a *TypeError* exception. - 1. Let _realm_ be _O_.[[Realm]]. - 1. Let _value_ be ? PerformRealmEvaluation(_sourceText_, _realm_). - 1. Return ? GetWrappedValue(_realm_, _value_). + 1. Let _callerRealm_ be the current Realm Record. + 1. Let _evalRealm_ be _O_.[[Realm]]. + 1. Let _value_ be ? PerformRealmEval(_sourceText_, _callerRealm_, _evalRealm_). + 1. Return ? GetWrappedValue(_callerRealm_, _value_). @@ -222,30 +279,22 @@

    Realm.prototype.evaluate ( _sourceText_ )

    -

    Realm.prototype.importBinding ( _specifier_, _bindingName_ )

    +

    Realm.prototype.importBinding ( _specifier_, _exportName_ )

    The following steps are performed:

    1. Let _O_ be *this* value. 1. Perform ? ValidateRealmObject(_O_). - 1. Let _referencingScriptOrModule_ be *null*. 1. Let _specifierString_ be ? ToString(_specifier_). - 1. Let __bindingNameString_ be ? ToString(_bindingName_). - 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). - 1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_). - 1. Let _callerContext_ be the running execution context. - 1. Push _O_.[[ExecutionContext]] onto the execution context stack; _O_.[[ExecutionContext]] is now the running execution context. - 1. Perform ! HostImportModuleBindingDynamically(_referencingScriptOrModule_, _specifierString_, __bindingNameString_, _promiseCapability_). - 1. Remove _O_.[[ExecutionContext]] from the execution context stack and restore _callerContext_ as the running execution context. - 1. Return _promiseCapability_.[[Promise]]. + 1. Let _exportNameString_ be ? ToString(_exportName_). + 1. Let _callerRealm_ be the current Realm Record. + 1. Let _evalRealm_ be _O_.[[Realm]]. + 1. Let _evalContext_ be _O_.[[ExecutionContext]]. + 1. Return ? PerformRealmImportBinding(_specifierString_, _exportNameString_, _callerRealm_, _evalRealm_, _evalContext_). Extensible web: This is equivalent to dynamic import without having to evaluate a script source, which might not be available (e.g.: when CSP is blocking source evaluation). - - - An extra execution context is created around the call to HostImportModuleDynamically in order to execute within the appropriate Realm--the host can reference the current Realm to figure out how the import should work. An alternative phrasing would be to pass the Realm as a parameter to HostImportModuleDynamically, which could be revisited when merging into the main specification. -
    @@ -309,8 +358,8 @@

    Runtime Semantics: HostInitializeSyntheticRealm ( _realm_ )

    -

    HostImportModuleBindingDynamically ( _referencingScriptOrModule_, _specifier_, _bindingName_, _promiseCapability_ )

    -

    The host-defined abstract operation HostImportModuleBindingDynamically takes arguments _referencingScriptOrModule_ (a Script Record or Module Record or *null*), _specifier_ (a |ModuleSpecifier| String), _bindingName_ (a |IdentifierName| String) and _promiseCapability_ (a PromiseCapability Record). It performs any necessary setup work in order to make available the module corresponding to _specifier_ occurring within the context of the script or module represented by _referencingScriptOrModule_. _referencingScriptOrModule_ is *null*. It then performs FinishDynamicImport to finish the dynamic import process.

    +

    HostImportModuleBindingDynamically (_callerRealm_, _evalRealm_, _specifier_, _exportName_, _promiseCapability_ )

    +

    The host-defined abstract operation HostImportModuleBindingDynamically takes arguments _callerRealm_ (a Realm Record), _evalRealm_ (a Realm Record), _specifier_ (a |ModuleSpecifier| String), _exportName_ (a |IdentifierName| String) and _promiseCapability_ (a PromiseCapability Record). It performs any necessary setup work in order to make available the module corresponding to _specifier_ occurring within the context of the script or module represented by _referencingScriptOrModule_. _referencingScriptOrModule_ is *null*. It then performs FinishDynamicImport to finish the dynamic import process.

    The implementation of HostImportModuleBindingDynamically must conform with the implementation of HostImportModuleDynamically first and foremost, second, it should conform with the following:

  • The host environment must conform to one of the two following sets of requirements: @@ -319,7 +368,7 @@

    HostImportModuleBindingDynamically ( _referencingScriptOrModule_, _specifier
      -
    • The completion value must be the exported value for the _bindingName_ associated to the Module Namespace Object.
    • +
    • The completion value must be the wrapped value exported value for the _exportName_ associated to the Module Namespace Object for the _callerRealm_.
    @@ -327,7 +376,7 @@

    HostImportModuleBindingDynamically ( _referencingScriptOrModule_, _specifier
      -
    • At some future time, the Module Namespace Object does not contain the _bindingName_ as part of the ExportNames, with the abrupt completion representing the cause of failure.
    • +
    • At some future time, the Module Namespace Object does not contain the _exportName_ as part of the ExportNames, with the abrupt completion representing the cause of failure for the _callerRealm_.
    From 40ce7bde89ae4968fcbc29fcea925b73ad47a1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caridy=20Pati=C3=B1o?= Date: Fri, 26 Mar 2021 17:03:40 -0400 Subject: [PATCH 3/5] completion records fixes --- spec.html | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/spec.html b/spec.html index 11f3c7e9..2ae30c5e 100644 --- a/spec.html +++ b/spec.html @@ -92,12 +92,14 @@

    [[Call]] ( _thisArgument_, _argumentsList_ )

    1. Set _argumentsList_[_key_] to ? GetWrappedValue(_targetRealm_, _o_). 1. Let _wrappedThisArgument_ to ? GetWrappedValue(_targetRealm_, _thisArgument_). 1. Let _result_ be the Completion Record of Call(_target_, _wrappedThisArgument_, _argumentsList_). - 1. If _result_ is an abrupt completion, throw a newly created TypeError object associate to the _callerRealm_. - 2. Else if _result_ is a Completion Record, set _value_ to _result_.[[Value]]. - 1. Return ? GetWrappedValue(_callerRealm_, _value_). + 1. If _result_.[[Type]] is ~normal~ or _result_.[[Type]] is ~return~, then + 1. Set _value_ to NormalCompletion(_result_.[[Value]]). + 1. Return ? GetWrappedValue(_callerRealm_, _value_). + 1. Else, + 1. Throw a newly created TypeError object associate to the _callerRealm_. - In the case of an abrupt completion, the type of error to be created should match the type of the abrupt completion record. This could be revisited when merging into the main specification. + In the case of an abrupt ~throw~ completion, the type of error to be created should match the type of the abrupt throw completion record. This could be revisited when merging into the main specification. Additionally, in the case of a ~break~ or ~continue~ completion, since those are not supported, a TypeError is expected. @@ -157,12 +159,14 @@

    PerformRealmEval ( _sourceText_, _callerRealm_, _evalRealm_ )

    1. Let _result_ be EvalDeclarationInstantiation(_body_, _varEnv_, _lexEnv_, _strictEval_). 1. If _result_.[[Type]] is ~normal~, then 1. Set _result_ to the result of evaluating _body_. - 1. If _result_.[[Type]] is ~normal~ and _result_.[[Value]] is ~empty~, then - 1. Set _result_ to NormalCompletion(*undefined*). 1. Suspend _evalContext_ and remove it from the execution context stack. 1. Resume the context that is now on the top of the execution context stack as the running execution context. - 1. Return Completion(_result_). + 1. If _result_.[[Type]] is not ~normal~, throw a newly created TypeError object associate to the _callerRealm_. + 1. Return ? GetWrappedValue(_callerRealm_, _result_.[[Value]]). + + In the case of an abrupt ~throw~ completion, the type of error to be created should match the type of the abrupt throw completion record. This could be revisited when merging into the main specification. Additionally, in the case of a ~break~ or ~continue~ completion, since those are not supported, a TypeError is expected. There should be no ~return~ completion because this is a top level script evaluation, in which case a return |Statement| must result in a parsing error. + @@ -269,8 +273,7 @@

    Realm.prototype.evaluate ( _sourceText_ )

    1. If Type(_sourceText_) is not String, throw a *TypeError* exception. 1. Let _callerRealm_ be the current Realm Record. 1. Let _evalRealm_ be _O_.[[Realm]]. - 1. Let _value_ be ? PerformRealmEval(_sourceText_, _callerRealm_, _evalRealm_). - 1. Return ? GetWrappedValue(_callerRealm_, _value_). + 1. Return ? PerformRealmEval(_sourceText_, _callerRealm_, _evalRealm_). From 1e67194b3b5cd0ce67471493e19ae17659cf7ad2 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Fri, 26 Mar 2021 14:46:26 -0700 Subject: [PATCH 4/5] Meta: Update ecmarkup --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 976839c4..33bdabaa 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ "watch": "npm run build -- --watch" }, "devDependencies": { - "ecmarkup": "^3.21.1" + "ecmarkup": "^7.0.3" } } From c90b0cab984f7ce3dd2582807e4a2b42cbd7b6e4 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Fri, 26 Mar 2021 14:46:52 -0700 Subject: [PATCH 5/5] Editorial: Small spec cleanup --- spec.html | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spec.html b/spec.html index 2ae30c5e..c33b4f94 100644 --- a/spec.html +++ b/spec.html @@ -1,5 +1,13 @@ + + + + + + + + - - -

    Well-known intrinsic objects

    @@ -39,7 +44,7 @@

    Wrapped Function Exotic Objects

    An object is a wrapped function exotic object if its [[Call]] internal method use the following implementations, and its other essential internal methods use the definitions found in . These methods are installed in WrappedFunctionCreate.

    Wrapped function exotic objects do not have the internal slots of ECMAScript function objects listed in . Instead they have the internal slots listed in , in addition to [[Prototype]] and [[Extensible]].

    - + @@ -202,7 +207,6 @@

    GetWrappedValue ( _callerRealm_, _value_ )

    1. Return _value_. - @@ -265,7 +269,7 @@

    Properties of the Realm Prototype Object

    Realm.prototype.evaluate ( _sourceText_ )

    - Synchronously execute a top-level script. The _sourceText_ is interpreted as a Script and evaluated with this bound to the realm's global object. +

    Synchronously execute a top-level script. The _sourceText_ is interpreted as a Script and evaluated with this bound to the realm's global object.

    1. Let _O_ be *this* value. @@ -359,7 +363,6 @@

    Runtime Semantics: HostInitializeSyntheticRealm ( _realm_ )

    -

    HostImportModuleBindingDynamically (_callerRealm_, _evalRealm_, _specifier_, _exportName_, _promiseCapability_ )

    The host-defined abstract operation HostImportModuleBindingDynamically takes arguments _callerRealm_ (a Realm Record), _evalRealm_ (a Realm Record), _specifier_ (a |ModuleSpecifier| String), _exportName_ (a |IdentifierName| String) and _promiseCapability_ (a PromiseCapability Record). It performs any necessary setup work in order to make available the module corresponding to _specifier_ occurring within the context of the script or module represented by _referencingScriptOrModule_. _referencingScriptOrModule_ is *null*. It then performs FinishDynamicImport to finish the dynamic import process.

    @@ -388,3 +391,5 @@

    HostImportModuleBindingDynamically (_callerRealm_, _evalRealm_, _specifier_, + +