该规范是 ECMAScript 规范的中文翻译。当前版本对应 0d37f42 版本,我们的愿景是对该规范中文版本提供长期维护。目前翻译进度到第七章,有大量的 Pull Requests 需要校对,也希望有兴趣各路大神可参与该翻译的校对和审校工作。以下是一些参与贡献的渠道。
此标准定义了 ECMAScript 2018 语言,是 ECMAScript 语言规范的第九版。自从 1997 年第一版发布以来,ECMAScript 已经成为世界上应用最广泛的编程语言之一。他最为认知的是作为嵌入在 Web 浏览器中的语言,但也被广泛应用于服务器和嵌入式应用程序。
ECMAScript 基于几种始发技术,最著名的是 Netscape 的 JavaScript 以及 Microsoft 的 JScript。该语言由 Netscape 的 Brendan Eich 发明,并首次出现在该公司的 Navigator2.0 浏览器中。它已经出现在 Netscape 的所有后续浏览器以及 Microsoft 自 Internet Explorer3.0 开始的所有浏览器中。
ECMAScript 语言规范的制定始于 1996 年 11 月。第一版的Ecma标准在 1997 年 6 月通过 Ecma 联合大会。
该(第一版) Ecma 标准为了采用快速通道通过,被提交给 ISO/IEC JIC 1,于 1998 年 4 月被批准为国际标准 ISO/IEC16262。在 1998 年 Ecma 联合大会通过了第二版 ECMA-262,以保证完全符合 ISO/IEC 16262。第一版和第二版的变化是编辑层面的。
第三版标准引入了强大的正则表达式,更好的字符串处理,新的控制语句,try/catch 异常处理,更严格的错误定义,数字输出的格式化以及预期未来语言发展的微小变化。第三版 ECMAScript 标准于1999年12月被 Ecma 联合大会采纳,于 2002 年 6 月作为 ISO/IEC 16262:2002 发布。
在第三版发布后,ECMAScript 在万维网上被大量使用,它成为所有Web浏览器支持的编程语言。为了开发第四版 ECMAScript,做了大量有意义的工作,然而这项工作未能完成,也没能作为第四版 ECMAScript 发布,不过其中一些被纳入第六版开发(工作)中。
第五版 ECMAScript(以 ECMA-262 5th 版本发布)为那些已经被浏览器广泛实现的语言规范编纂了实质的解释,同时增加了对第三版发布以来出现的新功能的支持。 这些功能包括
第五版为了采用快速通道通过,被提交给 ISO/IEC JIC 1,被批准为国际标准 ISO/IEC 16262:2011。第 5.1 版 ECMAScript 标准包含较少的更正,并与 ISO/IEC 16262:2011 保持一致。于2011年6月 Ecma 联合大会被采纳。
第六版于 2009 年开始作为重点开发,当时第五版正在准备出版。然而,这之前的重点实验以及语言增强设计工作可以追溯到 1999 年第三版发布。实际上,第六版的完成是十五年努力的结果。 这个版本中增加了包括对大型应用程序,库创建, 以及以 ECMAScript 作为其他语言的编译目标提供更好的支持。其中主要的增强功能包括模块化,类声明,词法块作用域,迭代器以及生成器,异步编程的promise,解构模式,以及正确的尾部调用。 ECMAScript内置库扩展支持了额外的数据抽象,包括Map,Set,二进制值的数组, 同时也支持Unicode补充字符在字符串及正则表达式中使用。内置库也通过子类进行了扩展。第六版为正则,渐进式语言以及库增强提供了基础。第六版于 2015 年 6 月被Ecma联合大会采纳。
ECMAScript2016使用 Ecma TC39 委员会新的年度发布策略以及公开开发流程的首个 ECMAScript 版本。从 ECMAScript2015 源文档作为基础构建一个纯文本的源文档,以支持完全在 GitHub 上进一步开发。在这个标准的发展的这一年,数百个pull requests和issues被提交,代表着成千上万的错误修复,编辑修复和其他改进。另外,许多软件工具被开发用来帮助这一工作,包括Ecmarkup,Ecmarkdown和Grammarkdown。ES2016还包括支持一个新的求幂运算符,以及为 Array.prototype 添加了一个名为include的新方法。
ECMAScript 2017 的规范引入了Async函数,共享内存, 以及更小语言和库增强的原子,错误修复,编辑更新。Async函数通过提供promise-returning函数语法来提高异步编程体验。共享内存和原子引入了一种新的内存模型,允许多个代理程序使用原子操作进行通信,以确保即便在并行 CPU 上程序也能有明确定义的执行顺序。此规范还包括 Object 新的静态方法:Object.values,Object.entries和Object.getOwnPropertyDescriptors。
本规范,第 9 版本通过引入异步迭代器协议和异步生成器支持异步迭代。该规范还包括四个新的正则表达式特性:dotAll 标志、命名的捕获组、Unicode 属性转义和后视断言。还包括REST参数和扩展运算符支持对象属性。也有许多小的更新,编辑和规范,贡献来自我们的社区。
许多个人和组织在 Ecma TC39 为当前版本以及以前的版本做出了非常重要的贡献。此外,有了一个充满活力的社区支持 TC39 为 ECMAScript 所做的努力。这个社区审查了许多草案,提交了大量的错误报告,执行实施实验,提供测试套件,全世界的 ECMAScript 的开发者都可以从中受益。然而遗憾的是,不能一一鸣谢为此做出贡献的每个人和组织。
Allen Wirfs-Brock
ECMA-262, 6th版本 项目编辑
Brian Terlson
ECMA-262, 7th版本 项目编辑
本标准定义了ECMAScript 2018通用编程语言。
一个符合ECMAScript标准的实现应该符合以下提议:
必须提供和支持本规范中描述的所有的类型,值,对象,属性,函数以及程序语法及语义。
解释源文本的输入必须与最新版本的Unicode标准和ISO/IEC 10646标准保持一致。
提供的应用程序接口的程序,需要适应使用不同自然语言的国家的语言和文化习惯,且最新版本的ECMA-402的实现必须与本规范的接口兼容。
应该提供那些超出该规范描述的额外类型,值,对象,属性以及方法。尤其对于该文档有提到但没描述其属性的那些对象,应该提供那些属性以及属性对应的值。
应该支持一些没有在规范中提及的程序或者正则表达式语法。尤其应该实现在
绝对不能实现在
为了实现符合本规范的应用程序,下列引用文档是不可或缺的。对于标注了日期的文档,仅适用标注的那个版本。 对于未标注日期的文档,以文档的最新版为准(包括任何修订版)。
ISO/IEC 10646:2003: 信息技术 –通用多八位编码字符集(UCS)以及修订 1:2005, 修订 2:2006, 修订 3:2008, 和修订 4:2008, 以及其他修订,更正,后继标准
ECMA-402, ECMAScript 2015 国际化API规范.
http://www.ecma-international.org/publications/standards/Ecma-402.htm
ECMA-404, JSON 数据交换格式化.
http://www.ecma-international.org/publications/standards/Ecma-404.htm
本节包含对 ECMAScript 语言非规范性的概述。
ECMAScript 是一门在宿主环境执行计算以及操作可计算对象的面向对象编程语言。这里定义的ECMAScript并不打算有自给自足的计算;事实上,该规范并没有规定外部数据的输入或者计算结果的输出。相反,我们期望 ECMAScript 程序的计算环境不仅提供本规范中描述的对象和能力,还包括特定的环境对象,本规范除了说明这些对象应该提供可被 ECMAScript 程序访问的某些属性,调用的某些方法外,关于它的其他描述和行为不在本规范涉及的范围。
ECMAScript 最初被设计为一门脚本语言,但是现在已经作为一门通用的编程语言被广泛应用。脚本语言是指一种用于操作,定制,自动化现有系统能力的编程语言。在这样的系统中,通过用户界面已经可以使用有用的功能,而脚本语言是将这些功能暴露给程序控制的机制。 通过这种方式,现有的系统被称为提供对象和能力的宿主环境,从而完成了脚本语言的功能。 脚本语言是供专业和非专业程序员使用的。
ECMAScript 最初被设计为 Web 脚本语言,提供了一种让网页更加富有生机的机制,并能够进行部分基于Web B/S架构的服务器端计算。ECMAScript 现在被用于在多种宿主中提供核心脚本能力。因此该文档描述的是除特定宿主环境外的语言核心。
ECMAScript 用法已经远超出了简单脚本,现在被用于很多不同的环境和规模的全方位编程任务。随着 ECMAScript 使用范围的扩大使,其功能和能力也得到了扩展。ECMAScript 现在成为了一个功能齐全的通用编程语言。
ECMAScript 的一些能力类似于其他编程语言中,特别是 C, Java™, Self, 如以及下所述的 Scheme:
ISO/IEC 9899:1996, Programming Languages – C.
Gosling, James, Bill Joy and Guy Steele. The Java™ Language Specification. Addison Wesley Publishing Co., 1996.
Ungar, David, and Smith, Randall B. Self: The Power of Simplicity. OOPSLA '87 Conference Proceedings, pp. 227-241,Orlando, FL, October 1987.
IEEE Standard for the Scheme Programming Language. IEEE Std 1178-1990.
web 浏览器提供用于客户端计算的 ECMAScript 宿主环境,包括如代表窗口,菜单,弹出窗口,对话框,文本域,锚点,框架,历史记录,cookies以及输入/输出的实例对象。此外,宿主环境还提供了脚本代码处理如焦点改变、页面和图片的加载、卸载、错误和中断,选择,表单提交和鼠标交互等等事件的能力。通过 HTML 中的脚本代码组合用户接口元素,固定及计算文本,图片来显示页面。脚本代码不需要一个主程序即可对用户交互进行响应。
WEB 服务器提供一个不同于客户端的如代表请求,客户端,文件等的对象,以及数据锁定和分享的机制。为基于 Web 的应用程序提供一个定制的用户界面,通过浏览器端脚本及服务端脚本的配合使用,可以在客户端和服务端之间进行分布式计算。
支持 ECMAScript 的 WEB 浏览器和服务器都将它们自身的宿主环境作为 ECMAScript 的补充,以使得 ECMAScript 的执行环境变得完整。
以下是 ECMAScript— 的非正式概述 —— 描述的只是该语言的一部分。这个概述不是标准的一部分。
ECMAScript 是基于对象的:基础语言以及主要能力都是通过对象提供,一个 ECMAScript 程序是一组可通信对象。在 ECMAScript 中,一个对象是零个或多个属性的的集合。每个属性都有确定其如何被使用的特性, 如当一个属性的 Writable 特性设置为
ECMAScript 定义了一组内置对象,从而勾勒出 ECMAScript 实体的定义。这些内置对象包括全局对象;基本的语言Object, Function, Boolean, Symbol,各种 Error 对象;代表和操作的数值对象,包括 Math, Number, Date;文本处理对象,String,RegExp;索引值集合的 Array 对象,以及九种值具有特定数字数据表示的 Typed Array 对象;泛型对象 Map, Set;支持结构化数据的 JSON, ArrayBuffer, SharedArrayBuffer,DataView 等对象;支持控制抽象的 generator 函数,Promise 对象;以及反射对象 Proxy,Reflect。
ECMAScript 还定义了一组内置运算符。ECMAScript 运算符包括各种一元运算,乘法运算符,加法运算符,位移运算符,关系运算符,等式运算符,二进制运算符,二进制逻辑运算符,赋值运算符和逗号运算符。
大型 ECMAScript 程序通过模块被支持,其允许程序可以被分化为多个语句和定义序列。每个模块明确地标识它所使用的其他模块提供的声明,哪些声明可供其他模块使用。
ECMAScript 语法有意地类似于 Java 语法。ECMAScript 语法是松散的,使其能够成为易于使用的脚本语言。例如,一个变量不需要声明其具体类型,也不需要与声明相关联属性类型,在调用定义的函数之前也不需要以文本方式显示的声明。
尽管 ECMAScript 包含了定义类的语法,但是 ECMAScript 对象从根本上来说并不是像 C++,Smalltalk,Java 那样基于类的。相反,对象可以通过各种方式创建,包括字面符号,或通过"prototype" 的属性的函数,此属性用于实现基于原型的继承 和共享属性。new Date(2009, 11) 创建一个新 Date 对象。不使用new调用一个Date()产生一个表示当前日期时间的字符串,而不是一个对象。
每个由"prototype" 属性值。再者,一个原型可能有一个非空隐式引用链接到它的原型,以此类推,这叫做原型链。当向对象的一个属性提出引用时,引用会指向原型链中包含此属性名的第一个对象的属性。换句话说,首先检查直接提及的对象的同名属性,如果对象包含同名的属性,引用即指向此属性,如果该对象不包含同名的属性,则下一步检查对象的原型;以此类推。
一般情况下基于类的面向对象语言的实例拥有状态,类拥有方法,并且只能继承结构和行为。在 ECMAScript 中,对象拥有状态和方法,并且结构,行为,状态全都可继承。
所有不直接包含特定属性的对象会共享他们原型中包含的此属性及属性值。图 1 说明了这一点:
CF 是一个new 表达式创建: cf1, cf2, cf3, cf4, cf5。每个对象都有名为 q1 和 q2 的属性。虚线表示隐式原型关系;例如:cf3 的原型是 CFp。P1 和 P2 的两个属性, 这对 CFp,cf1, cf2, cf3, cf4, cf5 是不可见的。CFp 的名为 CFP1 的属性共享给 cf1, cf2,cf3, cf4, 以及 cf5 ( 没有CF), 以及在 CFp 的隐式原型链中找不到任何名为 q1, q2,或 CFP1 的属性。请注意,CF 和 CFp 之间没有隐式原型链接。
不同于基于类的对象语言,属性可以通过赋值的方式动态添加给对象。也就是说,
尽管 ECMAScript 对象本质上不是基于类,但是基于构造函数,原型对象和方法通用模式来实现类似于类的抽象是很方便的。ECMAScript 内置对象本身即遵循这样的类模式。从 ECMAScript 2015 开始,ECMAScript 语言包含了类定义语法,允许程序员像内置对象那样简洁的定义对象。
ECMAScript 语言认识到有的开发者可能希望限制使用语言中的新特性。他们这样做可能是为了安全考虑,避免他们认为是容易出错的功能,获得增强的错误检查,或其他原因。因此,ECMAScript 中定义了语言的严格变体。语言的严格变体,排除了 ECMAScript 语言的某些特定的语法和语义特征,还修改了某些功能的详细语义。严格变体还指定了必须抛出错误异常报告的额外错误条件,即使在非严格的语言形式下这些条件不属于错误。
ECMAScript 的严格变体通常被称为语言的严格模式。严格模式选择和使用明确地适用于独特 ECMAScript 代码单元级别的,ECMAScript 严格模式语法和语义。由于语法代码单元级别的严格模式被选择,严格模式仅在这个代码单元内施加有局部效果的限制。严格模式不限制或修改任何层面的 ECMAScript 语义,必须一致地操作跨多个代码单元。一个 ECMAScript 程序可同时包含严格模式和非严格模式的代码单元。在这种情况下,严格的模式只适用于严格模式代码单元内实际执行的代码。
要符合这一规范,ECMAScript 的实现必须同时实现未限制的 ECMAScript 语言和按照这个规范定义的 ECMAScript 的严格模式变体。此外,实现还必须支持未限制的和严格模式代码单元的在同一个程序中混用。
本文档将使用下列术语和定义。
在本规范
指在
一个原始值直接代表语言实现的最低层次的数据
Object 类型的成员
对象是属性的集合,并且具有单个原型对象。原型可能是空值。
创建和初始化对象的
prototype 属性值是用来实现继承和共享的一个原型对象。
为其他对象提供共享属性的对象
默认行为拥有如那些所有对象都必须支持的内部方法的对象
默认行为缺少一个或多个必要内部方法的对象
任何对象不是
其语义由本规范定义的对象
ECMAScript 实现指定和提供的对象
一个在变量没有被赋值时就被使用的原始值
值只有
表示故意缺省任何对象值的原始值
值只有
Boolean 类型的成员
只有两个值,
由原始值
标准内置构造函数
通过使用 new 表达式,以一个 Boolean 值作为参数调用 Boolean
由零个或多个16位无符号整数组成的有限有序序列原始值
一个 String 值是 String 类型的成员。通常序列中的每个整数值代表 UTF-16 文本的单个 16 位单元。然而,对于其值,ECMAScript 只要求必须是 16 位无符号整数,除此之外没有任何限制或要求。
所有可能的 String 值的集合
标准内置String 实例,Object 类型成员之一
IEEE 754-2008 格式的 64 位双精度二进制的原始值
一个数字值是数字类型的成员,直接代表一个数字。
所有可能的 Number 值的集合,包括特殊 “Not-a-Number” (NaN) 值, 正无穷, 负无穷
标准内置Number 的一个实例,Object 类型成员之一
正无穷数值
值 IEEE 754-2008 “Not-a-Number” 的数值
表示一个唯一的,非字符串的属性键对象的原始值
所有可能的 Symbol 值集合
标准内置Symbol 的一个实例,Object 类型成员之一
可作为子程序调用的 Object 类型成员之一
函数除了其属性,还包含可执行代码、状态,用来确定被调用时的行为。函数的代码不限于 ECMAScript。
作为函数的内置对象
如 parseInt 和 Math.exp 就是内置函数。一个实现可以提供本规范没有描述的依赖于实现的内置函数。
将一个键(一个 String 值或 Symbor 值)和值相关联的对象的一部分
属性可能根据属性值的不同表现为直接的数据值(原始值,对象,或一个
作为属性值的函数
当一个函数被作为一个对象的方法调用,此对象将作为
作为内置函数的方法
标准内置方法由本规范定义,ECMAScript 实现可指定,提供其他额外的内置方法。
定义一个属性的一些特性的内部值
对象直接拥有的属性
不是对象的自身属性,但是是对象原型的属性(原型的自身属性或继承属性)
本规范的剩余部分章节组织如下:
第 5 章定义了在本规范中使用的一些符号或者语法的约定。
第 6-9 章定义了 ECMAScript 程序操作包含的执行环境。
第 10-16 章定义了实际的 ECMAScript 语言,包括它的语法编码以及语言特性的执行语义。
第 17-26 章定义了 ECMAScript 标准库。它们包括所有当 ECMAScript 程序执行时可用的标准对象的定义。
第 27 章描述了访问备用数组缓冲区内存和原子对象的内存一致性模型。
上下文无关文法由多个产生式组成。每个产生式左侧有一个称为非终结符的抽象符号的左值,右侧有一个或多个非终结符和终结符号组成的序列的右值。任何文法,它的终结符都来自指定的字母集。
一个产生式链是一个只含有一个非终结符以及 0 个或多个终结符作为其右值的产生式。
句子中单一可区分的非终结符——目标符,给定一个语言上下文无关文法。换句话说,重复用产生式右值替换序列中任何左值为非终结符所组成的终结符序列集合(可能是无限个)。
ECMAScript 词法文法在
空白和注释之外的输入元素构成 ECMAScript 语法文法的终结符,它们被称为 ECMAScript tokens。这些 tokens 是,ECMAScript 语言的保留字,标识符,字面量,标点符号。此外,行结束符虽然不被视为 tokens,但会成为输入元素流的一部分,用于引导处理自动插入分号(/*…*/ 的注释,不管是否跨越多行)不包含行结束符也会直接地丢弃,但如果一个
两个冒号 "::" 作为分隔符分割词法和正则的文法产生式。词法和正则的文法共享某些产生式。
用于转换字符串为数字值的一种文法。此文法与数字字面量词法文法的一部分类似,并且有终结符
三个冒号 ":::" 作为分隔符分割数字字符串文法的产生式。
第 11,12,13,14,15 章给出了 ECMAScript 的语法文法。词法文法定义的 ECMAScript tokens 是此文法的终结符(
当一个码点流解析成一个 ECMAScript 的
当一个解析成功的时候,它会构造一颗解析树,一颗根树结构是它的每个节点都是一个 Parse Node。每个 Parse Node 都是文法中的一个符号的一个实例。它代表了从这样的符号中派生出来的源代码文本的一个跨度。解析树的根节点代表着整个的源代码文本,是解析的
新的 Parse Nodes 在每次调用解析器时都会被重新实例化,也就是说解析相同源文本也永远不会重用。当且仅当它们表示相同的源文本范围,是相同语法符号的实例,并且是由调用相同的解析器产生的解析节点时被认为是相同的 Parse Node
多次解析同一字符串会得到不同的 Parse Nodes,例如:
eval(str); eval(str);
只用一个冒号 “:” 作为分隔符分割语法词法的产生式。
语法文法在条款 12,13,14,15 中提出。但是对于哪些 token 序列是正确被 ECMAScript
在某些情况下,为了避免歧义,语法文法使用广义的产生式,允许 token 序列形成一个不合法的 ECMAScript
不管是在文法的产生式,还是在本规范中,词法文法,正则文法以及数字字符串文法的终结符都用等宽字体展示。这些将以的脚本形式出现。所有通过这种方式指定的终结符码点都被当作合适的基本拉丁语 Unicode 码点理解,而不是来自其他任何类似 Unicode 范围的码点。
非终结符以斜体显示。非终结符(也叫产生式)的定义由非终结符名称和其后定义的一个或多个冒号给出。(冒号的数量表示产生式所属的文法。)非终结符的一个或多个替代右值紧跟在下一行。例如,语法定义:
表示这个非终结符 while token,其后跟左括号 token,其后跟 token,其后跟
表示这个
终结符或非终结符可能会出现后缀下标 “opt”,表示它是可选符号。包含可选符号实际指定了包含两个右值,一个是省略可选元素的,另一个是包含可选元素的。这意味着:
是以下的一种简便的缩写:
以及:
是以下的一种简便的缩写:
也是下面的一种缩写:
所以在这个例子中,非终结符
产生式可以通过形如 “[parameters]” 这样的下标注释被参数化,会以后缀的形式出现在产生式定义的非终结符中。“parameters” 可以是单独的名称,也可以是一个逗号分隔的名称列表。被参数化的产生式是一系列定义参数名称以下划线开头,追加到参数化的非终结符后面的所有组合的产生式的缩写。这就意味着:
是下面的缩写:
以及:
是下面的缩写:
多个参数产生数个产生式的组合,在一个完整语法中不必引用所有。
对生产式的非终结符右值的引用也可以被参数化,例如:
是下面的缩写:
又如:
是下面的缩写:
非终结符引用可能同时具有参数列表和一个 “opt” 后缀。例如:
是下面的缩写:
在右侧非终结符引用参数名称前置以 “?”,使该参数值取决于当前产生式的左侧符号引用的参数名称是否出现。例如:
是下面的缩写:
如果右值选择是以 “[+parameter]” 作为前缀,则表示选择只有命名参数用于引用产生式的非终结符时可用。如果右值选择是以 “[~parameter]” 作为前缀,则表示选择只有命名参数不是用于引用产生式的非终结符时可用。这意味着:
是下面的缩写:
另外一个例子:
是下面的缩写:
在文法定义中当单词 “one of” 跟随一个或多个分号后的时候,表示随后的一行或多行的终结符是一个可选的定义。例如,ECMAScript的词法文法包含下列的产生式:
它仅仅是下面的缩写:
如果 “[empty]” 出现在一个产生式的右值,它暗示着这个产生式的右值不包含终结符或者非终结符。
如果 “[lookahead ∉ set]” 出现在一个产生式的右值,它暗示着如果随后立即的输入的token序列是给出的集合(set)的成员,那么这个产生式也许不会被使用。这个集合可以用一个逗号分割的由一到两个被花括号包裹的元素终结序列的列表表示。为了方便,这个集合也可以用非终结符表示,在这种情况下,它代表所有能由非终结符展开得到的终结符的集合。如果这个集合包含一个单独的终结符,那么短语 “[lookahead ≠ terminal]” 也许会被使用。
例如,给出定义:
则定义:
能匹配字母 n 后跟随由偶数起始的一个或多个十进制数字,或一个十进制数字后面跟随一个非十进制数字。
类似的,如果产生式的右值出现 “[lookahead ∈ set]”,则表示产生式只有在随后立即的输入的token序列是给出的集合(set)的成员才能使用。如果集合只包含一个单一的终结符,则可以使用 “[lookahead == terminal]”。
如果产生式的右侧出现 “[no
如果一个 throw token 和
除非通过一个受限的产生式禁止一个
当一个词法文法或者数字字符串文法的产生式中可选部分出现多码点的 token 时,意味着码点序列将会组成一个 token。
一个产生式的右值也许会通过 “but not” 指定某些不被允许的扩展,然后暗示这个扩展将是被排除在外的。例如,产生式:
意味着非终结符
最后,一些非终结符通过 sans-serif 字体书写的描述性的短语来描述, 在这样的案例中,列出所有的可选部分是不切实际的。
此规范通常使用带编号的列表来指定算法的步骤。这些算法是用来精确地指定 ECMAScript 语言结构所需的语义。该算法无意暗示任何具体实现使用的技术。在实践中,也许可用更有效的算法实现一个给定功能。
算法可能被显式参数化,在这种情况下,参数名和用法必须作为算法定义的一部分提供。
算法步骤可以细分为多个连续的子步骤。子步骤需要用缩进表示,可以进一步被划分成缩进的子步骤。大纲编号约定用作标识子步骤,第一级子步骤使用小写字母字符标记,第二级小步骤用小写罗马数字标记。如果步骤超过三级,那么这些规则从第四级开始从数字重复进行标记。例如:
一个步骤或者子步骤也许会使用 “if” 去断言它的子步骤的条件。在这样的案例中,这些子步骤只能适用于 “if” 断言为真的情况。如果一个步骤或者子步骤以 “else” 开始,那么表示这是之前的 “if” 断言的同一级的否定断言。
一个步骤也许会指定它的子步骤的迭代程序。
一个以 “Assert:” 开头的步骤断言一个它的算法里不变的条件。这样的断言被用作使算法不变量显式地展示,否则它将是隐式的。这样的断言不增加额外的语义需求,因此实现不必检查。它们被使用只是为了使算法更清晰。
对于任意形如 “Let x be someValue” 的值,算法步骤也许会声明命名别名。这些别名都是类似类型的,即 x 和 someValue 指向同样的基础数据,对它们的修改是互相可见的。那些想避免这样的类似引用的算法步骤需要显式地复制一份右值:即 “Let_x_ be a copy of someValue” 创建了一个 someValue 的浅复制。
一旦声明完毕,别名可以在任何后续步骤中引用,而不能在别名声明前的步骤中使用。别名也许会通过形如 “Set x to someOtherValue” 这样的形式被修改。
为了便于它们在本规范的多个地方使用,一些算法,我们称之为抽象操作,以参数化函数形式命名和书写,以便它们能够在其它算法中通过名称来引用。抽象操作通常使用函数应用风格被引用,如 OperationName(arg1, arg2)。一些抽象操作被当作像类规范里抽象的多态发送一样。这样的类似类的方法抽象操作通常通过一个方法应用风格被引用,如 someValue.OperationName(arg1, arg2)。
一个语法导向操作是一个具名操作,它的定义包含了一系列算法,每个算法与一个或者多个 ECMAScript 文法的产生式相关联。一个有多个可选定义的产生式通常对于每个可选部分都有一个独立的算法。当一个算法与一个文法产生式相关联的时候,它也许会引用这个产生式可选部分的终结符或者非终结符,就好像它们是这个算法的参数一样。当出现这种情况时,非终结符指向实际的源代码中与之匹配的可选部分的定义。
当一个算法与一个产生式的可选部分关联的时候,这个可选部分通常不会带上 “[ ]” 文法注释。这样的注释只应该影响可选部分的语法识别,不应该对相关的可选部分的语义有影响。
语法导向操作同一个解析节点一起被调用,还可以在以下算法步骤 1,3,4 中使用这个约定的其它参数:
"value" as the argument.除非另有明确说明,否则,所有相关联的产生式对于每个也许会被应用到这个产生式左值的非终结符的操作都有一个隐式的定义。如果存在的话,这个隐式的定义简单地再次对同样的参数运用这个相同的定义,对于这些相关联的产生式唯一的右值非终结符,随后返回处理结果。例如,假设一些算法有如下形式的步骤: “Return the result of evaluating
但是解析操作并没有关联这个产生式的算法。那么在这样的案例中,解析操作隐式地包含了下面形式的关联:
必须在运行时被调用的指定语义的算法就叫运行时语义。 运行时语义通过
本规范的算法常常隐式地返回一个 [[Type]] 值为
"Infinity".与下面的是同一个含义:
"Infinity").然而,如果一个 “return” 语句的值表达式是一个
一个在算法步骤中没有值的 “return” 语句与下面的是同样的意思:
undefined).对于任意的在一个上下文中没有显示地需要一个完整的
描述抛出一个异常的算法步骤,例如:
TypeError exception.与下面的是同一个含义:
算法步骤说明或者等同于:
意思就是:
算法步骤说明或者等同于:
与下面的是同一个含义:
这里的 hygienicTemp 是临时的,并且只在 ReturnIfAbrupt 有关的步骤中中可见。
算法步骤说明或者等同于:
与下面的是同一个含义:
对? 为前缀的指定语法操作的调用暗示着
等价于下面的步骤:
相似的,对于程序方法的风格,步骤:
等价于:
相似的,前缀 ! 被用作暗示下列的对于抽象或者指定语法操作的调用将不会返回一个打断的完成值, 并且作为结果的
等价于下面的步骤:
对于! 或者 ? 来利用这个缩写。
上下文无关文法不能足够好的去表达所有定义的规则,不管是一个输入元素的流形成的一个合法的将被解析的 ECMAScript
静态语义规则拥有名称,并且通常用一个算法来定义。具有名称的静态语义规则与文法产生式相关联,对于每个可采用的具有名称的静态语义规则, 一个包含多个可选部分定义的产生式通常会对每个可选部分定义一个独有的算法。
除非在本规范中其它指定的文法产生式可选部分隐式地包含一个叫做 Contains 的接收一个值为包含相关产生式的文法的终结符或者非终结符的 symbol 参数静态语义规则的定义。 默认的包含定义为:
上面的定义是显式地重写了规范的产生式。
一个特殊的静态语义规则是早期(提前)错误规则。早期错误规则定了早期错误条件(见
除非其它地方特别注明不包括无限并且不包括负 0(为了与正 0 区分),数学操作,例如加,减,否定(逻辑非),乘,除以及随后在条款中定义的数学函数应总是被当作是对于数学中所有真实数字计算出来的准确的结果。本规范算法中的浮点运算包含显式地的步骤,它们对于处理无穷,有符号的0,以及舍入是必要的。如果一个数学操作或者函数被应用在一个浮点数上,那么它必须被当作应用到用浮点数表示的具体的数学值;这样的浮点数必须是有限的,并且如果它是
数学函数
数学函数
符号 “
��学函数
本规范中算法控制每个具有相关类型的值。可能的值类型直接定义在本章节中。这些类型进一步分为 ECMAScript 语言类型与规范类型。
在本规范中,“Type(x)”表示法是“the type of x”的简写, 其中“type”指的是在本章节中定义的 ECMAScript 语言类型与规范类型。当一个值使用术语“empty”命名值时,它相当于说“没有任何类型的值”。
一个 ECMAScript 语言类型对应那些 ECMAScript 程序员在 ECMAScript 语言中直接使用的值。 ECMAScript 语言类型有 Undefined, Null, Boolean, String,Symbol, Number, Object。 一个ECMAScript 语言值是指拥有一个 ECMAScript 语言类型特点的值。
Undefined 类型仅仅只有一个值,undefined。 任何尚未分配值的变量值都为 undefined。
Null 类型只有一个值, null.
Boolean 类型表示具有 true 和 false 两个值的一个逻辑实体。
String 类型是零个或多个 16 位无符号整数值(“元素”)的所有有序序列的集合,最大长度为 253-1 个元素。字符串类型通常用于表示正在运行的 ECMAScript 程序中的文本数据,在这种情况下,String中的每个元素都被视为一个 UTF-16 码元。 每个元素被认为占据该序列内的一个位置。 这些位置用非负整数索引。 第一个元素(如果有)在索引 0 处,下一个元素(如果有的话)在索引 1 处,以此类推。 String 的长度是序列中的元素个数(例如,十六位值)。空字符串的长度为零,因此不包含元素。
ECMAScript 操作符不应用不同的语义解释字符串内容。操作符把字符串的每个元素视为单个 UTF-16 代码单元进行解释。但是,ECMAScript 并不约束这些代码单元的值或这些代码单元之间的关系,因此进一步将字符串内容解释为 UTF-16 中编码的 Unicode 代码点序列的操作必须考虑格式不对的子序列。此类操作使用如下规则对每个代码单元特殊处理,使其数值范围在 0xD800 到 0xDBFF(Unicode 标准定义为 首代理,或者更正式的 高代理码元)或范围 0xDC00 到 0xDFFF(定义为尾代理,或者更正式的低代理码元):
函数 String.prototype.normalize (see String.prototype.localeCompare (see
这种设计背后的理由是尽可能的保持 String 的实现简单和高效。 如果 ECMAScript 源文本符合 Normalized Form C,只要它们不包含任何 Unicode 转义序列,则字符串字面量保证也是标准化的。
在本规范中,短语"the string-concatenation of A,B,..."表示字符串代码单元的序列是每个参数的代码单元的连接。
Symbol 类型是所有可以用于作为 Object 属性 key 值的非字符串值的集合。(
每个可能的 Symbol 值都是唯一的和不可变的。
每个 Symbol 值永远地保持一个与之关联的叫做 [[Description]] 的值(它要么是
总所周知的 Symbol 是那些被本规范中算法明确引用的内置 Symbol 值。它们通常被用作属性的 key,这些 key 的值作为规范的算法扩展点。除非另有说明,总所周知的 Symbol 的值被所有域(
在本规范内,一个总所周知的 Symbol 值通过形如 @@name 的形式被引用,这里的 “name” 是表
| 规范名称 | [[Description]] | 值和目的 |
|---|---|---|
| @@asyncIterator |
"Symbol.asyncIterator"
|
返回对象的默认 AsyncIterator 的方法。 由 for-await-of 语句的语义调用。
|
| @@hasInstance |
"Symbol.hasInstance"
|
确定构造instanceof 运算符语义来调用。
|
| @@isConcatSpreadable |
"Symbol.isConcatSpreadable"
|
一个 Boolean 值,如果为 true, 表示一个对象应该被 Array.prototype.concat |
| @@iterator |
"Symbol.iterator"
|
返回一个对象的默认 Iterator 的方法。由 for-of 声明的语义来调用。 |
| @@match |
"Symbol.match"
|
将字符串与正则表达式匹配的正则表达式方法。 由 String.prototype.match |
| @@replace |
"Symbol.replace"
|
替换匹配字符串子串的正则表达式方法。 由 String.prototype.replace |
| @@search |
"Symbol.search"
|
一个正则表达式方法,它返回正则表达式匹配到的内容在字符串中的索引。 由String.prototype.search |
| @@species |
"Symbol.species"
|
作为构造函数的函数值属性,用来创建派生对象。 |
| @@split |
"Symbol.split"
|
一个正则表达式方法,它在正则表达式匹配的索引位置拆分字符串。 由 String.prototype.split |
| @@toPrimitive |
"Symbol.toPrimitive"
|
将一个对象转换为相应原始值的方法。由 |
| @@toStringTag |
"Symbol.toStringTag"
|
用于创建对象的默认字符串描述的 String 值属性。通过内置方法 Object.prototype.toString |
| @@unscopables |
"Symbol.unscopables"
|
一个对象值属性,其自身和继承的属性名是从相关对象的 with 环境绑定中排除的属性名。 |
Number 类型有 18437736874454810627 (即,
还有另外两个特殊的值,叫做
其他 18437736874454810624(即,
注意其中有一个
18437736874454810622(即
其中 18428729675200069632 (即
其中 s 为 +1 或 -1,m 是一个小于 253 但大于等于 252 的整数,e 是从 -1074 到 971 的整数。
其余 9007199254740990 (即
其中 s 是 +1 或 -1 ,m 是小于 2 的 52 次方的正整数,e 是 -1074。
注意,大小不大于 253 的所有正整数和负整数可以在 Number 类型中表示(实际上,整数 0 具有两个表示,
如果一个有限的数值非零且用来表达它(上文两种形式之一)的整数 m 是奇数,则该数值有奇数意义。否则,它有偶数意义。
在本规范中,当 x 表示一个精确的非零实数数学量(甚至可以是无理数,比如π)时,“the
某些 ECMAScript 运算符仅处理闭区间
对象在逻辑上是属性的集合。每个属性都是一个数据属性或一个访问器属性:
属性使用 key 值来标识。一个属性的 key 值是 ECMAScript String 值或 Symbol 值。所有 String 值(包括空字符串) 和 Symbol 值作为属性的 key 都是有效的。属性名称是指属性的 key,其值为字符串。
一个值为 +0 或者一个 ≤ 253-1 的整数作为属性 key 字符串值的数字索引是一个以典型的数字 String(见
属性的 key 用来访问属性以及其值。属性有两种访问方式:get 和 set ,分别对应值的检索和赋值。通过 get 和 set 可访问的属性既包括直接属于的自身属性,也包括通过继承关系由其它相关对象提供的继承属性。继承属性也可能是另一个对象的自身属性或者继承属性。对象的每个自身属性必须有一个与对象的其他自身属性 key 值不同 key 值。
所有的对象都是逻辑上的属性集合,但是在用于访问和操纵它们的属性的语义中存在多种形式的对象。普通对象是对象的最常见形式,拥有默认的对象语义。奇异对象是指其属性语义与默认语义的各个方面都有区别的对象。
在本规范中特性用来定义和解释对象属性的状态。
| 特性名称 | 值域 | 描述 |
|---|---|---|
| [[Value]] | 任何 ECMAScript 语言类型 | get 访问检索到的属性值 |
| [[Writable]] | Boolean |
如果为 |
| [[Enumerable]] | Boolean |
如果为 |
| [[Configurable]] | Boolean |
如果为 |
| 特性名称 | 值域 | 描述 |
|---|---|---|
| [[Get]] | Object | Undefined |
如果这个值是一个对象,那么它必须是一个 |
| [[Set]] | Object | Undefined |
如果这个值是一个对象,那么它必须是一个 |
| [[Enumerable]] | Boolean |
如果为 |
| [[Configurable]] | Boolean |
如果为 |
如果一个属性的特性的初始值没有被本规范显式地指定的,那么使用在表
| 特性名 | 默认值 |
|---|---|
| [[Value]] |
|
| [[Get]] |
|
| [[Set]] |
|
| [[Writable]] |
|
| [[Enumerable]] |
|
| [[Configurable]] |
|
在 ECMAScript 中,对象的实际语义是通过算法来调用内部方法指定的。在 ECMAScript 引擎中的每个对象都与一系列的定义它的运行时行为的内部方法相关联。这些内部方法不属于 ECMAScript 语言的一部分。本规范定义它们纯粹是为了说明目的。但是,在 ECMAScript 具体实现中的每个对象必须表现得与其相关关联的内部方法一致。其中确切的方式由实现者来决定。
内部方法名称是多态的。这意味着当一个通用内部方法被调用的时候,不同的对象值可能会执行不同的算法。调用内部方法实际的对象是这个调用 “target”。如果在运行时,实现的算法尝试使用一个对象不支持的内部方法,抛出一个TypeError异常。
内部槽对应于相关对象的内部状态,用于各种 ECMAScript 规范算法。内部槽不是对象的属性,也不会被继承。根据具体的内部槽规范,内部状态可能由任意 ECMAScript 语言类型的值或者指定的 ECMAScript 规范类型的值组成。除非另有指定,否则分配内部槽应作为创建一个对象的过程的部分,并且不应该动态地添加到对象上。除非另有指定,否则一个内部槽的初始值是
本规范内的内部方法和内部槽使用闭合的双方括号 [[]] 来标识。
表
表
| Internal Method | Signature | Description |
|---|---|---|
| [[GetPrototypeOf]] | ( ) → Object | Null |
确定为对象提供继承属性的对象。 |
| [[SetPrototypeOf]] | (Object | Null) → Boolean |
关联这个对象与提供继承属性的对象。传递 |
| [[IsExtensible]] | ( ) → Boolean | 决定是否允许添加额外的属性到这个对象上。 |
| [[PreventExtensions]] | ( ) → Boolean | 控制一个新的属性是否能加到这个对象上。返回 true 表示操作成功,返回 false 表示操作失败。 |
| [[GetOwnProperty]] |
(propertyKey) → Undefined | |
返回对象自身属性中 key 值为 propertyKey 的属性的属性描述符,如果没有这个属性返回undefined。
|
| [[DefineOwnProperty]] | (propertyKey, PropertyDescriptor) → Boolean | 创建或者改变 key 值为 propertyKey 的自身属性状态为 PropertyDescriptor。返回 true 表示属性被成功创建/更新,返回 false 表示属性不能被创建/更新。 |
| [[HasProperty]] | (propertyKey) → Boolean | 返回一个 Boolean 值,代表这个对象自身或者继承了一个 key 值为 propertyKey 的属性。 |
| [[Get]] | (propertyKey, Receiver) → any |
返回这个对象里 key 值为 propertyKey 的属性的值。如果必须运行一些的 ECMAScript 代码来检索这个属性值,Receiver 就会作为解析代码时的 |
| [[Set]] | (propertyKey, value, Receiver) → Boolean |
设置这个对象 key 值为 propertyKey 的属性的值为 value。如果必须运行一些的 ECMAScript 代码来检索这个属性值,Receiver 就会作为解析代码时的 |
| [[Delete]] | (propertyKey) → Boolean |
移除这个对象 key 值为 propertyKey 的自身属性。 如果这个属性没有被移除,仍然存在,则返回 |
| [[OwnPropertyKeys]] |
( ) → |
返回一个包含所有自身属性 key 值的 |
表
| Internal Method | Signature | Description |
|---|---|---|
| [[Call]] |
(any, a |
执行这个对象相关联的代码。通过一个函数表达式来调用。通过调用表达式,传递给内部函数的 arguments 为一个 |
| [[Construct]] |
(a |
创建一个对象。通过 new 或者 super 操作符调用。这个内部方法的第一个参数是一个包含操作符的参数的列表。第二个参数是 new 操作符初始化时应用的对象。实现这个内部方法的对象被称为构造函数。一个 |
这些
ECMAScript 引擎中的内部方法必须符合以下指定的不变量列表。普通 ECMAScript 对象以及该规范中的标准怪异对象应保持这些不变量。ECMAScript Proxy 对象通过运行时检查 [[ProxyHandler]] 对象的陷阱调用结果的手段来保持这些不变量。
任何实现提供的怪异对象必须也保持这些不变量。违反这些不变量可能会导致 ECMAScript 代码出现不可预料的行为以及安全问题。然而,对于造成内存安全的违反不变量行为的实现决不能妥协。
实现不允许通过任何方式规避这些不变量。比如,通过提供替代接口来实现基本内部方法的功能而不强制执行他们的不变量。
作为第三个不变量的推论,如果一个属性被描述为一个
如果 P 预先已经作为 target 的一个不可配置的自身属性被观察,那么 [[DefineOwnProperty]] 必须返回 false,除非满足一下条件之一:
总所周知的内联函数是在该规范中通过算法明确引用的内置对象,这些内置对象通常有特定域的不变量。除非特别指出,每个内部对象在每个领域通常对应一系列相似对象的集合。
在本规范中像 %name% 这样的引用意味着关联到相应的 name 域的内部对象。决定当前域以及他的内联函数在
| 内在名称 | 全局名称 | ECMAScript 语言关联 |
|---|---|---|
|
|
Array
|
Array 构造函数 ( |
|
|
ArrayBuffer
|
ArrayBuffer 构造函数 ( |
|
|
ArrayBuffer.prototype
|
prototype |
|
|
数组迭代器对象的原型 ( |
|
|
|
Array.prototype
|
prototype |
|
|
Array.prototype.entries
|
entries |
|
|
Array.prototype.forEach
|
forEach |
|
|
Array.prototype.keys
|
keys |
|
|
Array.prototype.values
|
values |
|
|
The prototype of async-from-sync iterator objects ( |
|
|
|
async |
|
|
|
prototype |
|
|
|
The initial value of the prototype property of |
|
|
|
The |
|
|
|
The initial value of the prototype property of |
|
|
|
An object that all standard built-in async iterator objects indirectly inherit from | |
|
|
Atomics
|
Atomics 对象 ( |
|
|
Boolean
|
Boolean 构造函数 ( |
|
|
Boolean.prototype
|
prototype |
|
|
DataView
|
DataView 构造函数 ( |
|
|
DataView.prototype
|
prototype |
|
|
Date
|
Date 构造函数 ( |
|
|
Date.prototype
|
prototype |
|
|
decodeURI
|
decodeURI 函数 ( |
|
|
decodeURIComponent
|
decodeURIComponent 函数 ( |
|
|
encodeURI
|
encodeURI 函数 ( |
|
|
encodeURIComponent
|
encodeURIComponent 函数 ( |
|
|
Error
|
Error 构造函数 ( |
|
|
Error.prototype
|
prototype |
|
|
eval
|
eval 函数 ( |
| %EvalError% |
EvalError
|
EvalError 构造函数 ( |
| %EvalErrorPrototype% |
EvalError.prototype
|
%EvalError% prototype 属性的初始值
|
| %Float32Array% |
Float32Array
|
Float32Array 构造函数 ( |
| %Float32ArrayPrototype% |
Float32Array.prototype
|
%Float32Array% prototype |
| %Float64Array% |
Float64Array
|
Float64Array 构造函数 ( |
| %Float64ArrayPrototype% |
Float64Array.prototype
|
%Float64Array% prototype |
|
|
Function
|
Function 构造函数 ( |
|
|
Function.prototype
|
prototype |
|
|
prototype 属性的初始值
|
|
|
|
generator 对象的构造函数 ( |
|
|
|
prototype 属性的初始值
|
|
| %Int8Array% |
Int8Array
|
Int8Array 构造函数 ( |
| %Int8ArrayPrototype% |
Int8Array.prototype
|
%Int8Array% prototype |
| %Int16Array% |
Int16Array
|
Int16Array 构造函数 ( |
| %Int16ArrayPrototype% |
Int16Array.prototype
|
%Int16Array% prototype |
| %Int32Array% |
Int32Array
|
Int32Array 构造函数 ( |
| %Int32ArrayPrototype% |
Int32Array.prototype
|
%Int32Array% prototype |
|
|
isFinite
|
isFinite 函数 ( |
|
|
isNaN
|
isNaN 函数 ( |
|
|
所有标准内置迭代对象间接继承的对象 | |
|
|
JSON
|
JSON 对象 ( |
|
|
JSON.parse
|
parse |
|
|
Map
|
Map 构造函数 ( |
|
|
Map 迭代器对象的原型 ( |
|
|
|
Map.prototype
|
prototype |
|
|
Math
|
Math 对象 ( |
|
|
Number
|
Number 构造函数 ( |
|
|
Number.prototype
|
prototype 属性的初始值
|
|
|
Object
|
Object 构造函数 ( |
|
|
Object.prototype
|
prototype |
|
|
Object.prototype.toString
|
toString |
|
|
Object.prototype.valueOf
|
valueOf |
|
|
parseFloat
|
parseFloat 函数 ( |
|
|
parseInt
|
parseInt 函数 ( |
|
|
Promise
|
Promise 构造函数 ( |
|
|
Promise.prototype
|
prototype |
|
|
Promise.prototype.then
|
The initial value of the then |
|
|
Promise.all
|
The initial value of the all |
|
|
Promise.reject
|
The initial value of the reject |
|
|
Promise.resolve
|
The initial value of the resolve |
|
|
Proxy
|
Proxy 构造函数 ( |
| %RangeError% |
RangeError
|
RangeError 构造函数 ( |
| %RangeErrorPrototype% |
RangeError.prototype
|
%RangeError% prototype 属性的初始值
|
| %ReferenceError% |
ReferenceError
|
ReferenceError 构造函数 ( |
| %ReferenceErrorPrototype% |
ReferenceError.prototype
|
%ReferenceError% prototype 属性的初始值
|
|
|
Reflect
|
Reflect 对象 ( |
|
|
RegExp
|
RegExp 构造函数 ( |
|
|
RegExp.prototype
|
prototype |
|
|
Set
|
Set 构造函数 ( |
|
|
Set 迭代器对象的原型 ( |
|
|
|
Set.prototype
|
prototype |
|
|
SharedArrayBuffer
|
SharedArrayBuffer 构造函数 ( |
|
|
SharedArrayBuffer.prototype
|
prototype |
|
|
String
|
String 构造函数 ( |
|
|
String 迭代器对象的原型 ( |
|
|
|
String.prototype
|
prototype |
|
|
Symbol
|
Symbol 构造函数 ( |
|
|
Symbol.prototype
|
prototype |
| %SyntaxError% |
SyntaxError
|
SyntaxError 构造函数 ( |
| %SyntaxErrorPrototype% |
SyntaxError.prototype
|
%SyntaxError% prototype 属性的初始值
|
|
|
一个 |
|
|
|
所有数组类型 |
|
|
|
|
|
| %TypeError% |
TypeError
|
TypeError 构造函数 ( |
| %TypeErrorPrototype% |
TypeError.prototype
|
%TypeError% prototype 属性的初始值
|
| %Uint8Array% |
Uint8Array
|
Uint8Array 构造函数 ( |
| %Uint8ArrayPrototype% |
Uint8Array.prototype
|
%Uint8Array% prototype |
| %Uint8ClampedArray% |
Uint8ClampedArray
|
Uint8ClampedArray 构造函数 ( |
| %Uint8ClampedArrayPrototype% |
Uint8ClampedArray.prototype
|
%Uint8ClampedArray% prototype |
| %Uint16Array% |
Uint16Array
|
Uint16Array 构造函数 ( |
| %Uint16ArrayPrototype% |
Uint16Array.prototype
|
%Uint16Array% prototype |
| %Uint32Array% |
Uint32Array
|
Uint32Array 构造函数 ( |
| %Uint32ArrayPrototype% |
Uint32Array.prototype
|
%Uint32Array% prototype |
| %URIError% |
URIError
|
URIError 构造函数 ( |
| %URIErrorPrototype% |
URIError.prototype
|
%URIError% prototype 属性的初始值
|
|
|
WeakMap
|
WeakMap 构造函数 ( |
|
|
WeakMap.prototype
|
prototype |
|
|
WeakSet
|
WeakSet 构造函数 ( |
|
|
WeakSet.prototype
|
prototype |
规范类型对应那些在算法中用来描述 ECMAScript 语言结构以及 ECMAScript 语言类型语义的元数据。 规范类型包括
List 类型用来解释在 new 表达式,函数调用,以及其它需要一个简单的有序的值的 list 的算法中的参数列表(见
在规范中为了方便,一个字面量语法被用来表达一个新 List 值。 如 « 1, 2 » 定义一个新 List 值,它拥有两个元素,每个元素被初始化为一个特定的值。一个空的 List 值可以用 « » 表示。
Record 类型用来描述在该规范中的算法内的数据聚合。一个 Record 类型值包含一个或多个命名字段。每个字段的值是一个 ECMAScript 值或者通过由与 Record 类型相关联的名称代表的抽象值。字段名称始终用双括号括起来,例如 [[Value]]。
在规范中为了方便,使用类似对象字面量的语法来表示一个 Record 值。 如 { [[Field1]]: 42, [[Field2]]: false, [[Field3]]:
在规范文本和算法中,点记号可以用于指代记录值的特定字段。例如,如果 R 是上一段所示的记录,则 R.[[Field2]] 是 “R 中名称为 [[Field2]] 的字段 ” 的缩写。
应该命名常用记录字段组合的模式, 并且该名称可以用作Record字面量的前缀,以标识特定类型聚合的描述。 例如:PropertyDescriptor { [[Value]]: 42,[[Writable]]: false,[[Configurable]]: true }。
Set 类型被用来解释在内存模型中无序元素的集合。Set 类型的值是简单的元素的集合,其中没有任何元素出现超过一次。元素可以从 Set 中添加或者删除。不同的 Set 可以合并,相交或者相减。
Relation 类型被用来解释在 Set 上的约束。一个关系类型的值是它的的值域中有序对的集合。例如,一个在 event 上的关系是一个有序的的 event 对的集合。对于一个关系 R 以及在 R 的值域中的两个值 a 和 b,a R b 是有序对 (a, b) 是 R 的成员的简写。当 Relation 满足这些条件的最小 Relation 时,Relation 对于某些条件是最小的。
严格偏序是指一个 Relation 值 R 满足如下条件。
对于R值域中的 a,b,c:
上述两种关系的特性被称为自反性和传递性。
严格全序是指一个 Relation 值 R 满足如下条件。
R 值域中的 a,b,c:
上述三种关系的特性,按顺序被称为完全性,自反性,传递性
Completion 类型是一个用来解释运行时数值和控制流传播的 break,continue,return 和 throw)的行为。
Completion 类型值是字段名为表
| 字段名 | 值 | 意义 |
|---|---|---|
| [[Type]] |
|
结束发生的完成类型 |
| [[Value]] |
任何 ECMAScript 语言值或 |
产生的值 |
| [[Target]] |
任何 ECMAScript 字符串或 |
用于定向控制传输的目标标签。 |
术语 “异常结束” 是指 [[Type]] 值为除
Algorithm steps that say
mean the same thing as:
where all variables in the above steps, with the exception of completion, are ephemeral and visible only in the steps pertaining to Await.
Await can be combined with the ? and ! prefixes, so that for example
means the same thing as:
An
When an
The length property of an
An
When an
The length property of an
Is a shorthand that is defined as follows:
The abstract operation ThrowCompletion with a single argument, such as:
是下面定义的简写:
Reference 类型用于解释如 delete,typeof,分配操作,super 关键字以及其他语言功能的操作的行为。例如,分配一个左操作数预计将产生一个引用。
一个 Reference 是一个解析后的名称或者属性组合。一个 Reference 包含3个组件,基值组件,引用名组件,以及一个 Boolean 值的严格引用标志。一个基值组件可以是
一个 Super Reference 是指,用于表示使用 super 关键字表示一个名称组合的 Reference。一个
以下
在步骤 5.a.ii 中创建的对象在上面抽象方法和
ReferenceError exception.true, thentrue, thenReferenceError exception.false).true, thentrue, thenfalse and true, throw a TypeError exception.在步骤 6.a.ii 中创建的对象在上面抽象方法和
Property Descriptor 类型用来解释对象属性的特性的操作和具体化。Property Descriptor 的值为
Property Descriptor 值可以根据某些字段的存在或使用进一步分类为数据 Property Descriptor 和访问器 Property Descriptor。包含字段 [[Value]] 或 [[Writable]] 的是数据 Property Descriptor。包含字段 [[Get]] 或 [[Set]] 的是访问器 Property Descriptor。所有的 Property Descriptor 都可能包含 [[Enumerable]],[[Configurable]] 字段名。一个 Property Descriptor 值可能不会同时为一个数据 Property Descriptor 和一个访问器 Property Descriptor。然而,也不一定,一个通用 Property Descriptor 是一个既不是数据 Property Descriptor 也不是访问器 Property Descriptor 的 Property Descriptor值。一个完全填充的 Property Descriptor 既是一个数据 Property Descriptor 也是一个访问器 Property Descriptor, 他有所有符合表
在本规范中使用以下
当用
undefined, return false.false.true.当用
当用
undefined, return false.false, return true.false.当用
"value", Desc.[[Value]])."writable", Desc.[[Writable]])."get", Desc.[[Get]])."set", Desc.[[Set]])."enumerable", Desc.[[Enumerable]])."configurable", Desc.[[Configurable]]).当用一个对象 Obj 作为参数调用
"enumerable")."configurable")."value")."value")."writable")."get")."get")."set")."set").当用
Data Block 规范类型用来描述不同且可变的字节(8 bit)大小的数字值序列。一个 Data Block 值由初始值为 0,固定数量的字节构成。
在本规范中为了方便,可以使用类似数组的语法来访问一个 Data Block 值的各个字节。这些符号将 Data Block 值的这些字节表示为一个从 0 开始的索引队列。 例如,如果 db 是一个 5 字节的 Data Block 值,那么 db[2] 可以用来访问第三字节。
驻留在内存中,可以被多个代理并发引用的数据块被称为 Shared Data Block。一个 Shared Data Block 有一个 空地址 的标识(目的是平等检测 Shared Data Block 值): 它不依赖于所述块在任何进程中映射到的虚拟地址,而是用该块来表示内存中的位置集合。只有当两个块包含的位置集合相等时他们才相等。否则,他们地址集合的交集为空,他们是不相等的。最后,可以从 Data Block 区分 Shared Data Blocks。
Shared Data Block 的语义由内存模型中的 Shared Data Block 事件来定义。下方的
Shared Data Block 事件由
下列
当用整数参数 size 调用
当用整数参数 size 调用
"Init", [[NoTear]]: 当
"Unordered", [[NoTear]]: "Unordered", [[NoTear]]: 这些操作不是 ECMAScript 语言的一部分;在这里定义他们只是为了规范 ECMAScript 语言的语义。另外,本规范中还定义了其他特定的
ECMAScript 语言根据需要会自动执行类型转换。为了解释清楚某些结构的语义,定义一组转换
"default"."string"."number"."default", set hint to "number".当使用参数 O 和 hint 调用
"string" or "number"."string", then"toString", "valueOf" »."valueOf", "toString" ».| 参数类型 | 结果 |
|---|---|
| Undefined |
返回 |
| Null |
返回 |
| Boolean | 返回 argument。 |
| Number |
如果 argument 为 |
| String |
如果 argument 是一个空字符串 (长度为0的字符串), 返回 |
| Symbol |
返回 |
| Object |
返回 |
| 参数类型 | 结果 |
|---|---|
| Undefined |
返回 |
| Null |
返回 |
| Boolean |
如果 argument 是 |
| Number | 返回 argument (不转换)。 |
| String | 见下面语法和转换算法。 |
| Symbol |
抛出一个 |
| Object |
应用以下步骤:
|
应用
以上所有未明确定义的语法符号都在数字字面量词法定义(
应该注意
0 的数字。
+ 或 - 以指示其符号。
Infinity 和 -Infinity 公认是 字符串到 Number 值的转换和一个的数字字面量 Number 值的确定总体上来说是相似的(见
+∞).
一旦确定了字符串数字字面量确切的数值,它将被舍入为一个 Number 类型的值。如果数值为 0,那么它舍入的值为 "-",这种情况舍入值为
0; 或者
鉴于以上 ToInt32 的定义:
鉴于以上 ToUint16 的定义:
与其他 ECMAScript 整数转换
| 参数类型 | 结果 |
|---|---|
| Undefined |
返回 "undefined".
|
| Null |
返回 "null".
|
| Boolean |
如果 argument 是 如果 argument 是 |
| Number |
返回 |
| String | 返回 argument. |
| Symbol |
抛出一个 |
| Object |
应用如下步骤:
|
"NaN"."0"."-" and ! "Infinity".对于提供了比上述转换规则更准确的实现,建议其中第五步参考下面的另一个版本:
David M. Gay 编写的二进制转换为十进制中关于浮点数的文章和代码对于 ECMAScript 实现者可能会有帮助:
Gay, David M. Correctly Rounded Binary-Decimal and Decimal-Binary Conversions. Numerical Analysis, Manuscript 90-10. AT&T Bell Laboratories (Murray Hill, New Jersey). November 30, 1990. 相关文章可以在
http://ampl.com/REFS/abstracts.html#rounding 找到. 相关代码在
http://netlib.sandia.gov/fp/dtoa.c 和
http://netlib.sandia.gov/fp/g_fmt.c ,这些代码也可以在其他 netlib 镜像网站找到。
| 参数类型 | 结果 |
|---|---|
| Undefined |
抛出一个 |
| Null |
抛出一个 |
| Boolean |
返回一个内部槽 [[BooleanData]] 为 argument 的新 Boolean 对象。见 |
| Number |
返回一个内部槽 [[NumberData]] 为 argument 的新 Number 对象。见 |
| String |
返回一个内部槽 [[StringData]] 为 argument 的新 String 对象。见 |
| Symbol |
返回一个内部槽 [[SymbolData]] 为 argument 的新 Symbol 对象。见 |
| Object | 返回 argument。 |
如果 argument 为是一可以通过 "-0" 的字符串,则undefined。这个
一个规范的数字字符串是指 CanonicalNumericIndexString
undefined, then| 参数类型 | 结果 |
|---|---|
| Undefined |
抛出一个 |
| Null |
抛出一个 |
| Boolean | 返回 argument. |
| Number | 返回 argument. |
| String | 返回 argument. |
| Symbol | 返回 argument. |
| Object | 返回 argument. |
参数为 argument 的
内部比较
这个算法在比较有符号的 0 以及比较 NaN 时和严格相等比较算法不同。
内部比较
false.SameValueZero 与 +0 和 -0 时不同
内部比较
比较x < y,x 和 y 都是 ECMAScript 语言值,将可能产生
true, then算法中的第三步和第七步不同是加法运算 + (
字符串类型的比较使用码元值序列的简单词典排序。这里没有尝试使用 Unicode 规范定义的更复杂的,基于语义的字符或字符串相等,以及排序顺序进行比较。因此,根据 Unicode 标准在规范上相等的字符串值可能测试为不相等。实际上,该算法假设了两个值是已经标准化的值。另外还需注意,对于包含补充字符的字符串,UTF-16 码元值序列与普通码元值序列的词典排序是不同的。
比较 x == y,产生
比较 x === y,产生
该算法与
该
If newTarget is not present, this operation is equivalent to: new F(...argumentsList)
"sealed" or "frozen"."sealed", then"frozen","sealed" or "frozen"."frozen" and this 值, P 是属性 key, argumentsList 是传递给方法的参数列表。 如果 argumentsList 未提供,则使用一个空的
"prototype")."constructor").当使用对象 O 和字符串 kind 作为参数调用
参数为 obj 的
第五步只有在 obj 是一个没有 [[Realm]] 内部槽的非标准函数怪异对象时执行。
When the abstract operation CopyDataProperties is called with arguments target, source, and excludedItems, the following steps are taken:
The target passed in here is always a newly created object which is not directly accessible in case of an error being thrown.
参考常见的迭代接口 (
参数为 obj 和可选参数 hint, method 的
"next").参数为 iteratorRecord 和可选参数 value 的
参数为 iterResult 的
使用参数为 iterResult 的
使用参数 iteratorRecord 的
参数为 iteratorRecord 和 completion 的
"return").The abstract operation AsyncIteratorClose with arguments iteratorRecord and completion is used to notify an async iterator that it should perform any actions it would normally perform when it has reached its completed state:
"return").参数为 value 和 done 的
"value", value)."done", done).参数为 list 的
next (这个迭代器对象列表从不直接通过 ECMAScript 代码访问。
ListIterator next 方法是一个标准的内置函数方法(章节
A Lexical Environment is a specification type used to define the association of
An
The outer environment reference is used to model the logical nesting of Lexical Environment values. The outer reference of a (inner) Lexical Environment is a reference to the Lexical Environment that logically surrounds the inner Lexical Environment. An outer Lexical Environment may, of course, have its own outer Lexical Environment. A Lexical Environment may serve as the outer environment for multiple inner Lexical Environments. For example, if a
A global environment is a Lexical Environment which does not have an outer environment. The
A module environment is a Lexical Environment that contains the bindings for the top level declarations of a
A function environment is a Lexical Environment that corresponds to the invocation of an ECMAScript this binding. A super method invocations.
Lexical Environments and
There are two primary kinds of Environment Record values used in this specification: declarative Environment Records and object Environment Records. Declarative Environment Records are used to define the effect of ECMAScript language syntactic elements such as
For specification purposes Environment Record values are values of the
| Method | Purpose |
|---|---|
| HasBinding(N) |
Determine if an |
| CreateMutableBinding(N, D) |
Create a new but uninitialized mutable binding in an |
| CreateImmutableBinding(N, S) |
Create a new but uninitialized immutable binding in an |
| InitializeBinding(N, V) |
Set the value of an already existing but uninitialized binding in an |
| SetMutableBinding(N, V, S) |
Set the value of an already existing mutable binding in an |
| GetBindingValue(N, S) |
Returns the value of an already existing binding from an |
| DeleteBinding(N) |
Delete a binding from an |
| HasThisBinding() |
Determine if an this binding. Return |
| HasSuperBinding() |
Determine if an super method binding. Return |
| WithBaseObject() |
If this with statement, return the with object. Otherwise, return |
Each declarative
The behaviour of the concrete specification methods for declarative Environment Records is defined by the following algorithms.
The concrete
The concrete
The concrete
The concrete
The concrete
An example of ECMAScript code that results in a missing binding at step 2 is:
function f(){eval("var x; x = (delete x, 0);")}
The concrete
The concrete
Regular declarative Environment Records do not provide a this binding.
Regular declarative Environment Records do not provide a super binding.
Declarative Environment Records always return
Each object
Object Environment Records created for with statements (
The behaviour of the concrete specification methods for object Environment Records is defined by the following algorithms.
The concrete
The concrete
Normally envRec will not have a binding for N but if it does, the semantics of
The concrete
The concrete
In this specification, all uses of CreateMutableBinding for object Environment Records are immediately followed by a call to InitializeBinding for the same name. Hence, implementations do not need to explicitly track the initialization state of individual object
The concrete
The concrete
The concrete
Regular object Environment Records do not provide a this binding.
Regular object Environment Records do not provide a super binding.
Object Environment Records return
A function Environment Record is a declarative this binding. If a function is not an super, its function Environment Record also contains the state that is used to perform super method invocations from within the function.
Function Environment Records have the additional state fields listed in
| Field Name | Value | Meaning |
|---|---|---|
| [[ThisValue]] | Any |
This is the |
| [[ThisBindingStatus]] |
"lexical" | "initialized" | "uninitialized"
|
If the value is "lexical", this is an |
| [[FunctionObject]] | Object |
The |
| [[HomeObject]] |
Object | |
If the associated function has super property accesses and is not an |
| [[NewTarget]] |
Object | |
If this |
Function Environment Records support all of the declarative
| Method | Purpose |
|---|---|
| BindThisValue(V) | Set the [[ThisValue]] and record that it has been initialized. |
| GetThisBinding() |
Return the value of this this binding. Throws a this binding has not been initialized.
|
| GetSuperBase() |
Return the object that is the base for super property accesses bound in this super property accesses will produce runtime errors.
|
The behaviour of the additional concrete specification methods for function Environment Records is defined by the following algorithms:
"lexical"."initialized", throw a "initialized"."lexical", return "lexical", return "lexical"."uninitialized", throw a A global
A global
Properties may be created directly on a
Global Environment Records have the additional fields listed in
| Field Name | Value | Meaning |
|---|---|---|
| [[ObjectRecord]] |
Object |
Binding object is the |
| [[GlobalThisValue]] | Object |
The value returned by this in global scope. Hosts may provide any ECMAScript Object value.
|
| [[DeclarativeRecord]] |
Declarative |
Contains bindings for all declarations in global code for the associated |
| [[VarNames]] |
|
The string names bound by |
| Method | Purpose |
|---|---|
| GetThisBinding() |
Return the value of this this binding.
|
| HasVarDeclaration (N) |
Determines if the argument identifier has a binding in this |
| HasLexicalDeclaration (N) |
Determines if the argument identifier has a binding in this |
| HasRestrictedGlobalProperty (N) |
Determines if the argument is the name of a |
| CanDeclareGlobalVar (N) | Determines if a corresponding CreateGlobalVarBinding call would succeed if called for the same argument N. |
| CanDeclareGlobalFunction (N) | Determines if a corresponding CreateGlobalFunctionBinding call would succeed if called for the same argument N. |
| CreateGlobalVarBinding(N, D) |
Used to create and initialize to var binding in the [[ObjectRecord]] component of a global var. The String value N is the bound name. If D is |
| CreateGlobalFunctionBinding(N, V, D) |
Create and initialize a global function binding in the [[ObjectRecord]] component of a global function. The String value N is the bound name. V is the initialization value. If the Boolean argument D is |
The behaviour of the concrete specification methods for global Environment Records is defined by the following algorithms.
The concrete
The concrete
The concrete
The concrete
The concrete
The concrete
The concrete
Global Environment Records always return
The concrete
The concrete
The concrete
Properties may exist upon a undefined is an example of such a property.
The concrete
The concrete
The concrete
The concrete
Global function declarations are always represented as own properties of the
A module
Module Environment Records support all of the declarative
| Method | Purpose |
|---|---|
| CreateImportBinding(N, M, N2) |
Create an immutable indirect binding in a module |
| GetThisBinding() |
Return the value of this this binding.
|
The behaviour of the additional concrete specification methods for module Environment Records are defined by the following algorithms:
The concrete
S will always be
The concrete
Module Environment Records are only used within strict code and an
Module Environment Records provide a this binding.
The concrete
The following
The abstract operation GetIdentifierReference is called with a
When the abstract operation NewDeclarativeEnvironment is called with a
When the abstract operation NewObjectEnvironment is called with an Object O and a
When the abstract operation NewFunctionEnvironment is called with arguments F and newTarget the following steps are performed:
"lexical"."uninitialized".When the abstract operation NewGlobalEnvironment is called with arguments G and thisValue, the following steps are performed:
When the abstract operation NewModuleEnvironment is called with a
Before it is evaluated, all ECMAScript code must be associated with a realm. Conceptually, a
A
| Field Name | Value | Meaning |
|---|---|---|
| [[Intrinsics]] |
|
The intrinsic values used by code associated with this |
| [[GlobalObject]] | Object |
The |
| [[GlobalEnv]] |
|
The |
| [[TemplateMap]] |
A |
Template objects are canonicalized separately for each Once a |
| [[HostDefined]] |
Any, default value is |
Field reserved for use by host environments that need to associate additional information with a |
The abstract operation CreateRealm with no arguments performs the following steps:
The abstract operation CreateIntrinsics with argument realmRec performs the following steps:
The abstract operation SetRealmGlobalObject with arguments realmRec, globalObj, and thisValue performs the following steps:
The abstract operation SetDefaultGlobalBindings with argument realmRec performs the following steps:
An execution context is a specification device that is used to track the runtime evaluation of code by an ECMAScript implementation. At any point in time, there is at most one execution context per
The execution context stack is used to track execution contexts. The
An execution context contains whatever implementation specific state is necessary to track the execution progress of its associated code. Each execution context has at least the state components listed in
| Component | Purpose |
|---|---|
| code evaluation state |
Any state needed to perform, suspend, and resume evaluation of the code associated with this |
| Function |
If this |
|
|
The |
| ScriptOrModule |
The |
Evaluation of code by the
The value of the
Execution contexts for ECMAScript code have the additional state components listed in
| Component | Purpose |
|---|---|
| LexicalEnvironment |
Identifies the |
| VariableEnvironment |
Identifies the |
The LexicalEnvironment and VariableEnvironment components of an execution context are always Lexical Environments.
Execution contexts representing the evaluation of generator objects have the additional state components listed in
| Component | Purpose |
|---|---|
| Generator |
The GeneratorObject that this |
In most situations only the
An execution context is purely a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation. It is impossible for ECMAScript code to directly access or observe an execution context.
The GetActiveScriptOrModule abstract operation is used to determine the running script or module, based on the
The ResolveBinding abstract operation is used to determine the binding of name passed as a String value. The optional argument env can be used to explicitly provide the
The result of ResolveBinding is always a
The abstract operation GetThisEnvironment finds the this. GetThisEnvironment performs the following steps:
The loop in step 2 will always terminate because the list of environments always ends with the this binding.
The abstract operation ResolveThisBinding determines the binding of the this using the LexicalEnvironment of the
The abstract operation GetNewTarget determines the NewTarget value using the LexicalEnvironment of the
The abstract operation GetGlobalObject returns the
A
Execution of a
| Field Name | Value | Meaning |
|---|---|---|
| [[Job]] |
The name of a |
This is the abstract operation that is performed when execution of this PendingJob is initiated. |
| [[Arguments]] |
A |
The |
| [[Realm]] |
A |
The |
| [[ScriptOrModule]] |
A |
The script or module for the initial |
| [[HostDefined]] |
Any, default value is |
Field reserved for use by host environments that need to associate additional information with a pending |
A
Each
A request for the future execution of a
The PendingJob records from a single
Typically an ECMAScript implementation will have its
The following
The EnqueueJob abstract operation requires three arguments: queueName, job, and arguments. It performs the following steps:
The abstract operation InitializeHostDefinedRealm performs the following steps:
this binding in realm's global scope return an object other than the this binding should be the The abstract operation RunJobs performs the following steps:
"ScriptJobs", "ScriptJobs", An agent comprises a set of ECMAScript execution contexts, an
An
Some web browsers share a single
While an
| Field Name | Value | Meaning |
|---|---|---|
| [[LittleEndian]] | Boolean | The default value computed for the isLittleEndian parameter when it is needed by the algorithms |
| [[CanBlock]] | Boolean | Determines whether the |
| [[Signifier]] | Any globally-unique value | Uniquely identifies the |
| [[IsLockFree1]] | Boolean | |
| [[IsLockFree2]] | Boolean | |
| [[CandidateExecution]] | A |
See the |
Once the values of [[Signifier]], [[IsLockFree1]], and [[IsLockFree2]] have been observed by any
The values of [[IsLockFree1]] and [[IsLockFree2]] are not necessarily determined by the hardware, but may also reflect implementation choices that can vary over time and between ECMAScript implementations.
There is no [[IsLockFree4]] property: 4-byte atomic operations are always lock-free.
In practice, if an atomic operation is implemented with any type of lock the operation is not lock-free. Lock-free does not imply wait-free: there is no upper bound on how many machine steps may be required to complete a lock-free atomic operation.
That an atomic access of size n is lock-free does not imply anything about the (perceived) atomicity of non-atomic accesses of size n, specifically, non-atomic accesses may still be performed as a sequence of several separate memory accesses. See
An
The abstract operation AgentSignifier takes no arguments. It performs the following steps:
The abstract operation AgentCanSuspend takes no arguments. It performs the following steps:
In some environments it may not be reasonable for a given
An agent cluster is a maximal set of agents that can communicate by operating on shared memory.
Programs within different agents may share memory by unspecified means. At a minimum, the backing memory for SharedArrayBuffer objects can be shared among the agents in the cluster.
There may be agents that can communicate by message passing that cannot share memory; they are never in the same agent cluster.
Every
All agents within a cluster must have the same value for the [[LittleEndian]] property in their respective
If different agents within an agent cluster have different values of [[LittleEndian]] it becomes hard to use shared memory for multi-byte data.
All agents within a cluster must have the same values for the [[IsLockFree1]] property in their respective
All agents within a cluster must have different values for the [[Signifier]] property in their respective
An embedding may deactivate (stop forward progress) or activate (resume forward progress) an
The purpose of the preceding restriction is to avoid a situation where an
The implication of the restriction is that it will not be possible to share memory between agents that don't belong to the same suspend/wake collective within the embedding.
An embedding may terminate an
Prior to any evaluation of any ECMAScript code by any
All agents in an agent cluster share the same
An agent cluster is a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation.
For an
An
Implementations must ensure that:
This, along with the liveness guarantee in the "SeqCst" writes eventually become observable to all agents.
All ordinary objects have an internal slot called [[Prototype]]. The value of this internal slot is either
Every ordinary object has a Boolean-valued [[Extensible]] internal slot that controls whether or not properties may be added to the object. If the value of the [[Extensible]] internal slot is
In the following algorithm descriptions, assume O is an ordinary object, P is a property key value, V is any
Each ordinary object internal method delegates to a similarly-named abstract operation. If such an abstract operation depends on another internal method, then the internal method is invoked on O rather than calling the similarly-named abstract operation directly. These semantics ensure that exotic objects have their overridden internal methods invoked when ordinary object internal methods are applied to them.
When the [[GetPrototypeOf]] internal method of O is called, the following steps are taken:
When the abstract operation OrdinaryGetPrototypeOf is called with Object O, the following steps are taken:
When the [[SetPrototypeOf]] internal method of O is called with argument V, the following steps are taken:
When the abstract operation OrdinarySetPrototypeOf is called with Object O and value V, the following steps are taken:
The loop in step 8 guarantees that there will be no circularities in any prototype chain that only includes objects that use the ordinary object definitions for [[GetPrototypeOf]] and [[SetPrototypeOf]].
When the [[IsExtensible]] internal method of O is called, the following steps are taken:
When the abstract operation OrdinaryIsExtensible is called with Object O, the following steps are taken:
When the [[PreventExtensions]] internal method of O is called, the following steps are taken:
When the abstract operation OrdinaryPreventExtensions is called with Object O, the following steps are taken:
When the [[GetOwnProperty]] internal method of O is called with property key P, the following steps are taken:
When the abstract operation OrdinaryGetOwnProperty is called with Object O and with property key P, the following steps are taken:
When the [[DefineOwnProperty]] internal method of O is called with property key P and
When the abstract operation OrdinaryDefineOwnProperty is called with Object O, property key P, and
When the abstract operation IsCompatiblePropertyDescriptor is called with Boolean value Extensible, and Property Descriptors Desc, and Current, the following steps are taken:
When the abstract operation ValidateAndApplyPropertyDescriptor is called with Object O, property key P, Boolean value extensible, and Property Descriptors Desc, and current, the following steps are taken:
If
When the [[HasProperty]] internal method of O is called with property key P, the following steps are taken:
When the abstract operation OrdinaryHasProperty is called with Object O and with property key P, the following steps are taken:
When the [[Get]] internal method of O is called with property key P and
When the abstract operation OrdinaryGet is called with Object O, property key P, and
When the [[Set]] internal method of O is called with property key P, value V, and
When the abstract operation OrdinarySet is called with Object O, property key P, value V, and
When the abstract operation OrdinarySetWithOwnDescriptor is called with Object O, property key P, value V,
When the [[Delete]] internal method of O is called with property key P, the following steps are taken:
When the abstract operation OrdinaryDelete is called with Object O and property key P, the following steps are taken:
When the [[OwnPropertyKeys]] internal method of O is called, the following steps are taken:
When the abstract operation OrdinaryOwnPropertyKeys is called with Object O, the following steps are taken:
The abstract operation ObjectCreate with argument proto (an object or null) is used to specify the runtime creation of new ordinary objects. The optional argument internalSlotsList is a
The abstract operation OrdinaryCreateFromConstructor creates an ordinary object whose [[Prototype]] value is retrieved from a prototype property, if it exists. Otherwise the intrinsic named by intrinsicDefaultProto is used for [[Prototype]]. The optional internalSlotsList is a
The abstract operation GetPrototypeFromConstructor determines the [[Prototype]] value that should be used to create an object corresponding to a specific prototype property, if it exists. Otherwise the intrinsic named by intrinsicDefaultProto is used for [[Prototype]]. This abstract operation performs the following steps:
"prototype").If constructor does not supply a [[Prototype]] value, the default value that is used is obtained from the
ECMAScript function objects encapsulate parameterized ECMAScript code closed over a lexical environment and support the dynamic evaluation of that code. An ECMAScript
ECMAScript function objects have the additional internal slots listed in
| Internal Slot | Type | Description |
|---|---|---|
| [[Environment]] |
|
The |
| [[FormalParameters]] |
|
The root parse node of the source text that defines the function's formal parameter list. |
| [[FunctionKind]] | String |
Either "normal", "classConstructor", "generator", or "async".
|
| [[ECMAScriptCode]] |
|
The root parse node of the source text that defines the function's body. |
| [[ConstructorKind]] | String |
Either "base" or "derived".
|
| [[Realm]] |
|
The |
| [[ScriptOrModule]] |
|
The script or module in which the function was created. |
| [[ThisMode]] | (lexical, strict, global) |
Defines how this references are interpreted within the formal parameters and code body of the function. this refers to the |
| [[Strict]] | Boolean |
|
| [[HomeObject]] | Object |
If the function uses super, this is the object whose [[GetPrototypeOf]] provides the object where super property lookups begin.
|
All ECMAScript function objects have the [[Call]] internal method defined here. ECMAScript functions that are also constructors in addition have the [[Construct]] internal method.
The [[Call]] internal method for an ECMAScript
"classConstructor", throw a When calleeContext is removed from the
When the abstract operation PrepareForOrdinaryCall is called with
When the abstract operation OrdinaryCallBindThis is called with
"initialized".When the abstract operation OrdinaryCallEvaluateBody is called with
The [[Construct]] internal method for an ECMAScript
"base", then"%ObjectPrototype%")."base", perform "base", return The abstract operation FunctionAllocate requires the three arguments functionPrototype, strict and functionKind. FunctionAllocate performs the following steps:
"normal", "non-constructor", "generator", "async", or "async generator"."normal", let needsConstruct be "non-constructor", set functionKind to "normal"."base".The abstract operation FunctionInitialize requires the arguments: a
The abstract operation FunctionCreate requires the arguments: kind which is one of (Normal, Method, Arrow), a parameter list
"non-constructor"."normal".The abstract operation GeneratorFunctionCreate requires the arguments: kind which is one of (Normal, Method), a parameter list