generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 11
/
0-module-and-module-source.emu
855 lines (798 loc) · 40.2 KB
/
0-module-and-module-source.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
<!doctype html>
<html lang="en-GB-oxendict">
<head>
<meta charset="utf8">
<link href="ecmarkup.css" rel="stylesheet">
<script src="ecmarkup.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/solarized-light.min.css">
</head>
<body>
<pre class="metadata">
title: 'Module & ModuleSource API'
stage: 1
contributors: Mark Miller, Caridy Patiño, Patrick Soquet, Kris Kowal, Jack Works, Guy Bedford, Nicolò Ribaudo
status: proposal
copyright: false
location: https://tc39.es/proposal-compartments/
</pre>
<emu-clause id="sec-well-known-intrinsic-objects">
<h1>Well-known intrinsic objects</h1>
<emu-table id="table-7" caption="Well-known Intrinsic Objects">
<table>
<tbody>
<tr>
<th>Intrinsic Name</th>
<th>Global Name</th>
<th>ECMAScript Language Association</th>
</tr>
<tr>
<td>%ModuleSource%</td>
<td>`ModuleSource`</td>
<td>The ModuleSource constructor (<emu-xref href="#sec-modulesource-constructor"></emu-xref>)</td>
</tr>
<tr>
<td>%Module%</td>
<td>`Module`</td>
<td>The Module constructor (<emu-xref href="#sec-module-constructor"></emu-xref>)</td>
</tr>
</tbody>
</table>
</emu-table>
</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.1">
<h1>Module Semantics</h1>
<emu-clause id="sec-cyclic-module-records" number="5">
<h1>Cyclic Module Records</h1>
<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></td>
<td></td>
</tr>
<tr>
<td>
[[EvaluationError]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[DFSIndex]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[DFSAncestorIndex]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[RequestedModules]]
</td>
<td></td>
<td></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>
<ins>[[LoadingModules]]</ins>
</td>
<td>
<ins>a List of Records with fields [[Specifier]] (a String) and [[LoadStates]] (a List of either GraphLoadingState Records or PromiseCapability Records)</ins>
</td>
<td>
<ins> A map from the specifier strings imported by this module to the states of the loading processes that are waiting for the resolved module record. It is used to avoid multiple calls to the loading hook with the same (_specifier_, _referrer_) pair. The list does not contain two different Records with the same [[Specifier]].</ins>
<emu-note type="editor">
This field must also be added to Script Records and Realm Records, in parallel to the existing [[LoadedModules]] fields.
</emu-note>
</td>
</tr>
<tr>
<td>
[[CycleRoot]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[HasTLA]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[AsyncEvaluation]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[TopLevelCapability]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[AsyncParentModules]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[PendingAsyncDependencies]]
</td>
<td></td>
<td></td>
</tr>
</table>
</emu-table>
<emu-clause id="sec-LoadRequestedModules" type="concrete method">
<h1>
LoadRequestedModules (
optional _hostDefined_: anything,
): a Promise object
</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">
<dt>description</dt>
<dd>It is used by LoadRequestedModules to recursively perform the actual loading process for _module_'s dependency graph.</dd>
</dl>
<emu-alg>
1. Assert: _state_.[[IsLoading]] is *true*.
1. If _module_ is a Cyclic Module Record, _module_.[[Status]] is ~new~, and _state_.[[Visited]] does not contain _module_, then
1. Append _module_ to _state_.[[Visited]].
1. Let _requestedModulesCount_ be the length of _module_.[[RequestedModules]].
1. Set _state_.[[PendingModulesCount]] to _state_.[[PendingModulesCount]] + _requestedModulesCount_.
1. For each String _required_ of _module_.[[RequestedModules]], do
1. If _module_.[[LoadedModules]] contains a Record _record_ whose [[Specifier]] is _required_, then
1. Perform InnerModuleLoading(_state_, _record_.[[Module]]).
1. Else,
1. Perform <del>HostLoadImportedModule</del><ins>LoadImportedModule</ins>(_module_, _required_, _state_.[[HostDefined]], _state_).
1. NOTE: <del>HostLoadImportedModule</del><ins>LoadImportedModule</ins> will call FinishLoadingImportedModule, which re-enters the graph loading process through ContinueModuleLoading.
1. If _state_.[[IsLoading]] is *false*, return ~unused~.
1. Assert: _state_.[[PendingModulesCount]] ≥ 1.
1. Set _state_.[[PendingModulesCount]] to _state_.[[PendingModulesCount]] - 1.
1. If _state_.[[PendingModulesCount]] = 0, then
1. Set _state_.[[IsLoading]] to *false*.
1. For each Cyclic Module Record _loaded_ in _state_.[[Visited]], do
1. If _loaded_.[[Status]] is ~new~, set _loaded_.[[Status]] to ~unlinked~.
1. Perform ! Call(_state_.[[PromiseCapability]].[[Resolve]], *undefined*, « *undefined* »).
1. Return ~unused~.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-source-text-module-records" number="6">
<h1>Source Text Module Records</h1>
<p>In addition to the fields defined in <emu-xref href="#table-cyclic-module-fields"></emu-xref>, Source Text Module Records have the additional fields listed in <emu-xref href="#table-additional-fields-of-source-text-module-records"></emu-xref>. Each of these fields is initially set in ParseModule.</p>
<emu-table id="table-additional-fields-of-source-text-module-records" caption="Additional Fields of Source Text Module Records" oldids="table-38">
<table>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
...
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<ins>[[ModuleInstance]]</ins>
</td>
<td>
An instance of a %Module% constructor or *undefined*.
</td>
<td>
A Module Instance or *undefined* if no Module Instance is associated to this Record.
</td>
</tr>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-LoadImportedModule" type="abstract operation">
<h1>
<ins>
LoadImportedModule(
_referrer_: a Script Record, a Cyclic Module Record, or a Realm Record,
_specifier_: a String,
_hostDefined_: anything,
_state_: a GraphLoadingState Record or a PromiseCapability Record,
): ~unused~
</ins>
</h1>
<dl class="header"></dl>
<emu-alg>
1. If _referrer_.[[LoadedModules]] contains a Record _loaded_ whose [[Specifier]] is _specifier_, then
1. Let _module_ be _loaded_.[[Module]].
1. Perform FinishLoadingImportedModule(_referrer_, _specifier_, NormalCompletion(_module_)).
1. Return ~unused~.
1. If _referrer_.[[LoadingModules]] contains a Record _loading_ whose [[Specifier]] is _specifier_, then
1. Add _state_ to _loading_.[[LoadStates]].
1. Return ~unused~.
1. Append the Record { [[Specifier]]: _specifier_, [[LoadStates]]: « _state_ » } to _referrer_.[[LoadingModules]].
1. If _referrer_ is not a Source Text Module Record, _referrer_.[[ModuleInstance]] is *undefined*, or _referrer_.[[ModuleInstance]].[[ImportHook]] is *undefined*, then
1. Perform HostLoadImportedModule(_referrer_, _specifier_, _hostDefined_).
1. Return ~unused~.
1. Let _importHookResult_ be Completion(Call(_referrer_.[[ModuleInstance]].[[ImportHook]], _referrer_.[[ModuleInstance]].[[HandlerValue]], « _specifier_ »).
1. If _importHookResult_ is an abrupt completion, then
1. Perform FinishLoadingImportedModule(_referrer_, _specifier_, _importHookResult_).
1. Return ~unused~.
1. Let _importHookPromise_ be Completion(PromiseResolve(%Promise%, _importHookResult_.[[Value]])).
1. If _importHookPromise_ is an abrupt completion, then
1. Perform FinishLoadingImportedModule(_referrer_, _specifier_, _importHookPromise_).
1. Return ~unused~.
1. Let _fulfilledClosure_ be a new Abstract Closure with parameters (_result_) that captures _referrer_ and _specifier_, and performs the following steps when called:
1. Let _completion_ be *null*.
1. If Type(_result_) is Object and _result_ has a [[ImportHook]] internal slot, then
1. Set _completion_ to NormalCompletion(_result_.[[Module]]).
1. Else,
1. Set _completion_ to ThrowCompletion(a newly created *TypeError* object).
1. Perform FinishLoadingImportedModule(_referrer_, _specifier_, _completion_).
1. Return ~unused~.
1. Let _onFulfilled_ be CreateBuiltinFunction(_fulfilledClosure_, 0, *""*, « »).
1. Let _rejectedClosure_ be a new Abstract Closure with parameters (_error_) that captures _referrer_ and _specifier_, and performs the following steps when called:
1. Perform FinishLoadingImportedModule(_referrer_, _specifier_, ThrowCompletion(_error_)).
1. Return ~unused~.
1. Let _onRejected_ be CreateBuiltinFunction(_rejectedClosure_, 1, *""*, « »).
1. Perform PerformPromiseThen(_importHookPromise_.[[Value]], _onFulfilled_, _onRejected_).
1. Return ~unused~.
</emu-alg>
</emu-clause>
<emu-clause id="sec-HostLoadImportedModule" type="host-defined abstract operation">
<h1>
HostLoadImportedModule (
_referrer_: a Script Record, a Cyclic Module Record, or a Realm Record,
_specifier_: a String,
_hostDefined_: anything,
<del>_payload_: a GraphLoadingState Record or a PromiseCapability Record,</del>
): ~unused~
</h1>
<dl class="header">
<dt>description</dt>
<dd></dd>
</dl>
<emu-note>
<p>An example of when _referrer_ can be a Realm Record is in a web browser host. There, if a user clicks on a control given by</p>
<pre><code class="html"><button type="button" onclick="import('./foo.mjs')">Click me</button></code></pre>
<p>there will be no active script or module at the time the <emu-xref href="#sec-import-calls">`import()`</emu-xref> expression runs. More generally, this can happen in any situation where the host pushes execution contexts with *null* ScriptOrModule components onto the execution context stack.</p>
</emu-note>
<p>An implementation of HostLoadImportedModule must conform to the following requirements:</p>
<ul>
<li>
The host environment must perform FinishLoadingImportedModule(_referrer_, _specifier_, <del>_payload_,</del> _result_), where _result_ is either a normal completion containing the loaded Module Record or a throw completion, either synchronously or asynchronously.
</li>
<li>
If this operation is called multiple times with the same (_referrer_, _specifier_) pair and it performs FinishLoadingImportedModule(_referrer_, _specifier_, <del>_payload_,</del> _result_) where _result_ is a normal completion, then it must perform FinishLoadingImportedModule(_referrer_, _specifier_, <del>_payload_,</del> _result_) with the same _result_ each time.
</li>
<li>
<del>The operation must treat _payload_ as an opaque value to be passed through to FinishLoadingImportedModule.</del>
</li>
</ul>
<p>The actual process performed is host-defined, but typically consists of performing whatever I/O operations are necessary to load the appropriate Module Record. Multiple different (_referrer_, _specifier_) pairs may map to the same Module Record instance. The actual mapping semantics is host-defined but typically a normalization process is applied to _specifier_ as part of the mapping process. A typical normalization process would include actions such as expansion of relative and abbreviated path specifiers.</p>
</emu-clause>
<emu-clause id="sec-FinishLoadingImportedModule" type="abstract operation">
<h1>
FinishLoadingImportedModule (
_referrer_: a Script Record, a Cyclic Module Record, or a Realm Record,
_specifier_: a String,
<del>_payload_: a GraphLoadingState Record or a PromiseCapability Record,</del>
_result_: either a normal completion containing a Module Record or a throw completion,
): ~unused~
</h1>
<dl class="header">
<dt>description</dt>
<dd></dd>
</dl>
<emu-alg>
1. If _result_ is a normal completion, then
1. If _referrer_.[[LoadedModules]] contains a Record _record_ whose [[Specifier]] is _specifier_, then
1. Assert: _record_.[[Module]] is _result_.[[Value]].
1. Else, append the Record { [[Specifier]]: _specifier_, [[Module]]: _result_.[[Value]] } to _referrer_.[[LoadedModules]].
1. <ins>Let _loading_ be the Record in _referrer_.[[LoadingModules]] whose [[Specifier]] is _specifier_.</ins>
1. <ins>Assert: _loading_ exists and is unique.</ins>
1. <ins>Remove _loading_ from _referrer_.[[LoadingModules]].</ins>
1. <ins>For each Record _state_ in _loading_.[[LoadStates]], do</ins>
1. If <del>_payload_</del><ins>_state_</ins> is a GraphLoadingState Record, then
1. Perform ContinueModuleLoading(<del>_payload_</del><ins>_state_</ins>, _result_).
1. Else,
1. Perform ContinueDynamicImport(<del>_payload_</del><ins>_state_</ins>, _result_).
1. Return ~unused~.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-meta-properties">
<h1>Meta Properties</h1>
<emu-clause id="sec-meta-properties-runtime-semantics-evaluation" type="sdo">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>ImportMeta : `import` `.` `meta`</emu-grammar>
<emu-alg>
1. Let _module_ be GetActiveScriptOrModule().
1. Assert: _module_ is a Source Text Module Record.
1. Let _importMeta_ be _module_.[[ImportMeta]].
1. If _importMeta_ is ~empty~, then
1. Set _importMeta_ to OrdinaryObjectCreate(*null*).
1. <ins>If _module_.[[ModuleInstance]] is *undefined* or _module_.[[ModuleInstance]].[[ImportMetaHook]] is *undefined*, then</ins>
1. Let _importMetaValues_ be HostGetImportMetaProperties(_module_).
1. For each Record { [[Key]], [[Value]] } _p_ of _importMetaValues_, do
1. Perform ! CreateDataPropertyOrThrow(_importMeta_, _p_.[[Key]], _p_.[[Value]]).
1. Perform HostFinalizeImportMeta(_importMeta_, _module_).
1. <ins>Else,</ins>
1. <ins>Let _importMetaHook_ be _module_.[[ModuleInstance]].[[ImportMetaHook]].</ins>
1. <ins>Let _handler_ be _module_.[[ModuleInstance]].[[HandlerValue]].</ins>
1. <ins>Perform ? Call(_importMetaHook_, _handler_, « _importMeta_ »).</ins>
1. Set _module_.[[ImportMeta]] to _importMeta_.
1. Return _importMeta_.
1. Else,
1. Assert: Type(_importMeta_) is Object.
1. Return _importMeta_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-modulesource-records">
<h1>Module Source Records</h1>
<p>A <dfn id="modulesource-record" variants="Module Source Records">Module Source Record</dfn> is used to represent information about a module source that was defined from ECMAScript source text (<emu-xref href="#sec-ecmascript-language-source-code"></emu-xref>) that was parsed using the goal symbol |Module|. Its fields contain digested information about the names that are imported and exported by the module.</p>
<p>Module Source Records have the fields listed in <emu-xref href="#table-fields-of-module-source-records"></emu-xref>. Each of these fields is initially set in CreateModuleSourceRecord.</p>
<emu-table id="table-fields-of-module-source-records" caption="Fields of Module Source Records">
<table>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
[[ECMAScriptCode]]
</td>
<td>
a Parse Node
</td>
<td>
The result of parsing the source text of this module using |Module| as the goal symbol.
</td>
</tr>
<tr>
<td>
[[ImportEntries]]
</td>
<td>
a List of ImportEntry Records
</td>
<td>
A List of ImportEntry records derived from the code of this module source.
</td>
</tr>
<tr>
<td>
[[LocalExportEntries]]
</td>
<td>
a List of ExportEntry Records
</td>
<td>
A List of ExportEntry records derived from the code of this module that correspond to declarations that occur within the module source.
</td>
</tr>
<tr>
<td>
[[IndirectExportEntries]]
</td>
<td>
a List of ExportEntry Records
</td>
<td>
A List of ExportEntry records derived from the code of this module source that correspond to reexported imports that occur within the module or exports from `export * as namespace` declarations.
</td>
</tr>
<tr>
<td>
[[StarExportEntries]]
</td>
<td>
a List of ExportEntry Records
</td>
<td>
A List of ExportEntry records derived from the code of this module source that correspond to `export *` declarations that occur within the module, not including `export * as namespace` declarations.
</td>
</tr>
<tr>
<td>
[[HasTLA]]
</td>
<td>
a Boolean
</td>
<td>
Whether this module source is individually asynchronous. Having an asynchronous dependency does not mean this field is *true*.
</td>
</tr>
<tr>
<td>
[[RequestedModules]]
</td>
<td>
a List of Strings
</td>
<td>
A List of all the |ModuleSpecifier| strings used by the module source represented by this record to request the importation of a module. The List is source text occurrence ordered.
</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 source.
</td>
</tr>
</table>
</emu-table>
<emu-note type="editor">
A Module Source Record is the static portion of a Module Record. A refactor of the spec can make this separation more formal instead of just copying internal slot from one record to another.
</emu-note>
</emu-clause>
<emu-clause id="sec-import-calls">
<h1>Import Calls</h1>
<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. Let _referrer_ be GetActiveScriptOrModule().
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record.
1. Let _argRef_ be ? Evaluation of |AssignmentExpression|.
1. Let <del>_specifier_</del><ins>_specifierOrModule_</ins> be ? GetValue(_argRef_).
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. <ins>If Type(_specifierOrModule_) is Object that has a [[ModuleSourceInstance]] internal slot, then</ins>
1. <ins>Perform ContinueDynamicImport(_promiseCapability_, _specifierOrModule_.[[Module]]).</ins>
1. <ins>Else,</ins>
1. Let _specifierString_ be Completion(ToString(<del>_specifier_</del><ins>_specifierOrModule_</ins>)).
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
1. Perform <del>HostLoadImportedModule</del><ins>LoadImportedModule</ins>(_referrer_, _specifierString_, ~empty~, _promiseCapability_).
1. Return _promiseCapability_.[[Promise]].
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-modulesource-objects">
<h1>ModuleSource Objects</h1>
<emu-clause id="sec-modulesource-abstracts">
<h1>ModuleSource Abstract Operations</h1>
<emu-clause id="sec-createmodulesourcerecord" type="abstract operation">
<h1>
CreateModuleSourceRecord (
_body_: Parse Node,
): a Module Source Record
</h1>
<dl class="header">
<dt>description</dt>
<dd>It creates a Module Source Record based upon a |Module| Parse Node.</dd>
</dl>
<emu-alg>
1. Let _requestedModules_ be the ModuleRequests of _body_.
1. Let _importEntries_ be ImportEntries of _body_.
1. Let _importedBoundNames_ be ImportedLocalNames(_importEntries_).
1. Let _indirectExportEntries_ be a new empty List.
1. Let _localExportEntries_ be a new empty List.
1. Let _starExportEntries_ be a new empty List.
1. Let _exportEntries_ be ExportEntries of _body_.
1. For each ExportEntry Record _ee_ of _exportEntries_, do
1. If _ee_.[[ModuleRequest]] is *null*, then
1. If _ee_.[[LocalName]] is not an element of _importedBoundNames_, then
1. Append _ee_ to _localExportEntries_.
1. Else,
1. Let _ie_ be the element of _importEntries_ whose [[LocalName]] is the same as _ee_.[[LocalName]].
1. If _ie_.[[ImportName]] is ~namespace-object~, then
1. NOTE: This is a re-export of an imported module namespace object.
1. Append _ee_ to _localExportEntries_.
1. Else,
1. NOTE: This is a re-export of a single name.
1. Append the ExportEntry Record { [[ModuleRequest]]: _ie_.[[ModuleRequest]], [[ImportName]]: _ie_.[[ImportName]], [[LocalName]]: *null*, [[ExportName]]: _ee_.[[ExportName]] } to _indirectExportEntries_.
1. Else if _ee_.[[ImportName]] is ~all-but-default~, then
1. Assert: _ee_.[[ExportName]] is *null*.
1. Append _ee_ to _starExportEntries_.
1. Else,
1. Append _ee_ to _indirectExportEntries_.
1. Let _async_ be _body_ Contains `await`.
1. NOTE: How should _hostDefined_ be populated if this operation is triggered by the user and whether or not _hostDefined_ should be used for sources created in user land.
1. Let _hostDefined_ be *undefined*.
1. Return Module Source Record { [[HasTLA]]: _async_, [[ECMAScriptCode]]: _body_, [[RequestedModules]]: _requestedModules_, [[ImportEntries]]: _importEntries_, [[LocalExportEntries]]: _localExportEntries_, [[IndirectExportEntries]]: _indirectExportEntries_, [[StarExportEntries]]: _starExportEntries_, [[HostDefined]]: _hostDefined_ }.
</emu-alg>
<emu-note type="editor">
A Module Source Record is the static portion of a Module Record. A refactor of the spec can make this separation more formal instead of just having both of them sharing the same set of Internal Slots.
</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-modulesource-constructor">
<h1>The ModuleSource Constructor</h1>
<p>The ModuleSource constructor:</p>
<ul>
<li>is the intrinsic object <dfn>%ModuleSource%</dfn>.</li>
<li>is the initial value of the *"ModuleSource"* property of the global object.</li>
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
<li>creates and initializes a new ModuleSource object when called as a constructor.</li>
</ul>
<emu-clause id="sec-modulesource">
<h1>ModuleSource ( _sourceText_ )</h1>
<p>When the `ModuleSource` function is called with argument _sourceText_, the following steps are taken:</p>
<emu-alg>
1. If NewTarget is *undefined*, throw a *TypeError* exception.
1. Let _O_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%ModuleSource.prototype%"*, « [[ModuleSource]] »).
1. Let _body_ be ParseText(_sourceText_, |Module|).
1. If _body_ is a List of errors, throw a *SyntaxError* exception.
1. Set _O_.[[ModuleSource]] to ? CreateModuleSourceRecord(_body_).
1. Return _O_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-modulesource-constructor">
<h1>Properties of the ModuleSource Constructor</h1>
<p>The ModuleSource constructor:</p>
<ul>
<li>has a [[Prototype]] internal slot whose value is %Function.prototype%.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-modulesource.prototype">
<h1>ModuleSource.prototype</h1>
<p>The initial value of *ModuleSource.prototype* is %ModuleSource.prototype%.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-modulesource-prototype-object">
<h1>Properties of the ModuleSource Prototype Object</h1>
<p>The ModuleSource prototype object:</p>
<ul>
<li>has a [[Prototype]] internal slot whose value is %Object.prototype%.</li>
<li>is %ModuleSource.prototype%.</li>
<li>is an ordinary object.</li>
</ul>
<emu-clause id="sec-modulesource.prototype.constructor">
<h1>ModuleSource.prototype.constructor</h1>
<p>The initial value of `ModuleSource.prototype.constructor` is %ModuleSource%.</p>
</emu-clause>
<emu-clause id="sec-modulesource.prototype-@@tostringtag">
<h1>ModuleSource.prototype [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the String value *"ModuleSource"*.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-modulesource-instances">
<h1>Properties of ModuleSource Instances</h1>
<p>ModuleSource instances are ordinary objects that inherit properties from the ModuleSource prototype object (the intrinsic, %ModuleSource.prototype%). ModuleSource instances are initially created with the internal slots described in <emu-xref href="#table-internal-slots-of-modulesource-instances"></emu-xref>.</p>
<emu-table id="table-internal-slots-of-modulesource-instances" caption="Internal Slots of ModuleSource Instances">
<table>
<tbody>
<tr>
<th>Internal Slot</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>[[ModuleSource]]</td>
<td>Module Source Record</td>
<td>The Module Source Record for the provided source text.</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
</emu-clause>
<emu-clause id="sec-module-objects">
<h1>Module Objects</h1>
<emu-clause id="sec-module-abstracts">
<h1>Module Abstract Operations</h1>
<emu-clause id="sec-createmodulerecord" type="abstract operation">
<h1>
CreateModuleRecord (
_moduleSource_: a Module Source Record
): a Source Text Module Record
</h1>
<dl class="header">
<dt>description</dt>
<dd>It creates a Source Text Module Record based upon the result of a previously parsed _sourceText_ as a |Module| associated to the provided Module Source Record.</dd>
</dl>
<emu-alg>
1. Assert: _moduleSource_ is a Module Source Record.
1. Let _async_ be _sourceModule_.[[HasTLA]].
1. Let _body_ be _sourceModule_.[[ECMAScriptCode]].
1. Let _requestedModules_ be _sourceModule_.[[RequestedModules]].
1. Let _importEntries_ be _sourceModule_.[[ImportEntries]].
1. Let _localExportEntries_ be _sourceModule_.[[LocalExportEntries]].
1. Let _indirectExportEntries_ be _sourceModule_.[[IndirectExportEntries]].
1. Let _starExportEntries_ be _sourceModule_.[[StarExportEntries]].
1. Let _hostDefined_ be _sourceModule_.[[HostDefined]].
1. Let _realm_ be the current Realm Record.
1. Return Source Text Module Record { [[Realm]]: _realm_, [[Environment]]: ~empty~, [[Namespace]]: ~empty~, [[CycleRoot]]: ~empty~, [[HasTLA]]: _async_, [[AsyncEvaluation]]: *false*, [[TopLevelCapability]]: ~empty~, [[AsyncParentModules]]: « », [[PendingAsyncDependencies]]: ~empty~, [[Status]]: ~unlinked~, [[EvaluationError]]: ~empty~, [[HostDefined]]: _hostDefined_, [[ECMAScriptCode]]: _body_, [[Context]]: ~empty~, [[ImportMeta]]: ~empty~, [[RequestedModules]]: _requestedModules_, [[ImportEntries]]: _importEntries_, [[LocalExportEntries]]: _localExportEntries_, [[IndirectExportEntries]]: _indirectExportEntries_, [[StarExportEntries]]: _starExportEntries_, [[DFSIndex]]: ~empty~, [[DFSAncestorIndex]]: ~empty~, [[ModuleInstance]]: *undefined* }.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-module-constructor">
<h1>The Module Constructor</h1>
<p>The Module constructor:</p>
<ul>
<li>is the intrinsic object <dfn>%Module%</dfn>.</li>
<li>is the initial value of the *"Module"* property of the global object.</li>
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
<li>creates and initializes a new Module object when called as a constructor.</li>
</ul>
<emu-clause id="sec-module">
<h1>Module ( _moduleSource_, _handler_ )</h1>
<p>When the `Module` function is called with the arguments _moduleSource_ and _handler_, the following steps are taken:</p>
<emu-alg>
1. If NewTarget is *undefined*, throw a *TypeError* exception.
1. Perform ? RequireInternalSlot(_moduleSource_, [[ModuleSource]]).
1. Let _moduleRecord_ to ! CreateModuleRecord(_moduleSource_.[[ModuleSource]]).
1. If Type(_handler_) is Object, then
1. Let _importHook_ be ? GetMethod(_handler_, *"importHook"*).
1. If _importHook_ is not *undefined* and IsCallable(_importHook_) is *false*, throw a *TypeError* exception.
1. Let _importMetaHook_ be ? GetMethod(_handler_, *"importMetaHook"*).
1. If _importMetaHook_ is not *undefined* and IsCallable(_importMetaHook_) is *false*, throw a *TypeError* exception.
1. Else if _handler_ is *undefined*, then
1. Let _importHook_ be *undefined*.
1. Let _importMetaHook_ be *undefined*.
1. Else,
1. Throw a *TypeError* exception.
1. Let _O_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%Module.prototype%"*, « [[Module]], [[ModuleSourceInstance]], [[HandlerValue]], [[ImportHook]], [[ImportMetaHook]] »).
1. Set _O_.[[ModuleSourceInstance]] to _moduleSource_.
1. Set _O_.[[HandlerValue]] be _handler_.
1. Set _O_.[[ImportHook]] be _importHook_.
1. Set _O_.[[ImportMetaHook]] be _importMetaHook_.
1. Set _moduleRecord_.[[ModuleInstance]] to _O_.
1. Set _O_.[[Module]] to _moduleRecord_.
1. Return _O_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-module-constructor">
<h1>Properties of the Module Constructor</h1>
<p>The Module constructor:</p>
<ul>
<li>has a [[Prototype]] internal slot whose value is %Function.prototype%.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-module.prototype">
<h1>Module.prototype</h1>
<p>The initial value of *Module.prototype* is %Module.prototype%.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-module-prototype-object">
<h1>Properties of the Module Prototype Object</h1>
<p>The Module prototype object:</p>
<ul>
<li>has a [[Prototype]] internal slot whose value is <dfn>%Object.prototype%</dfn>.</li>
<li>is %Module.prototype%.</li>
<li>is an ordinary object.</li>
<li>does not have a [[Module]] or any other of the internal slots that are specific to _Realm_ instance objects.</li>
</ul>
<emu-clause id="sec-module.prototype.constructor">
<h1>Module.prototype.constructor</h1>
<p>The initial value of `Module.prototype.constructor` is %Module%.</p>
</emu-clause>
<emu-clause id="sec-module.prototype.source">
<h1>get Module.prototype.source</h1>
<p>`Module.prototype.source` is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps:</p>
<emu-alg>
1. Let _M_ be the *this* value.
1. Perform ? RequireInternalSlot(_M_, [[ModuleSourceInstance]]).
1. Return _M_.[[ModuleSourceInstance]].
</emu-alg>
</emu-clause>
<emu-clause id="sec-module.prototype-@@tostringtag">
<h1>Module.prototype [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the String value *"Module"*.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-module-instances">
<h1>Properties of Module Instances</h1>
<p>Module instances are ordinary objects that inherit properties from the Module prototype object (the intrinsic, %Module.prototype%). Module instances are initially created with the internal slots described in <emu-xref href="#table-internal-slots-of-module-instances"></emu-xref>.</p>
<emu-table id="table-internal-slots-of-module-instances" caption="Internal Slots of Module Instances">
<table>
<tbody>
<tr>
<th>Internal Slot</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>[[Module]]</td>
<td>Source Text Module Record</td>
<td>The Source Text Module Record that represents this Module Instance.</td>
</tr>
<tr>
<td>[[ModuleSourceInstance]]</td>
<td>ModuleSource Instance or *null*</td>
<td>The ModuleSource Instance associated to Module Instance. *null* if this Module Instance has not a source associated to it.</td>
</tr>
<tr>
<td>[[HandlerValue]]</td>
<td>an ECMAScript language value</td>
<td>This is the *this* value used for invocation of the hook functions.</td>
</tr>
<tr>
<td>[[ImportHook]]</td>
<td>a function object or *undefined*</td>
<td>Defaults to *undefined*. The function can return a module instance to resolve module dependencies.</td>
</tr>
<tr>
<td>[[ImportMetaHook]]</td>
<td>a function object or *undefined*</td>
<td>Defaults to *undefined*. The function can augment the `import.meta` object provided as the first argument.</td>
</tr>
</tbody>
</table>
</emu-table>
<emu-note type="editor">
A Module Instance without a [[ModuleSourceInstance]] value associated to it is a Module Instance created via the Import Reflection API where the host decides that the source is not available. E.g.: `fs` module or any built-in module in the future.
</emu-note>
</emu-clause>
</emu-clause>
</body>
</html>