Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normative: Define module root level context #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 97 additions & 1 deletion spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ <h1>Agents</h1>
<ins>a List of Async Context Mapping Records</ins>
</td>
<td>
<ins>A map from the AsyncContext.Variable instances to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]]. The map is initially empty.</ins>
<ins>A map from the AsyncContext.Variable instances to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]]. The map is initially the return value of HostGetTopLevelAsyncContextMapping(*null*).</ins>
</td>
</tr>
</table>
Expand Down Expand Up @@ -255,6 +255,59 @@ <h1>
</emu-clause>
</emu-clause>

<emu-clause id="sec-ecmascript-language-scripts-and-modules">
<h1>ECMAScript Language: Scripts and Modules</h1>

<emu-clause id="sec-modules">
<h1>Modules</h1>

<emu-clause id="sec-module-semantics">
<h1>Module Semantics</h1>

<emu-clause id="sec-source-text-module-records">
<h1>Source Text Module Records</h1>
<emu-clause id="sec-source-text-module-record-execute-module" type="concrete method">
<h1>
ExecuteModule (
optional _capability_: a PromiseCapability Record,
): either a normal completion containing ~unused~ or a throw completion
</h1>
<dl class="header">
<dt>for</dt>
<dd>a Source Text Module Record _module_</dd>
</dl>

<emu-alg>
1. Let _moduleContext_ be a new ECMAScript code execution context.
1. Set the Function of _moduleContext_ to *null*.
1. Set the Realm of _moduleContext_ to _module_.[[Realm]].
1. Set the ScriptOrModule of _moduleContext_ to _module_.
1. Assert: _module_ has been linked and declarations in its module environment have been instantiated.
1. Set the VariableEnvironment of _moduleContext_ to _module_.[[Environment]].
1. Set the LexicalEnvironment of _moduleContext_ to _module_.[[Environment]].
1. Suspend the running execution context.
1. <ins>Let _previousContextMapping_ be AsyncContextSwap(HostGetTopLevelAsyncContextMapping(_module_)).</ins>
1. If _module_.[[HasTLA]] is *false*, then
1. Assert: _capability_ is not present.
1. Push _moduleContext_ onto the execution context stack; _moduleContext_ is now the running execution context.
1. Let _result_ be Completion(Evaluation of _module_.[[ECMAScriptCode]]).
1. <ins>AsyncContextSwap(_previousContextMapping_).</ins>
1. Suspend _moduleContext_ 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. If _result_ is an abrupt completion, then
1. Return ? _result_.
1. Else,
1. Assert: _capability_ is a PromiseCapability Record.
1. Perform AsyncBlockStart(_capability_, _module_.[[ECMAScriptCode]], _moduleContext_).
1. <ins>AsyncContextSwap(_previousContextMapping_).</ins>
1. Return ~unused~.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>

<emu-clause id="sec-control-abstraction-objects">
<h1>Control Abstraction Objects</h1>

Expand Down Expand Up @@ -936,6 +989,25 @@ <h1>The AsyncContext Object</h1>

<emu-clause id="sec-asynccontext-abstract-operations">
<h1>AsyncContext Abstract Operations</h1>

<emu-clause id="sec-hostgettoplevelasynccontextmapping" type="abstract operation">
<h1>
HostGetTopLevelAsyncContextMapping (
_module_: a Module Record or *null*
): a List of Async Context Mapping Records</h1>
<dl class="header">
<dt>description</dt>
<dd>It allows hosts to provide the top level async context mapping for a given module record.</dd>
</dl>
<p>The default implementation of HostGetTopLevelAsyncContextMapping performs the following steps when called:</p>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-note>
<p>ECMAScript hosts may add host defined async context mapping entries to the list.</p>
</emu-note>
</emu-clause>

<emu-clause id="sec-asynccontextsnapshot" type="abstract operation">
<h1>
AsyncContextSnapshot (
Expand Down Expand Up @@ -1358,3 +1430,27 @@ <h1>FinalizationRegistry ( _cleanupCallback_ )</h1>
</emu-clause>
</emu-clause>
</emu-clause>

<emu-annex id="sec-host-layering-points">
<h1>Host Layering Points</h1>

<emu-annex id="sec-host-hooks-summary">
<h1>Host Hooks</h1>
<p><b>HostCallJobCallback(...)</b></p>
<p><b>HostEnqueueFinalizationRegistryCleanupJob(...)</b></p>
<p><b>HostEnqueueGenericJob(...)</b></p>
<p><b>HostEnqueuePromiseJob(...)</b></p>
<p><b>HostEnqueueTimeoutJob(...)</b></p>
<p><b>HostEnsureCanCompileStrings(...)</b></p>
<p><b>HostFinalizeImportMeta(...)</b></p>
<p><b>HostGetImportMetaProperties(...)</b></p>
<p><b><ins>HostGetTopLevelAsyncContextMapping(...)</ins></b></p>
<p><b>HostGrowSharedArrayBuffer(...)</b></p>
<p><b>HostHasSourceTextAvailable(...)</b></p>
<p><b>HostLoadImportedModule(...)</b></p>
<p><b>HostMakeJobCallback(...)</b></p>
<p><b>HostPromiseRejectionTracker(...)</b></p>
<p><b>HostResizeArrayBuffer(...)</b></p>
<p><b>InitializeHostDefinedRealm(...)</b></p>
</emu-annex>
</emu-annex>