Skip to content

Commit 2e37bc6

Browse files
authored
feat: adding support for filtered namespace on import calls (#40)
1 parent 5e8e90b commit 2e37bc6

1 file changed

Lines changed: 40 additions & 8 deletions

File tree

spec.emu

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ contributors: Nicolò Ribaudo
197197
1. Let _specifierString_ be Completion(ToString(_specifier_)).
198198
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
199199
1. Let _attributes_ be a new empty List.
200+
1. <ins>Let _importedNames_ be ~all~.</ins>
200201
1. If _options_ is not *undefined*, then
201202
1. If _options_ is not an Object, then
202203
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
@@ -221,7 +222,31 @@ contributors: Nicolò Ribaudo
221222
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
222223
1. Return _promiseCapability_.[[Promise]].
223224
1. Sort _attributes_ according to the lexicographic order of their [[Key]] field, treating the value of each such field as a sequence of UTF-16 code unit values. NOTE: This sorting is observable only in that hosts are prohibited from changing behaviour based on the order in which attributes are enumerated.
224-
1. Let _moduleRequest_ be a new ModuleRequest Record { [[Specifier]]: _specifierString_, [[Attributes]]: _attributes_, [[Phase]]: _phase_, <ins>[[ImportedNames]]: ~all~</ins> }.
225+
1. <ins>Let _exports_ be Completion(Get(_options_, *"exports"*)).</ins>
226+
1. <ins>IfAbruptRejectPromise(_exports_, _promiseCapability_).</ins>
227+
1. <ins>If _exports_ is not *undefined*, then</ins>
228+
1. <ins>If _exports_ is not an Object, then</ins>
229+
1. <ins>Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; a newly created *TypeError* object &raquo;).</ins>
230+
1. <ins>Return _promiseCapability_.[[Promise]].</ins>
231+
1. <ins>Let _iteratorRecord_ be Completion(GetIterator(_exports_, ~sync~)).</ins>
232+
1. <ins>IfAbruptRejectPromise(_iteratorRecord_, _promiseCapability_).</ins>
233+
1. <ins>Let _names_ be a new empty List.</ins>
234+
1. <ins>Let _done_ be *false*.</ins>
235+
1. <ins>Repeat, while _done_ is *false*,</ins>
236+
1. <ins>Let _next_ be Completion(IteratorStepValue(_iteratorRecord_)).</ins>
237+
1. <ins>IfAbruptRejectPromise(_next_, _promiseCapability_).</ins>
238+
1. <ins>If _next_ is ~done~, then</ins>
239+
1. <ins>Set _done_ to *true*.</ins>
240+
1. <ins>Else if _next_ is not a String, then</ins>
241+
1. <ins>Let _error_ be ThrowCompletion(a newly created *TypeError* object).</ins>
242+
1. <ins>Let _closeResult_ be Completion(IteratorClose(_iteratorRecord_, _error_)).</ins>
243+
1. <ins>Assert: _closeResult_ and _error_ are the same Completion Record.</ins>
244+
1. <ins>Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _error_.[[Value]] »).</ins>
245+
1. <ins>Return _promiseCapability_.[[Promise]].</ins>
246+
1. <ins>Else if _names_ does not contain _next_, then</ins>
247+
1. <ins>Append _next_ to _names_.</ins>
248+
1. <ins>Set _importedNames_ to _names_.</ins>
249+
1. Let _moduleRequest_ be a new ModuleRequest Record { [[Specifier]]: _specifierString_, [[Attributes]]: _attributes_, [[Phase]]: _phase_, <ins>[[ImportedNames]]: _importedNames_</ins> }.
225250
1. Perform HostLoadImportedModule(_referrer_, _moduleRequest_, ~empty~, _promiseCapability_).
226251
1. Return _promiseCapability_.[[Promise]].
227252
</emu-alg>
@@ -232,6 +257,7 @@ contributors: Nicolò Ribaudo
232257
_promiseCapability_: a PromiseCapability Record,
233258
_moduleCompletion_: either a normal completion containing a Module Record or a throw completion,
234259
_phase_: ~defer~ or ~evaluation~,
260+
<ins>_importedNames_: ~all~ or a List of Strings,</ins>
235261
): ~unused~
236262
</h1>
237263
<dl class="header">
@@ -243,18 +269,24 @@ contributors: Nicolò Ribaudo
243269
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _moduleCompletion_.[[Value]] &raquo;).
244270
1. Return ~unused~.
245271
1. Let _module_ be _moduleCompletion_.[[Value]].
246-
1. Let _loadPromise_ be _module_.LoadRequestedModules(<ins>~all~</ins>).
272+
1. Let _loadPromise_ be _module_.LoadRequestedModules(<ins>_importedNames_</ins>).
247273
1. Let _rejectedClosure_ be a new Abstract Closure with parameters (_reason_) that captures _promiseCapability_ and performs the following steps when called:
248274
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _reason_ &raquo;).
249275
1. Return ~unused~.
250276
1. Let _onRejected_ be CreateBuiltinFunction(_rejectedClosure_, 1, *""*, &laquo; &raquo;).
251-
1. Let _linkAndEvaluateClosure_ be a new Abstract Closure with no parameters that captures _module_, _promiseCapability_, _phase_ and _onRejected_ and performs the following steps when called:
252-
1. Let _link_ be Completion(_module_.Link(<ins>~all~</ins>)).
277+
1. Let _linkAndEvaluateClosure_ be a new Abstract Closure with no parameters that captures _module_, _promiseCapability_, _phase_<ins>, _importedNames_</ins> and _onRejected_ and performs the following steps when called:
278+
1. Let _link_ be Completion(_module_.Link(<ins>_importedNames_</ins>)).
253279
1. If _link_ is an abrupt completion, then
254280
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _link_.[[Value]] &raquo;).
255281
1. Return ~unused~.
256-
1. Let _fulfilledClosure_ be a new Abstract Closure with no parameters that captures _module_, _phase_, and _promiseCapability_ and performs the following steps when called:
257-
1. Let _namespace_ be GetModuleNamespace(_module_, _phase_, <ins>~all~</ins>).
282+
1. <ins>If _importedNames_ is a List of Strings, then</ins>
283+
1. <ins>For each String _name_ of _importedNames_, do</ins>
284+
1. <ins>Let _resolvable_ be Completion(EnsureResolvableBinding(_module_, _name_, ~disallow-ambiguous~)).</ins>
285+
1. <ins>If _resolvable_ is an abrupt completion, then</ins>
286+
1. <ins>Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *ReferenceError* object »).</ins>
287+
1. <ins>Return ~unused~.</ins>
288+
1. Let _fulfilledClosure_ be a new Abstract Closure with no parameters that captures _module_, _phase_, <ins>_importedNames_,</ins> and _promiseCapability_ and performs the following steps when called:
289+
1. Let _namespace_ be GetModuleNamespace(_module_, _phase_, <ins>_importedNames_</ins>).
258290
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; _namespace_ &raquo;).
259291
1. Return ~unused~.
260292
1. <del>If _phase_ is ~defer~, then </del>
@@ -270,7 +302,7 @@ contributors: Nicolò Ribaudo
270302
1. <del>Let _evaluatePromise_ be _module_.Evaluate().</del>
271303
1. <ins>If _phase_ is ~defer~, let _evaluationList_ be GatherAsynchronousTransitiveDependencies(_module_).</ins>
272304
1. <ins>Else, let _evaluationList_ be « _module_ ».</ins>
273-
1. <ins>Let _optionalIndirectRequests_ be _module_.GetOptionalIndirectExportsModuleRequests(~all~).</ins>
305+
1. <ins>Let _optionalIndirectRequests_ be _module_.GetOptionalIndirectExportsModuleRequests(_importedNames_).</ins>
274306
1. <ins>Perform ListAppendUnique(_evaluationList_, GatherAsynchronousTransitiveDependenciesForRequests(_module_, _optionalIndirectRequests_, « »)).</ins>
275307
1. <ins>If _evaluationList_ is empty, then</ins>
276308
1. <ins>Assert: _phase_ is ~defer~.</ins>
@@ -2600,7 +2632,7 @@ contributors: Nicolò Ribaudo
26002632
1. If _payload_ is a GraphLoadingState Record, then
26012633
1. Perform ContinueModuleLoading(_payload_, _result_, <ins>_moduleRequest_.[[ImportedNames]]</ins>).
26022634
1. Else,
2603-
1. Perform ContinueDynamicImport(_payload_, _result_, _moduleRequest_.[[Phase]]).
2635+
1. Perform ContinueDynamicImport(_payload_, _result_, _moduleRequest_.[[Phase]], <ins>_moduleRequest_.[[ImportedNames]]</ins>).
26042636
1. Return ~unused~.
26052637
</emu-alg>
26062638
</emu-clause>

0 commit comments

Comments
 (0)