This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathspec.emu
264 lines (257 loc) · 16.4 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
<!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: dynamic modules reform
stage: 1
contributors: Caridy Patiño
</pre>
<!-- es6num="15.2.1.16" -->
<emu-table id="table-38" caption="Additional Fields of Source Text Module Records">
<table>
<tbody>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
[[ImportEntries]]
</td>
<td>
List of ImportEntry Records
</td>
<td>
A List of ImportEntry records derived from the code of this module.
</td>
</tr>
<tr>
<td>
<ins>[[PendingImportEntries]]</ins>
</td>
<td>
<ins>List of ImportEntry Records</ins>
</td>
<td>
<ins>A List of ImportEntry records that are pending to be validated.</ins>
</td>
</tr>
<tr>
<td>
[[LocalExportEntries]]
</td>
<td>
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.
</td>
</tr>
</tbody>
</table>
</emu-table>
<!-- es6num="9.4.6.8" -->
<emu-clause id="sec-module-namespace-exotic-objects-get-p-receiver">
<h1>[[Get]] (_P_, _Receiver_)</h1>
<p>When the [[Get]] internal method of a module namespace exotic object _O_ is called with property key _P_ and ECMAScript language value _Receiver_, the following steps are taken:</p>
<emu-alg>
1. Assert: IsPropertyKey(_P_) is *true*.
1. If Type(_P_) is Symbol, then
1. Return ? OrdinaryGet(_O_, _P_, _Receiver_).
1. Let _exports_ be _O_.[[Exports]].
1. If _P_ is not an element of _exports_, return *undefined*.
1. Let _m_ be _O_.[[Module]].
1. Let _binding_ be ! _m_.ResolveExport(_P_, « », « »).
1. <del>Assert: _binding_ is neither *null* nor `"ambiguous"`.</del>
1. <ins>If _binding_ is `"pending"` or _binding_ is *null* or resolution is `"ambiguous"`, throw a *SyntaxError* exception.</ins>
1. Let _targetModule_ be _binding_.[[Module]].
1. Assert: _targetModule_ is not *undefined*.
1. Let _targetEnv_ be _targetModule_.[[Environment]].
1. If _targetEnv_ is *undefined*, throw a *ReferenceError* exception.
1. Let _targetEnvRec_ be _targetEnv_'s EnvironmentRecord.
1. Return ? _targetEnvRec_.GetBindingValue(_binding_.[[BindingName]], *true*).
</emu-alg>
<emu-note>
<p>ResolveExport is idempotent and side-effect free. 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>
<!-- es6num="15.2.1.16.3" -->
<emu-clause id="sec-resolveexport">
<h1>ResolveExport( _exportName_, _resolveSet_, _exportStarSet_ ) Concrete Method</h1>
<p>The ResolveExport concrete method of a Source Text Module Record with arguments _exportName_, _resolveSet_, and _exportStarSet_ performs the following steps:</p>
<emu-alg>
1. Let _module_ be this Source Text Module Record.
1. For each Record {[[Module]], [[ExportName]]} _r_ in _resolveSet_, do:
1. If _module_ and _r_.[[Module]] are the same Module Record and SameValue(_exportName_, _r_.[[ExportName]]) is *true*, then
1. Assert: This is a circular import request.
1. Return *null*.
1. Append the Record {[[Module]]: _module_, [[ExportName]]: _exportName_} to _resolveSet_.
1. For each ExportEntry Record _e_ in _module_.[[LocalExportEntries]], do
1. If SameValue(_exportName_, _e_.[[ExportName]]) is *true*, then
1. Assert: _module_ provides the direct binding for this export.
1. Return Record{[[Module]]: _module_, [[BindingName]]: _e_.[[LocalName]]}.
1. For each ExportEntry Record _e_ in _module_.[[IndirectExportEntries]], do
1. If SameValue(_exportName_, _e_.[[ExportName]]) is *true*, then
1. Assert: _module_ imports a specific binding for this export.
1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]).
1. Return ? _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_, _exportStarSet_).
1. If SameValue(_exportName_, `"default"`) is *true*, then
1. Assert: A `default` export was not explicitly defined by this module.
1. Return *null*.
1. NOTE A `default` export cannot be provided by an `export *`.
1. If _exportStarSet_ contains _module_, return *null*.
1. Append _module_ to _exportStarSet_.
1. Let _starResolution_ be *null*.
1. For each ExportEntry Record _e_ in _module_.[[StarExportEntries]], do
1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]).
1. Let _resolution_ be ? _importedModule_.ResolveExport(_exportName_, _resolveSet_, _exportStarSet_).
1. If _resolution_ is `"ambiguous"`, return `"ambiguous"`.
1. <ins>If _resolution_ is `"pending"`, return `"pending"`.</ins>
1. If _resolution_ is not *null*, then
1. If _starResolution_ is *null*, let _starResolution_ be _resolution_.
1. Else,
1. Assert: There is more than one `*` import that includes the requested name.
1. If _resolution_.[[Module]] and _starResolution_.[[Module]] are not the same Module Record or SameValue(_resolution_.[[BindingName]], _starResolution_.[[BindingName]]) is *false*, return `"ambiguous"`.
1. Return _starResolution_.
</emu-alg>
<emu-note>
<p>ResolveExport attempts to resolve an imported binding to the actual defining module and local binding name. The defining module may be the module represented by the Module Record this method was invoked on or some other module that is imported by that module. The parameter _resolveSet_ is use to detect unresolved circular import/export paths. If a pair consisting of specific Module Record and _exportName_ is reached that is already in _resolveSet_, an import circularity has been encountered. Before recursively calling ResolveExport, a pair consisting of _module_ and _exportName_ is added to _resolveSet_.</p>
<p>If a defining module is found a Record {[[Module]], [[BindingName]]} is returned. This record identifies the resolved binding of the originally requested export. If no definition was found or the request is found to be circular, *null* is returned. If the request is found to be ambiguous, the string `"ambiguous"` is returned.<ins> If the request is found to be pending, the string `"pending"` is returned.</ins></p>
</emu-note>
</emu-clause>
<!-- es6num="15.2.1.16.4" -->
<emu-clause id="sec-moduledeclarationinstantiation">
<h1>ModuleDeclarationInstantiation( ) Concrete Method</h1>
<p>The ModuleDeclarationInstantiation concrete method of a Source Text Module Record performs the following steps:</p>
<emu-alg>
1. Let _module_ be this Source Text Module Record.
1. Let _realm_ be _module_.[[Realm]].
1. Assert: _realm_ is not *undefined*.
1. Let _code_ be _module_.[[ECMAScriptCode]].
1. If _module_.[[Environment]] is not *undefined*, return NormalCompletion(~empty~).
1. Let _env_ be NewModuleEnvironment(_realm_.[[GlobalEnv]]).
1. Set _module_.[[Environment]] to _env_.
1. For each String _required_ that is an element of _module_.[[RequestedModules]] do,
1. NOTE: Before instantiating a module, all of the modules it requested must be available. An implementation may perform this test at any time prior to this point.
1. Let _requiredModule_ be ? HostResolveImportedModule(_module_, _required_).
1. Perform ? _requiredModule_.ModuleDeclarationInstantiation().
1. For each ExportEntry Record _e_ in _module_.[[IndirectExportEntries]], do
1. Let _resolution_ be ? _module_.ResolveExport(_e_.[[ExportName]], « », « »).
1. If _resolution_ is *null* or _resolution_ is `"ambiguous"`, throw a *SyntaxError* exception.
1. Assert: All named exports from _module_ are resolvable.
1. Let _envRec_ be _env_'s EnvironmentRecord.
1. For each ImportEntry Record _in_ in _module_.[[ImportEntries]], do
1. Let _importedModule_ be ! HostResolveImportedModule(_module_, _in_.[[ModuleRequest]]).
1. NOTE: The above call cannot fail because imported module requests are a subset of _module_.[[RequestedModules]], and these have been resolved earlier in this algorithm.
1. If _in_.[[ImportName]] is `"*"`, then
1. Let _namespace_ be ? GetModuleNamespace(_importedModule_).
1. Perform ! _envRec_.CreateImmutableBinding(_in_.[[LocalName]], *true*).
1. Call _envRec_.InitializeBinding(_in_.[[LocalName]], _namespace_).
1. Else,
1. Let _resolution_ be ? _importedModule_.ResolveExport(_in_.[[ImportName]], « », « »).
1. If _resolution_ is *null* or _resolution_ is `"ambiguous"`, throw a *SyntaxError* exception.
1. <ins>If _resolution_ is `"pending"`, then append _in_ to _module_.[[PendingImportEntries]].<ins>
1. <ins>Else, </ins>call _envRec_.CreateImportBinding(_in_.[[LocalName]], _resolution_.[[Module]], _resolution_.[[BindingName]]).
1. Let _varDeclarations_ be the VarScopedDeclarations of _code_.
1. Let _declaredVarNames_ be a new empty List.
1. For each element _d_ in _varDeclarations_ do
1. For each element _dn_ of the BoundNames of _d_ do
1. If _dn_ is not an element of _declaredVarNames_, then
1. Perform ! _envRec_.CreateMutableBinding(_dn_, *false*).
1. Call _envRec_.InitializeBinding(_dn_, *undefined*).
1. Append _dn_ to _declaredVarNames_.
1. Let _lexDeclarations_ be the LexicallyScopedDeclarations of _code_.
1. For each element _d_ in _lexDeclarations_ do
1. For each element _dn_ of the BoundNames of _d_ do
1. If IsConstantDeclaration of _d_ is *true*, then
1. Perform ! _envRec_.CreateImmutableBinding(_dn_, *true*).
1. Else,
1. Perform ! _envRec_.CreateMutableBinding(_dn_, *false*).
1. If _d_ is a |GeneratorDeclaration| production or a |FunctionDeclaration| production, then
1. Let _fo_ be the result of performing InstantiateFunctionObject for _d_ with argument _env_.
1. Call _envRec_.InitializeBinding(_dn_, _fo_).
1. Return NormalCompletion(~empty~).
</emu-alg>
</emu-clause>
<!-- es6num="15.2.1.16.5" -->
<emu-clause id="sec-moduleevaluation">
<h1>ModuleEvaluation() Concrete Method</h1>
<p>The ModuleEvaluation concrete method of a Source Text Module Record performs the following steps:</p>
<emu-alg>
1. Let _module_ be this Source Text Module Record.
1. Assert: ModuleDeclarationInstantiation has already been invoked on _module_ and successfully completed.
1. Assert: _module_.[[Realm]] is not *undefined*.
1. If _module_.[[Evaluated]] is *true*, return *undefined*.
1. Set _module_.[[Evaluated]] to *true*.
1. For each String _required_ that is an element of _module_.[[RequestedModules]] do,
1. Let _requiredModule_ be ! HostResolveImportedModule(_module_, _required_).
1. NOTE: ModuleDeclarationInstantiation must be completed prior to invoking this method, so every requested module is guaranteed to resolve successfully.
1. Perform ? _requiredModule_.ModuleEvaluation().
1. <ins>Let _env_ be _module_.[[Environment]]</ins>.
1. <ins>Let _envRec_ be _env_'s EnvironmentRecord</ins>.
1. <ins>For each ImportEntry Record _in_ in _module_.[[PendingImportEntries]], do</ins>
1. <ins>Let _resolution_ be ? _importedModule_.ResolveExport(_in_.[[ImportName]], « », « »)</ins>.
1. <ins>If _resolution_ is *null* or _resolution_ is `"ambiguous"` or _resultion_ is `"pending"`, throw a *SyntaxError* exception</ins>.
1. <ins>Remove ImportEntry Record _in_ from _module_.[[PendingImportEntries]]</ins>.
1. <ins>Call _envRec_.CreateImportBinding(_in_.[[LocalName]], _resolution_.[[Module]</ins>.
1. Let _moduleCxt_ be a new ECMAScript code execution context.
1. Set the Function of _moduleCxt_ to *null*.
1. Set the Realm of _moduleCxt_ to _module_.[[Realm]].
1. Set the ScriptOrModule of _moduleCxt_ to _module_.
1. Assert: _module_ has been linked and declarations in its module environment have been instantiated.
1. Set the VariableEnvironment of _moduleCxt_ to _module_.[[Environment]].
1. Set the LexicalEnvironment of _moduleCxt_ to _module_.[[Environment]].
1. Suspend the currently running execution context.
1. Push _moduleCxt_ on to the execution context stack; _moduleCxt_ is now the running execution context.
1. Let _result_ be the result of evaluating _module_.[[ECMAScriptCode]].
1. Suspend _moduleCxt_ and remove it from the execution context stack.
1. Resume the context that is now on the top of the execution context stack as the running execution context.
1. Return Completion(_result_).
</emu-alg>
</emu-clause>
<!-- es6num="15.2.1.16.1" -->
<emu-clause id="sec-parsemodule" aoid="ParseModule">
<h1>ParseModule ( _sourceText_, _realm_, _hostDefined_ )</h1>
<p>The abstract operation ParseModule with arguments _sourceText_, _realm_, and _hostDefined_ creates a Source Text Module Record based upon the result of parsing _sourceText_ as a |Module|. ParseModule performs the following steps:</p>
<emu-alg>
1. Assert: _sourceText_ is an ECMAScript source text (see clause <emu-xref href="#sec-ecmascript-language-source-code"></emu-xref>).
1. Parse _sourceText_ using |Module| as the goal symbol and analyze the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let _body_ be the resulting parse tree. Otherwise, let _body_ be a List of one or more *SyntaxError* or *ReferenceError* objects representing the parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation dependent manner. If more than one parsing error or early error is present, the number and ordering of error objects in the list is implementation dependent, but at least one must be present.
1. If _body_ is a List of errors, then return _body_.
1. Let _requestedModules_ be the ModuleRequests of _body_.
1. Let _importEntries_ be ImportEntries of _body_.
1. <ins>Let _pendingImportEntries_ be a new empty List.<ins>
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 record _ee_ in _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 `"*"`, then
1. Assert: This is a re-export of an imported module namespace object.
1. Append _ee_ to _localExportEntries_.
1. Else this is a re-export of a single name,
1. Append to _indirectExportEntries_ the Record {[[ModuleRequest]]: _ie_.[[ModuleRequest]], [[ImportName]]: _ie_.[[ImportName]], [[LocalName]]: *null*, [[ExportName]]: _ee_.[[ExportName]] }.
1. Else if _ee_.[[ImportName]] is `"*"`, then
1. Append _ee_ to _starExportEntries_.
1. Else,
1. Append _ee_ to _indirectExportEntries_.
1. Return Source Text Module Record {[[Realm]]: _realm_, [[Environment]]: *undefined*, [[HostDefined]]: _hostDefined_, [[Namespace]]: *undefined*, [[Evaluated]]: *false*, [[ECMAScriptCode]]: _body_, [[RequestedModules]]: _requestedModules_, [[ImportEntries]]: _importEntries_, <ins>[[PendingImportEntries]]: _pendingImportEntries_, </ins>[[LocalExportEntries]]: _localExportEntries_, [[StarExportEntries]]: _starExportEntries_, [[IndirectExportEntries]]: _indirectExportEntries_}.
</emu-alg>
<emu-note>
<p>An implementation may parse module source text and analyze it for Early Error conditions prior to the evaluation of ParseModule for that module source text. However, the reporting of any errors must be deferred until the point where this specification actually performs ParseModule upon that source text.</p>
</emu-note>
</emu-clause>