ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 19

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     17      18      19      20     ..

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 19

 

 

ClassElement

 

:

 

;

1.  Return 

empty

.

AsyncMethod

 

:

 

async

 

PropertyName

 

(

 

UniqueFormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

1.  Return 

PropName

 of 

PropertyName

.

Environment Record

 is a specification type used to define the association of 

Identifier

s to specific variables and

functions, based upon the lexical nesting structure of ECMAScript code. Usually an Environment Record is associated
with some specific syntactic structure of ECMAScript code such as a 

FunctionDeclaration

, a 

BlockStatement

, or a 

Catch

clause of a 

TryStatement

. Each time such code is evaluated, a new Environment Record is created to record the

identifier bindings that are created by that code.

Every Environment Record has an [[OuterEnv]] field, which is either 

null

 or a reference to an outer Environment

Record. This is used to model the logical nesting of Environment Record values. The outer reference of an (inner)
Environment Record is a reference to the Environment Record that logically surrounds the inner Environment Record.
An outer Environment Record may, of course, have its own outer Environment Record. An Environment Record may
serve as the outer environment for multiple inner Environment Records. For example, if a 

FunctionDeclaration

 contains

two nested 

FunctionDeclaration

s then the Environment Records of each of the nested functions will have as their outer

Environment Record the Environment Record of the current evaluation of the surrounding function.

Environment Records are purely specification mechanisms and need not correspond to any specific artefact of an
ECMAScript implementation. It is impossible for an ECMAScript program to directly access or manipulate such
values.

Environment Records can be thought of as existing in a simple object-oriented hierarchy wher

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

.

Environment Record

 (abstract)

declarative Environment Record

 is used to define the effect of ECMAScript language syntactic elements

such as 

FunctionDeclaration

s, 

VariableDeclaration

s, and 

Catch

 clauses that directly associate identifier

bindings with ECMAScript language values.

function Environment Record

 corresponds to the invocation of an ECMAScript 

function object

,

and contains bindings for the top-level declarations within that function. It may establish a new

this

this

 binding. It also captures the state necessary to support 

super

super

 method invocations.

module Environment Record

 contains the bindings for the top-level declarations of a 

Module

. It

9  Executable Code and Execution Contexts

9.1  Environment Records

9.1.1  The Environment Record Type Hierarchy

186

also contains the bindings that are explicitly imported by the 

Module

. Its [[OuterEnv]] is a 

global

Environment Record

.

An 

object Environment Record

 is used to define the effect of ECMAScript elements such as 

WithStatement

that associate identifier bindings with the properties of some object.

global Environment Record

 is used for 

Script

 global declarations. It does not have an outer environment;

its [[OuterEnv]] is 

null

. It may be prepopulated with identifier bindings and it includes an associated

global object

 whose properties provide some of the global environment's identifier bindings. As

ECMAScript code is executed, additional properties may be added to the 

global object

 and the initial

properties may be modified.

The 

Environment Record

 abstract class includes the abstract specification methods defined in 

Table 17

. These abstract

methods have distinct concrete algorithms for each of the concrete subclasses.

187

Table 17: Abstract Methods of Environment Records

Method

Purpose

HasBinding(N)

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)

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)

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)

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)

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)

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)

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()

Determine if an 

Environment Record

 establishes a 

this

this

 binding. Return 

true

 if it

does and 

false

 if it does not.

HasSuperBinding()

Determine if an 

Environment Record

 establishes a 

super

super

 method binding. Return

true

 if it does and 

false

 if it does not.

WithBaseObject()

If this 

Environment Record

 is associated with a 

with

with

 statement, return the with

object. Otherwise, return 

undefined

.

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.

9.1.1.1  Declarative Environment Records

188

The behaviour of the concrete specification methods for declarative Environment Records is defined by the following
algorithms.

The HasBinding concrete method of a 

declarative Environment Record

 

envRec

 takes argument 

N

 (a String). It

determines if the argument identifier is one of the identifiers bound by the record. It performs the following steps
when called:

1.  If 

envRec

 has a binding for the name that is the value of 

N

, return 

true

.

2.  Return 

false

.

The CreateMutableBinding concrete method of a 

declarative Environment Record

 

envRec

 takes arguments 

N

 (a String)

and 

D

 (a Boolean). It 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 

