Skip to content

Commit f074b63

Browse files
Normative: Add JSON modules
1 parent 59c29bb commit f074b63

File tree

1 file changed

+192
-0
lines changed

1 file changed

+192
-0
lines changed

spec.html

+192
Original file line numberDiff line numberDiff line change
@@ -28621,6 +28621,191 @@ <h1>
2862128621
</emu-clause>
2862228622
</emu-clause>
2862328623

28624+
<emu-clause id="sec-synthetic-module-records">
28625+
<h1>Synthetic Module Records</h1>
28626+
28627+
<p>A <dfn variants="Synthetic Module Records">Synthetic Module Record</dfn> is used to represent information about a module that is defined by specifications. Its exported names are statically defined at creation, while their corresponding values can change over time using SetSyntheticModuleExport. It has no imports or dependencies.</p>
28628+
28629+
<emu-note>A Synthetic Module Record could be used for defining a variety of module types: for example, JSON modules or CSS modules.</emu-note>
28630+
28631+
<p>In addition to the fields defined in <emu-xref href="#table-module-record-fields"></emu-xref> Synthetic Module Records have the additional fields listed in <emu-xref href="#table-synthetic-module-record-fields"></emu-xref>.</p>
28632+
28633+
<emu-table id="table-synthetic-module-record-fields" caption="Additional Fields of Synthetic Module Records">
28634+
<table>
28635+
<thead>
28636+
<tr>
28637+
<th>Field Name</th>
28638+
<th>Value Type</th>
28639+
<th>Meaning</th>
28640+
</tr>
28641+
</thead>
28642+
<tr>
28643+
<td>[[ExportNames]]</td>
28644+
<td>a List of Strings</td>
28645+
<td>The names of the exports of the module. This list does not contain duplicates.</td>
28646+
</tr>
28647+
<tr>
28648+
<td>[[EvaluationSteps]]</td>
28649+
<td>an Abstract Closure</td>
28650+
<td>The initialization logic to perform upon evaluation of the module, taking the Synthetic Module Record as its sole argument. It must not modify [[ExportNames]]. It may return an abrupt completion.</td>
28651+
</tr>
28652+
</table>
28653+
</emu-table>
28654+
28655+
<emu-clause id="sec-create-default-export-synthetic-module" type="abstract operation">
28656+
<h1>
28657+
CreateDefaultExportSyntheticModule (
28658+
_defaultExport_: an ECMAScript language value,
28659+
): a Synthetic Module Record
28660+
</h1>
28661+
<dl class="header">
28662+
<dt>description</dt>
28663+
<dd>It creates a Synthetic Module Record whose default export is _defaultExport_.</dd>
28664+
</dl>
28665+
<emu-alg>
28666+
1. Let _realm_ be the current Realm Record.
28667+
1. Let _setDefaultExport_ be a new Abstract Closure with parameters (_module_) that captures _defaultExport_ and performs the following steps when called:
28668+
1. Perform SetSyntheticModuleExport(_module_, *"default"*, _defaultExport_).
28669+
1. Return the Synthetic Module Record { [[Realm]]: _realm_, [[Environment]]: ~empty~, [[Namespace]]: ~empty~, [[HostDefined]]: *undefined*, [[ExportNames]]: « *"default"* », [[EvaluationSteps]]: _setDefaultExport_ }.
28670+
</emu-alg>
28671+
</emu-clause>
28672+
28673+
<emu-clause id="sec-parse-json-module" type="abstract operation">
28674+
<h1>
28675+
ParseJSONModule (
28676+
_source_: a String,
28677+
): either a normal completion containing a Synthetic Module Record, or a throw completion
28678+
</h1>
28679+
<dl class="header">
28680+
<dt>description</dt>
28681+
<dd></dd>
28682+
</dl>
28683+
28684+
<emu-alg>
28685+
1. Let _json_ be ? Call(%JSON.parse%, *undefined*, « _source_ »).
28686+
1. Return CreateDefaultExportSyntheticModule(_json_).
28687+
</emu-alg>
28688+
</emu-clause>
28689+
28690+
<emu-clause id="sec-setsyntheticmoduleexport" type="abstract operation">
28691+
<h1>
28692+
SetSyntheticModuleExport (
28693+
_module_: a Synthetic Module Record,
28694+
_exportName_: a String,
28695+
_exportValue_: an ECMAScript language value,
28696+
): ~unused~
28697+
</h1>
28698+
<dl class="header">
28699+
<dt>description</dt>
28700+
<dd>It can be used to set or change the exported value for an existing export of a Synthetic Module Record.</dd>
28701+
</dl>
28702+
28703+
<emu-alg>
28704+
1. Assert: _module_.[[ExportNames]] contains _exportName_.
28705+
1. Let _envRec_ be _module_.[[Environment]].
28706+
1. Assert: _envRec_ is not ~empty~.
28707+
1. Perform _envRec_.SetMutableBinding(_exportName_, _exportValue_, *true*).
28708+
1. Return ~unused~.
28709+
</emu-alg>
28710+
</emu-clause>
28711+
28712+
<emu-clause id="sec-smr-module-record-methods">
28713+
<h1>Implementation of Module Record Abstract Methods</h1>
28714+
28715+
<p>The following are the concrete methods for Synthetic Module Record that implement the corresponding Module Record abstract methods defined in <emu-xref href="#table-abstract-methods-of-module-records"></emu-xref>.</p>
28716+
28717+
<emu-clause id="sec-smr-LoadRequestedModules" type="concrete method">
28718+
<h1>LoadRequestedModules ( ): a Promise</h1>
28719+
<dl class="header">
28720+
<dt>for</dt>
28721+
<dd>a Synthetic Module Record _module_</dd>
28722+
</dl>
28723+
28724+
<emu-alg>
28725+
1. Return ! PromiseResolve(%Promise%, *undefined*).
28726+
</emu-alg>
28727+
28728+
<emu-note>
28729+
Synthetic Module Records have no dependencies.
28730+
</emu-note>
28731+
</emu-clause>
28732+
28733+
<emu-clause id="sec-smr-getexportednames" type="concrete method">
28734+
<h1>GetExportedNames ( ): a List of Strings</h1>
28735+
<dl class="header">
28736+
<dt>for</dt>
28737+
<dd>a Synthetic Module Record _module_</dd>
28738+
</dl>
28739+
28740+
<emu-alg>
28741+
1. Return _module_.[[ExportNames]].
28742+
</emu-alg>
28743+
</emu-clause>
28744+
28745+
<emu-clause id="sec-smr-resolveexport" type="concrete method">
28746+
<h1>
28747+
ResolveExport (
28748+
_exportName_: a String,
28749+
): a ResolvedBinding Record or *null*
28750+
</h1>
28751+
<dl class="header">
28752+
<dt>for</dt>
28753+
<dd>a Synthetic Module Record _module_</dd>
28754+
</dl>
28755+
28756+
<emu-alg>
28757+
1. If _module_.[[ExportNames]] does not contain _exportName_, return *null*.
28758+
1. Return ResolvedBinding Record { [[Module]]: _module_, [[BindingName]]: _exportName_ }.
28759+
</emu-alg>
28760+
</emu-clause>
28761+
28762+
<emu-clause id="sec-smr-Link" type="concrete method">
28763+
<h1>Link ( ): ~unused~</h1>
28764+
<dl class="header">
28765+
<dt>for</dt>
28766+
<dd>a Synthetic Module Record _module_</dd>
28767+
</dl>
28768+
28769+
<emu-alg>
28770+
1. Let _realm_ be _module_.[[Realm]].
28771+
1. Let _env_ be NewModuleEnvironment(_realm_.[[GlobalEnv]]).
28772+
1. Set _module_.[[Environment]] to _env_.
28773+
1. For each String _exportName_ of _module_.[[ExportNames]], do
28774+
1. Perform ! _env_.CreateMutableBinding(_exportName_, *false*).
28775+
1. Perform ! _env_.InitializeBinding(_exportName_, *undefined*).
28776+
1. Return ~unused~.
28777+
</emu-alg>
28778+
</emu-clause>
28779+
28780+
<emu-clause id="sec-smr-Evaluate" type="concrete method">
28781+
<h1>Evaluate ( ): a Promise</h1>
28782+
<dl class="header">
28783+
<dt>for</dt>
28784+
<dd>a Synthetic Module Record _module_</dd>
28785+
</dl>
28786+
28787+
<emu-alg>
28788+
1. Let _moduleContext_ be a new ECMAScript code execution context.
28789+
1. Set the Function of _moduleContext_ to *null*.
28790+
1. Set the Realm of _moduleContext_ to _module_.[[Realm]].
28791+
1. Set the ScriptOrModule of _moduleContext_ to _module_.
28792+
1. Set the VariableEnvironment of _moduleContext_ to _module_.[[Environment]].
28793+
1. Set the LexicalEnvironment of _moduleContext_ to _module_.[[Environment]].
28794+
1. Suspend the running execution context.
28795+
1. Push _moduleContext_ onto the execution context stack; _moduleContext_ is now the running execution context.
28796+
1. Let _steps_ be _module_.[[EvaluationSteps]].
28797+
1. Let _result_ be Completion(_steps_(_module_)).
28798+
1. Suspend _moduleContext_ and remove it from the execution context stack.
28799+
1. Resume the context that is now on the top of the execution context stack as the running execution context.
28800+
1. Let _pc_ be ! NewPromiseCapability(%Promise%).
28801+
1. IfAbruptRejectPromise(_result_, _pc_).
28802+
1. Perform ! Call(_pc_.[[Resolve]], *undefined*, « *undefined* »).
28803+
1. Return _pc_.[[Promise]].
28804+
</emu-alg>
28805+
</emu-clause>
28806+
</emu-clause>
28807+
</emu-clause>
28808+
2862428809
<emu-clause id="sec-GetImportedModule" type="abstract operation">
2862528810
<h1>
2862628811
GetImportedModule (
@@ -28676,12 +28861,19 @@ <h1>
2867628861
</ul>
2867728862
<p>and it performs FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_) where _result_ is a normal completion, then it must perform FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_) with the same _result_ each time.</p>
2867828863
</li>
28864+
<li>
28865+
<p>If _moduleRequest_.[[Attributes]] has an entry _entry_ such that _entry_.[[Key]] is *"type"* and _entry_.[[Value]] is *"json"*, when the host environment performs FinishLoadingImportedModule(_referrer_, _moduleRequest_, _payload_, _result_), _result_ must either be the Completion Record returned by an invocation of ParseJSONModule or a throw completion.</p>
28866+
</li>
2867928867
<li>
2868028868
The operation must treat _payload_ as an opaque value to be passed through to FinishLoadingImportedModule.
2868128869
</li>
2868228870
</ul>
2868328871

2868428872
<p>The actual process performed is host-defined, but typically consists of performing whatever I/O operations are necessary to load the appropriate Module Record. Multiple different (_referrer_, _moduleRequest_.[[Specifier]], _moduleRequest_.[[Attributes]]) triples may map to the same Module Record instance. The actual mapping semantics is host-defined but typically a normalization process is applied to _specifier_ as part of the mapping process. A typical normalization process would include actions such as expansion of relative and abbreviated path specifiers.</p>
28873+
28874+
<emu-note>
28875+
<p>The above text requires that hosts support JSON modules when imported with `type: "json"` (and HostLoadImportedModule completes normally), but it does not prohibit hosts from supporting JSON modules when imported without `type: "json"`.</p>
28876+
</emu-note>
2868528877
</emu-clause>
2868628878

2868728879
<emu-clause id="sec-FinishLoadingImportedModule" type="abstract operation" oldids="sec-finishdynamicimport">

0 commit comments

Comments
 (0)