generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathspec.emu
2002 lines (1848 loc) · 107 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<meta charset="utf8">
<link rel="stylesheet" href="./spec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="./spec.js"></script>
<pre class="metadata">
title: Deferred Imports Evaluation
stage: 2
contributors: Nicolò Ribaudo
</pre>
<emu-note type="editor">The diff markers in this proposal are on top of <a href="https://github.com/tc39/ecma262/pull/3057">tc39/ecma262#3057</a> (Import Attributes).</emu-note>
<emu-clause id="sec-ordinary-and-exotic-objects-behaviours" number="10">
<h1>Ordinary and Exotic Objects Behaviours</h1>
<emu-clause id="sec-built-in-exotic-object-internal-methods-and-slots" number="4">
<h1>Built-in Exotic Object Internal Methods and Slots</h1>
<p>This specification defines several kinds of built-in exotic objects. These objects generally behave similar to ordinary objects except for a few specific situations. The following exotic objects use the ordinary object internal methods except where it is explicitly specified otherwise below:</p>
<!-- NOTE!!!!: the oldids here is new, don't forget it in the ecma262 PR -->
<emu-clause id="sec-module-namespace-exotic-objects" oldids="sec-module-namespace-objects" number="6">
<h1>Module Namespace Exotic Objects</h1>
<p>A module namespace exotic object is an exotic object that exposes the bindings exported from an ECMAScript |Module| (See <emu-xref href="#sec-exports"></emu-xref>). There is a one-to-one correspondence between the String-keyed own properties of a module namespace exotic object and the binding names exported by the |Module|. The exported bindings include any bindings that are indirectly exported using `export *` export items. Each String-valued own property key is the StringValue of the corresponding exported binding name. These are the only String-keyed properties of a module namespace exotic object. Each such property has the attributes { [[Writable]]: *true*, [[Enumerable]]: *true*, [[Configurable]]: *false* }. Module namespace exotic objects are not extensible.</p>
<p>An object is a <dfn id="module-namespace-exotic-object" variants="module namespace exotic objects">module namespace exotic object</dfn> if its [[GetPrototypeOf]], [[SetPrototypeOf]], [[IsExtensible]], [[PreventExtensions]], [[GetOwnProperty]], [[DefineOwnProperty]], [[HasProperty]], [[Get]], [[Set]], [[Delete]], and [[OwnPropertyKeys]] internal methods use the definitions in this section, and its other essential internal methods use the definitions found in <emu-xref href="#sec-ordinary-object-internal-methods-and-internal-slots"></emu-xref>. These methods are installed by ModuleNamespaceCreate.</p>
<p>Module namespace exotic objects have the internal slots defined in <emu-xref href="#table-internal-slots-of-module-namespace-exotic-objects"></emu-xref>.</p>
<emu-table id="table-internal-slots-of-module-namespace-exotic-objects" caption="Internal Slots of Module Namespace Exotic Objects" oldids="table-29">
<table>
<tr>
<th>
Internal Slot
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
<tr>
<td>
[[Module]]
</td>
<td>
a Module Record
</td>
<td>
The Module Record whose exports this namespace exposes.
</td>
</tr>
<tr>
<td>
[[Exports]]
</td>
<td>
a List of Strings
</td>
<td>
A List whose elements are the String values of the exported names exposed as own properties of this object. The list is ordered as if an Array of those String values had been sorted using %Array.prototype.sort% using *undefined* as _comparefn_.
</td>
</tr>
<tr>
<td>
<ins>[[Deferred]]</ins>
</td>
<td>
<ins>a Boolean</ins>
</td>
<td>
<ins>Whether this module namespace was obtained through `import defer`/`import.defer()`. Deferred namespaces can have side effects when accessing properties on them.</ins>
</td>
</tr>
</table>
</emu-table>
<emu-clause id="sec-module-namespace-exotic-objects-getownproperty-p" type="internal method" number="5">
<h1>
[[GetOwnProperty]] (
_P_: a property key,
): either a normal completion containing either a Property Descriptor or *undefined*, or a throw completion
</h1>
<dl class="header">
<dt>for</dt>
<dd>a module namespace exotic object _O_</dd>
</dl>
<emu-alg>
1. If <del>_P_ is a Symbol</del><ins>IsSymbolLikeNamespaceKey(_P_, _O_)</ins> is *true*, return OrdinaryGetOwnProperty(_O_, _P_).
1. Let _exports_ be <del>_O_.[[Exports]]</del><ins>? GetModuleExportsList(_O_)</ins>.
1. If _exports_ does not contain _P_, return *undefined*.
1. Let _value_ be ? _O_.[[Get]](_P_, _O_).
1. Return PropertyDescriptor { [[Value]]: _value_, [[Writable]]: *true*, [[Enumerable]]: *true*, [[Configurable]]: *false* }.
</emu-alg>
</emu-clause>
<emu-clause id="sec-module-namespace-exotic-objects-defineownproperty-p-desc" type="internal method">
<h1>
[[DefineOwnProperty]] (
_P_: a property key,
_Desc_: a Property Descriptor,
): either a normal completion containing a Boolean or a throw completion
</h1>
<dl class="header">
<dt>for</dt>
<dd>a module namespace exotic object _O_</dd>
</dl>
<emu-alg>
1. If <del>_P_ is a Symbol</del><ins>IsSymbolLikeNamespaceKey(_P_, _O_)</ins>, return ! OrdinaryDefineOwnProperty(_O_, _P_, _Desc_).
1. Let _current_ be ? _O_.[[GetOwnProperty]](_P_).
1. <ins>NOTE: If _O_.[[Deferred]] is *true*, the step above will ensure that the module is evaluated.</ins>
1. If _current_ is *undefined*, return *false*.
1. If _Desc_ has a [[Configurable]] field and _Desc_.[[Configurable]] is *true*, return *false*.
1. If _Desc_ has an [[Enumerable]] field and _Desc_.[[Enumerable]] is *false*, return *false*.
1. If IsAccessorDescriptor(_Desc_) is *true*, return *false*.
1. If _Desc_ has a [[Writable]] field and _Desc_.[[Writable]] is *false*, return *false*.
1. If _Desc_ has a [[Value]] field, return SameValue(_Desc_.[[Value]], _current_.[[Value]]).
1. Return *true*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-module-namespace-exotic-objects-hasproperty-p" type="internal method">
<h1>
[[HasProperty]] (
_P_: a property key,
): a normal completion containing a Boolean
</h1>
<dl class="header">
<dt>for</dt>
<dd>a module namespace exotic object _O_</dd>
</dl>
<emu-alg>
1. If <del>_P_ is a Symbol</del><ins>IsSymbolLikeNamespaceKey(_P_, _O_)</ins>, return ! OrdinaryHasProperty(_O_, _P_).
1. Let _exports_ be <del>_O_.[[Exports]]</del><ins>? GetModuleExportsList(_O_)</ins>.
1. If _exports_ contains _P_, return *true*.
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-module-namespace-exotic-objects-get-p-receiver" type="internal method">
<h1>
[[Get]] (
_P_: a property key,
_Receiver_: an ECMAScript language value,
): either a normal completion containing an ECMAScript language value or a throw completion
</h1>
<dl class="header">
<dt>for</dt>
<dd>a module namespace exotic object _O_</dd>
</dl>
<emu-alg>
1. If <del>_P_ is a Symbol</del><ins>IsSymbolLikeNamespaceKey(_P_, _O_)</ins>, return ! OrdinaryGet(_O_, _P_, _Receiver_).
1. Let _exports_ be <del>_O_.[[Exports]]</del><ins>? GetModuleExportsList(_O_)</ins>.
1. If _exports_ does not contain _P_, return *undefined*.
1. Let _m_ be _O_.[[Module]].
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_, <ins>~evaluation~</ins>).
1. <ins>NOTE: The phase here is always ~evaluation~ because in `import defer * as x from "..."; export { x }`, _binding_.[[BindingName]] is *"x"* and not ~namespace~.</ins>
1. Let _targetEnv_ be _targetModule_.[[Environment]].
1. If _targetEnv_ is ~empty~, throw a *ReferenceError* exception.
1. Return ? _targetEnv_.GetBindingValue(_binding_.[[BindingName]], *true*).
</emu-alg>
<emu-note>
<p>ResolveExport is side-effect free. Each time this operation is called with a specific _exportName_, _resolveSet_ pair as arguments it must return the same result. An implementation might choose to pre-compute or cache the ResolveExport results for the [[Exports]] of each module namespace exotic object.</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-module-namespace-exotic-objects-set-p-v-receiver" type="internal method">
<h1>
[[Set]] (
_P_: a property key,
_V_: an ECMAScript language value,
_Receiver_: an ECMAScript language value,
): a normal completion containing *false*
</h1>
<dl class="header">
<dt>for</dt>
<dd>a module namespace exotic object</dd>
</dl>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-module-namespace-exotic-objects-delete-p" type="internal method">
<h1>
[[Delete]] (
_P_: a property key,
): a normal completion containing a Boolean
</h1>
<dl class="header">
<dt>for</dt>
<dd>a module namespace exotic object _O_</dd>
</dl>
<emu-alg>
1. If <del>_P_ is a Symbol</del><ins>IsSymbolLikeNamespaceKey(_P_, _O_)</ins>, return ! OrdinaryDelete(_O_, _P_).
1. Let _exports_ be <del>_O_.[[Exports]]</del><ins>? GetModuleExportsList(_O_)</ins>.
1. If _exports_ contains _P_, return *false*.
1. Return *true*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-module-namespace-exotic-objects-ownpropertykeys" type="internal method">
<h1>[[OwnPropertyKeys]] ( ): a normal completion containing a List of property keys</h1>
<dl class="header">
<dt>for</dt>
<dd>a module namespace exotic object _O_</dd>
</dl>
<emu-alg>
1. Let _exports_ be <del>_O_.[[Exports]]</del><ins>? GetModuleExportsList(_O_)</ins>.
1. <ins>If _O_.[[Deferred]] is *true*, and _exports_ contains *"then"*, then</ins>
1. <ins>Set _exports_ to a copy of _exports_.</ins>
1. <ins>Remove *"then"* from _exports_.</ins>
1. Let _symbolKeys_ be OrdinaryOwnPropertyKeys(_O_).
1. Return the list-concatenation of _exports_ and _symbolKeys_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-modulenamespacecreate" type="abstract operation">
<h1>
ModuleNamespaceCreate (
_module_: a Module Record,
_exports_: a List of Strings,
<ins>_phase_: ~defer~ or ~evaluation~,</ins>
): a module namespace exotic object
</h1>
<dl class="header">
<dt>description</dt>
<dd>It is used to specify the creation of new module namespace exotic objects.</dd>
</dl>
<emu-alg>
1. <del>Assert: _module_.[[Namespace]] is ~empty~.</del>
1. Let _internalSlotsList_ be the internal slots listed in <emu-xref href="#table-internal-slots-of-module-namespace-exotic-objects"></emu-xref>.
1. Let _M_ be MakeBasicObject(_internalSlotsList_).
1. Set _M_'s essential internal methods to the definitions specified in <emu-xref href="#sec-module-namespace-exotic-objects"></emu-xref>.
1. Set _M_.[[Module]] to _module_.
1. [declared="comparefn"] Let _sortedExports_ be a List whose elements are the elements of _exports_ ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using *undefined* as _comparefn_.
1. Set _M_.[[Exports]] to _sortedExports_.
1. <del>Create own properties of _M_ corresponding to the definitions in <emu-xref href="#sec-module-namespace-objects"></emu-xref>.</del>
1. <ins>If _phase_ is ~defer~, then</ins>
1. <ins>Assert: _module_.[[DeferredNamespace]] is ~empty~.</ins>
1. <ins>Set _module_.[[DeferredNamespace]] to _M_.</ins>
1. <ins>Set _M_.[[Deferred]] to *true*.</ins>
1. <ins>Let _toStringTag_ be *"Deferred Module"*.</ins>
1. <ins>Else,</ins>
1. <ins>Assert: _module_.[[Namespace]] is ~empty~.</ins>
1. Set _module_.[[Namespace]] to _M_.
1. <ins>Set _M_.[[Deferred]] to *false*.</ins>
1. <ins>Let _toStringTag_ be *"Module"*.</ins>
1. <ins>Create an own data property of _M_ named %Symbol.toStringTag% whose [[Value]] is _toStringTag_ and whose [[Writable]], [[Enumerable]], and [[Configurable]] attributes are *false*.</ins>
1. Return _M_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-IsSymbolLikeNamespaceKey" type="abstract operation">
<h1>
<ins>
IsSymbolLikeNamespaceKey (
_P_: a property key,
_ns_: a module namespace exotic object,
): a Boolean
</ins>
</h1>
<dl class="header">
<dt>description</dt>
<dd>It determines if a property of _ns_ with key _P_ would be an ordinary property, rather than being mapped to one of the module exports.</dd>
</dl>
<emu-alg>
1. If _P_ is a Symbol, return *true*.
1. If _ns_.[[Deferred]] is *true* and _P_ is *"then"*, return *true*.
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-GetModuleExportsList" type="abstract operation">
<h1>
<ins>
GetModuleExportsList (
_O_: a module namespace exotic object,
): either a normal completion containing a List of Strings, or a throw completion
</ins>
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns a List whose elements are the names of the module's exports, triggering module evaluation if needed.</dd>
</dl>
<emu-alg>
1. If _O_.[[Deferred]] is *true*, then
1. Let _m_ be _O_.[[Module]].
1. If _m_ is a Cyclic Module Record, _m_.[[Status]] is not ~evaluated~, and ReadyForSyncExecution(_m_) is *false*, throw a *TypeError* exception.
1. Perform ? EvaluateSync(_m_).
1. Return _O_.[[Exports]].
</emu-alg>
<emu-clause id="sec-ReadyForSyncExecution" type="abstract operation">
<h1>
<ins>
ReadyForSyncExecution (
_module_: a Cyclic Module Record,
optional _seen_: a List of Module Records,
): a Boolean
</ins>
</h1>
<dl class="header"></dl>
<emu-alg>
1. If _seen_ is not present, set _seen_ to a new empty List.
1. If _seen_ contains _module_, return *true*.
1. Append _module_ to _seen_.
1. If _module_.[[Status]] is ~evaluated~, return *true*.
1. If _module_.[[Status]] is ~evaluating~ or ~evaluating-async~, return *false*.
1. Assert: _module_.[[Status]] is ~linked~.
1. If _module_.[[HasTLA]] is *true*, return *false*.
1. For each ModuleRequest Record _request_ of _module_.[[RequestedModules]], do
1. Let _requiredModule_ be GetImportedModule(_module_, _request_).
1. If ReadyForSyncExecution(_requiredModule_, _seen_) is *false*, then
1. Return *false*.
1. Return *true*.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-ecmascript-language-expressions" number="13">
<h1>ECMAScript Language: Expressions</h1>
<emu-clause id="sec-left-hand-side-expressions" number="3">
<h1>Left-Hand-Side Expressions</h1>
<h2>Syntax</h2>
<emu-grammar type="definition">
ImportCall[Yield, Await] :
<del>`import` `(` AssignmentExpression[+In, ?Yield, ?Await] `,`? `)`</del>
<del>`import` `(` AssignmentExpression[+In, ?Yield, ?Await] `,` AssignmentExpression[+In, ?Yield, ?Await] `,`? `)`</del>
<ins>`import` ImportCallArguments[?Yield, ?Await]</ins>
<ins>`import` `.` `defer` ImportCallArguments[?Yield, ?Await]</ins>
<ins>
ImportCallArguments[Yield, Await] :
`(` AssignmentExpression[+In, ?Yield, ?Await] `,`? `)`
`(` AssignmentExpression[+In, ?Yield, ?Await] `,` AssignmentExpression[+In, ?Yield, ?Await] `,`? `)`
</ins>
</emu-grammar>
<emu-clause id="sec-import-calls" number="10">
<h1>Import Calls</h1>
<emu-note type="editor">
The changes to this section are intended to mirror the changes proposed by the
<a href="https://tc39.es/proposal-source-phase-imports/#sec-import-calls">Source
Phase Imports</a> proposal, but adapted to the ~defer~ phase.
</emu-note>
<emu-clause id="sec-import-call-runtime-semantics-evaluation" type="sdo">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar><del>ImportCall : `import` `(` AssignmentExpression `,`? `)`</del></emu-grammar>
<emu-alg>
1. <del>Return ? EvaluateImportCall(|AssignmentExpression|).</del>
</emu-alg>
<emu-grammar><del>ImportCall : `import` `(` AssignmentExpression `,` AssignmentExpression `,`? `)`</del></emu-grammar>
<emu-alg>
1. <del>Return ? EvaluateImportCall(the first |AssignmentExpression|, the second |AssignmentExpression|).</del>
</emu-alg>
<emu-grammar>ImportCall : `import` ImportCallArguments</emu-grammar>
<emu-alg>
1. <ins>Return ? EvaluateImportCall(|ImportCallArguments|, ~evaluation~).</ins>
</emu-alg>
<emu-grammar>ImportCall : `import` `.` `defer` ImportCallArguments</emu-grammar>
<emu-alg>
1. <ins>Return ? EvaluateImportCall(|ImportCallArguments|, ~defer~).</ins>
</emu-alg>
</emu-clause>
<emu-clause id="sec-import-call-runtime-semantics-EvaluateImportCallSpecifier" type="sdo">
<h1><ins>Runtime Semantics: EvaluateImportCallSpecifier</ins></h1>
<emu-grammar>ImportCallArguments : `(` AssignmentExpression `,`? `)`</emu-grammar>
<emu-alg>
1. Let _ref_ be ? Evaluation of |AssignmentExpression|.
1. Return ? GetValue(_ref_).
</emu-alg>
<emu-grammar>ImportCallArguments : `(` AssignmentExpression `,` AssignmentExpression `,`? `)`</emu-grammar>
<emu-alg>
1. Let _ref_ be ? Evaluation of the first |AssignmentExpression|.
1. Return ? GetValue(_ref_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-import-call-runtime-semantics-EvaluateImportCallOptions" type="sdo">
<h1><ins>Runtime Semantics: EvaluateImportCallOptions</ins></h1>
<emu-grammar>ImportCallArguments : `(` AssignmentExpression `,`? `)`</emu-grammar>
<emu-alg>
1. Return *undefined*.
</emu-alg>
<emu-grammar>ImportCallArguments : `(` AssignmentExpression `,` AssignmentExpression `,`? `)`</emu-grammar>
<emu-alg>
1. Let _ref_ be ? Evaluation of the second |AssignmentExpression|.
1. Return ? GetValue(_ref_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-evaluate-import-call" type="abstract operation">
<h1>
EvaluateImportCall (
<ins>_arguments_: a Parse Node,</ins>
<ins>_phase_: ~defer~ or ~evaluation~,</ins>
<del>_specifierExpression_: a Parse Node,</del>
<del>optional _optionsExpression_: a Parse Node,</del>
): either a normal completion containing a Promise or an abrupt completion
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _referrer_ be GetActiveScriptOrModule().
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record.
1. <del>Let _specifierRef_ be ? Evaluation of _specifierExpression_.</del>
1. Let _specifier_ be ? <del>GetValue(_specifierRef_)</del><ins>EvaluateImportCallSpecifier of _arguments_</ins>.
1. <del>If _optionsExpression_ is present, then</del>
1. <del>Let _optionsRef_ be ? Evaluation of _optionsExpression_.</del>
1. <del>Let _options_ be ? GetValue(_optionsRef_).</del>
1. <del>Else,</del>
1. <del>Let _options_ be *undefined*.</del>
1. <ins>Let _options_ be ? EvaluateImportCallOptions of _arguments_.</ins>
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. Let _specifierString_ be Completion(ToString(_specifier_)).
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
1. Let _attributes_ be a new empty List.
1. If _options_ is not *undefined*, then
1. If _options_ is not an Object, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
1. Let _attributesObj_ be Completion(Get(_options_, *"with"*)).
1. IfAbruptRejectPromise(_attributesObj_, _promiseCapability_).
1. If _attributesObj_ is not *undefined*, then
1. If _attributesObj_ is not an Object, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
1. Let _entries_ be Completion(EnumerableOwnProperties(_attributesObj_, ~key+value~)).
1. IfAbruptRejectPromise(_entries_, _promiseCapability_).
1. For each element _entry_ of _entries_, do
1. Let _key_ be ! Get(_entry_, *"0"*).
1. Let _value_ be ! Get(_entry_, *"1"*).
1. If _key_ is a String, then
1. If _value_ is not a String, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
1. Append the ImportAttribute Record { [[Key]]: _key_, [[Value]]: _value_ } to _attributes_.
1. If AllImportAttributesSupported(_attributes_) is *false*, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
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.
1. Let _moduleRequest_ be a new ModuleRequest Record { [[Specifier]]: _specifierString_, [[Attributes]]: _attributes_ }.
1. <ins>Let _payload_ be a new DynamicImportState Record { [[PromiseCapability]]: _promiseCapability_, [[Phase]]: _phase_ }.</ins>
1. Perform HostLoadImportedModule(_referrer_, _moduleRequest_, ~empty~, <del>_promiseCapability_</del><ins>_payload_</ins>).
1. Return _promiseCapability_.[[Promise]].
</emu-alg>
<p><ins>A <dfn id="dynamicimportstate-record" variants="DynamicImportState Records">DynamicImportState Record</dfn> is a Record that contains information about a dynamic import call. It's used to continue loading after a call to HostLoadImportedModule. Each DynamicImportState Record has the fields defined in <emu-xref href="#table-dynamicimportstate-record-fields"></emu-xref>:</ins></p>
<emu-table id="table-dynamicimportstate-record-fields" caption="DynamicImportState Record Fields">
<table>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
<ins>[[PromiseCapability]]</ins>
</td>
<td>
<ins>a PromiseCapability Record</ins>
</td>
<td>
<ins>The promise to resolve when the loading process finishes.</ins>
</td>
</tr>
<tr>
<td>
<ins>[[Phase]]</ins>
</td>
<td>
<ins>~defer~ or ~evaluation~</ins>
</td>
<td>
<ins>The target import phase</ins>
</td>
</tr>
</table>
</emu-table>
<emu-clause id="sec-ContinueDynamicImport" type="abstract operation">
<h1>
ContinueDynamicImport (
<del>_promiseCapability_: a PromiseCapability Record,</del>
<ins>_payload_: a DynamicImportState Record,</ins>
_moduleCompletion_: either a normal completion containing a Module Record or a throw completion,
): ~unused~
</h1>
<dl class="header">
<dt>description</dt>
<dd>It completes the process of a dynamic import originally started by an <emu-xref href="#sec-import-calls">`import()`</emu-xref> call, resolving or rejecting the promise returned by that call as appropriate.</dd>
</dl>
<emu-alg>
1. <ins>Let _promiseCapability_ be _payload_.[[PromiseCapability]].</ins>
1. <ins>Let _phase_ be _payload_.[[Phase]].</ins>
1. If _moduleCompletion_ is an abrupt completion, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _moduleCompletion_.[[Value]] »).
1. Return ~UNUSED~.
1. Let _module_ be _moduleCompletion_.[[Value]].
1. Let _loadPromise_ be _module_.LoadRequestedModules().
1. Let _rejectedClosure_ be a new Abstract Closure with parameters (_reason_) that captures _promiseCapability_ and performs the following steps when called:
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _reason_ »).
1. Return ~UNUSED~.
1. Let _onRejected_ be CreateBuiltinFunction(_rejectedClosure_, 1, *""*, « »).
1. Let _linkAndEvaluateClosure_ be a new Abstract Closure with no parameters that captures _module_, _promiseCapability_, <ins>_phase_</ins> and _onRejected_ and performs the following steps when called:
1. Let _link_ be Completion(_module_.Link()).
1. If _link_ is an abrupt completion, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _link_.[[Value]] »).
1. Return ~UNUSED~.
1. <del>Let _evaluatePromise_ be _module_.Evaluate().</del>
1. Let _fulfilledClosure_ be a new Abstract Closure with no parameters that captures _module_, <ins>_phase_,</ins> and _promiseCapability_ and performs the following steps when called:
1. Let _namespace_ be GetModuleNamespace(_module_, <ins>_phase_</ins>).
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _namespace_ »).
1. Return ~UNUSED~.
1. <ins>If _phase_ is ~defer~, then</ins>
1. <ins>Let _evaluationList_ be GatherAsynchronousTransitiveDependencies(_module_).</ins>
1. <ins>If _evaluationList_ is empty, then</ins>
1. <ins>Perform _fulfilledClosure_().</ins>
1. <ins>Return ~UNUSED~.</ins>
1. <ins>Let _asyncDepsEvaluationPromises_ be a new empty List.</ins>
1. <ins>For each Module Record _dep_ of _evaluationList_, append _dep_.Evaluate() to _asyncDepsEvaluationPromises_.</ins>
1. <ins>Let _iterator_ be CreateListIteratorRecord(_asyncDepsEvaluationPromises_).</ins>
1. <ins>Let _pc_ be ! NewPromiseCapability(%Promise%).</ins>
1. <ins>Let _evaluatePromise_ be ! PerformPromiseAll(_iterator_, %Promise%, _pc_, %Promise.resolve%).</ins>
1. <ins>Else,</ins>
1. <ins>Assert: _phase_ is ~evaluation~.</ins>
1. <ins>Let _evaluatePromise_ be _module_.Evaluate().</ins>
1. Let _onFulfilled_ be CreateBuiltinFunction(_fulfilledClosure_, *""*, 0, « »).
1. Perform PerformPromiseThen(_evaluatePromise_, _onFulfilled_, _onRejected_).
1. Return ~UNUSED~.
1. Let _linkAndEvaluate_ be CreateBuiltinFunction(_linkAndEvaluateClosure_, *""*, 0, « »).
1. Perform PerformPromiseThen(_loadPromise_, _linkAndEvaluate_, _onRejected_).
1. Return ~UNUSED~.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-ecmascript-language-scripts-and-modules" number="16">
<h1>ECMAScript Language: Scripts and Modules</h1>
<emu-clause id="sec-modules" number="2">
<h1>Modules</h1>
<h2>Syntax</h2>
<emu-grammar type="definition">
Module :
ModuleBody?
ModuleBody :
ModuleItemList
ModuleItemList :
ModuleItem
ModuleItemList ModuleItem
ModuleItem :
ImportDeclaration
ExportDeclaration
StatementListItem[~Yield, +Await, ~Return]
ModuleExportName :
IdentifierName
StringLiteral
</emu-grammar>
<emu-clause id="sec-module-semantics">
<h1>Module Semantics</h1>
<emu-clause id="sec-modulerequest-record">
<h1><ins>ModuleRequest Records</ins></h1>
<p>A <dfn id="modulerequest-record" variants="ModuleRequest Records">ModuleRequest Record</dfn> represents the request to import a module with given import attributes <ins>and import phase</ins>. It consists of the following fields:</p>
<emu-table id="table-modulerequest-fields" caption="ModuleRequest Record Fields">
<table>
<tbody>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
[[Specifier]]
</td>
<td>
a String
</td>
<td>
The module specifier
</td>
</tr>
<tr>
<td>
[[Attributes]]
</td>
<td>
a List of ImportAttribute Records
</td>
<td>
The import attributes
</td>
</tr>
<tr>
<td>
<ins>[[Phase]]</ins>
</td>
<td>
<ins>~defer~ or ~evaluation~</ins>
</td>
<td>
<ins>The target import phase</ins>
</td>
</tr>
</tbody>
</table>
</emu-table>
<emu-clause id="sec-ModuleRequestsEqual" type="abstract operation">
<h1>
ModuleRequestsEqual (
_left_: a ModuleRequest Record or a LoadedModuleRequest Record,
_right_: a ModuleRequest Record or a LoadedModuleRequest Record,
): a Boolean
</h1>
<dl class="header">
<dt>description</dt>
<dd>‍<ins>It checks whether the two ModuleRequest Records have the same specifier and attributes.</ins></dd>
</dl>
<emu-alg>
1. If _left_.[[Specifier]] is not _right_.[[Specifier]], return *false*.
1. Let _leftAttrs_ be _left_.[[Attributes]].
1. Let _rightAttrs_ be _right_.[[Attributes]].
1. Let _leftAttrsCount_ be the number of elements in _leftAttrs_.
1. Let _rightAttrsCount_ be the number of elements in _rightAttrs_.
1. If _leftAttrsCount_ ≠ _rightAttrsCount_, return *false*.
1. For each ImportAttribute Record _l_ of _leftAttrs_, do
1. If _rightAttrs_ does not contain an ImportAttribute Record _r_ such that _l_.[[Key]] is _r_.[[Key]] and _l_.[[Value]] is _r_.[[Value]], return *false*.
1. Return *true*.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-static-semantics-modulerequests" type="sdo" number="3">
<h1>Static Semantics: ModuleRequests ( ): a List of ModuleRequest Records</h1>
<dl class="header">
</dl>
<emu-grammar>Module : [empty]</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>ModuleItemList : ModuleItem</emu-grammar>
<emu-alg>
1. Return ModuleRequests of |ModuleItem|.
</emu-alg>
<emu-grammar>ModuleItemList : ModuleItemList ModuleItem</emu-grammar>
<emu-alg>
1. Let _requests_ be the ModuleRequests of |ModuleItemList|.
1. Let _additionalRequests_ be the ModuleRequests of |ModuleItem|.
1. For each ModuleRequest Record _mr_ of _additionalRequests_, do
1. If _requests_ does not contain a ModuleRequest Record _mr2_ such that ModuleRequestsEqual(_mr_, _mr2_) is *true* <ins>and _mr_.[[Phase]] is _mr2_.[[Phase]]</ins>, then
1. Append _mr_ to _requests_.
1. Return _requests_.
</emu-alg>
<emu-grammar>ModuleItem : StatementListItem</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>
ImportDeclaration : `import` ImportClause FromClause `;`
</emu-grammar>
<emu-alg>
1. Let _specifier_ be the SV of |FromClause|.
1. Return a List whose sole element is the ModuleRequest Record { [[Specifier]]: _specifier_, [[Attributes]]: « », <ins>[[Phase]]: ~evaluation~</ins> }.
</emu-alg>
<emu-grammar>ImportDeclaration : `import` ImportClause FromClause WithClause `;`</emu-grammar>
<emu-alg>
1. Let _specifier_ be the SV of |FromClause|.
1. Let _attributes_ be WithClauseToAttributes of |WithClause|.
1. Return a List whose sole element is the ModuleRequest Record { [[Specifier]]: _specifier_, [[Attributes]]: _attributes_, <ins>[[Phase]]: ~evaluation~</ins> }.
</emu-alg>
<emu-grammar>
<ins>ImportDeclaration : `import` `defer` NameSpaceImport FromClause `;`</ins>
</emu-grammar>
<emu-alg>
1. <ins>Let _specifier_ be SV of |FromClause|.</ins>
1. <ins>Return a List whose sole element is the ModuleRequest Record { [[Specifier]]: _specifier_, [[Attributes]]: « », [[Phase]]: ~defer~ }.</ins>
</emu-alg>
<emu-grammar>
<ins>ImportDeclaration : `import` `defer` NameSpaceImport FromClause WithClause `;`</ins>
</emu-grammar>
<emu-alg>
1. <ins>Let _specifier_ be SV of |FromClause|.</ins>
1. <ins>Let _attributes_ be WithClauseToAttributes of |WithClause|.</ins>
1. <ins>Return a List whose sole element is the ModuleRequest Record { [[Specifier]]: _specifier_, [[Attributes]]: _attributes_, [[Phase]]: ~defer~ }.</ins>
</emu-alg>
<emu-grammar><del>ModuleSpecifier : StringLiteral</del></emu-grammar>
<emu-alg>
1. <del>Return a List whose sole element is the SV of |StringLiteral|.</del>
</emu-alg>
<emu-grammar>
ExportDeclaration : `export` ExportFromClause FromClause `;`
</emu-grammar>
<emu-alg>
1. Let _specifier_ be SV of |FromClause|.
1. Return a List whose sole element is the ModuleRequest Record { [[Specifier]]: _specifier_, [[Attributes]]: « », <ins>[[Phase]]: ~evaluation~</ins> }.
</emu-alg>
<emu-grammar>
ExportDeclaration : `export` ExportFromClause FromClause WithClause `;`
</emu-grammar>
<emu-alg>
1. Let _specifier_ be the SV of |FromClause|.
1. Let _attributes_ be WithClauseToAttributes of |WithClause|.
1. Return a List whose sole element is the ModuleRequest Record { [[Specifier]]: _specifier_, [[Attributes]]: _attributes_, <ins>[[Phase]]: ~evaluation~</ins> }.
</emu-alg>
<emu-grammar>
ExportDeclaration :
`export` NamedExports `;`
`export` VariableStatement
`export` Declaration
`export` `default` HoistableDeclaration
`export` `default` ClassDeclaration
`export` `default` AssignmentExpression `;`
</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
</emu-clause>
<emu-clause id="sec-abstract-module-records">
<h1>Abstract Module Records</h1>
<p>A <dfn variants="Module Records">Module Record</dfn> encapsulates structural information about the imports and exports of a single module. This information is used to link the imports and exports of sets of connected modules. A Module Record includes four fields that are only used when evaluating a module.</p>
<p>For specification purposes Module Record values are values of the Record specification type and can be thought of as existing in a simple object-oriented hierarchy where Module Record is an abstract class with both abstract and concrete subclasses. This specification defines the abstract subclass named Cyclic Module Record and its concrete subclass named Source Text Module Record. Other specifications and implementations may define additional Module Record subclasses corresponding to alternative module definition facilities that they defined.</p>
<p>Module Record defines the fields listed in <emu-xref href="#table-module-record-fields"></emu-xref>. All Module Definition subclasses include at least those fields. Module Record also defines the abstract method list in <emu-xref href="#table-abstract-methods-of-module-records"></emu-xref>. All Module definition subclasses must provide concrete implementations of these abstract methods.</p>
<emu-table id="table-module-record-fields" caption="Module Record Fields" oldids="table-36">
<table>
<thead>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
</thead>
<tr>
<td>
[[Realm]]
</td>
<td>
a Realm Record
</td>
<td>
The Realm within which this module was created.
</td>
</tr>
<tr>
<td>
[[Environment]]
</td>
<td>
a Module Environment Record or ~empty~
</td>
<td>
The Environment Record containing the top level bindings for this module. This field is set when the module is linked.
</td>
</tr>
<tr>
<td>
[[Namespace]]
</td>
<td>
an Object or ~empty~
</td>
<td>
The Module Namespace Object (<emu-xref href="#sec-module-namespace-exotic-objects"></emu-xref>) whose [[Deferred]] slot is *false*, if one has been created for this module.
</td>
</tr>
<tr>
<td>
<ins>[[DeferredNamespace]]</ins>
</td>
<td>
<ins>an Object or ~empty~</ins>
</td>
<td>
<ins>The Module Namespace Object (<emu-xref href="#sec-module-namespace-exotic-objects"></emu-xref>) whose [[Deferred]] slot is *true*, if one has been requested for this module.</ins>
</td>
</tr>
<tr>
<td>
[[HostDefined]]
</td>
<td>
anything (default value is *undefined*)
</td>
<td>
Field reserved for use by host environments that need to associate additional information with a module.
</td>
</tr>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-cyclic-module-records" number="5">
<h1>Cyclic Module Records</h1>
<p>A <dfn id="cyclic-module-record" variants="Cyclic Module Records">Cyclic Module Record</dfn> is used to represent information about a module that can participate in dependency cycles with other modules that are subclasses of the Cyclic Module Record type. Module Records that are not subclasses of the Cyclic Module Record type must not participate in dependency cycles with Source Text Module Records.</p>
<emu-clause id="sec-LoadRequestedModules" type="concrete method">
<h1>
LoadRequestedModules (
optional _hostDefined_: anything,
): a Promise
</h1>
<dl class="header">
<dt>for</dt>
<dd>a Cyclic Module Record _module_</dd>
</dl>
<emu-clause id="sec-InnerModuleLoading" type="abstract operation">
<h1>
InnerModuleLoading (
_state_: a GraphLoadingState Record,
_module_: a Module Record,
): ~unused~
</h1>
<dl class="header">
</dl>
<emu-note>
<ins>There is no special handling for ModuleRequests whose [[Phase]] is ~defer~: any error from loading or parsing the corresponding modules will make InnerModuleLoading fail.</ins>
</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-moduledeclarationlinking" type="concrete method" oldids="sec-moduledeclarationinstantiation">
<h1>Link ( ): either a normal completion containing ~unused~ or a throw completion</h1>
<dl class="header">
<dt>for</dt>
<dd>a Cyclic Module Record _module_</dd>
</dl>
<emu-clause id="sec-InnerModuleLinking" type="abstract operation" oldids="sec-innermoduleinstantiation">
<h1>
InnerModuleLinking (
_module_: a Module Record,
_stack_: a List of Cyclic Module Records,
_index_: a non-negative integer,
): either a normal completion containing a non-negative integer or a throw completion
</h1>
<dl class="header">
</dl>
<emu-note>
<ins>There is no special handling for ModuleRequests whose [[Phase]] is ~defer~: any error from linking the corresponding modules will make InnerModuleLinking fail.</ins>
</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-moduleevaluation" type="concrete method">
<h1>Evaluate ( ): a Promise</h1>
<dl class="header">
<dt>for</dt>
<dd>a Cyclic Module Record _module_</dd>
<dt>description</dt>
<dd>Evaluate transitions this module's [[Status]] from ~linked~ to either ~evaluating-async~ or ~evaluated~. The first time it is called on a module in a given strongly connected component, Evaluate creates and returns a Promise which resolves when the module has finished evaluating. This Promise is stored in the [[TopLevelCapability]] field of the [[CycleRoot]] for the component. Future invocations of Evaluate on any module in the component return the same Promise. (Most of the work is done by the auxiliary function InnerModuleEvaluation.)</dd>
</dl>
<emu-alg>
1. <del>Assert: This call to Evaluate is not happening at the same time as another call to Evaluate within the surrounding agent.</del>.
1. <ins>Assert: None of _module_ or any of its recursive dependencies have [[Status]] set to ~evaluating~, ~linking~, ~unlinked~, or ~new~.</ins>
1. Assert: _module_.[[Status]] is one of ~linked~, ~evaluating-async~, or ~evaluated~.
1. If _module_.[[Status]] is either ~evaluating-async~ or ~evaluated~, set _module_ to _module_.[[CycleRoot]].
1. If _module_.[[TopLevelCapability]] is not ~empty~, then
1. Return _module_.[[TopLevelCapability]].[[Promise]].
1. Let _stack_ be a new empty List.
1. Let _capability_ be ! NewPromiseCapability(%Promise%).
1. Set _module_.[[TopLevelCapability]] to _capability_.
1. Let _result_ be Completion(InnerModuleEvaluation(_module_, _stack_, 0)).
1. If _result_ is an abrupt completion, then
1. For each Cyclic Module Record _m_ of _stack_, do
1. Assert: _m_.[[Status]] is ~evaluating~.
1. Set _m_.[[Status]] to ~evaluated~.
1. Set _m_.[[EvaluationError]] to _result_.
1. Assert: _module_.[[Status]] is ~evaluated~.
1. Assert: _module_.[[EvaluationError]] is _result_.
1. Perform ! Call(_capability_.[[Reject]], *undefined*, « _result_.[[Value]] »).
1. Else,
1. Assert: _module_.[[Status]] is either ~evaluating-async~ or ~evaluated~.
1. Assert: _module_.[[EvaluationError]] is ~empty~.
1. If _module_.[[AsyncEvaluation]] is *false*, then
1. Assert: _module_.[[Status]] is ~evaluated~.
1. Perform ! Call(_capability_.[[Resolve]], *undefined*, « *undefined* »).
1. Assert: _stack_ is empty.
1. Return _capability_.[[Promise]].
</emu-alg>
<emu-clause id="sec-innermoduleevaluation" type="abstract operation">
<h1>
InnerModuleEvaluation (
_module_: a Module Record,
_stack_: a List of Cyclic Module Records,
_index_: a non-negative integer,
): either a normal completion containing a non-negative integer or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It is used by Evaluate to perform the actual evaluation process for _module_, as well as recursively on all other modules in the dependency graph. The _stack_ and _index_ parameters, as well as _module_'s [[DFSIndex]] and [[DFSAncestorIndex]] fields, are used the same way as in InnerModuleLinking.</dd>
</dl>
<emu-alg>
1. If _module_ is not a Cyclic Module Record, then
1. <del>Let _promise_ be ! _module_.Evaluate().</del>
1. <del>Assert: _promise_.[[PromiseState]] is not ~pending~.</del>
1. <del>If _promise_.[[PromiseState]] is ~rejected~, then</del>
1. <del>Return ThrowCompletion(_promise_.[[PromiseResult]]).</del>
1. <ins>Perform ? EvaluateSync(_module_).</ins>
1. Return _index_.
1. If _module_.[[Status]] is either ~evaluating-async~ or ~evaluated~, then
1. If _module_.[[EvaluationError]] is ~empty~, return _index_.
1. Otherwise, return ? _module_.[[EvaluationError]].
1. If _module_.[[Status]] is ~evaluating~, return _index_.
1. Assert: _module_.[[Status]] is ~linked~.
1. Set _module_.[[Status]] to ~evaluating~.
1. Set _module_.[[DFSIndex]] to _index_.
1. Set _module_.[[DFSAncestorIndex]] to _index_.
1. Set _module_.[[PendingAsyncDependencies]] to 0.
1. Set _index_ to _index_ + 1.
1. <ins>Let _evaluationList_ be a new empty List.</ins>
1. <ins>For each ModuleRequest Record _request_ of _module_.[[RequestedModules]], do</ins>
1. <ins>Let _requiredModule_ be GetImportedModule(_module_, _request_).</ins>
1. <ins>If _request_.[[Phase]] is ~defer~, then</ins>
1. <ins>Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_).</ins>
1. <ins>For each Module Record _additionalModule_ of _additionalModules_, do</ins>
1. <ins>If _evaluationList_ does not contain _additionalModule_, then</ins>
1. <ins>Append _additionalModule_ to _evaluationList_.</ins>
1. <ins>Else if _evaluationList_ does not contain _requiredModule_, then</ins>
1. <ins>Append _requiredModule_ to _evaluationList_.</ins>
1. Append _module_ to _stack_.
1. <del>For each ModuleRequest Record _request_ of _module_.[[RequestedModules]], do</del>
1. <del>Let _requiredModule_ be GetImportedModule(_module_, _request_).</del>
1. <ins>For each Module Record _requiredModule_ of _evaluationList_, do</ins>
1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_).
1. If _requiredModule_ is a Cyclic Module Record, then
1. Assert: _requiredModule_.[[Status]] is one of ~evaluating~, ~evaluating-async~, or ~evaluated~.
1. Assert: _requiredModule_.[[Status]] is ~evaluating~ if and only if _stack_ contains _requiredModule_.
1. If _requiredModule_.[[Status]] is ~evaluating~, then
1. Set _module_.[[DFSAncestorIndex]] to min(_module_.[[DFSAncestorIndex]], _requiredModule_.[[DFSAncestorIndex]]).
1. Else,
1. Set _requiredModule_ to _requiredModule_.[[CycleRoot]].
1. Assert: _requiredModule_.[[Status]] is either ~evaluating-async~ or ~evaluated~.
1. If _requiredModule_.[[EvaluationError]] is not ~empty~, return ? _requiredModule_.[[EvaluationError]].
1. If _requiredModule_.[[AsyncEvaluation]] is *true*, then
1. Set _module_.[[PendingAsyncDependencies]] to _module_.[[PendingAsyncDependencies]] + 1.
1. Append _module_ to _requiredModule_.[[AsyncParentModules]].
1. If _module_.[[PendingAsyncDependencies]] > 0 or _module_.[[HasTLA]] is *true*, then
1. Assert: _module_.[[AsyncEvaluation]] is *false*.
1. Set _module_.[[AsyncEvaluation]] to *true*.
1. NOTE: The order in which module records have their [[AsyncEvaluation]] fields transition to *true* is significant. (See <emu-xref href="#sec-async-module-execution-fulfilled"></emu-xref>.)
1. If _module_.[[PendingAsyncDependencies]] = 0, perform ExecuteAsyncModule(_module_).
1. Otherwise, perform ? <emu-meta effects="user-code">_module_.ExecuteModule()</emu-meta>.