?um/p1-90`super,则为语法错误,除非super 的源文本是正在由直接 eval 处理的 eval 代码。直接 eval 内 super 的其他The syntax-directed operation ScriptIsStrict takes no arguments and returns a Boolean. It is defined piecewise over the following productions:
Script Record 封装关于正在求值的脚本的信息。每个 script record 都
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Realm]] |
a |
创建此脚本所在的 |
| [[ECMAScriptCode]] |
a |
解析此脚本源文本的结果。 |
| [[LoadedModules]] |
a |
从此脚本导入的说明符字符串到已解析 |
| [[HostDefined]] |
anything(默认值为 |
为需要把附加信息与脚本关联起来的 |
The abstract operation ParseScript takes arguments sourceText (a String or a sequence of Unicode code points), realm (a
实现可以在对脚本源文本求值 ParseScript 之前解析脚本源文本并分析其
The abstract operation ScriptEvaluation takes argument scriptRecord (a
The abstract operation GlobalDeclarationInstantiation takes arguments script (a
当为求值脚本而建立执行上下文时,声明会在当前全局环境中实例化。代码中声明的每个全局绑定都会被实例化。
它在被调用时执行以下步骤:
var 和 function 绑定(由非严格直接 eval 引入的那些绑定除外)是不可配置的,因此是受限制的全局属性。不同于显式 var 或函数声明,直接在
super,则为语法错误。
重复 export default
The abstract operation ImportedLocalNames takes argument importEntries (a
ModuleRequest Record 表示带有给定导入属性的导入模块请求。它由以下字段组成:
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Specifier]] | a String | 模块说明符 |
| [[Attributes]] |
a |
导入属性 |
LoadedModuleRequest Record 表示导入模块的请求以及所得的
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Specifier]] | a String | 模块说明符 |
| [[Attributes]] |
a |
导入属性 |
| [[Module]] |
a |
与此模块请求对应的已加载模块 |
ImportAttribute Record 由以下字段组成:
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Key]] | a String |
|
| [[Value]] | a String | 属性值 |
The abstract operation ModuleRequestsEqual takes arguments x (a
The syntax-directed operation ModuleRequests takes no arguments and returns a
Module Record 封装关于单个模块的导入和导出的结构信息。此信息用于链接一组相互连接模块的导入和导出。Module Record
出于规范目的,Module Record 值是
Module Record 定义
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Realm]] |
a |
创建此模块所在的 |
| [[Environment]] |
a |
|
| [[Namespace]] |
an Object or |
如果已为此模块创建 Module Namespace Object( |
| [[HostDefined]] |
anything(默认值为 |
为需要把附加信息与模块关联起来的 |
| 方法 | 目的 | 定义 |
|---|---|---|
| LoadRequestedModules ( [ hostDefined ] ) | The abstract method LoadRequestedModules takes optional argument hostDefined (anything) and returns a Promise. 它通过递归加载所有依赖项,为模块链接做准备。 |
在本规范内,它在以下类型中有定义; |
| GetExportedNames ( [ exportStarSet ] ) | The abstract method GetExportedNames takes optional argument exportStarSet (a 它返回从此模块直接或间接导出的所有名称的列表。 在调用此方法之前, |
在本规范内,它在以下类型中有定义; |
| ResolveExport ( exportName [ , resolveSet ] ) | The abstract method ResolveExport takes argument exportName (a String) and optional argument resolveSet (a 它返回此模块导出名称的绑定。绑定由 ResolvedBinding Record 表示,其形式为 { [[Module]]: 每次以特定的 exportName、resolveSet 参数对调用此操作时,都必须返回相同的结果。 在调用此方法之前, |
在本规范内,它在以下类型中有定义; |
| Link ( ) | The abstract method Link takes no arguments and returns either a normal completion containing 它通过传递地解析所有模块依赖项并创建 在调用此方法之前, |
在本规范内,它在以下类型中有定义; |
| Evaluate ( ) | The abstract method Evaluate takes no arguments and returns a Promise. 它返回一个用于此模块及其依赖项求值的 promise,该 promise 会在成功求值时或已经成功求值过时兑现,并在求值错误或已经求值失败过时拒绝。如果 promise 被拒绝,期望 在调用此方法之前, |
在本规范内,它在以下类型中有定义; |
The abstract operation EvaluateModuleSync takes argument module (a
Cyclic Module Record 用于表示关于某个模块的信息,该模块可以与作为
除了
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Status]] |
|
初始为 |
| [[EvaluationError]] |
a throw completion or |
表示求值期间发生的异常的 throw completion。如果没有发生异常,或 [[Status]] 不是 |
| [[DFSAncestorIndex]] |
an |
仅在 |
| [[RequestedModules]] |
a |
与此模块中导入关联的 |
| [[LoadedModules]] |
a |
从由此 |
| [[CycleRoot]] |
a |
循环中第一个被访问的模块,即强连通分量的根 DFS 祖先。对于不在循环中的模块,这将是该模块自身。一旦 |
| [[HasTLA]] | a Boolean |
此模块是否单独异步(例如,如果它是 |
| [[AsyncEvaluationOrder]] |
|
此字段最初设置为 |
| [[TopLevelCapability]] |
a |
如果此模块是某个循环的 [[CycleRoot]],且该循环中的某个模块调用了 |
| [[AsyncParentModules]] |
a |
如果此模块或某个依赖项具有 [[HasTLA]] |
| [[PendingAsyncDependencies]] |
an |
如果此模块有任何异步依赖项,则此字段跟踪此模块剩余要执行的异步依赖模块数量。具有异步依赖项的模块会在此字段达到 0 且没有执行错误时执行。 |
除了
| 方法 | 目的 | 定义 |
|---|---|---|
| InitializeEnvironment ( ) | The abstract method InitializeEnvironment takes no arguments and returns either a normal completion containing |
在本规范内,它在以下类型中有定义; |
| ExecuteModule ( [ capability ] ) | The abstract method ExecuteModule takes optional argument capability (a |
在本规范内,它在以下类型中有定义; |
GraphLoadingState Record 是一个
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[PromiseCapability]] |
a |
加载过程结束时要 resolve 的 promise。 |
| [[IsLoading]] | a Boolean | 如果加载过程尚未结束(既没有成功,也没有出错),则为 true。 |
| [[PendingModulesCount]] |
a non-negative |
它跟踪待处理的 |
| [[Visited]] |
a |
它是当前加载过程中已经加载的 |
| [[HostDefined]] |
anything (default value is |
它 |
以下是
The
<link rel="preload" as="..."> 标签设置正确的 fetch destination。
import() 表达式永远不会设置 hostDefined 参数。
The abstract operation InnerModuleLoading takes arguments state (a
The abstract operation ContinueModuleLoading takes arguments state (a
The
The abstract operation InnerModuleLinking takes arguments module (a
The
The abstract operation InnerModuleEvaluation takes arguments module (a
模块在被 InnerModuleEvaluation 遍历期间是
当异步循环不处于
The abstract operation ExecuteAsyncModule takes argument module (a
The abstract operation GatherAvailableAncestors takes arguments module (a
当根 module 的异步执行被 fulfilled 时,此函数会确定能够在此完成时一起同步执行的模块列表,并将其填充到 execList 中。
The abstract operation AsyncModuleExecutionFulfilled takes argument module (a
The abstract operation AsyncModuleExecutionRejected takes arguments module (a
本非规范性小节给出一些常见模块图的链接和求值的一系列示例,并特别关注错误如何发生。
首先考虑以下简单模块图:
我们先假设没有错误条件。当
接下来考虑在成功调用 A.
最后,考虑在成功调用
现在考虑另一种类型的错误条件:
在此场景中,模块 A 声明了对某个其他模块的依赖,但不存在该模块的
这里加载、链接和求值错误之间的差异,是由于以下特性:
现在,考虑一个带有循环的模块图:
这里我们假设入口点是模块 A,因此
然后
在循环模块图求值阶段的成功情况下,也会发生类似的过程。
现在考虑 A 有链接错误的情况;例如,它尝试从 C 导入一个不存在的绑定。在这种情况下,上述步骤仍会发生,包括第二次在 A 上调用
或者,考虑 A 有求值错误的情况;例如,其源代码抛出异常。在这种情况下,上述步骤的求值时类比仍会发生,包括第二次在 A 上调用 await 或依赖顶层 await 的模块,通过
最后,考虑一个带有循环且所有模块都异步完成的模块图:
加载和链接按之前一样发生,并且所有模块最终的 [[Status]] 都设置为
调用 A.
|
字段
|
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 和 C) | 1(D) | 2(D 和 E) | 0 | 0 |
让我们假设 E 最先完成执行。当这发生时,会调用
|
字段
|
C | E |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 4 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | 3 | |
| [[AsyncParentModules]] | « A » | « C » |
| [[PendingAsyncDependencies]] | 1(D) | 0 |
D 接下来完成(因为它是唯一仍在执行的模块)。当这发生时,会再次调用 await,则可能与 B 并行)。更新后的模块字段如
|
字段
|
B | C | D |
|---|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 | 0 |
| [[Status]] | |||
| [[AsyncEvaluationOrder]] | 1 | 3 | |
| [[AsyncParentModules]] | « A » | « A » | « B, C » |
| [[PendingAsyncDependencies]] | 0 | 0 | 0 |
让我们假设 C 接下来完成执行。当这发生时,会再次调用
|
字段
|
A | C |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | 4 | |
| [[AsyncParentModules]] | « » | « A » |
| [[PendingAsyncDependencies]] | 1(B) | 0 |
然后,B 完成执行。当这发生时,会再次调用
|
字段
|
A | B |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | 4 | |
| [[AsyncParentModules]] | « » | « A » |
| [[PendingAsyncDependencies]] | 0 | 0 |
最后,A 完成执行。当这发生时,会再次调用
|
字段
|
A |
|---|---|
| [[DFSAncestorIndex]] | 0 |
| [[Status]] | |
| [[AsyncEvaluationOrder]] | |
| [[AsyncParentModules]] | « » |
| [[PendingAsyncDependencies]] | 0 |
或者,考虑一个失败情况,其中 C 执行失败,并在 B 完成执行之前返回错误。当这发生时,会调用
|
字段
|
A | C |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | ||
| [[AsyncParentModules]] | « » | « A » |
| [[PendingAsyncDependencies]] | 1(B) | 0 |
| [[EvaluationError]] | C 的求值错误 |
由于 C 会以 C 的错误在 A 上调用
|
字段
|
A |
|---|---|
| [[DFSAncestorIndex]] | 0 |
| [[Status]] | |
| [[AsyncEvaluationOrder]] | |
| [[AsyncParentModules]] | « » |
| [[PendingAsyncDependencies]] | 0 |
| [[EvaluationError]] | C 的 |
然后,B 完成执行且没有错误。当这发生时,会再次调用
|
字段
|
A | B |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | 4 | 1 |
| [[AsyncParentModules]] | « » | « A » |
| [[PendingAsyncDependencies]] | 0 | 0 |
| [[EvaluationError]] | C 的 |
Source Text Module Record 用于表示关于从 ECMAScript 源文本(
除了
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[ECMAScriptCode]] |
a |
使用 |
| [[Context]] |
an |
与此模块关联的执行上下文。直到模块环境被初始化之前,它都是 |
| [[ImportMeta]] |
an Object or |
通过 import.meta 元属性暴露的对象。直到 ECMAScript 代码访问它之前,它都是 |
| [[ImportEntries]] |
a |
从此模块代码派生出的 |
| [[LocalExportEntries]] |
a |
从此模块代码派生出的 |
| [[IndirectExportEntries]] |
a |
从此模块代码派生出的 export * as namespace 声明的导出。
|
| [[StarExportEntries]] |
a |
从此模块代码派生出的 export * 声明,但不包括 export * as namespace 声明。
|
ImportEntry Record 是摘要化关于单个声明式导入的信息的
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[ModuleRequest]] |
a |
表示 |
| [[ImportName]] |
a String or |
所需绑定由 [[ModuleRequest]] 标识的模块导出时使用的名称。值 |
| [[LocalName]] | a String | 在导入模块内部本地访问导入值时使用的名称。 |
| Import 语句形式 | [[ModuleRequest]] | [[ImportName]] | [[LocalName]] |
|---|---|---|---|
import v from "mod";
|
|
|
|
import * as ns from "mod";
|
|
|
|
import {x} from "mod";
|
|
|
|
import {x as v} from "mod";
|
|
|
|
import "mod";
|
不会创建 |
||
ExportEntry Record 是摘要化关于单个声明式导出的信息的
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[ExportName]] |
a String or |
此绑定被此模块导出时使用的名称。 |
| [[ModuleRequest]] |
a |
表示 |
| [[ImportName]] |
a String, |
所需绑定由 [[ModuleRequest]] 标识的模块导出时使用的名称。如果 export * as ns from "mod" 声明。export * from "mod" 声明。
|
| [[LocalName]] |
a String or |
在导入模块内部本地访问被导出值时使用的名称。如果被导出的值不能从模块内部本地访问,则为 |
| Export 语句形式 | [[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 abstract operation ParseModule takes arguments sourceText (a String or a sequence of Unicode code points), realm (a
export * from 以同一名称两次导出同一绑定或命名空间所产生的冲突被忽略,而不是在 await。实现可以在对模块源文本求值 ParseModule 之前解析模块源文本并分析其
以下是
The
export * 循环的起点。The
如果找到定义模块,则返回
It performs the following steps when called:
default 导出。default 导出不能由 export * from "mod" 声明提供。* 导出。以下是
The
The
Synthetic Module Record 用于表示由规范定义的模块相关信息。其导出名称在创建时静态定义,而其对应值可以随时间通过
除了
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[ExportNames]] | a |
模块的导出名称。此列表不 |
| [[EvaluationSteps]] | an |
在求值模块时要执行的初始化逻辑,以 |
The abstract operation CreateDefaultExportSyntheticModule takes argument defaultExport (an ECMAScript language value) and returns a
The abstract operation ParseJSONModule takes argument source (a String) and returns either a normal completion containing a
The abstract operation SetSyntheticModuleExport takes arguments module (a
以下是
The
The
The
The
The
The abstract operation GetImportedModule takes arguments referrer (a
The host-defined abstract operation HostLoadImportedModule takes arguments referrer (a
referrer 可以是
<button type="button" onclick="import('./foo.mjs')">Click me</button>
则在 import()
HostLoadImportedModule 的实现必须符合以下要求:
如果此操作以两个 (referrer, moduleRequest) pair 多次调用,且满足:
并且它执行
如果 moduleRequest.[[Attributes]] 有一个条目 entry,使得 entry.[[Key]] 是
实际执行的过程由
The abstract operation FinishLoadingImportedModule takes arguments referrer (a
The abstract operation AllImportAttributesSupported takes argument attrs (a
The host-defined abstract operation HostGetSupportedImportAttributes takes no arguments and returns a
HostGetSupportedImportAttributes 的实现必须符合以下要求:
HostGetSupportedImportAttributes 的默认实现是返回新的空
The abstract operation GetModuleNamespace takes argument module (an instance of a concrete subclass of
GetModuleNamespace 永远不会抛出。相反,无法解析的名称只是在此时从 namespace 中排除。它们稍后会导致真正的链接错误,除非它们全都是未在任何地方被显式请求的 ambiguous 星号导出。
The syntax-directed operation ImportEntries takes no arguments and returns a
The syntax-directed operation ImportEntriesForModule takes argument module (a
The syntax-directed operation WithClauseToAttributes takes no arguments and returns a
上述规则意味着
The syntax-directed operation ExportedBindings takes no arguments and returns a
ExportedBindings 是与
It is defined piecewise over the following productions:
The syntax-directed operation ExportedNames takes no arguments and returns a
ExportedNames 是外部可见名称,
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 (a
The syntax-directed operation ReferencedBindings takes no arguments and returns a