generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 12
/
spec.emu
2393 lines (2242 loc) · 126 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-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>
[[Deferred]]
</td>
<td>
a Boolean
</td>
<td>
Whether this module namespace was obtained through `import defer`/`import.defer()`. Deferred namespaces can have side effects when accessing properties on them.
</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 key corresponds to a potential ordinary property of _ns_, 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 String values of 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 provided, let _seen_ be 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 _required_ of _module_.[[RequestedModules]], do
1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]).
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] :
`import` `(` AssignmentExpression[+In, ?Yield, ?Await] `)`
<ins>`import` `.` `defer` `(` 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 intendend 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>ImportCall : `import` `(` AssignmentExpression `)`</emu-grammar>
<emu-alg>
1. <ins>Return ? EvaluateImportCall(|AssignmentExpression|, ~evaluation~).</ins>
1. <del>Let _referrer_ be GetActiveScriptOrModule().</del>
1. <del>If _referrer_ is *null*, set _referrer_ to the current Realm Record.</del>
1. <del>Let _argRef_ be ? Evaluation of |AssignmentExpression|.</del>
1. <del>Let _specifier_ be ? GetValue(_argRef_).</del>
1. <del>Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).</del>
1. <del>Let _specifierString_ be Completion(ToString(_specifier_)).</del>
1. <del>IfAbruptRejectPromise(_specifierString_, _promiseCapability_).</del>
1. <del>Perform HostLoadImportedModule(_referrer_, _specifierString_, ~empty~, _promiseCapability_).</del>
1. <del>Return _promiseCapability_.[[Promise]].</del>
</emu-alg>
<emu-grammar><ins>ImportCall : `import` `.` `defer` `(` AssignmentExpression[+In, ?Yield, ?Await] `)`</ins></emu-grammar>
<emu-alg>
1. <ins>Return ? EvaluateImportCall(|AssignmentExpression|, ~defer~).</ins>
</emu-alg>
</emu-clause>
<emu-clause id="sec-evaluate-import-call" type="abstract operation">
<h1>
<ins>
EvaluateImportCall (
_specifierExpression_: a ParseNode,
_phase_: ~defer~ or ~evaluation~
): either a normal completion containing a Promise or a throw completion
</ins>
</h1>
<dl class="header"></dl>
<emu-note type="editor">
The diff presented for this algorithm is relative to the original algorithm for the Evaluation of |ImportCall| : `import` `(` |AssignmentExpression| `)`.
</emu-note>
<emu-alg>
1. Let _referrer_ be GetActiveScriptOrModule().
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record.
1. Let _specifierRef_ be ? Evaluation of <del>|AssignmentExpression|</del><ins>_specifierExpression_</ins>.
1. Let _specifier_ be ? GetValue(_specifierRef_).
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. Let _specifierString_ be Completion(ToString(_specifier_)).
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
1. <ins>Let _payload_ be a new DynamicImportState Record { [[PromiseCapability]]: _promiseCapability_, [[Phase]]: _phase_ }.</ins>
1. Perform HostLoadImportedModule(_referrer_, _specifierString_, ~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 up to a given phase. 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>
String
</td>
<td>
The module specifier
</td>
</tr>
<tr>
<td>
[[Phase]]
</td>
<td>
~defer~ or ~evaluation~
</td>
<td>
The target import phase
</td>
</tr>
</tbody>
</table>
</emu-table>
<emu-note type="editor">In general, this proposal replaces places where module specifiers are passed around with ModuleRequest Records. For example, several syntax-directed operations, such as ModuleRequests produce Lists of ModuleRequest Records rather than Lists of Strings which are interpreted as module specifiers. Some algorithms like ImportEntries and ImportEntriesForModule pass around ModuleRequest Records rather than Strings, in a way which doesn't require any particular textual change. Additionally, record fields in Cyclic Module Records and Source Text Module Records which contained Lists of Strings are replaced by Lists of ModuleRequest Records, as indicated above.</emu-note>
</emu-clause>
<emu-clause id="sec-static-semantics-modulerequests" type="sdo" number="3">
<h1>
Static Semantics: ModuleRequests ( ): a List of <del>Strings</del><ins>ModuleRequest Records</ins>
</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 <del>_moduleNames_</del><ins>_requests_</ins> be ModuleRequests of |ModuleItemList|.
1. Let <del>_additionalNames_</del><ins>_additionalRequests_</ins> be ModuleRequests of |ModuleItem|.
1. <del>For each String _name_ of _additionalNames_, do</del>
1. <ins>For each ModuleRequest Record _mr_ of _additionalRequests_, do</ins>
1. <ins>Let _found_ be *false*.</ins>
1. <ins>For each ModuleRequest Record _mr2_ of _requests_, do</ins>
1. <ins>If _mr_.[[Specifier]] is _mr2_.[[Specifier]] and _mr_.[[Phase]] is _mr2_.[[Phase]], then</ins>
1. <ins>Assert: _found_ is *false*.</ins>
1. <ins>Set _found_ to *true*.</ins>
1. <del>If _moduleNames_ does not contain _name_, then</del>
1. <ins>If _found_ is *false*, then</ins>
1. Append <del>_name_</del><ins>_mr_</ins> to <del>_moduleNames_</del><ins>_requests_</ins>.
1. Return <del>_moduleNames_</del><ins>_requests_</ins>.
</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. <del>Return ModuleRequests of |FromClause|.</del>
1. <ins>Let _specifier_ be SV of |FromClause|.</ins>
1. <ins>Return a List whose sole element is the ModuleRequest Record { [[Specifier]]: _specifier_, [[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_, [[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. <del>Return ModuleRequests of |FromClause|.</del>
1. <ins>Let _specifier_ be SV of |FromClause|.</ins>
1. <ins>Return a List whose sole element is the ModuleRequest Record { [[Specifier]]: _specifier_, [[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>
<p>In addition to the fields defined in <emu-xref href="#table-module-record-fields"></emu-xref> Cyclic Module Records have the additional fields listed in <emu-xref href="#table-cyclic-module-fields"></emu-xref></p>
<emu-table id="table-cyclic-module-fields" caption="Additional Fields of Cyclic Module Records">
<table>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
[[Status]]
</td>
<td>
~new~, ~unlinked~, ~linking~, ~linked~, ~evaluating~, ~evaluating-async~, or ~evaluated~
</td>
<td>
Initially ~new~. Transitions to ~unlinked~, ~linking~, ~linked~, ~evaluating~, possibly ~evaluating-async~, ~evaluated~ (in that order) as the module progresses throughout its lifecycle. ~evaluating-async~ indicates this module is queued to execute on completion of its asynchronous dependencies or it is a module whose [[HasTLA]] field is *true* that has been executed and is pending top-level completion.
</td>
</tr>
<tr>
<td>
[[EvaluationError]]
</td>
<td>
a throw completion or ~empty~
</td>
<td>
A throw completion representing the exception that occurred during evaluation. *undefined* if no exception occurred or if [[Status]] is not ~evaluated~.
</td>
</tr>
<tr>
<td>
[[DFSIndex]]
</td>
<td>
an integer or ~empty~
</td>
<td>
Auxiliary field used during Link and Evaluate only. If [[Status]] is either ~linking~ or ~evaluating~, this non-negative number records the point at which the module was first visited during the depth-first traversal of the dependency graph.
</td>
</tr>
<tr>
<td>
[[DFSAncestorIndex]]
</td>
<td>
an integer or ~empty~
</td>
<td>
Auxiliary field used during Link and Evaluate only. If [[Status]] is either ~linking~ or ~evaluating~, this is either the module's own [[DFSIndex]] or that of an "earlier" module in the same strongly connected component.
</td>
</tr>
<tr>
<td>
[[RequestedModules]]
</td>
<td>
a List of <del>Strings</del><ins>ModuleRequest Records</ins>
</td>
<td>
A List of all the |ModuleSpecifier| strings used by the module represented by this record to request the importation of a module, <ins>along with their maximum specified import phase (~defer~ or ~evaluation~)</ins>. The List is in source text occurrence order.
</td>
</tr>
<tr>
<td>
[[LoadedModules]]
</td>
<td>
a List of Records with fields [[Specifier]] (a String) and [[Module]] (a Module Record)
</td>
<td>
A map from the specifier strings used by the module represented by this record to request the importation of a module to the resolved Module Record. The list does not contain two different Records with the same [[Specifier]].
</td>
</tr>
<tr>
<td>
[[CycleRoot]]
</td>
<td>
a Cyclic Module Record or ~empty~
</td>
<td>
The first visited module of the cycle, the root DFS ancestor of the strongly connected component. For a module not in a cycle, this would be the module itself. Once Evaluate has completed, a module's [[DFSAncestorIndex]] is the [[DFSIndex]] of its [[CycleRoot]].
</td>
</tr>
<tr>
<td>
[[HasTLA]]
</td>
<td>
a Boolean
</td>
<td>
Whether this module is individually asynchronous (for example, if it's a Source Text Module Record containing a top-level await). Having an asynchronous dependency does not mean this field is *true*. This field must not change after the module is parsed.
</td>
</tr>
<tr>
<td>
[[AsyncEvaluation]]
</td>
<td>
a Boolean
</td>
<td>
Whether this module is either itself asynchronous or has an asynchronous dependency. Note: The order in which this field is set is used to order queued executions, see <emu-xref href="#sec-async-module-execution-fulfilled"></emu-xref>.
</td>
</tr>
<tr>
<td>
[[TopLevelCapability]]
</td>
<td>
a PromiseCapability Record or ~empty~
</td>
<td>
If this module is the [[CycleRoot]] of some cycle, and Evaluate() was called on some module in that cycle, this field contains the PromiseCapability Record for that entire evaluation. It is used to settle the Promise object that is returned from the Evaluate() abstract method. This field will be ~empty~ for any dependencies of that module, unless a top-level Evaluate() has been initiated for some of those dependencies.
</td>
</tr>
<tr>
<td>
[[AsyncParentModules]]
</td>
<td>
a List of Cyclic Module Records
</td>
<td>
If this module or a dependency has [[HasTLA]] *true*, and execution is in progress, this tracks the parent importers of this module for the top-level execution job. These parent modules will not start executing before this module has successfully completed execution.
</td>
</tr>
<tr>
<td>
[[PendingAsyncDependencies]]
</td>
<td>
an integer or ~empty~
</td>
<td>
If this module has any asynchronous dependencies, this tracks the number of asynchronous dependency modules remaining to execute for this module. A module with asynchronous dependencies will be executed when this field reaches 0 and there are no execution errors.
</td>
</tr>
</table>
</emu-table>
<p>In addition to the methods defined in <emu-xref href="#table-abstract-methods-of-module-records"></emu-xref> Cyclic Module Records have the additional methods listed in <emu-xref href="#table-cyclic-module-methods"></emu-xref></p>
<emu-table id="table-cyclic-module-methods" caption="Additional Abstract Methods of Cyclic Module Records">
<table>
<tr>
<th>
Method
</th>
<th>
Purpose
</th>
</tr>
<tr>
<td>
InitializeEnvironment()
</td>
<td>
Initialize the Environment Record of the module, including resolving all imported bindings, and create the module's execution context.
</td>
</tr>
<tr>
<td>
ExecuteModule( [ _promiseCapability_ ] )
</td>
<td>
Evaluate the module's code within its execution context. If this module has *true* in [[HasTLA]], then a PromiseCapability Record is passed as an argument, and the method is expected to resolve or reject the given capability. In this case, the method must not throw an exception, but instead reject the PromiseCapability Record if necessary.
</td>
</tr>
</table>
</emu-table>
<p>A <dfn id="graphloadingstate-record" variants="GraphLoadingState Records">GraphLoadingState Record</dfn> is a Record that contains information about the loading process of a module graph. It's used to continue loading after a call to HostLoadImportedModule. Each GraphLoadingState Record has the fields defined in <emu-xref href="#table-graphloadingstate-record-fields"></emu-xref>:</p>
<emu-table id="table-graphloadingstate-record-fields" caption="GraphLoadingState Record Fields">
<table>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
[[PromiseCapability]]
</td>
<td>
a PromiseCapability Record
</td>
<td>
The promise to resolve when the loading process finishes.
</td>
</tr>
<tr>
<td>
[[IsLoading]]
</td>
<td>
a Boolean
</td>
<td>
It is true if the loading process has not finished yet, neither successfully nor with an error.
</td>
</tr>
<tr>
<td>
[[PendingModulesCount]]
</td>
<td>
a non-negative integer
</td>
<td>
It tracks the number of pending HostLoadImportedModule calls.
</td>
</tr>
<tr>
<td>
[[Visited]]
</td>
<td>
a List of Cyclic Module Records
</td>
<td>
It is a list of the Cyclic Module Records that have been already loaded by the current loading process, to avoid infinite loops with circular dependencies.
</td>
</tr>
<tr>
<td>
[[HostDefined]]
</td>
<td>
anything (default value is ~empty~)
</td>
<td>
It contains host-defined data to pass from the LoadRequestedModules caller to HostLoadImportedModule.
</td>
</tr>
</table>
</emu-table>
<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>
<dt>description</dt>
<dd>It populates the [[LoadedModules]] of all the Module Records in the dependency graph of _module_ (most of the work is done by the auxiliary function InnerModuleLoading). It takes an optional _hostDefined_ parameter that is passed to the HostLoadImportedModule hook.</dd>
</dl>
<emu-alg>
1. If _hostDefined_ is not present, let _hostDefined_ be ~empty~.
1. Let _pc_ be ! NewPromiseCapability(%Promise%).
1. Let _state_ be the GraphLoadingState Record { [[IsLoading]]: *true*, [[PendingModulesCount]]: 1, [[Visited]]: « », [[PromiseCapability]]: _pc_, [[HostDefined]]: _hostDefined_ }.
1. Perform InnerModuleLoading(_state_, _module_).
1. Return _pc_.[[Promise]].
</emu-alg>