Skip to content

Commit

Permalink
Require LoadRequestedModules before ResolveExport and GetExportedNames
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 20, 2022
1 parent 24f5631 commit 4b83bcc
Showing 1 changed file with 33 additions and 38 deletions.
71 changes: 33 additions & 38 deletions spec.html
Expand Up @@ -15031,12 +15031,12 @@ <h1>
1. Let _exports_ be _O_.[[Exports]].
1. If _P_ is not an element of _exports_, return *undefined*.
1. Let _m_ be _O_.[[Module]].
1. Let _binding_ be ! _m_.ResolveExport(_P_).
1. Let _binding_ be _m_.ResolveExport(_P_).
1. Assert: _binding_ is a ResolvedBinding Record.
1. Let _targetModule_ be _binding_.[[Module]].
1. Assert: _targetModule_ is not *undefined*.
1. If _binding_.[[BindingName]] is ~namespace~, then
1. Return ? GetModuleNamespace(_targetModule_).
1. Return GetModuleNamespace(_targetModule_).
1. Let _targetEnv_ be _targetModule_.[[Environment]].
1. If _targetEnv_ is ~empty~, throw a *ReferenceError* exception.
1. Return ? _targetEnv_.GetBindingValue(_binding_.[[BindingName]], *true*).
Expand Down Expand Up @@ -19515,11 +19515,8 @@ <h1>
1. Return ~unused~.
1. Let _evaluatePromise_ be _module_.Evaluate().
1. Let _fulfilledClosure_ be a new Abstract Closure with no parameters that captures _module_ and _promiseCapability_ and performs the following steps when called:
1. Let _namespace_ be Completion(GetModuleNamespace(_module_)).
1. If _namespace_ is an abrupt completion, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _namespace_.[[Value]] &raquo;).
1. Else,
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; _namespace_.[[Value]] &raquo;).
1. Let _namespace_ be GetModuleNamespace(_module_).
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; _namespace_ &raquo;).
1. Return ~unused~.
1. Let _onFulfilled_ be CreateBuiltinFunction(_fulfilledClosure_, *""*, 0, &laquo; &raquo;).
1. Perform PerformPromiseThen(_evaluatePromise_, _onFulfilled_, _onRejected_).
Expand Down Expand Up @@ -26259,27 +26256,29 @@ <h1>Abstract Module Records</h1>
</tr>
<tr>
<td>
GetExportedNames([_exportStarSet_])
LoadRequestedModules( [ _hostDefined_ ] )
</td>
<td>
Return a list of all names that are either directly or indirectly exported from this module.
<p>Prepares the module for linking by recursively loading all its dependencies, and returns a promise.</p>
</td>
</tr>
<tr>
<td>
ResolveExport(_exportName_ [, _resolveSet_])
GetExportedNames([_exportStarSet_])
</td>
<td>
<p>Return the binding of a name exported by this module. Bindings are represented by a <dfn id="resolvedbinding-record" variants="ResolvedBinding Records">ResolvedBinding Record</dfn>, of the form { [[Module]]: Module Record, [[BindingName]]: String | ~namespace~ }. If the export is a Module Namespace Object without a direct binding in any module, [[BindingName]] will be set to ~namespace~. Return *null* if the name cannot be resolved, or ~ambiguous~ if multiple bindings were found.</p>
<p>Each time this operation is called with a specific _exportName_, _resolveSet_ pair as arguments it must return the same result if it completes normally.</p>
<p>Return a list of all names that are either directly or indirectly exported from this module.</p>
<p>LoadRequestedModules must have completed successfully prior to invoking this method.</p>
</td>
</tr>
<tr>
<td>
LoadRequestedModules( [ _hostDefined_ ] )
ResolveExport(_exportName_ [, _resolveSet_])
</td>
<td>
<p>Prepares the module for linking by recursively loading all its dependencies, and returns a promise.</p>
<p>Return the binding of a name exported by this module. Bindings are represented by a <dfn id="resolvedbinding-record" variants="ResolvedBinding Records">ResolvedBinding Record</dfn>, of the form { [[Module]]: Module Record, [[BindingName]]: String | ~namespace~ }. If the export is a Module Namespace Object without a direct binding in any module, [[BindingName]] will be set to ~namespace~. Return *null* if the name cannot be resolved, or ~ambiguous~ if multiple bindings were found.</p>
<p>Each time this operation is called with a specific _exportName_, _resolveSet_ pair as arguments it must return the same result.</p>
<p>LoadRequestedModules must have completed successfully prior to invoking this method.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -26696,7 +26695,6 @@ <h1>
1. Append _module_ to _stack_.
1. For each String _required_ of _module_.[[RequestedModules]], do
1. Let _requiredModule_ be GetImportedModule(_module_, _required_).
1. Assert: _requiredModule_ is not ~empty~, because LoadRequestedModules must have completed successfully prior to invoking this method.
1. Set _index_ to ? InnerModuleLinking(_requiredModule_, _stack_, _index_).
1. If _requiredModule_ is a Cyclic Module Record, then
1. Assert: _requiredModule_.[[Status]] is either ~linking~, ~linked~, ~evaluating-async~, or ~evaluated~.
Expand Down Expand Up @@ -26790,7 +26788,6 @@ <h1>
1. Append _module_ to _stack_.
1. For each String _required_ of _module_.[[RequestedModules]], do
1. Let _requiredModule_ be GetImportedModule(_module_, _required_).
1. Assert: _requiredModule_ is not ~empty~, because LoadRequestedModules must have completed successfully prior to invoking this method.
1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_).
1. If _requiredModule_ is a Cyclic Module Record, then
1. Assert: _requiredModule_.[[Status]] is either ~evaluating~, ~evaluating-async~, or ~evaluated~.
Expand Down Expand Up @@ -27903,13 +27900,14 @@ <h1>
<h1>
GetExportedNames (
optional _exportStarSet_: a List of Source Text Module Records,
): either a normal completion containing a List of either Strings or *null*, or a throw completion
): a List of either Strings or *null*
</h1>
<dl class="header">
<dt>for</dt>
<dd>a Source Text Module Record _module_</dd>
</dl>
<emu-alg>
1. Assert: _module_.[[Status]] is not ~new~.
1. If _exportStarSet_ is not present, set _exportStarSet_ to a new empty List.
1. If _exportStarSet_ contains _module_, then
1. Assert: We've reached the starting point of an `export *` circularity.
Expand All @@ -27924,8 +27922,7 @@ <h1>
1. Append _e_.[[ExportName]] to _exportedNames_.
1. For each ExportEntry Record _e_ of _module_.[[StarExportEntries]], do
1. Let _requiredModule_ be GetImportedModule(_module_, _e_.[[ModuleRequest]]).
1. If _requiredModule_ is ~empty~, throw a *TypeError* exception.
1. Let _starNames_ be ? _requestedModule_.GetExportedNames(_exportStarSet_).
1. Let _starNames_ be _requestedModule_.GetExportedNames(_exportStarSet_).
1. For each element _n_ of _starNames_, do
1. If SameValue(_n_, *"default"*) is *false*, then
1. If _n_ is not an element of _exportedNames_, then
Expand All @@ -27942,7 +27939,7 @@ <h1>
ResolveExport (
_exportName_: a String,
optional _resolveSet_: a List of Records that have [[Module]] and [[ExportName]] fields,
): either a normal completion containing either a ResolvedBinding Record, *null*, or ~ambiguous~, or a throw completion
): a ResolvedBinding Record, *null*, or ~ambiguous~
</h1>
<dl class="header">
<dt>for</dt>
Expand All @@ -27956,6 +27953,7 @@ <h1>
</dl>