D

 has the value 

true

, the new binding is marked as being subject to deletion.

It performs the following steps when called:

1. 

Assert

envRec

 does not already have a binding for 

N

.

2.  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.

3.  Return 

NormalCompletion

(

empty

).

The CreateImmutableBinding concrete method of a 

declarative Environment Record

 

envRec

 takes arguments 

N

 (a

String) and 

S

 (a Boolean). It 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 

S

 has the value 

true

, the new binding is marked as a strict binding.

It performs the following steps when called:

1. 

Assert

envRec

 does not already have a binding for 

N

.

2.  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.

3.  Return 

NormalCompletion

(

empty

).

The InitializeBinding concrete method of a 

declarative Environment Record

 

envRec

 takes arguments 

N

 (a String) and

V

 (an 

ECMAScript language value

). It 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. It

performs the following steps when called:

1. 

Assert

envRec

 must have an uninitialized binding for 

N

.

2.  Set the bound value for 

N

 in 

envRec

 to 

V

.

3.  Record that the binding for 

N

 in 

envRec

 has been initialized.

4.  Return 

NormalCompletion

(

empty

).

The SetMutableBinding concrete method of a 

declarative Environment Record

 

envRec

 takes arguments 

N

 (a String), 

V

9.1.1.1.1  HasBinding ( 

N

 )

9.1.1.1.2  CreateMutableBinding ( 

N

D

 )

9.1.1.1.3  CreateImmutableBinding ( 

N

S

 )

9.1.1.1.4  InitializeBinding ( 

N

V

 )

9.1.1.1.5  SetMutableBinding ( 

N

V

S

 )

189

(an 

ECMAScript language value

), and 

S

 (a Boolean). It 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

. It

performs the following steps when called:

1.  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

).

2.  If the binding for 

N

 in 

envRec

 is a strict binding, set 

S

 to 

true

.

3.  If the binding for 

N

 in 

envRec

 has not yet been initialized, throw a 

ReferenceError

 exception.

4.  Else if the binding for 

N

 in 

envRec

 is a mutable binding, change its bound value to 

V

.

5.  Else,

a. 

Assert

: This is an attempt to change the value of an immutable binding.

b.  If 

S

 is 

true

, throw a 

TypeError

 exception.

6.  Return 

NormalCompletion

(

empty

).

NOTE

The GetBindingValue concrete method of a 

declarative Environment Record

 

envRec

 takes arguments 

N

 (a String) and

S

 (a Boolean). It 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

. It performs the following steps

when called:

1. 

Assert

envRec

 has a binding for 

N

.

2.  If the binding for 

N

 in 

envRec

 is an uninitialized binding, throw a 

ReferenceError

 exception.

3.  Return the value currently bound to 

N

 in 

envRec

.

The DeleteBinding concrete method of a 

declarative Environment Record

 

envRec

 takes argument 

N

 (a String). It can

only delete bindings that have been explicitly designated as being subject to deletion. It performs the following steps
when called:

1. 

Assert

envRec

 has a binding for the name that is the value of 

N

.

2.  If the binding for 

N

 in 

envRec

 cannot be deleted, return 

false

.

3.  Remove the binding for 

N

 from 

envRec

.

4.  Return 

true

.

The HasThisBinding concrete method of a 

declarative Environment Record

 

envRec

 takes no arguments. It performs

the following steps when called:

An example of ECMAScript code that results in a missing binding at step 

1

 is:

function

 

f

() { 

eval

(

"var x; x = (delete x, 0);"

); }

9.1.1.1.6  GetBindingValue ( 

N

S

 )

9.1.1.1.7  DeleteBinding ( 

N

 )

9.1.1.1.8  HasThisBinding ( )

190

1.  Return 

false

.

NOTE

The HasSuperBinding concrete method of a 

declarative Environment Record

 

envRec

 takes no arguments. It performs

the following steps when called:

1.  Return 

false

.

NOTE

The WithBaseObject concrete method of a 

declarative Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  Return 

undefined

.

Each 

object Environment Record

 is associated with an object called its 

binding object

. An object Environment Record

binds the set of string identifier names that directly correspond to the property names of its binding object. Property
keys that are not strings in the form of an 

IdentifierName

 are not included in the set of bound identifiers. Both own and

