Skip to content

Commit 22d8d0c

Browse files
Unify evaluation logic, aligning Evaluate() with Link()
1 parent 99b8150 commit 22d8d0c

1 file changed

Lines changed: 37 additions & 20 deletions

File tree

spec.emu

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ contributors: Nicolò Ribaudo
4242
1. Let _exports_ be ? GetModuleExportsList(_O_).
4343
1. If _exports_ does not contain _P_, return *undefined*.
4444
1. Let _m_ be _O_.[[Module]].
45+
1. <ins>If _m_ is a Cyclic Module Record and _m_.GetOptionalIndirectExportsModuleRequests(« _P_ ») is not empty, then</ins>
46+
1. <ins>Perform ? EvaluateModuleSync(_m_, « _P_ »).</ins>
4547
1. Let _binding_ be _m_.ResolveExport(_P_).
4648
1. Assert: _binding_ is a ResolvedBinding Record.
47-
1. <ins>For each Module Record _deferredModule_ of _binding_.[[DeferredModules]], do</ins>
48-
1. <ins>Perform ? EvaluateModuleSync(_deferredModule_).</ins>
4949
1. Let _targetModule_ be _binding_.[[Module]].
5050
1. Assert: _targetModule_ is not *undefined*.
5151
1. If _binding_.[[BindingName]] is ~namespace~, then
@@ -500,7 +500,7 @@ contributors: Nicolò Ribaudo
500500
ResolveExport(_exportName_ [, _resolveSet_])
501501
</td>
502502
<td>
503-
<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~, <ins>[[DeferredModules]]: List of Module Records</ins> }. If the export is a Module Namespace Object without a direct binding in any module, [[BindingName]] will be set to ~namespace~. <ins>[[DeferredModules]] is the list of modules imported through `export defer` that the binding resolution process needs to go through which need to be evaluated in order to have access to the resolved binding.</ins> Return *null* if the name cannot be resolved, or ~ambiguous~ if multiple bindings were found.</p>
503+
<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>
504504
<p>Each time this operation is called with a specific _exportName_, _resolveSet_ pair as arguments it must return the same result.</p>
505505
<p>LoadRequestedModules must have completed successfully prior to invoking this method.</p>
506506
</td>
@@ -517,11 +517,12 @@ contributors: Nicolò Ribaudo
517517
</tr>
518518
<tr>
519519
<td>
520-
Evaluate()
520+
Evaluate(<ins>[_importedNames_]</ins>)
521521
</td>
522522
<td>
523523
<p>Returns a promise for the evaluation of this module and its dependencies, resolving on successful evaluation or if it has already been evaluated successfully, and rejecting for an evaluation error or if it has already been evaluated unsuccessfully. If the promise is rejected, hosts are expected to handle the promise rejection and rethrow the evaluation error.</p>
524-
<p>Link must have completed successfully prior to invoking this method.</p>
524+
<p><ins>When this module is a Cyclic Module Record, _importedNames_ is the list of binding names (or ~all~) whose additional modules need to be evaluated, for usage with GetOptionalIndirectExportsModuleRequests(). By default, modules re-exported by this module through GetOptionalIndirectExportsModuleRequests() are not evaluated.</ins></p>
525+
<p>Link must have completed successfully prior to invoking this method<ins>, with an _importNames_ list that includes at least the _importedNames_ passed to Evaluate</ins>.</p>
525526
</td>
526527
</tr>
527528
</table>
@@ -531,6 +532,7 @@ contributors: Nicolò Ribaudo
531532
<h1>
532533
EvaluateModuleSync (
533534
_module_: a Module Record,
535+
<ins>optional _importedNames_: ~all~ or a List of Strings,</ins>
534536
): either a normal completion containing ~unused~ or a throw completion
535537
</h1>
536538
<dl class="header">
@@ -539,8 +541,9 @@ contributors: Nicolò Ribaudo
539541
</dl>
540542