<emu-alg>
1. Assert: _module_.[[Status]] is not ~new~.
1. If _resolveSet_ is not present, set _resolveSet_ to a new empty List.
1. For each Record { [[Module]], [[ExportName]] } _r_ of _resolveSet_, do
1. If _module_ and _r_.[[Module]] are the same Module Record and SameValue(_exportName_, _r_.[[ExportName]]) is *true*, then
Expand All @@ -27969,22 +27967,20 @@ <h1>
1. For each ExportEntry Record _e_ of _module_.[[IndirectExportEntries]], do
1. If SameValue(_exportName_, _e_.[[ExportName]]) is *true*, then
1. Let _importedModule_ be GetImportedModule(_module_, _e_.[[ModuleRequest]]).
1. If _importedModule_ is ~empty~, throw a *TypeError* exception.
1. If _e_.[[ImportName]] is ~all~, then
1. Assert: _module_ does not provide the direct binding for this export.
1. Return ResolvedBinding Record { [[Module]]: _importedModule_, [[BindingName]]: ~namespace~ }.
1. Else,
1. Assert: _module_ imports a specific binding for this export.
1. Return ? _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_).
1. Return _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_).
1. If SameValue(_exportName_, *"default"*) is *true*, then
1. Assert: A `default` export was not explicitly defined by this module.
1. Return *null*.
1. NOTE: A `default` export cannot be provided by an `export * from "mod"` declaration.
1. Let _starResolution_ be *null*.
1. For each ExportEntry Record _e_ of _module_.[[StarExportEntries]], do
1. Let _importedModule_ be GetImportedModule(_module_, _e_.[[ModuleRequest]]).
1. If _importedModule_ is ~empty~, throw a *TypeError* exception.
1. Let _resolution_ be ? _importedModule_.ResolveExport(_exportName_, _resolveSet_).
1. Let _resolution_ be _importedModule_.ResolveExport(_exportName_, _resolveSet_).
1. If _resolution_ is ~ambiguous~, return ~ambiguous~.
1. If _resolution_ is not *null*, then
1. Assert: _resolution_ is a ResolvedBinding Record.
Expand All @@ -28007,7 +28003,7 @@ <h1>InitializeEnvironment ( ): either a normal completion containing ~unused~ or