inherited properties are included in the set regardless of the setting of their [[Enumerable]] attribute. Because
properties can be dynamically added and deleted from objects, the set of identifiers bound by an object Environment
Record may potentially change as a side-effect of any operation that adds or deletes properties. Any bindings that are
created as a result of such a side-effect are considered to be a mutable binding even if the Writable attribute of the
corresponding property has the value 

false

. Immutable bindings do not exist for object Environment Records.

Object Environment Records created for 

with

with

 statements (

14.11

) can provide their binding object as an implicit 

this

value for use in function calls. The capability is controlled by a 

withEnvironment

 Boolean value that is associated with

each object Environment Record. By default, the value of 

withEnvironment

 is 

false

 for any object Environment Record.

The behaviour of the concrete specification methods for object Environment Records is defined by the following
algorithms.

The HasBinding concrete method of an 

object Environment Record

 

envRec

 takes argument 

N

 (a String). It determines

if its associated binding object has a property whose name is the value of the argument 

N

. It performs the following

steps when called:

1.  Let 

bindings

 be the binding object for 

envRec

.

2.  Let 

foundBinding

 be ? 

HasProperty

(

bindings

N

).

3.  If 

foundBinding

 is 

false

, return 

false

.

A regular 

declarative Environment Record

 (i.e., one that is neither a 

function Environment

Record

 nor a 

module Environment Record

) does not provide a 

this

this

 binding.

A regular 

declarative Environment Record

 (i.e., one that is neither a 

function Environment

Record

 nor a 

module Environment Record

) does not provide a 

super

super

 binding.

9.1.1.1.9  HasSuperBinding ( )

9.1.1.1.10  WithBaseObject ( )

9.1.1.2  Object Environment Records

9.1.1.2.1  HasBinding ( 

N

 )

191

4.  If the 

withEnvironment

 flag of 

envRec

 is 

false

, return 

true

.

5.  Let 

unscopables

 be ? 

Get

(

bindings

@@unscopables

).

6.  If 

Type

(

unscopables

) is Object, then

a.  Let 

blocked

 be ! 

ToBoolean

(? 

Get

(

unscopables

N

)).

b.  If 

blocked

 is 

true

, return 

false

.

7.  Return 

true

.

The CreateMutableBinding concrete method of an 

object Environment Record

 

envRec

 takes arguments 

N

 (a String)

and 

D

 (a Boolean). It creates in an 

Environment Record

's associated binding object a property whose name is the

String value and initializes it to the value 

undefined

. If 

D

 has the value 

true

, the new property's [[Configurable]]

attribute is set to 

true

; otherwise it is set to 

false

. It performs the following steps when called:

1.  Let 

bindings

 be the binding object for 

envRec

.

2.  Return ? 

DefinePropertyOrThrow

(

bindings

N

, PropertyDescriptor { [[Value]]: 

undefined

, [[Writable]]: 

true

,

[[Enumerable]]: 

true

, [[Configurable]]: 

D

 }).

NOTE

The CreateImmutableBinding concrete method of an 

object Environment Record

 is never used within this

specification.

The InitializeBinding concrete method of an 

object Environment Record

 

envRec

 takes arguments 

N

 (a String) and 

V

 (an

ECMAScript language value

). It 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

. It performs the following steps when called:

1.  Return ? 

envRec

.SetMutableBinding(

N

V

false

).

NOTE

The SetMutableBinding concrete method of an 

object Environment Record

 

envRec

 takes arguments 

N

 (a String), 

V

 (an

ECMAScript language value

), and 

S

 (a Boolean). It attempts to set the value of the 

Environment Record

's associated

binding object's property whose name is the value of the argument 

N

 to the value of argument 

V

. A property named 

N

normally already exists but if it does not or is not currently writable, error handling is determined by 

S

. It performs

the following steps when called:

1.  Let 

bindings

 be the binding object for 

envRec

.

2.  Let 

stillExists

 be ? 

HasProperty

(

bindings

N

).

Normally 

envRec

 will not have a binding for 

N

 but if it does, the semantics of

DefinePropertyOrThrow

 may result in an existing binding being replaced or shadowed or cause

an 

abrupt completion

 to be returned.

In this specification, all uses of CreateMutableBinding for object Environment Records are
immediately followed by a call to InitializeBinding for the same name. Hence, this specification
does not explicitly track the initialization state of bindings in object Environment Records.

