本规范中使用的环境记录的值主要有两种:声明性环境记录和对象环境记录。声明性环境记录用于定义ECMAScript语言语法元素(例如 FunctionDeclarations,VariableDeclarations 和 Catch 语句)的效果,这些元素直接将标识符绑定与 ECMAScript 语言的值关联起来。对象环境记录用于定义 ECMAScript 元素(例如WithStatement)的效果,它将标识符绑定与某些对象的属性关联起来。全局环境记录和函数环境记录是特殊的东西,专门用于脚本全局声明和函数中的顶层声明。
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 FunctionDeclarations, VariableDeclarations, and Catch clauses that directly associate identifier bindings with ECMAScript language values. Object Environment Records are used to define the effect of ECMAScript elements such as WithStatement that associate identifier bindings with the properties of some object. Global Environment Records and function Environment Records are specializations that are used for specifically for Script global declarations and for top-level declarations within functions.
出于规范目的,环境记录的值是 Record 规范类型的值,可以认为是存在于一个简单的面向对象的层次结构中,其中环境记录是一个抽象的类,有三个具体的子类,声明式环境记录、对象环境记录和全局环境记录。函数环境记录和模块环境记录是声明性环境记录的子类。抽象类包括表 14 中定义的抽象规范方法。这些抽象方法在每个具体的子类中都有不同的具体算法。
For specification purposes Environment Record values are values of the Record specification type and can be thought of as existing in a simple object-oriented hierarchy where Environment Record is an abstract class with three concrete subclasses, declarative Environment Record, object Environment Record, and global Environment Record. Function Environment Records and module Environment Records are subclasses of declarative Environment Record. The abstract class includes the abstract specification methods defined in Table 14. These abstract methods have distinct concrete algorithms for each of the concrete subclasses.
表 14:环境记录的抽象方法
Table 14: Abstract Methods of Environment Records
| Method(函数) | Purpose(目的) |
|---|---|
| HasBinding(N) | 判断一个环境记录是否绑定了 字符串 N 。如果有,则返回 true,如果没有,则返回 false。 Determine if an Environment Record has a binding for the String value N. Return true if it does and false if it does not. |
| CreateMutableBinding(N, D) | 在环境记录中创建一个新的但未初始化的可变绑定。字符串值 N 是绑定名称的文本。如果布尔参数 D 为 true,则绑定可以之后删除。 Create a new but uninitialized mutable binding in an Environment Record. The String value N is the text of the bound name. If the Boolean argument D is true the binding may be subsequently deleted. |
| CreateImmutableBinding(N, S) | 在环境记录中创建一个新的但未初始化的不可变绑定。字符串值 N 是绑定名称的文本。如果 S 为 true,则无论初始化该绑定的操作的严格模式如何设置,在初始化后尝试对其进行设置总是会引发异常。 Create a new but uninitialized immutable binding in an Environment Record. The String value N is the text of the bound name. If S is true then attempts to set it after it has been initialized will always throw an exception, regardless of the strict mode setting of operations that reference that binding. |
| InitializeBinding(N, V) | 设置环境记录中已经存在但未初始化的绑定的值。字符串值 N 是绑定名称的文本。V 是绑定的值,并且是任何 ECMAScript 语言类型的值。 Set the value of an already existing but uninitialized binding in an Environment Record. The String value N is the text of the bound name. V is the value for the binding and is a value of any ECMAScript language type. |
| SetMutableBinding(N, V, S) | 设置环境记录中已经存在的可变绑定的值。字符串值 N 是绑定名称的文本。 V 是绑定的值,并且可以是任何 ECMAScript 语言类型的值。 S 是布尔值标志。 如果 S 为 true,并且绑定无法设置,则抛出 TypeError 异常。 Set the value of an already existing mutable binding in an Environment Record. The String value N is the text of the bound name. V is the value for the binding and may be a value of any ECMAScript language type. S is a Boolean flag. If S is true and the binding cannot be set throw a TypeError exception. |
| GetBindingValue(N, S) | 返回环境记录中已经存在的绑定的值。字符串值 N 是绑定名称的文本。 S 用于识别源于严格模式代码中的引用,或者是需要严格模式引用语义的引用。 如果 S 为 true 并且绑定不存在,则引发 ReferenceError 异常。 如果绑定存在但未初始化,则无论 S 的值如何,都会引发 ReferenceError。 Returns the value of an already existing binding from an Environment Record. The String value N is the text of the bound name. S is used to identify references originating in strict mode code or that otherwise require strict mode reference semantics. If S is true and the binding does not exist throw a ReferenceError exception. If the binding exists but is uninitialized a ReferenceError is thrown, regardless of the value of S. |
| DeleteBinding(N) | 从环境记录中删除绑定。字符串值 N 是绑定名称的文本。 如果存在 N 的绑定,请删除该绑定并返回 true。如果绑定存在但无法删除,则返回false。 如果绑定不存在,则返回 true。 Delete a binding from an Environment Record. The String value N is the text of the bound name. If a binding for N exists, remove the binding and return true. If the binding exists but cannot be removed return false. If the binding does not exist return true. |
| HasThisBinding() | 确定环境记录是否建立了此绑定。如果是,则返回 true;否则,则返回 false。 Determine if an Environment Record establishes a this binding. Return true if it does and false if it does not. |
| HasSuperBinding() | 确定环境记录是否建立了 super 方法绑定。如果是,则返回 true;否则,则返回 false。 Determine if an Environment Record establishes a super method binding. Return true if it does and false if it does not. |
| WithBaseObject() | 如果这个环境记录与 with 语句关联,则返回 with 对象。否则,返回未定义。 If this Environment Record is associated with a with statement, return the with object. Otherwise, return undefined. |
