?
u
m
/
super
unless the source text containing super
is eval code that is being processed by a super
within The syntax-directed operation IsStrict takes no arguments and returns a Boolean. It is defined piecewise over the following productions:
A Script Record encapsulates information about a script being evaluated. Each script record contains the fields listed in
Field Name | Value Type | Meaning |
---|---|---|
[[Realm]] |
a |
The |
[[ECMAScriptCode]] |
a |
The result of parsing the source text of this script using |
[[HostDefined]] |
anything (default value is |
Field reserved for use by |
The abstract operation ParseScript takes arguments sourceText (ECMAScript source text), realm, and hostDefined and returns a
An implementation may parse script source text and analyse it for Early Error conditions prior to evaluation of ParseScript for that script source text. However, the reporting of any errors must be deferred until the point where this specification actually performs ParseScript upon that source text.
The abstract operation ScriptEvaluation takes argument scriptRecord and returns either a
The abstract operation GlobalDeclarationInstantiation takes arguments script (a
When an
It performs the following steps when called:
Unlike explicit var or function declarations, properties that are directly created on the
super
.
The duplicate export default
The abstract operation ImportedLocalNames takes argument importEntries (a
The syntax-directed operation ModuleRequests takes no arguments and returns a
A Module Record 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.
For specification purposes Module Record values are values of the
Module Record defines the fields listed in
Field Name | Value Type | Meaning |
---|---|---|
[[Realm]] |
a |
The |
[[Environment]] |
a |
The |
[[Namespace]] |
an Object or |
The Module Namespace Object ( |
[[HostDefined]] |
anything (default value is |
Field reserved for use by |
Method | Purpose |
---|---|
GetExportedNames([exportStarSet]) | Return a list of all names that are either directly or indirectly exported from this module. |
ResolveExport(exportName [, resolveSet]) |
Return the binding of a name exported by this module. Bindings are represented by a ResolvedBinding Record, of the form { [[Module]]: Each time this operation is called with a specific exportName, resolveSet pair as arguments it must return the same result if it completes normally. |
Link() |
Prepare the module for evaluation by transitively resolving all module dependencies and creating a |
Evaluate() |
Returns a promise for the evaluation of this module and its dependencies, resolving on successful evaluation or if it has already been evaluated successfully, and rejecting for an evaluation error or if it has already been evaluated unsuccessfully. If the promise is rejected, Link must have completed successfully prior to invoking this method. |
A Cyclic Module Record is used to represent information about a module that can participate in dependency cycles with other modules that are subclasses of the
In addition to the fields defined in
Field Name | Value Type | Meaning |
---|---|---|
[[Status]] |
|
Initially |
[[EvaluationError]] |
an |
A |
[[DFSIndex]] |
an |
Auxiliary field used during Link and Evaluate only. If [[Status]] is |
[[DFSAncestorIndex]] |
an |
Auxiliary field used during Link and Evaluate only. If [[Status]] is |
[[RequestedModules]] |
a |
A |
[[CycleRoot]] |
a |
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 equal to the [[DFSIndex]] of its [[CycleRoot]]. |
[[HasTLA]] | a Boolean |
Whether this module is individually asynchronous (for example, if it's a |
[[AsyncEvaluation]] | a Boolean |
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 |
[[TopLevelCapability]] |
a |
If this module is the [[CycleRoot]] of some cycle, and Evaluate() was called on some module in that cycle, this field contains the |
[[AsyncParentModules]] |
a |
If this module or a dependency has [[HasTLA]] |
[[PendingAsyncDependencies]] |
an |
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. |
In addition to the methods defined in
Method | Purpose |
---|---|
InitializeEnvironment() |
Initialize the |
ExecuteModule( [ promiseCapability ] ) |
Evaluate the module's code within its |
The Link concrete method of a
The abstract operation InnerModuleLinking takes arguments module (a
The Evaluate concrete method of a
The abstract operation InnerModuleEvaluation takes arguments module (a
A module is
Any modules depending on a module of an asynchronous cycle when that cycle is not
The abstract operation ExecuteAsyncModule takes argument module (a
The abstract operation GatherAvailableAncestors takes arguments module (a
When an asynchronous execution for a root module is fulfilled, this function determines the list of modules which are able to synchronously execute together on this completion, populating them in execList.
The abstract operation AsyncModuleExecutionFulfilled takes argument module (a
The abstract operation AsyncModuleExecutionRejected takes arguments module (a
This non-normative section gives a series of examples of the linking and evaluation of a few common module graphs, with a specific focus on how errors can occur.
First consider the following simple module graph:
Let's first assume that there are no error conditions. When a
Consider then cases involving linking errors. If
Finally, consider a case involving evaluation errors. If
The difference here between linking and evaluation errors is due to how evaluation must be only performed once, as it can cause side effects; it is thus important to remember whether evaluation has already been performed, even if unsuccessfully. (In the error case, it makes sense to also remember the exception because otherwise subsequent Evaluate() calls would have to synthesize a new one.) Linking, on the other hand, is side-effect-free, and thus even if it fails, it can be retried at a later time with no issues.
Now consider a different type of error condition:
In this scenario, module A declares a dependency on some other module, but no
Now, consider a module graph with a cycle:
Here we assume that the entry point is module A, so that the
An analogous story occurs for the evaluation phase of a cyclic module graph, in the success case.
Now consider a case where A has an linking error; for example, it tries to import a binding from C that does not exist. In that case, the above steps still occur, including the early return from the second call to
Alternatively, consider a case where A has an evaluation error; for example, its source code throws an exception. In that case, the evaluation-time analog of the above steps still occurs, including the early return from the second call to await
through the whole dependency graph through the
Lastly, consider a module graph with a cycle, where all modules complete asynchronously:
Linking happens as before, and all modules end up with [[Status]] set to
Calling A.Evaluate() calls
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] |
---|---|---|---|---|---|---|
A | 0 | 0 | « » | 2 (B and C) | ||
B | 1 | 0 | « A » | 1 (D) | ||
C | 2 | 0 | « A » | 2 (D and E) | ||
D | 3 | 0 | « B, C » | 0 | ||
E | 4 | 4 | « C » | 0 |
Let us assume that E finishes executing first. When that happens,
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] |
---|---|---|---|---|---|---|
C | 2 | 0 | « A » | 1 (D) | ||
E | 4 | 4 | « C » | 0 |
D is next to finish (as it was the only module that was still executing). When that happens, await
). The fields of the updated modules are as given in
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] |
---|---|---|---|---|---|---|
B | 1 | 0 | « A » | 0 | ||
C | 2 | 0 | « A » | 0 | ||
D | 3 | 0 | « B, C » | 0 |
Let us assume that C finishes executing next. When that happens,
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] |
---|---|---|---|---|---|---|
A | 0 | 0 | « » | 1 (B) | ||
C | 2 | 0 | « A » | 0 |
Then, B finishes executing. When that happens,
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] |
---|---|---|---|---|---|---|
A | 0 | 0 | « » | 0 | ||
B | 1 | 0 | « A » | 0 |
Finally, A finishes executing. When that happens,
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] |
---|---|---|---|---|---|---|
A | 0 | 0 | « » | 0 |
Alternatively, consider a failure case where C fails execution and returns an error before B has finished executing. When that happens,
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] | [[EvaluationError]] |
---|---|---|---|---|---|---|---|
A | 0 | 0 | « » | 1 (B) | |||
C | 2 | 1 | « A » | 0 | C's evaluation error |
A will be rejected with the same error as C since C will call
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] | [[EvaluationError]] |
---|---|---|---|---|---|---|---|
A | 0 | 0 | « » | 0 | C's Evaluation Error |
Then, B finishes executing without an error. When that happens,
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] | [[EvaluationError]] |
---|---|---|---|---|---|---|---|
A | 0 | 0 | « » | 0 | C's Evaluation Error | ||
B | 1 | 0 | « A » | 0 |
A Source Text Module Record is used to represent information about a module that was defined from ECMAScript source text (
A
In addition to the fields defined in
Field Name | Value Type | Meaning |
---|---|---|
[[ECMAScriptCode]] |
a |
The result of parsing the source text of this module using |
[[Context]] |
an ECMAScript |
The |
[[ImportMeta]] | an Object |
An object exposed through the import.meta meta property. It is |
[[ImportEntries]] |
a |
A |
[[LocalExportEntries]] |
a |
A |
[[IndirectExportEntries]] |
a |
A export * as namespace declarations.
|
[[StarExportEntries]] |
a |
A export * declarations that occur within the module, not including export * as namespace declarations.
|
An ImportEntry Record is a
Field Name | Value Type | Meaning |
---|---|---|
[[ModuleRequest]] | a String |
String value of the |
[[ImportName]] |
a String or |
The name under which the desired binding is exported by the module identified by [[ModuleRequest]]. The value |
[[LocalName]] | a String | The name that is used to locally access the imported value from within the importing module. |
Import Statement Form | [[ModuleRequest]] | [[ImportName]] | [[LocalName]] |
---|---|---|---|
import v from "mod";
|
|
|
|
import * as ns from "mod";
|
|
|
|
import {x} from "mod";
|
|
|
|
import {x as v} from "mod";
|
|
|
|
import "mod";
|
An |
An ExportEntry Record is a
Field Name | Value Type | Meaning |
---|---|---|
[[ExportName]] |
a String or |
The name used to export this binding by this module. |
[[ModuleRequest]] |
a String or |
The String value of the |
[[ImportName]] |
a String, |
The name under which the desired binding is exported by the module identified by [[ModuleRequest]]. export * as ns from "mod" declarations. export * from "mod" declarations.
|
[[LocalName]] |
a String or |
The name that is used to locally access the exported value from within the importing module. |
Export Statement Form | [[ExportName]] | [[ModuleRequest]] | [[ImportName]] | [[LocalName]] |
---|---|---|---|---|
export var v;
|
|
|
|
|
export default function f() {}
|
|
|
|
|
export default function () {}
|
|
|
|
|
export default 42;
|
|
|
|
|
export {x};
|
|
|
|
|
export {v as x};
|
|
|
|
|
export {x} from "mod";
|
|
|
|
|
export {v as x} from "mod";
|
|
|
|
|
export * from "mod";
|
|
|
|
|
export * as ns from "mod";
|
|
|
|
|
The following definitions specify the required concrete methods and other
The abstract operation ParseModule takes arguments sourceText (ECMAScript source text), realm, and hostDefined and returns a
await
.An implementation may parse module source text and analyse 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.
The GetExportedNames concrete method of a
GetExportedNames does not filter out or throw an exception for names that have ambiguous star export bindings.
The ResolveExport concrete method of a
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
If a defining module is found, a
It performs the following steps when called:
default
export was not explicitly defined by this module.default
export cannot be provided by an export * from "mod"
declaration.*
import that includes the requested name.The InitializeEnvironment concrete method of a
The ExecuteModule concrete method of a
The import()
An example of when referencingScriptOrModule can be
<button type="button" onclick="import('./foo.mjs')">Click me</button>
there will be no import()
An implementation of HostResolveImportedModule must conform to the following requirements:
Multiple different referencingScriptOrModule, specifier pairs may map to the same
The import()
An implementation of HostImportModuleDynamically must conform to the following requirements:
The actual process performed is
The abstract operation FinishDynamicImport takes arguments referencingScriptOrModule, specifier, promiseCapability (a import()
The abstract operation GetModuleNamespace takes argument module (an instance of a concrete subclass of
The only way GetModuleNamespace can throw is via one of the triggered
The value of a
The syntax-directed operation ImportEntries takes no arguments and returns a
The syntax-directed operation ImportEntriesForModule takes argument module and returns a
The above rule means that each
The syntax-directed operation ExportedBindings takes no arguments and returns a
ExportedBindings are the locally bound names that are explicitly associated with a
It is defined piecewise over the following productions:
The syntax-directed operation ExportedNames takes no arguments and returns a
ExportedNames are the externally visible names that a
It is defined piecewise over the following productions:
The syntax-directed operation ExportEntries takes no arguments and returns a
The syntax-directed operation ExportEntriesForModule takes argument module and returns a
The syntax-directed operation ReferencedBindings takes no arguments and returns a