9.1.1.2.2  CreateMutableBinding ( 

N

D

 )

9.1.1.2.3  CreateImmutableBinding ( 

N

S

 )

9.1.1.2.4  InitializeBinding ( 

N

V

 )

9.1.1.2.5  SetMutableBinding ( 

N

V

S

 )

192

3.  If 

stillExists

 is 

false

 and 

S

 is 

true

, throw a 

ReferenceError

 exception.

4.  Return ? 

Set

(

bindings

N

V

S

).

The GetBindingValue concrete method of an 

object Environment Record

 

envRec

 takes arguments 

N

 (a String) and 

S

 (a

Boolean). It returns the value of its associated binding object's property whose name is the String value of the
argument identifier 

N

. The property should already exist but if it does not the result depends upon 

S

. It performs the

following steps when called:

1.  Let 

bindings

 be the binding object for 

envRec

.

2.  Let 

value

 be ? 

HasProperty

(

bindings

N

).

3.  If 

value

 is 

false

, then

a.  If 

S

 is 

false

, return the value 

undefined

; otherwise throw a 

ReferenceError

 exception.

4.  Return ? 

Get

(

bindings

N

).

The DeleteBinding concrete method of an 

object Environment Record

 

envRec

 takes argument 

N

 (a String). It can only

delete bindings that correspond to properties of the environment object whose [[Configurable]] attribute have the
value 

true

. It performs the following steps when called:

1.  Let 

bindings

 be the binding object for 

envRec

.

2.  Return ? 

bindings

.[[Delete]](

N

).

The HasThisBinding concrete method of an 

object Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  Return 

false

.

NOTE

The HasSuperBinding concrete method of an 

object Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  Return 

false

.

NOTE

The WithBaseObject concrete method of an 

object Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  If the 

withEnvironment

 flag of 

envRec

 is 

true

, return the binding object for 

envRec

.

2.  Otherwise, return 

undefined

.

Object Environment Records do not provide a 

this

this

 binding.

Object Environment Records do not provide a 

super

super

 binding.

9.1.1.2.6  GetBindingValue ( 

N

S

 )

9.1.1.2.7  DeleteBinding ( 

N

 )

9.1.1.2.8  HasThisBinding ( )

9.1.1.2.9  HasSuperBinding ( )

9.1.1.2.10  WithBaseObject ( )

193

function Environment Record

 is a 

declarative Environment Record

 that is used to represent the top-level scope of a

function and, if the function is not an 

ArrowFunction

, provides a 

this

this

 binding. If a function is not an 

ArrowFunction

function and references 

super

super

, its function Environment Record also contains the state that is used to perform

super

super

 method invocations from within the function.

Function Environment Records have the additional state fields listed in 

Table 18

.

Table 18: Additional Fields of Function Environment Records

Field Name

Value

Meaning

[[ThisValue]]

Any

This is the 

this

 value used for this invocation of the function.

[[ThisBindingStatus]]

lexical

 |

initialized

 |

uninitialized

If the value is 

lexical

, this is an 

ArrowFunction

 and does not have a local 

this

value.

[[FunctionObject]]

Object

The 

function object

 whose invocation caused this 

Environment Record

 to be

created.

[[NewTarget]]

Object |

undefined

If this 

Environment Record

 was created by the [[Construct]] internal method,

[[NewTarget]] is the value of the [[Construct]] 

newTarget

 parameter.

Otherwise, its value is 

undefined

.

Function Environment Records support all of the 

declarative Environment Record

 methods listed in 

Table 17

 and

share the same specifications for all of those methods except for HasThisBinding and HasSuperBinding. In addition,
function Environment Records support the methods listed in 

Table 19

:

Table 19: Additional Methods of Function Environment Records

Method

Purpose

BindThisValue(V) Set the [[ThisValue]] and record that it has been initialized.

GetThisBinding() Return the value of this 

Environment Record

's 

this

this

 binding. Throws a 

ReferenceError

 if the

this

this

 binding has not been initialized.

GetSuperBase()

Return the object that is the base for 

super

super

 property accesses bound in this 

Environment

Record

. The value 

undefined

 indicates that 

super

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:

The BindThisValue concrete method of a 

function Environment Record

 

envRec

 takes argument 

