?
u
m
/
p
1-9
super
unless the source text containing super
is eval code that is being processed by a super
within The
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. |
[[LoadedModules]] |
a |
A map from the specifier strings imported by this script to the resolved |
[[HostDefined]] |
anything (default value is |
Field reserved for use by |
The abstract operation ParseScript takes arguments sourceText (
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 (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
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 |
---|---|
LoadRequestedModules( [ hostDefined ] ) |
Prepares the module for linking by recursively loading all its dependencies, and returns a promise. |
GetExportedNames([exportStarSet]) |
Return a list of all names that are either directly or indirectly exported from this module. LoadRequestedModules must have completed successfully prior to invoking this method. |
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. LoadRequestedModules must have completed successfully prior to invoking this method. |
Link() |
Prepare the module for evaluation by transitively resolving all module dependencies and creating a LoadRequestedModules must have completed successfully prior to invoking this method. |
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]] |
a |
A |
[[DFSIndex]] |
an |
Auxiliary field used during Link and Evaluate only. If [[Status]] is either |
[[DFSAncestorIndex]] |
an |
Auxiliary field used during Link and Evaluate only. If [[Status]] is either |
[[RequestedModules]] |
a |
A |
[[LoadedModules]] |
a |
A map from the specifier strings used by the module represented by this record to request the importation of a module to the resolved |
[[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 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 |
A GraphLoadingState Record is a
Field Name | Value Type | Meaning |
---|---|---|
[[PromiseCapability]] |
a |
The promise to resolve when the loading process finishes. |
[[IsLoading]] | a Boolean | It is true if the loading process has not finished yet, neither successfully nor with an error. |
[[PendingModulesCount]] |
a non-negative |
It tracks the number of pending |
[[Visited]] |
a |
It is a list of the |
[[HostDefined]] |
anything (default value is |
It contains |
The LoadRequestedModules concrete method of a
<link rel="preload" as="...">
tags.
import()
expressions never set the hostDefined parameter.
The abstract operation InnerModuleLoading takes arguments state (a
The abstract operation ContinueModuleLoading takes arguments state (a
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, after a successful call to A.LoadRequestedModules(). If
Finally, consider a case involving evaluation errors after a successful call to Link(). If
Now consider a different type of error condition:
In this scenario, module A declares a dependency on some other module, but no
The difference here between loading, linking and evaluation errors is due to the following characteristic:
Now, consider a module graph with a cycle:
Here we assume that the entry point is module A, so that the
Then 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 a 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:
Loading and linking happen 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 |
Then, B finishes executing without an error. When that happens,
Module | [[DFSIndex]] | [[DFSAncestorIndex]] | [[Status]] | [[AsyncEvaluation]] | [[AsyncParentModules]] | [[PendingAsyncDependencies]] | [[EvaluationError]] |
---|---|---|---|---|---|---|---|
A | 0 | 0 | « » | 0 | C's |
||
B | 1 | 0 | « A » | 0 |
A Source Text Module Record is used to represent information about a module that was defined from
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 |
The |
[[ImportMeta]] |
an Object or |
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 (
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 abstract operation GetImportedModule takes arguments referrer (a
The
An example of when referrer can be a
<button type="button" onclick="import('./foo.mjs')">Click me</button>
there will be no import()
An implementation of HostLoadImportedModule must conform to the following requirements:
The actual process performed is
The abstract operation FinishLoadingImportedModule takes arguments referrer (a
The abstract operation GetModuleNamespace takes argument module (an instance of a concrete subclass of
GetModuleNamespace never throws. Instead, unresolvable names are simply excluded from the namespace at this point. They will lead to a real linking error later unless they are all ambiguous star exports that are not explicitly requested anywhere.
The value of a
The
The
The above rule means that each
The
ExportedBindings are the locally bound names that are explicitly associated with a
It is defined piecewise over the following productions:
The
ExportedNames are the externally visible names that a
It is defined piecewise over the following productions:
The
The
The