new
Operatorsuper
Keyword? :
),
)if
Statementdo
-while
Statementwhile
Statementfor
Statementfor
-in
,for
-of
, andfor
-await
-of
Statementscontinue
Statementbreak
Statementreturn
Statementwith
Statementswitch
Statementthrow
Statementtry
Statementdebugger
Statement?
u
m
/
p
1-9
0
`
super
unless the source text containingsuper
is eval code that is being processed by asuper
withinThe
AScript 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 argumentssourceText (
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 argumentscriptRecord (a
The abstract operation GlobalDeclarationInstantiation takes argumentsscript (a
When an
It performs the following steps when called:
var
andfunction
bindings (except those that are introduced by non-strictUnlike explicit var or function declarations, properties that are directly created on the
super
.The duplicateexport default
The abstract operation ImportedLocalNames takes argumentimportEntries (a
AModuleRequest Record represents the request to import a module with given import attributes. It consists of the following fields:
Field Name | Value Type | Meaning |
---|---|---|
[[Specifier]] | a String | The module specifier |
[[Attributes]] | a | The import attributes |
ALoadedModuleRequest Record represents the request to import a module together with the resulting
Field Name | Value Type | Meaning |
---|---|---|
[[Specifier]] | a String | The module specifier |
[[Attributes]] | a | The import attributes |
[[Module]] | a | The loaded module corresponding to this module request |
AnImportAttribute Record consists of the following fields:
Field Name | Value Type | Meaning |
---|---|---|
[[Key]] | a String | The attribute key |
[[Value]] | a String | The attribute value |
The abstract operation ModuleRequestsEqual takes argumentsleft (a
The
AModule 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 aResolvedBinding Record, of the form {[[Module]]: Each time this operation is called with a specificexportName,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. |
The abstract operation EvaluateModuleSync takes argumentmodule (a
ACyclic 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 |
[[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 with the relative import attributes 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 depth-first traversal index of its[[CycleRoot]]. |
[[HasTLA]] | a Boolean | Whether this module is individually asynchronous (for example, if it's a |
[[AsyncEvaluationOrder]] | This field is initially set to | |
[[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 |
AGraphLoadingState 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 following are the concrete methods for
The LoadRequestedModules concrete method of a
<link rel="preload" as="...">
tags.import()
expressions never set thehostDefined parameter.The abstract operation InnerModuleLoading takes argumentsstate (a
The abstract operation ContinueModuleLoading takes argumentsstate (a
The Link concrete method of a
The abstract operation InnerModuleLinking takes argumentsmodule (a
The Evaluate concrete method of a
The abstract operation InnerModuleEvaluation takes argumentsmodule (a
A module is
Any modules depending on a module of an asynchronous cycle when that cycle is not
The abstract operation ExecuteAsyncModule takes argumentmodule (a
The abstract operation GatherAvailableAncestors takes argumentsmodule (a
When an asynchronous execution for a rootmodule is fulfilled, this function determines the list of modules which are able to synchronously execute together on this completion, populating them inexecList.
The abstract operation AsyncModuleExecutionFulfilled takes argumentmodule (a
The abstract operation AsyncModuleExecutionRejected takes argumentsmodule (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 toA.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, moduleA 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 moduleA, 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 whereA has a linking error; for example, it tries to import a binding fromC 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 whereA has an evaluation error; for example, its source code throws an exception. In that case, the evaluation-time analogue of the above steps still occurs, including the early return from the second call toawait
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
CallingA.Evaluate() calls
FieldModule | A | B | C | D | E |
---|---|---|---|---|---|
[[DFSAncestorIndex]] | 0 | 0 | 0 | 0 | 4 |
[[Status]] | |||||
[[AsyncEvaluationOrder]] | 4 | 1 | 3 | 0 | 2 |
[[AsyncParentModules]] | « » | «A » | «A » | «B,C » | «C » |
[[PendingAsyncDependencies]] | 2 (B andC) | 1 (D) | 2 (D andE) | 0 | 0 |
Let us assume thatE finishes executing first. When that happens,
FieldModule | C | E |
---|---|---|
[[DFSAncestorIndex]] | 0 | 4 |
[[Status]] | ||
[[AsyncEvaluationOrder]] | 3 | |
[[AsyncParentModules]] | «A » | «C » |
[[PendingAsyncDependencies]] | 1 (D) | 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
FieldModule | B | C | D |
---|---|---|---|
[[DFSAncestorIndex]] | 0 | 0 | 0 |
[[Status]] | |||
[[AsyncEvaluationOrder]] | 1 | 3 | |
[[AsyncParentModules]] | «A » | «A » | «B,C » |
[[PendingAsyncDependencies]] | 0 | 0 | 0 |
Let us assume thatC finishes executing next. When that happens,
FieldModule | A | C |
---|---|---|
[[DFSAncestorIndex]] | 0 | 0 |
[[Status]] | ||
[[AsyncEvaluationOrder]] | 4 | |
[[AsyncParentModules]] | « » | «A » |
[[PendingAsyncDependencies]] | 1 (B) | 0 |
Then,B finishes executing. When that happens,
FieldModule | A | B |
---|---|---|
[[DFSAncestorIndex]] | 0 | 0 |
[[Status]] | ||
[[AsyncEvaluationOrder]] | 4 | |
[[AsyncParentModules]] | « » | «A » |
[[PendingAsyncDependencies]] | 0 | 0 |
Finally,A finishes executing. When that happens,
FieldModule | A |
---|---|
[[DFSAncestorIndex]] | 0 |
[[Status]] | |
[[AsyncEvaluationOrder]] | |
[[AsyncParentModules]] | « » |
[[PendingAsyncDependencies]] | 0 |
Alternatively, consider a failure case whereC fails execution and returns an error beforeB has finished executing. When that happens,
FieldModule | A | C |
---|---|---|
[[DFSAncestorIndex]] | 0 | 0 |
[[Status]] | ||
[[AsyncEvaluationOrder]] | ||
[[AsyncParentModules]] | « » | «A » |
[[PendingAsyncDependencies]] | 1 (B) | 0 |
[[EvaluationError]] | C's evaluation error |
A will be rejected with the same error asC sinceC will call
FieldModule | A |
---|---|
[[DFSAncestorIndex]] | 0 |
[[Status]] | |
[[AsyncEvaluationOrder]] | |
[[AsyncParentModules]] | « » |
[[PendingAsyncDependencies]] | 0 |
[[EvaluationError]] | C's |
Then,B finishes executing without an error. When that happens,
FieldModule | A | B |
---|---|---|
[[DFSAncestorIndex]] | 0 | 0 |
[[Status]] | ||
[[AsyncEvaluationOrder]] | 4 | 1 |
[[AsyncParentModules]] | « » | «A » |
[[PendingAsyncDependencies]] | 0 | 0 |
[[EvaluationError]] | C's |
ASource 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 theimport.meta meta property. It is |
[[ImportEntries]] | a | A |
[[LocalExportEntries]] | a | A |
[[IndirectExportEntries]] | a | Aexport * as namespace declarations. |
[[StarExportEntries]] | a | Aexport * declarations that occur within the module, not includingexport * as namespace declarations. |
AnImportEntry Record is a
Field Name | Value Type | Meaning |
---|---|---|
[[ModuleRequest]] | a | |
[[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 |
AnExportEntry Record is a
Field Name | Value Type | Meaning |
---|---|---|
[[ExportName]] | a String or | The name used to export this binding by this module. |
[[ModuleRequest]] | a | 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 argumentssourceText (
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 following are the concrete methods for
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 anexport * from "mod"
declaration.*
import that includes the requested name.The following are the concrete methods for
The InitializeEnvironment concrete method of a
The ExecuteModule concrete method of a
ASynthetic Module Record is used to represent information about a module that is defined by specifications. Its exported names are statically defined at creation, while their corresponding values can change over time using
In addition to the fields defined in
Field Name | Value Type | Meaning |
---|---|---|
[[ExportNames]] | a | The names of the exports of the module. This list does not contain duplicates. |
[[EvaluationSteps]] | an | The initialization logic to perform upon evaluation of the module, taking the |
The abstract operation CreateDefaultExportSyntheticModule takes argumentdefaultExport (an
The abstract operation ParseJSONModule takes argumentsource (a String) and returns either a
The abstract operation SetSyntheticModuleExport takes argumentsmodule (a
The following are the concrete methods for
The LoadRequestedModules concrete method of a
The GetExportedNames concrete method of a
The ResolveExport concrete method of a
The Link concrete method of a
The Evaluate concrete method of a
The abstract operation GetImportedModule takes argumentsreferrer (a
The
An example of whenreferrer can be a
<buttontype="button"onclick="import('./foo.mjs')">Click me</button>
there will be noimport()
An implementation of HostLoadImportedModule must conform to the following requirements:
If this operation is called multiple times with two (referrer,moduleRequest) pairs such that:
and it performs
IfmoduleRequest.[[Attributes]] has an entryentry such thatentry.[[Key]] is
The actual process performed is
The abstract operation FinishLoadingImportedModule takes argumentsreferrer (a
The abstract operation AllImportAttributesSupported takes argumentattributes (a
The
An implementation of HostGetSupportedImportAttributes must conform to the following requirements:
The default implementation of HostGetSupportedImportAttributes is to return a new empty
The abstract operation GetModuleNamespace takes argumentmodule (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
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