V

 (an 

ECMAScript

language value

). It performs the following steps when called:

9.1.1.3  Function Environment Records

9.1.1.3.1  BindThisValue ( 

V

 )

194

1. 

Assert

envRec

.[[ThisBindingStatus]] is not 

lexical

.

2.  If 

envRec

.[[ThisBindingStatus]] is 

initialized

, throw a 

ReferenceError

 exception.

3.  Set 

envRec

.[[ThisValue]] to 

V

.

4.  Set 

envRec

.[[ThisBindingStatus]] to 

initialized

.

5.  Return 

V

.

The HasThisBinding concrete method of a 

function Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  If 

envRec

.[[ThisBindingStatus]] is 

lexical

, return 

false

; otherwise, return 

true

.

The HasSuperBinding concrete method of a 

function Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  If 

envRec

.[[ThisBindingStatus]] is 

lexical

, return 

false

.

2.  If 

envRec

.[[FunctionObject]].[[HomeObject]] has the value 

undefined

, return 

false

; otherwise, return 

true

.

The GetThisBinding concrete method of a 

function Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1. 

Assert

envRec

.[[ThisBindingStatus]] is not 

lexical

.

2.  If 

envRec

.[[ThisBindingStatus]] is 

uninitialized

, throw a 

ReferenceError

 exception.

3.  Return 

envRec

.[[ThisValue]].

The GetSuperBase concrete method of a 

function Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  Let 

home

 be 

envRec

.[[FunctionObject]].[[HomeObject]].

2.  If 

home

 has the value 

undefined

, return 

undefined

.

3. 

Assert

Type

(

home

) is Object.

4.  Return ? 

home

.[[GetPrototypeOf]]().

global Environment Record

 is used to represent the outer most scope that is shared by all of the ECMAScript 

Script

elements that are processed in a common 

realm

. A global Environment Record provides the bindings for built-in

globals (clause 

19

), properties of the 

global object

, and for all top-level declarations (

8.1.9

8.1.11

) that occur within a 

Script

.

A global Environment Record is logically a single record but it is specified as a composite encapsulating an 

object

Environment Record

 and a 

declarative Environment Record

. The 

object Environment Record

 has as its base object the

global object

 of the associated 

Realm Record

. This 

global object

 is the value returned by the global Environment

Record's GetThisBinding concrete method. The 

object Environment Record

 component of a global Environment

9.1.1.3.2  HasThisBinding ( )

9.1.1.3.3  HasSuperBinding ( )

9.1.1.3.4  GetThisBinding ( )

9.1.1.3.5  GetSuperBase ( )

9.1.1.4  Global Environment Records

195

Record contains the bindings for all built-in globals (clause 

19

) and all bindings introduced by a 

FunctionDeclaration

GeneratorDeclaration

AsyncFunctionDeclaration

AsyncGeneratorDeclaration

, or 

VariableStatement

 contained in global

code. The bindings for all other ECMAScript declarations in global code are contained in the 

declarative Environment

Record

 component of the global Environment Record.

Properties may be created directly on a 

global object

. Hence, the 

object Environment Record

 component of a global

Environment Record may contain both bindings created explicitly by 

FunctionDeclaration

GeneratorDeclaration

AsyncFunctionDeclaration

AsyncGeneratorDeclaration

, or 

VariableDeclaration

 declarations and bindings created

implicitly as properties of the 

global object

. In order to identify which bindings were explicitly created using

declarations, a global Environment Record maintains a list of the names bound using its CreateGlobalVarBinding and
CreateGlobalFunctionBinding concrete methods.

Global Environment Records have the additional fields listed in 

Table 20

 and the additional methods listed in 

Table 21

.

Table 20: Additional Fields of Global Environment Records

Field Name

Value

Meaning

[[ObjectRecord]]

Object
Environment
Record

Binding object is the 

global object

. It contains global built-in bindings as well

as 

FunctionDeclaration

GeneratorDeclaration

AsyncFunctionDeclaration

AsyncGeneratorDeclaration

, and 

VariableDeclaration

 bindings in global code for

the associated 

realm

.

[[GlobalThisValue]]

Object

The value returned by 

this

this

 in global scope. Hosts may provide any

ECMAScript Object value.

[[DeclarativeRecord]]

Declarative
Environment
Record

Contains

 bindings for all declarations in global code for the associated 