541543
<emu-alg>
542-
1. If ReadyForSyncExecution(_module_, « ») is *false*, throw a *TypeError* exception.
543-
1. Let _promise_ be _module_.Evaluate().
544+
1. <ins>If _importedNames_ is not present, let _importedNames_ be « ».</ins>
545+
1. If ReadyForSyncExecution(_module_, <ins>_importedNames_</ins>) is *false*, throw a *TypeError* exception.
546+
1. Let _promise_ be _module_.Evaluate(<ins>_importedNames_</ins>).
544547
1. Assert: _promise_.[[PromiseState]] is either ~fulfilled~ or ~rejected~.
545548
1. If _promise_.[[PromiseState]] is ~rejected~, then
546549
1. If _promise_.[[PromiseIsHandled]] is *false*, perform HostPromiseRejectionTracker(_promise_, *"handle"*).
@@ -557,7 +560,11 @@ contributors: Nicolò Ribaudo
557560
optional _seen_: a List of Module Records,
558561
): a Boolean
559562
</h1>
560-
<dl class="header"></dl>
563+
<dl class="header">
564+
<dt>description</dt>
565+
<!-- &zwj; to prevent ecmarkup from wrapping this in a <p> -->
566+
<dd>&zwj;<ins>It tests whether a given (_module_, _importedNames_) pair can be safely evaluated through EvaluateModuleSync.</ins></dd>
567+
</dl>
561568
<emu-alg>
562569
1. If _module_ is not a Cyclic Module Record, return *true*.
563570
1. If _seen_ is not present, set _seen_ to a new empty List.
@@ -843,7 +850,7 @@ contributors: Nicolò Ribaudo
843850
<emu-clause id="sec-LoadRequestedModules" type="concrete method">
844851
<h1>
845852
LoadRequestedModules (
846-
<ins>_importedNames_: ~all~ or an empty List,</ins>
853+
<ins>optional _importedNames_: ~all~ or an empty List,</ins>
847854
optional _hostDefined_: anything,
848855
): a Promise
849856
</h1>
@@ -1061,7 +1068,11 @@ contributors: Nicolò Ribaudo
10611068
</emu-clause>
10621069

10631070
<emu-clause id="sec-moduleevaluation" type="concrete method">
1064-
<h1>Evaluate ( ): a Promise</h1>
1071+
<h1>
1072+
Evaluate (
1073+
<ins>optional _importedNames_: ~all~ or a List of Strings,</ins>
1074+
): a Promise
1075+
</h1>
10651076
<dl class="header">
10661077
<dt>for</dt>
10671078
<dd>a Cyclic Module Record _module_</dd>
@@ -1073,6 +1084,7 @@ contributors: Nicolò Ribaudo
10731084
<emu-alg>
10741085
1. Assert: None of _module_ or any of its recursive dependencies have [[Status]] set to ~evaluating~, ~linking~, ~unlinked~, or ~new~.
10751086
1. Assert: _module_.[[Status]] is one of ~linked~, ~evaluating-async~, or ~evaluated~.
1087+
1. <ins>If _importedNames_ is not present, let _importedNames_ be « ».</ins>
10761088
1. <del>If _module_.[[Status]] is either ~evaluating-async~ or ~evaluated~, set _module_ to _module_.[[CycleRoot]].</del>
10771089
1. <del>If _module_.[[TopLevelCapability]] is not ~empty~, then</del>
10781090
1. <del>Return _module_.[[TopLevelCapability]].[[Promise]].</del>
@@ -1103,6 +1115,18 @@ contributors: Nicolò Ribaudo
11031115
1. Assert: _stack_ is empty.
11041116
1. <del>Return _capability_.[[Promise]].</del>
11051117
1. <ins>Let _topLevelPromise_ be _capability_.[[Promise]].</ins>
1118+
1. <ins>If _topLevelPromise_.[[PromiseState]] is ~rejected~, return _topLevelPromise_.</ins>
1119+
1. <ins>Let _indirectRequests_ be _module_.GetOptionalIndirectExportsModuleRequests(_importedNames_ ).</ins>
1120+
1. <ins>Let _promises_ be « _topLevelPromise_ ».</ins>
1121+
1. <ins>For each ModuleRequest Record _request_ of _indirectRequests_, do</ins>
1122+
1. <ins>Let _requiredModule_ be GetImportedModule(_module_, _request_).</ins>
1123+
1. <ins>Assert: _requiredModule_.[[Status]] is one of ~linked~, ~evaluating-async~, or ~evaluated~.</ins>
1124+
1. <ins>Let _innerPromise_ be _requiredModule_.Evaluate(_request_.[[ImportedNames]]).</ins>
1125+
1. <ins>If _innerPromise_.[[PromiseState]] is ~rejected~, return _innerPromise_.</ins>
1126+
1. <ins>Append _innerPromise_ to _promises_.</ins>
1127+
1. <ins>If _promises_ contains a Promise _P_ such that _P_.[[PromiseState]] is ~pending~, then</ins>
1128+
1. <ins>NOTE: If all modules in the graph are synchronous, the usage of promises is an internal specification detail. In that case, we do not use PerformPromiseAll to keep returning an already settled promise.</ins>
1129+
1. <ins>Return ! PerformPromiseAll(CreateListIteratorRecord(_promises_), %Promise%, ! NewPromiseCapability(%Promise%), %Promise.resolve%).</ins>
11061130
1. <ins>Return _topLevelPromise_.</ins>
11071131
</emu-alg>
11081132

