- 8.1.1.1.1 HasBinding( N )
- 8.1.1.1.2 CreateMutableBinding( N, D )
- 8.1.1.1.3 CreateImmutableBinding( N, S )
- 8.1.1.1.4 InitializeBinding( N, V )
- 8.1.1.1.5 SetMutableBinding( N, V, S )
- 8.1.1.1.6 GetBindingValue( N, S )
- 8.1.1.1.7 DeleteBinding( N )
- 8.1.1.1.8 HasThisBinding( )
- 8.1.1.1.9 HasSuperBinding( )
- 8.1.1.1.10 WithBaseObject( )
每个声明性环境记录都与一个 ECMAScript 程序作用域相关联,其中包含了变量、常量、let、类、模块、导入和函数声明。一个声明性环境记录绑定了由其作用域中的声明定义的标识符集。
Each declarative Environment Record is associated with an ECMAScript program scope containing variable, constant, let, class, module, import, and/or function declarations. A declarative Environment Record binds the set of identifiers defined by the declarations contained within its scope.
声明性环境记录的具体规范方法的行为由以下算法定义。
The behaviour of the concrete specification methods for declarative Environment Records is defined by the following algorithms.
8.1.1.1.1 HasBinding( N )
声明性环境记录的具体环境记录方法 HasBinding 只需确定参数标识符是否是记录绑定的标识符之一。
The concrete Environment Record method HasBinding for declarative Environment Records simply determines if the argument identifier is one of the identifiers bound by the record:
- 让 envRec 成为调用该方法的声明性环境记录。
- 如果 envRec 具有值为 N 的名称的绑定,则返回 true。
- 否则返回 false。
- Let envRec be the declarative Environment Record for which the method was invoked.
- If envRec has a binding for the name that is the value of N, return true.
- Return false.
8.1.1.1.2 CreateMutableBinding( N, D )
声明性环境记录的具体环境记录方法 CreateMutableBinding 为未初始化的名称 N 创建一个新的可变绑定。N 在此环境记录中必须不存在绑定。如果布尔参数 D 的值为 true,则新绑定被标记为可以删除。
The concrete Environment Record method CreateMutableBinding for declarative Environment Records creates a new mutable binding for the name N that is uninitialized. A binding must not already exist in this Environment Record for N. If Boolean argument D has the value true the new binding is marked as being subject to deletion.
- 让 envRec 成为调用该方法的声明性环境记录。
- 断言: envRec 还没有 N 的绑定。
- 在 envRec 中为 N 创建一个可变绑定,并记录它未初始化。如果 D 为真,则记录新创建的绑定可能会被后续的 DeleteBinding 调用删除。
- 返回 NormalCompletion(empty)。
- Let envRec be the declarative Environment Record for which the method was invoked.
- Assert: envRec does not already have a binding for N.
- Create a mutable binding in envRec for N and record that it is uninitialized. If D is true, record that the newly created binding may be deleted by a subsequent DeleteBinding call.
- Return NormalCompletion(empty).
8.1.1.1.3 CreateImmutableBinding( N, S )
声明性环境记录的具体环境记录方法 CreateImmutableBinding 为名称 N 创建了一个新的不可更改的绑定,该绑定是未初始化的。如果布尔参数 S 的值为 true,则新的绑定被标记为严格绑定。
The concrete Environment Record method CreateImmutableBinding for declarative Environment Records creates a new immutable binding for the name N that is uninitialized. A binding must not already exist in this Environment Record for N. If the Boolean argument S has the value true the new binding is marked as a strict binding.
- 让 envRec 成为调用该方法的声明性环境记录。
- 断言: envRec 还没有 N 的绑定。
- 在 envRec 中为 N 创建一个不可变绑定,并记录它未初始化。如果 S 为真,则记录新创建的绑定是严格绑定。
- 返回 NormalCompletion(empty)。
- Let envRec be the declarative Environment Record for which the method was invoked.
- Assert: envRec does not already have a binding for N.
- Create an immutable binding in envRec for N and record that it is uninitialized. If S is true, record that the newly created binding is a strict binding.
- Return NormalCompletion(empty).
8.1.1.1.4 InitializeBinding( N, V )
声明性环境记录的具体环境记录方法InitializeBinding用于设置当前绑定的标识符的绑定值,该标识符的名称是参数N的值,而参数V的值是当前绑定的值,未初始化的N的绑定必须已经存在。
The concrete Environment Record method InitializeBinding for declarative Environment Records is used to set the bound value of the current binding of the identifier whose name is the value of the argument N to the value of argument V. An uninitialized binding for N must already exist.
- 让 envRec 成为调用该方法的声明性环境记录。
- 断言: envRec 必须具有 N 的未初始化绑定。
- 将 envRec 中 N 的绑定值设置为 V。
- 记录 envRec 中 N 的绑定已初始化。
- 返回 NormalCompletion(empty)。
- Let envRec be the declarative Environment Record for which the method was invoked.
- Assert: envRec must have an uninitialized binding for N.
- Set the bound value for N in envRec to V.
- Record that the binding for N in envRec has been initialized.
- Return NormalCompletion(empty).
8.1.1.1.5 SetMutableBinding( N, V, S )
声明性环境记录的具体环境记录方法 SetMutableBinding 试图将名称为参数 N 的值的标识符的当前绑定的绑定值更改为参数 V 的值。N 的绑定通常已经存在,但在极少数情况下可能不存在。如果绑定是不可变绑定,如果 S 为 true,则引发 TypeError。
The concrete Environment Record method SetMutableBinding for declarative Environment Records attempts to change the bound value of the current binding of the identifier whose name is the value of the argument N to the value of argument V. A binding for N normally already exists, but in rare cases it may not. If the binding is an immutable binding, a TypeError is thrown if S is true.
- 让 envRec 成为调用该方法的声明性环境记录。
- 如果 envRec 没有绑定 N,那么:
- 如果 S 为 true,则抛出一个 ReferenceError 的异常。
- 执行 envRec.CreateMutableBinding(N, true)。
- 执行 envRec.InitializeBinding(N, V)。
- 返回 NormalCompletion(empty)。
- 如果 envRec 中 N 的绑定是严格绑定,请将 S 设置为 true。
- 如果 envRec 中 N 的绑定尚未初始化,则抛出一个 Reference 的异常。
- 否则,如果 envRec 中的 N 的绑定是可变绑定,则将其绑定值改为 V。
- 否则,
- 断言: 这是试图更改不可变绑定的值。
- 如果 S 为 true,则抛出一个 TypeError 的异常。
- 返回 NormalCompletion(empty)。
- Let envRec be the declarative Environment Record for which the method was invoked.
- If envRec does not have a binding for N, then
a. If S is true, throw a ReferenceError exception. b. Perform envRec.CreateMutableBinding(N, true). c. Perform envRec.InitializeBinding(N, V). d. Return NormalCompletion(empty).
- If the binding for N in envRec is a strict binding, set S to true.
- If the binding for N in envRec has not yet been initialized, throw a ReferenceError exception.
- Else if the binding for N in envRec is a mutable binding, change its bound value to V.
- Else,
a. Assert: This is an attempt to change the value of an immutable binding. b. If S is true, throw a TypeError exception.
- Return NormalCompletion(empty).
NOTE
在步骤 2 中导致缺少绑定的 ECMAScript 代码示例是:
An example of ECMAScript code that results in a missing binding at step 2 is: function f(){eval(“var x; x = (delete x, 0);”)}
8.1.1.1.6 GetBindingValue( N, S )
声明性环境记录的具体环境记录方法 GetBindingValue 只需返回其绑定的标识符的值,该标识符的名称是参数 N 的值。如果绑定存在,但未初始化,则会抛出一个ReferenceError,而不考虑S的值。
The concrete Environment Record method GetBindingValue for declarative Environment Records simply returns the value of its bound identifier whose name is the value of the argument N. If the binding exists but is uninitialized a ReferenceError is thrown, regardless of the value of S.
- 让 envRec 成为调用该方法的声明性环境记录。
- 断言: envRec 具有 N 的绑定。
- 如果 envRec 中 N 的绑定是未初始化的绑定,则抛出一个 ReferenceError 的异常。
- 返回 envRec 中当前绑定到 N 的值。
- Let envRec be the declarative Environment Record for which the method was invoked.
- Assert: envRec has a binding for N.
- If the binding for N in envRec is an uninitialized binding, throw a ReferenceError exception.
- Return the value currently bound to N in envRec.
8.1.1.1.7 DeleteBinding( N )
声明性环境记录的具体环境记录方法 DeleteBinding 只能删除已明确指定为可以删除的绑定。
The concrete Environment Record method DeleteBinding for declarative Environment Records can only delete bindings that have been explicitly designated as being subject to deletion.
- 让 envRec 成为调用该方法的声明性环境记录。
- 断言: envRec 有一个值为 N 的名称的绑定。
- 如果无法删除 envRec 中 N 的绑定,则返回 false。
- 从 envRec 中删除 N 的绑定。
- 返回 true。
- Let envRec be the declarative Environment Record for which the method was invoked.
- Assert: envRec has a binding for the name that is the value of N.
- If the binding for N in envRec cannot be deleted, return false.
- Remove the binding for N from envRec.
- Return true.
8.1.1.1.8 HasThisBinding( )
常规声明性环境记录不提供 this 绑定。
Regular declarative Environment Records do not provide a this binding.
- 返回 false。
- Return false.
8.1.1.1.9 HasSuperBinding( )
常规声明性环境记录不提供 super 绑定。
Regular declarative Environment Records do not provide a super binding.
- 返回 false。
- Return false.
8.1.1.1.10 WithBaseObject( )
声明性环境记录总是返回 undefined 作为其 WithBaseObject。
Declarative Environment Records always return undefined as their WithBaseObject.
- 返回 Undefined。
- Return undefined.