realm

code except for 

FunctionDeclaration

GeneratorDeclaration

AsyncFunctionDeclaration

AsyncGeneratorDeclaration

, and 

VariableDeclaration

bindings

.

[[VarNames]]

List

 of String The string names bound by 

FunctionDeclaration

GeneratorDeclaration

AsyncFunctionDeclaration

AsyncGeneratorDeclaration

, and 

VariableDeclaration

declarations in global code for the associated 

realm

.

196

Table 21: Additional Methods of Global Environment Records

Method

Purpose

GetThisBinding()

Return the value of this 

Environment Record

's 

this

this

 binding.

HasVarDeclaration (N)

Determines if the argument identifier has a binding in this 

Environment Record

that was created using a 

VariableDeclaration

FunctionDeclaration

GeneratorDeclaration

AsyncFunctionDeclaration

, or 

AsyncGeneratorDeclaration

.

HasLexicalDeclaration (N)

Determines if the argument identifier has a binding in this 

Environment Record

that was created using a lexical declaration such as a 

LexicalDeclaration

 or a 

ClassDeclaration

.

HasRestrictedGlobalProperty
(N)

Determines if the argument is the name of a 

global object

 property that may not

be shadowed by a global lexical binding.

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 

undefined

 a global 

var

var

 binding in the

[[ObjectRecord]] component of a 

global Environment Record

. The binding will

be a mutable binding. The corresponding 

global object

 property will have

attribute values appropriate for a 

var

var

. The String value 

N

 is the bound name. If

D

 is 

true

 the binding may be deleted. Logically equivalent to

CreateMutableBinding followed by a SetMutableBinding but it allows var
declarations to receive special treatment.

CreateGlobalFunctionBinding(N,
V, D)

Create and initialize a global 

function

function

 binding in the [[ObjectRecord]]

component of a 

global Environment Record

. The binding will be a mutable

binding. The corresponding 

global object

 property will have attribute values

appropriate for a 

function

function

. The String value 

N

 is the bound name. 

V

 is the

initialization value. If the Boolean argument 

D

 is 

true

 the binding may be

deleted. Logically equivalent to CreateMutableBinding followed by a
SetMutableBinding but it allows function declarations to receive special
treatment.

The behaviour of the concrete specification methods for global Environment Records is defined by the following
algorithms.

The HasBinding concrete method of a 

global Environment Record

 

envRec

 takes argument 

N

 (a String). It determines if

the argument identifier is one of the identifiers bound by the record. It performs the following steps when called:

1.  Let 

DclRec

 be 

envRec

.[[DeclarativeRecord]].

2.  If 

DclRec

.HasBinding(

N

) is 

true

, return 

true

.

9.1.1.4.1  HasBinding ( 

N

 )

197

3.  Let 

ObjRec

 be 

envRec

.[[ObjectRecord]].

4.  Return ? 

ObjRec

.HasBinding(

N

).

The CreateMutableBinding concrete method of a 

global Environment Record

 

envRec

 takes arguments 

N

 (a String) and

D

 (a Boolean). It creates a new mutable binding for the name 

N

 that is uninitialized. The binding is created in the

associated DeclarativeRecord. A binding for 

N

 must not already exist in the DeclarativeRecord. If 

D

 has the value 

true

,

the new binding is marked as being subject to deletion. It performs the following steps when called:

1.  Let 

DclRec

 be 

envRec

.[[DeclarativeRecord]].

2.  If 

DclRec

.HasBinding(

N

) is 

true

, throw a 

TypeError

 exception.

3.  Return 

DclRec

.CreateMutableBinding(

N

D

).

The CreateImmutableBinding concrete method of a 

global Environment Record

 

envRec

 takes arguments 

N

 (a String)

and 

S

 (a Boolean). It 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 

S

 has the value 

true

, the new binding is marked as a strict binding. It

performs the following steps when called:

1.  Let 

DclRec

 be 

envRec

.[[DeclarativeRecord]].

2.  If 

DclRec

.HasBinding(

N

) is 

true

, throw a 

TypeError

 exception.

3.  Return 

DclRec

.CreateImmutableBinding(

N

S

).

The InitializeBinding concrete method of a 

global Environment Record

 

envRec

 takes arguments 

N

 (a String) and 