@@ -1561,24 +1585,19 @@ contributors: Nicolò Ribaudo
15611585
1. For each ExportEntry Record _e_ of _module_.[[LocalExportEntries]], do
15621586
1. If _e_.[[ExportName]] is _exportName_, then
15631587
1. Assert: _module_ provides the direct binding for this export.
1564-
1. Return ResolvedBinding Record { [[Module]]: _module_, [[BindingName]]: _e_.[[LocalName]], <ins>[[DeferredModules]]: « »</ins> }.
1588+
1. Return ResolvedBinding Record { [[Module]]: _module_, [[BindingName]]: _e_.[[LocalName]] }.
15651589
1. <ins>Let _allIndirectEntries_ be the list-concatenation of _module_.[[IndirectExportEntries]] and _module_.[[OptionalIndirectExportEntries]].</ins>
15661590
1. For each ExportEntry Record _e_ of <del>_module_.[[IndirectExportEntries]]</del><ins>_allIndirectEntries_</ins>, do
15671591
1. If _e_.[[ExportName]] is _exportName_, then
15681592
1. Assert: _e_.[[ModuleRequest]] is not *null*.
15691593
1. Let _importedModule_ be GetImportedModule(_module_, _e_.[[ModuleRequest]]).
15701594
1. If _e_.[[ImportName]] is ~all~, then
15711595
1. Assert: _module_ does not provide the direct binding for this export.
1572-
1. Return ResolvedBinding Record { [[Module]]: _importedModule_, [[BindingName]]: ~namespace~, <ins>[[DeferredModules]]: « »</ins> }.
1596+
1. Return ResolvedBinding Record { [[Module]]: _importedModule_, [[BindingName]]: ~namespace~ }.
15731597
1. Else,
15741598
1. Assert: _module_ imports a specific binding for this export.
15751599
1. Assert: _e_.[[ImportName]] is a String.
1576-
1. <del>Return _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_).</del>
1577-
1. <ins>Let _resolvedBinding_ be _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_).</ins>
1578-
1. <ins>If _resolvedBinding_ is a ResolvedBinding Record and _module_.[[OptionalIndirectExportEntries]] contains _e_, then</ins>
1579-
1. <ins>Let _deferredModules_ be the list-concatenation of « _importedModule_ » and _resolvedBinding_.[[DeferredModules]].</ins>
1580-
1. <ins>Return ResolvedBinding Record { [[Module]]: _resolvedBinding_.[[Module]], [[BindingName]]: _resolvedBinding_.[[BindingName]], [[DeferredModules]]: _deferredModules_ }.</ins>
1581-
1. <ins>Return _resolvedBinding_.</ins>
1600+
1. Return _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_).
15821601
1. If _exportName_ is *"default"*, then
15831602
1. Assert: A `default` export was not explicitly defined by this module.
15841603
1. Return *null*.
@@ -1598,8 +1617,6 @@ contributors: Nicolò Ribaudo
15981617
1. If _resolution_.[[Module]] and _starResolution_.[[Module]] are not the same Module Record, return ~ambiguous~.
15991618
1. If _resolution_.[[BindingName]] is not _starResolution_.[[BindingName]] and either _resolution_.[[BindingName]] or _starResolution_.[[BindingName]] is ~namespace~, return ~ambiguous~.
16001619
1. If _resolution_.[[BindingName]] is a String, _starResolution_.[[BindingName]] is a String, and _resolution_.[[BindingName]] is not _starResolution_.[[BindingName]], return ~ambiguous~.
1601-
1. <ins>Let _deferredModules_ be the list-concatenation of _starResolution_.[[DeferredModules]] and _resolution_.[[DeferredModules]].</ins>
1602-
1. <ins>Set _starResolution_ to the ResolvedBinding Record { [[Module]]: _starResolution_.[[Module]], [[BindingName]]: _starResolution_.[[BindingName]], [[DeferredModules]]: _deferredModules_ }.</ins>
16031620
1. Return _starResolution_.
16041621
</emu-alg>
16051622
</emu-clause>

0 commit comments

Comments
 (0)