<emu-alg>
1. For each ExportEntry Record _e_ of _module_.[[IndirectExportEntries]], do
1. Let _resolution_ be ? _module_.ResolveExport(_e_.[[ExportName]]).
1. Let _resolution_ be _module_.ResolveExport(_e_.[[ExportName]]).
1. If _resolution_ is *null* or ~ambiguous~, throw a *SyntaxError* exception.
1. Assert: _resolution_ is a ResolvedBinding Record.
1. Assert: All named exports from _module_ are resolvable.
Expand All @@ -28017,16 +28013,15 @@ <h1>InitializeEnvironment ( ): either a normal completion containing ~unused~ or
1. Set _module_.[[Environment]] to _env_.
1. For each ImportEntry Record _in_ of _module_.[[ImportEntries]], do
1. Let _importedModule_ be GetImportedModule(_module_, _in_.[[ModuleRequest]]).
1. Assert: _importedModule_ is not ~empty~, because imported module requests are a subset of _module_.[[RequestedModules]], and these have been resolved earlier in this algorithm.
1. If _in_.[[ImportName]] is ~namespace-object~, then
1. Let _namespace_ be ? GetModuleNamespace(_importedModule_).
1. Let _namespace_ be GetModuleNamespace(_importedModule_).
1. Perform ! _env_.CreateImmutableBinding(_in_.[[LocalName]], *true*).
1. Perform ! _env_.InitializeBinding(_in_.[[LocalName]], _namespace_).
1. Else,
1. Let _resolution_ be ? _importedModule_.ResolveExport(_in_.[[ImportName]]).
1. Let _resolution_ be _importedModule_.ResolveExport(_in_.[[ImportName]]).
1. If _resolution_ is *null* or ~ambiguous~, throw a *SyntaxError* exception.
1. If _resolution_.[[BindingName]] is ~namespace~, then
1. Let _namespace_ be ? GetModuleNamespace(_resolution_.[[Module]]).
1. Let _namespace_ be GetModuleNamespace(_resolution_.[[Module]]).
1. Perform ! _env_.CreateImmutableBinding(_in_.[[LocalName]], *true*).
1. Perform ! _env_.InitializeBinding(_in_.[[LocalName]], _namespace_).
1. Else,
Expand Down Expand Up @@ -28107,17 +28102,17 @@ <h1>
GetImportedModule (
_referrer_: a Cyclic Module Record,
_specifier_: a String,
): a Module Record or ~empty~
): a Module Record
</h1>
<dl class="header">
<dt>description</dt>
<dd></dd>
</dl>

<emu-alg>
1. If _referrer_.[[LoadedModules]] contains a Record _record_ whose [[Specifier]] is _specifier_, then
1. Return _record_.[[Module]].
1. Return ~empty~.
1. Let _record_ be the sole element of _referrer_.[[LoadedModules]] whose [[Specifier]] is _specifier_.
1. Assert: _record_ exists, because LoadRequestedModules has completed successfully on _referrer_ prior to invoking this abstract operation.
1. Return _record_.[[Module]].
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -28189,27 +28184,27 @@ <h1>
<h1>
GetModuleNamespace (
_module_: an instance of a concrete subclass of Module Record,
): either a normal completion containing either a Module Namespace Object or ~empty~, or a throw completion
): a Module Namespace Object or ~empty~
</h1>
<dl class="header">
<dt>description</dt>
<dd>It retrieves the Module Namespace Object representing _module_'s exports, lazily creating it the first time it was requested, and storing it in _module_.[[Namespace]] for future retrieval.</dd>
</dl>

<emu-alg>
1. Assert: If _module_ is a Cyclic Module Record, then _module_.[[Status]] is not ~unlinked~.
1. Assert: If _module_ is a Cyclic Module Record, then _module_.[[Status]] is not ~new~ or ~unlinked~.
1. Let _namespace_ be _module_.[[Namespace]].
1. If _namespace_ is ~empty~, then
1. Let _exportedNames_ be ? _module_.GetExportedNames().
1. Let _exportedNames_ be _module_.GetExportedNames().
1. Let _unambiguousNames_ be a new empty List.
1. For each element _name_ of _exportedNames_, do
1. Let _resolution_ be ? _module_.ResolveExport(_name_).
1. Let _resolution_ be _module_.ResolveExport(_name_).
1. If _resolution_ is a ResolvedBinding Record, append _name_ to _unambiguousNames_.
1. Set _namespace_ to ModuleNamespaceCreate(_module_, _unambiguousNames_).
1. Return _namespace_.
</emu-alg>
<emu-note>
<p>If _module_ is a Cyclic Module Record, the only way GetModuleNamespace can throw is if one of its recursive dependencies has not been loaded. Unresolvable names are simply excluded from the namespace at this point. They will lead to a real linking error later unless they are all ambiguous star exports that are not explicitly requested anywhere.</p>
<p>GetModuleNamespace never throws. Instead, unresolvable names are simply excluded from the namespace at this point. They will lead to a real linking error later unless they are all ambiguous star exports that are not explicitly requested anywhere.</p>
</emu-note>
</emu-clause>

Expand Down

0 comments on commit 4b83bcc

Please sign in to comment.