V

 (an

ECMAScript language value

). It 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. It

performs the following steps when called:

1.  Let 

DclRec

 be 

envRec

.[[DeclarativeRecord]].

2.  If 

DclRec

.HasBinding(

N

) is 

true

, then

a.  Return 

DclRec

.InitializeBinding(

N

V

).

3. 

Assert

: If the binding exists, it must be in the 

object Environment Record

.

4.  Let 

ObjRec

 be 

envRec

.[[ObjectRecord]].

5.  Return ? 

ObjRec

.InitializeBinding(

N

V

).

The SetMutableBinding concrete method of a 

global Environment Record

 

envRec

 takes arguments 

N

 (a String), 

V

 (an

ECMAScript language value

), and 

S

 (a Boolean). It 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

. If the binding is an immutable

binding, a 

TypeError

 is thrown if 

S

 is 

true

. A property named 

N

 normally already exists but if it does not or is not

currently writable, error handling is determined by 

S

. It performs the following steps when called:

1.  Let 

DclRec

 be 

envRec

.[[DeclarativeRecord]].

2.  If 

DclRec

.HasBinding(

N

) is 

true

, then

a.  Return 

DclRec

.SetMutableBinding(

N

V

S

).

9.1.1.4.2  CreateMutableBinding ( 

N

D

 )

9.1.1.4.3  CreateImmutableBinding ( 

N

S

 )

9.1.1.4.4  InitializeBinding ( 

N

V

 )

9.1.1.4.5  SetMutableBinding ( 

N

V

S

 )

198

3.  Let 

ObjRec

 be 

envRec

.[[ObjectRecord]].

4.  Return ? 

ObjRec

.SetMutableBinding(

N

V

S

).

The GetBindingValue concrete method of a 

global Environment Record

 

envRec

 takes arguments 

N

 (a String) and 

S

 (a

Boolean). It returns the value of its bound identifier whose name is the value of the argument 

N

. If the binding is an

uninitialized binding throw a 

ReferenceError

 exception. A property named 

N

 normally already exists but if it does

not or is not currently writable, error handling is determined by 

S

. It performs the following steps when called:

1.  Let 

DclRec

 be 

envRec

.[[DeclarativeRecord]].

2.  If 

DclRec

.HasBinding(

N

) is 

true

, then

a.  Return 

DclRec

.GetBindingValue(

N

S

).

3.  Let 

ObjRec

 be 

envRec

.[[ObjectRecord]].

4.  Return ? 

ObjRec

.GetBindingValue(

N

S

).

The DeleteBinding concrete method of a 

global Environment Record

 

envRec

 takes argument 

N

 (a String). It can only

delete bindings that have been explicitly designated as being subject to deletion. It performs the following steps when
called:

1.  Let 

DclRec

 be 

envRec

.[[DeclarativeRecord]].

2.  If 

DclRec

.HasBinding(

N

) is 

true

, then

a.  Return 

DclRec

.DeleteBinding(

N

).

3.  Let 

ObjRec

 be 

envRec

.[[ObjectRecord]].

4.  Let 

globalObject

 be the binding object for 

ObjRec

.

5.  Let 

existingProp

 be ? 

HasOwnProperty

(

globalObject

N

).

6.  If 

existingProp

 is 

true

, then

a.  Let 

status

 be ? 

ObjRec

.DeleteBinding(

N

).

b.  If 

status

 is 

true

, then

i.  Let 

varNames

 be 

envRec

.[[VarNames]].

ii.  If 

N

 is an element of 

varNames

, remove that element from the 

varNames

.

c.  Return 

status

.

7.  Return 

true

.

The HasThisBinding concrete method of a 

global Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  Return 

true

.

NOTE

The HasSuperBinding concrete method of a 

global Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

Global Environment Records always provide a 

this

this

 binding.

9.1.1.4.6  GetBindingValue ( 

N

S

 )

9.1.1.4.7  DeleteBinding ( 

N

 )

9.1.1.4.8  HasThisBinding ( )

9.1.1.4.9  HasSuperBinding ( )

199

1.  Return 

false

.

NOTE

The WithBaseObject concrete method of a 

global Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  Return 

undefined

.

The GetThisBinding concrete method of a 

global Environment Record

 

envRec

 takes no arguments. It performs the

following steps when called:

1.  Return 

envRec

.[[GlobalThisValue]].

The HasVarDeclaration concrete method of a 

global Environment Record

 

envRec

 takes argument 

N

 (a String). It

determines if the argument identifier has a binding in this record that was created using a 

VariableStatement

 or a 

FunctionDeclaration

. It performs the following steps when called:

1.  Let 

varDeclaredNames

 be 

envRec

.[[VarNames]].

2.  If 

varDeclaredNames

 contains 

N

, return 

true

.

3.  Return 

false

.

The HasLexicalDeclaration concrete method of a 

global Environment Record

 

envRec

 takes argument 

N

 (a String). It

determines if the argument identifier has a binding in this record that was created using a lexical declaration such as a 

LexicalDeclaration

 or a 

ClassDeclaration

. It performs the following steps when called:

1.  Let 

DclRec

 be 

envRec

.[[DeclarativeRecord]].

2.  Return 

DclRec

.HasBinding(

N

).

The HasRestrictedGlobalProperty concrete method of a 

global Environment Record

 

envRec

 takes argument 

N

 (a

String). It determines if the argument identifier is the name of a property of the 

global object

 that must not be

shadowed by a global lexical binding. It performs the following steps when called:

1.  Let 

ObjRec

 be 

envRec

.[[ObjectRecord]].

2.  Let 

globalObject

 be the binding object for 

ObjRec

.

3.  Let 

existingProp

 be ? 

globalObject

.[[GetOwnProperty]](

N

).

4.  If 

existingProp

 is 

undefined

, return 

false

.

5.  If 

existingProp

.[[Configurable]] is 

true

, return 

false

.

6.  Return 

true

.

Global Environment Records do not provide a 

super

super

 binding.

9.1.1.4.10  WithBaseObject ( )

9.1.1.4.11  GetThisBinding ( )

9.1.1.4.12  HasVarDeclaration ( 

N

 )

9.1.1.4.13  HasLexicalDeclaration ( 

N

 )

9.1.1.4.14  HasRestrictedGlobalProperty ( 

N

 )

200

3.  If the code matching the syntactic production that is being evaluated is contained in 

strict mode code

, let 

strict

be 

true

; else let 

strict

 be 

false

.

4.  Return ? 

GetIdentifierReference

(

env

name

strict

).

NOTE

The abstract operation GetThisEnvironment takes no arguments. It finds the 

Environment Record

 that currently

supplies the binding of the 

keyword

 

this

this

. It performs the following steps when called:

1.  Let 

env

 be the 

running execution context

's LexicalEnvironment.

2.  Repeat,

a.  Let 

exists

 be 

env

.HasThisBinding().

b.  If 

exists

 is 

true

, return 

env

.

c.  Let 

outer

 be 

env

.[[OuterEnv]].

d. 

Assert

outer

 is not 

null

.

e.  Set 

env

 to 

outer

.

NOTE

The abstract operation ResolveThisBinding takes no arguments. It determines the binding of the 

keyword

 

this

this

 using

the LexicalEnvironment of the 

running execution context

. It performs the following steps when called:

1.  Let 

envRec

 be 

GetThisEnvironment

().

2.  Return ? 

envRec

.GetThisBinding().

The abstract operation GetNewTarget takes no arguments. It determines the NewTarget value using the
LexicalEnvironment of the 

running execution context

. It performs the following steps when called:

1.  Let 

envRec

 be 

GetThisEnvironment

().

2. 

Assert

envRec

 has a [[NewTarget]] field.

3.  Return 

envRec

.[[NewTarget]].

The abstract operation GetGlobalObject takes no arguments. It returns the 

global object

 used by the currently 

running

execution context

. It performs the following steps when called:

1.  Let 

currentRealm

 be 

the current Realm Record

.

2.  Return 

currentRealm

.[[GlobalObject]].

The result of ResolveBinding is always a 

Reference Record

 whose [[ReferencedName]] field is

name

.

The loop in step 

2

 will always terminate because the list of environments always ends with the

global environment which has a 

this

this

 binding.

9.3.3  GetThisEnvironment ( )

9.3.4  ResolveThisBinding ( )

9.3.5  GetNewTarget ( )

9.3.6  GetGlobalObject ( )

210

 

 

 

 

 

 

 

Content      ..     17      18      19      20     ..