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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     42      43      44      45     ..

 

 

 

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

 

 

assignmentOpText opText

**=

**=

**

**

*=

*=

**

/=

/=

//

%=

%=

%%

+=

+=

++

-=

-=

--

<<=

<<=

<<

<<

>>=

>>=

>>

>>

>>>=

>>>=

>>>

>>>

&=

&=

&&

^=

^=

^^

|=

|=

||

7.  Let 

r

 be 

ApplyStringOrNumericBinaryOperator

(

lval

opText

rval

).

8.  Perform ? 

PutValue

(

lref

r

).

9.  Return 

r

.

AssignmentExpression

 

:

 

LeftHandSideExpression

 

&&=

 

AssignmentExpression

1.  Let 

lref

 be the result of evaluating 

LeftHandSideExpression

.

2.  Let 

lval

 be ? 

GetValue

(

lref

).

3.  Let 

lbool

 be ! 

ToBoolean

(

lval

).

4.  If 

lbool

 is 

false

, return 

lval

.

5.  If 

IsAnonymousFunctionDefinition

(

AssignmentExpression

) is 

true

 and 

IsIdentifierRef

 of 

LeftHandSideExpression

is 

true

, then

a.  Let 

rval

 be 

NamedEvaluation

 of 

AssignmentExpression

 with argument 

lref

.[[ReferencedName]].

6.  Else,

a.  Let 

rref

 be the result of evaluating 

AssignmentExpression

.

b.  Let 

rval

 be ? 

GetValue

(

rref

).

7.  Perform ? 

PutValue

(

lref

rval

).

8.  Return 

rval

.

AssignmentExpression

 

:

 

LeftHandSideExpression

 

||=

 

AssignmentExpression

1.  Let 

lref

 be the result of evaluating 

LeftHandSideExpression

.

2.  Let 

lval

 be ? 

GetValue

(

lref

).

3.  Let 

lbool

 be ! 

ToBoolean

(

lval

).

4.  If 

lbool

 is 

true

, return 

lval

.

5.  If 

IsAnonymousFunctionDefinition

(

AssignmentExpression

) is 

true

 and 

IsIdentifierRef

 of 

LeftHandSideExpression

is 

true

, then

a.  Let 

rval

 be 

NamedEvaluation

 of 

AssignmentExpression

 with argument 

lref

.[[ReferencedName]].

6.  Else,

a.  Let 

rref

 be the result of evaluating 

AssignmentExpression

.

b.  Let 

rval

 be ? 

GetValue

(

rref

).

7.  Perform ? 

PutValue

(

lref

rval

).

8.  Return 

rval

.

346

AssignmentExpression

 

:

 

LeftHandSideExpression

 

??=

 

AssignmentExpression

1.  Let 

lref

 be the result of evaluating 

LeftHandSideExpression

.

2.  Let 

lval

 be ? 

GetValue

(

lref

).

3.  If 

lval

 is neither 

undefined

 nor 

null

, return 

lval

.

4.  If 

IsAnonymousFunctionDefinition

(

AssignmentExpression

) is 

true

 and 

IsIdentifierRef

 of 

LeftHandSideExpression

is 

true

, then

a.  Let 

rval

 be 

NamedEvaluation

 of 

AssignmentExpression

 with argument 

lref

.[[ReferencedName]].

5.  Else,

a.  Let 

rref

 be the result of evaluating 

AssignmentExpression

.

b.  Let 

rval

 be ? 

GetValue

(

rref

).

6.  Perform ? 

PutValue

(

lref

rval

).

7.  Return 

rval

.

NOTE

The abstract operation ApplyStringOrNumericBinaryOperator takes arguments 

lval

 (an 

ECMAScript language value

),

opText

 (a sequence of Unicode code points), and 

rval

 (an 

ECMAScript language value

). It performs the following steps

when called:

1. 

Assert

opText

 is present in the table in step 

8

.

2.  If 

opText

 is 

++

, then

a.  Let 

lprim

 be ? 

ToPrimitive

(

lval

).

b.  Let 

rprim

 be ? 

ToPrimitive

(

rval

).

c.  If 

Type

(

lprim

) is String or 

Type

(

rprim

) is String, then

i.  Let 

lstr

 be ? 

ToString

(

lprim

).

ii.  Let 

rstr

 be ? 

ToString

(

rprim

).

iii.  Return the 

string-concatenation

 of 

lstr

 and 

rstr

.

d.  Set 

lval

 to 

lprim

.

e.  Set 

rval

 to 

rprim

.

3.  NOTE: At this point, it must be a numeric operation.
4.  Let 

lnum

 be ? 

ToNumeric

(

lval

).

5.  Let 

rnum

 be ? 

ToNumeric

(

rval

).

6.  If 

Type

(

lnum

) is different from 

Type

(

rnum

), throw a 

TypeError

 exception.

7.  Let 

T

 be 

Type

(

lnum

).

8.  Let 

operation

 be the abstract operation associated with 

opText

 in the following table:

opText operation

**

**

T

::exponentiate

**

T

::multiply

//

T

::divide

When this expression occurs within 

strict mode code

, it is a runtime error if 

lref

 in step 

1.e

2

2

2

,

2

 is an unresolvable reference. If it is, a 

ReferenceError

 exception is thrown. Additionally, it is a

runtime error if the 

lref

 in step 

8

7

7

6

 is a reference to a 

data property

 with the attribute value {

[[Writable]]: 

false

 }, to an 

accessor property

 with the attribute value { [[Set]]: 

undefined

 }, or to a

non-existent property of an object for which the 

IsExtensible

 predicate returns the value 

false

. In

these cases a 

TypeError

 exception is thrown.

13.15.3  ApplyStringOrNumericBinaryOperator ( 

lval

opText

rval

 )

347

%%

T

::remainder

++

T

::add

--

T

::subtract

<<

<<

T

::leftShift

>>

>>

T

::signedRightShift

>>>

>>>

T

::unsignedRightShift

&&

T

::bitwiseAND

^^

T

::bitwiseXOR

||

T

::bitwiseOR

9.  Return ? 

operation

(

lnum

rnum

).

NOTE 1

NOTE 2

The abstract operation EvaluateStringOrNumericBinaryExpression takes arguments 

leftOperand

 (a 

Parse Node

), 

opText

(a sequence of Unicode code points), and 

rightOperand

 (a 

Parse Node

). It performs the following steps when called:

1.  Let 

lref

 be the result of evaluating 

leftOperand

.

2.  Let 

lval

 be ? 

GetValue

(

lref

).

3.  Let 

rref

 be the result of evaluating 

rightOperand

.

4.  Let 

rval

 be ? 

GetValue

(

rref

).

5.  Return ? 

ApplyStringOrNumericBinaryOperator

(

lval

opText

rval

).

In certain circumstances when processing an instance of the production 

AssignmentExpression

 

:

 

LeftHandSideExpression

 

=

 

AssignmentExpression

 

the interpretation of 

LeftHandSideExpression

 is refined using the following grammar:

AssignmentPattern

[Yield, Await]

 

:

ObjectAssignmentPattern

[?Yield, ?Await]

ArrayAssignmentPattern

[?Yield, ?Await]

ObjectAssignmentPattern

[Yield, Await]

 

:

{

 

}

No hint is provided in the calls to 

ToPrimitive

 in steps 

2.a

 and 

2.b

. All standard objects except

Date objects handle the absence of a hint as if 

number

 were given; Date objects handle the

absence of a hint as if 

string

 were given. Exotic objects may handle the absence of a hint in some

other manner.

Step 

2.c

 differs from step 

3

 of the 

Abstract Relational Comparison

 algorithm, by using the logical-

or operation instead of the logical-and operation.

13.15.4  EvaluateStringOrNumericBinaryExpression ( 

leftOperand

opText

rightOperand

 )

13.15.5  Destructuring Assignment

Supplemental Syntax

348

{

 

AssignmentRestProperty

[?Yield, ?Await]

 

}

{

 

AssignmentPropertyList

[?Yield, ?Await]

 

}

{

 

AssignmentPropertyList

[?Yield, ?Await]

 

,

 

AssignmentRestProperty

[?Yield, ?Await]

opt

 

}

ArrayAssignmentPattern

[Yield, Await]

 

:

[

 

Elision

opt

 

AssignmentRestElement

[?Yield, ?Await]

opt

 

]

[

 

AssignmentElementList

[?Yield, ?Await]

 

]

[

 

AssignmentElementList

[?Yield, ?Await]

 

,

 

Elision

opt

 

AssignmentRestElement

[?Yield, ?Await]

opt

 

]

AssignmentRestProperty

[Yield, Await]

 

:

...

 

DestructuringAssignmentTarget

[?Yield, ?Await]

AssignmentPropertyList

[Yield, Await]

 

:

AssignmentProperty

[?Yield, ?Await]

AssignmentPropertyList

[?Yield, ?Await]

 

,

 

AssignmentProperty

[?Yield, ?Await]

AssignmentElementList

[Yield, Await]

 

:

AssignmentElisionElement

[?Yield, ?Await]

AssignmentElementList

[?Yield, ?Await]

 

,

 

AssignmentElisionElement

[?Yield, ?Await]

AssignmentElisionElement

[Yield, Await]

 

:

Elision

opt

 

AssignmentElement

[?Yield, ?Await]

AssignmentProperty

[Yield, Await]

 

:

IdentifierReference

[?Yield, ?Await]

 

Initializer

[+In, ?Yield, ?Await]

opt

PropertyName

[?Yield, ?Await]

 

:

 

AssignmentElement

[?Yield, ?Await]

AssignmentElement

[Yield, Await]

 

:

DestructuringAssignmentTarget

[?Yield, ?Await]

 

Initializer

[+In, ?Yield, ?Await]

opt

AssignmentRestElement

[Yield, Await]

 

:

...

 

DestructuringAssignmentTarget

[?Yield, ?Await]

DestructuringAssignmentTarget

[Yield, Await]

 

:

LeftHandSideExpression

[?Yield, ?Await]

AssignmentProperty

 

:

 

IdentifierReference

 

Initializer

opt

It is a Syntax Error if 

AssignmentTargetType

 of 

IdentifierReference

 is not 

simple

.

AssignmentRestProperty

 

:

 

...

 

DestructuringAssignmentTarget

It is a Syntax Error if 

DestructuringAssignmentTarget

 is an 

ArrayLiteral

 or an 

ObjectLiteral

.

DestructuringAssignmentTarget

 

:

 

LeftHandSideExpression

13.15.5.1  Static Semantics: Early Errors

349

If 

LeftHandSideExpression

 is an 

ObjectLiteral

 or an 

ArrayLiteral

, the following Early Error rules are applied:

It is a Syntax Error if 

LeftHandSideExpression

 is not 

covering

 an 

AssignmentPattern

.

All Early Error rules for 

AssignmentPattern

 and its derived productions also apply to the 

AssignmentPattern

 that

is 

covered

 by 

LeftHandSideExpression

.

If 

LeftHandSideExpression

 is neither an 

ObjectLiteral

 nor an 

ArrayLiteral

, the following Early Error rule is applied:

It is a Syntax Error if 

AssignmentTargetType

 of 

LeftHandSideExpression

 is not 

simple

.

With parameter 

value

.

ObjectAssignmentPattern

 

:

 

{

 

}

1.  Perform ? 

RequireObjectCoercible

(

value

).

2.  Return 

NormalCompletion

(

empty

).

ObjectAssignmentPattern

 

:

{

 

AssignmentPropertyList

 

}

{

 

AssignmentPropertyList

 

,

 

}

1.  Perform ? 

RequireObjectCoercible

(

value

).

2.  Perform ? 

PropertyDestructuringAssignmentEvaluation

 for 

AssignmentPropertyList

 using 

value

 as the

argument.

3.  Return 

NormalCompletion

(

empty

).

ArrayAssignmentPattern

 

:

 

[

 

]

1.  Let 

iteratorRecord

 be ? 

GetIterator

(

value

).

2.  Return ? 

IteratorClose

(

iteratorRecord

NormalCompletion

(

empty

)).

ArrayAssignmentPattern

 

:

 

[

 

Elision

 

]

1.  Let 

iteratorRecord

 be ? 

GetIterator

(

value

).

2.  Let 

result

 be 

IteratorDestructuringAssignmentEvaluation

 of 

Elision

 with argument 

iteratorRecord

.

3.  If 

iteratorRecord

.[[Done]] is 

false

, return ? 

IteratorClose

(

iteratorRecord

result

).

4.  Return 

result

.

ArrayAssignmentPattern

 

:

 

[

 

Elision

opt

 

AssignmentRestElement

 

]

1.  Let 

iteratorRecord

 be ? 

GetIterator

(

value

).

2.  If 

Elision

 is present, then

a.  Let 

status

 be 

IteratorDestructuringAssignmentEvaluation

 of 

Elision

 with argument 

iteratorRecord

.

b.  If 

status

 is an 

abrupt completion

, then

i. 

Assert

iteratorRecord

.[[Done]] is 

true

.

ii.  Return 

Completion

(

status

).

3.  Let 

result

 be 

IteratorDestructuringAssignmentEvaluation

 of 

AssignmentRestElement

 with argument

iteratorRecord

.

4.  If 

iteratorRecord

.[[Done]] is 

false

, return ? 

IteratorClose

(

iteratorRecord

result

).

5.  Return 

result

.

13.15.5.2  Runtime Semantics: DestructuringAssignmentEvaluation

350

ArrayAssignmentPattern

 

:

 

[

 

AssignmentElementList

 

]

1.  Let 

iteratorRecord

 be ? 

GetIterator

(

value

).

2.  Let 

result

 be 

IteratorDestructuringAssignmentEvaluation

 of 

AssignmentElementList

 with argument

iteratorRecord

.

3.  If 

iteratorRecord

.[[Done]] is 

false

, return ? 

IteratorClose

(

iteratorRecord

result

).

4.  Return 

result

.

ArrayAssignmentPattern

 

:

 

[

 

AssignmentElementList

 

,

 

Elision

opt

 

AssignmentRestElement

opt

 

]

1.  Let 

iteratorRecord

 be ? 

GetIterator

(

value

).

2.  Let 

status

 be 

IteratorDestructuringAssignmentEvaluation

 of 

AssignmentElementList

 with argument

iteratorRecord

.

3.  If 

status

 is an 

abrupt completion

, then

a.  If 

iteratorRecord

.[[Done]] is 

false

, return ? 

IteratorClose

(

iteratorRecord

status

).

b.  Return 

Completion

(

status

).

4.  If 

Elision

 is present, then

a.  Set 

status

 to the result of performing 

IteratorDestructuringAssignmentEvaluation

 of 

Elision

 with

iteratorRecord

 as the argument.

b.  If 

status

 is an 

abrupt completion

, then

i. 

Assert

iteratorRecord

.[[Done]] is 

true

.

ii.  Return 

Completion

(

status

).

5.  If 

AssignmentRestElement

 is present, then

a.  Set 

status

 to the result of performing 

IteratorDestructuringAssignmentEvaluation

 of 

AssignmentRestElement

 with 

iteratorRecord

 as the argument.

6.  If 

iteratorRecord

.[[Done]] is 

false

, return ? 

IteratorClose

(

iteratorRecord

status

).

7.  Return 

Completion

(

status

).

ObjectAssignmentPattern

 

:

 

{

 

AssignmentRestProperty

 

}

1.  Perform ? 

RequireObjectCoercible

(

value

).

2.  Let 

excludedNames

 be a new empty 

List

.

3.  Return the result of performing 

RestDestructuringAssignmentEvaluation

 of 

AssignmentRestProperty

 with 

value

and 

excludedNames

 as the arguments.

ObjectAssignmentPattern

 

:

 

{

 

AssignmentPropertyList

 

,

 

AssignmentRestProperty

 

}

1.  Perform ? 

RequireObjectCoercible

(

value

).

2.  Let 

excludedNames

 be ? 

PropertyDestructuringAssignmentEvaluation

 of 

AssignmentPropertyList

 with argument

value

.

3.  Return the result of performing 

RestDestructuringAssignmentEvaluation

 of 

AssignmentRestProperty

 with

arguments 

value

 and 

excludedNames

.

With parameter 

value

.

NOTE

AssignmentPropertyList

 

:

 

AssignmentPropertyList

 

,

 

AssignmentProperty

The following operations collect a list of all destructured property names.

13.15.5.3  Runtime Semantics: PropertyDestructuringAssignmentEvaluation

351

1.  Let 

propertyNames

 be ? 

PropertyDestructuringAssignmentEvaluation

 of 

AssignmentPropertyList

 with argument

value

.

2.  Let 

nextNames

 be ? 

PropertyDestructuringAssignmentEvaluation

 of 

AssignmentProperty

 with argument 

value

.

3.  Append each item in 

nextNames

 to the end of 

propertyNames

.

4.  Return 

propertyNames

.

AssignmentProperty

 

:

 

IdentifierReference

 

Initializer

opt

1.  Let 

P

 be 

StringValue

 of 

IdentifierReference

.

2.  Let 

lref

 be ? 

ResolveBinding

(

P

).

3.  Let 

v

 be ? 

GetV

(

value

P

).

4.  If 

Initializer

opt

 is present and 

v

 is 

undefined

, then

a.  If 

IsAnonymousFunctionDefinition

(

Initializer

) is 

true

, then

i.  Set 

v

 to the result of performing 

NamedEvaluation

 for 

Initializer

 with argument 

P

.

b.  Else,

i.  Let 

defaultValue

 be the result of evaluating 

Initializer

.

ii.  Set 

v

 to ? 

GetValue

(

defaultValue

).

5.  Perform ? 

PutValue

(

lref

v

).

6.  Return a 

List

 whose sole element is 

P

.

AssignmentProperty

 

:

 

PropertyName

 

:

 

AssignmentElement

1.  Let 

name

 be the result of evaluating 

PropertyName

.

2. 

ReturnIfAbrupt

(

name

).

3.  Perform ? 

KeyedDestructuringAssignmentEvaluation

 of 

AssignmentElement

 with 

value

 and 

name

 as the

arguments.

4.  Return a 

List

 whose sole element is 

name

.

With parameters 

value

 and 

excludedNames

.

AssignmentRestProperty

 

:

 

...

 

DestructuringAssignmentTarget

1.  Let 

lref

 be the result of evaluating 

DestructuringAssignmentTarget

.

2. 

ReturnIfAbrupt

(

lref

).

3.  Let 

restObj

 be ! 

OrdinaryObjectCreate

(

%Object.prototype%

).

4.  Perform ? 

CopyDataProperties

(

restObj

value

excludedNames

).

5.  Return 

PutValue

(

lref

restObj

).

With parameter 

iteratorRecord

.

AssignmentElementList

 

:

 

AssignmentElisionElement

1.  Return the result of performing 

IteratorDestructuringAssignmentEvaluation

 of 

AssignmentElisionElement

 using

iteratorRecord

 as the argument.

AssignmentElementList

 

:

 

AssignmentElementList

 

,

 

AssignmentElisionElement

13.15.5.4  Runtime Semantics: RestDestructuringAssignmentEvaluation

13.15.5.5  Runtime Semantics: IteratorDestructuringAssignmentEvaluation

352

1.  Perform ? 

IteratorDestructuringAssignmentEvaluation

 of 

AssignmentElementList

 using 

iteratorRecord

 as the

argument.

2.  Return the result of performing 

IteratorDestructuringAssignmentEvaluation

 of 

AssignmentElisionElement

 using

iteratorRecord

 as the argument.

AssignmentElisionElement

 

:

 

AssignmentElement

1.  Return the result of performing 

IteratorDestructuringAssignmentEvaluation

 of 

AssignmentElement

 with

iteratorRecord

 as the argument.

AssignmentElisionElement

 

:

 

Elision

 

AssignmentElement

1.  Perform ? 

IteratorDestructuringAssignmentEvaluation

 of 

Elision

 with 

iteratorRecord

 as the argument.

2.  Return the result of performing 

IteratorDestructuringAssignmentEvaluation

 of 

AssignmentElement

 with

iteratorRecord

 as the argument.

Elision

 

:

 

,

1.  If 

iteratorRecord

.[[Done]] is 

false

, then

a.  Let 

next

 be 

IteratorStep

(

iteratorRecord

).

b.  If 

next

 is an 

abrupt completion

, set 

iteratorRecord

.[[Done]] to 

true

.

c. 

ReturnIfAbrupt

(

next

).

d.  If 

next

 is 

false

, set 

iteratorRecord

.[[Done]] to 

true

.

2.  Return 

NormalCompletion

(

empty

).

Elision

 

:

 

Elision

 

,

1.  Perform ? 

IteratorDestructuringAssignmentEvaluation

 of 

Elision

 with 

iteratorRecord

 as the argument.

2.  If 

iteratorRecord

.[[Done]] is 

false

, then

a.  Let 

next

 be 

IteratorStep

(

iteratorRecord

).

b.  If 

next

 is an 

abrupt completion

, set 

iteratorRecord

.[[Done]] to 

true

.

c. 

ReturnIfAbrupt

(

next

).

d.  If 

next

 is 

false

, set 

iteratorRecord

.[[Done]] to 

true

.

3.  Return 

NormalCompletion

(

empty

).

AssignmentElement

 

:

 

DestructuringAssignmentTarget

 

Initializer

opt

1.  If 

DestructuringAssignmentTarget

 is neither an 

ObjectLiteral

 nor an 

ArrayLiteral

, then

a.  Let 

lref

 be the result of evaluating 

DestructuringAssignmentTarget

.

b. 

ReturnIfAbrupt

(

lref

).

2.  If 

iteratorRecord

.[[Done]] is 

false

, then

a.  Let 

next

 be 

IteratorStep

(

iteratorRecord

).

b.  If 

next

 is an 

abrupt completion

, set 

iteratorRecord

.[[Done]] to 

true

.

c. 

ReturnIfAbrupt

(

next

).

d.  If 

next

 is 

false

, set 

iteratorRecord

.[[Done]] to 

true

.

e.  Else,

i.  Let 

value

 be 

IteratorValue

(

next

).

ii.  If 

value

 is an 

abrupt completion

, set 

iteratorRecord

.[[Done]] to 

true

.

iii. 

ReturnIfAbrupt

(

value

).

3.  If 

iteratorRecord

.[[Done]] is 

true

, let 

value

 be 

undefined

.

4.  If 

Initializer

 is present and 

value

 is 

undefined

, then

353

a.  If 

IsAnonymousFunctionDefinition

(

Initializer

) is 

true

 and 

IsIdentifierRef

 of 

DestructuringAssignmentTarget

 is 

true

, then

i.  Let 

v

 be ? 

NamedEvaluation

 of 

Initializer

 with argument 

lref

.[[ReferencedName]].

b.  Else,

i.  Let 

defaultValue

 be the result of evaluating 

Initializer

.

ii.  Let 

v

 be ? 

GetValue

(

defaultValue

).

5.  Else, let 

v

 be 

value

.

6.  If 

DestructuringAssignmentTarget

 is an 

ObjectLiteral

 or an 

ArrayLiteral

, then

a.  Let 

nestedAssignmentPattern

 be the 

AssignmentPattern

 that is 

covered

 by 

DestructuringAssignmentTarget

.

b.  Return the result of performing 

DestructuringAssignmentEvaluation

 of 

nestedAssignmentPattern

 with 

v

as the argument.

7.  Return ? 

PutValue

(

lref

v

).

NOTE

AssignmentRestElement

 

:

 

...

 

DestructuringAssignmentTarget

1.  If 

DestructuringAssignmentTarget

 is neither an 

ObjectLiteral

 nor an 

ArrayLiteral

, then

a.  Let 

lref

 be the result of evaluating 

DestructuringAssignmentTarget

.

b. 

ReturnIfAbrupt

(

lref

).

2.  Let 

A

 be ! 

ArrayCreate

(0).

3.  Let 

n

 be 0.

4.  Repeat, while 

iteratorRecord

.[[Done]] is 

false

,

a.  Let 

next

 be 

IteratorStep

(

iteratorRecord

).

b.  If 

next

 is an 

abrupt completion

, set 

iteratorRecord

.[[Done]] to 

true

.

c. 

ReturnIfAbrupt

(

next

).

d.  If 

next

 is 

false

, set 

iteratorRecord

.[[Done]] to 

true

.

e.  Else,

i.  Let 

nextValue

 be 

IteratorValue

(

next

).

ii.  If 

nextValue

 is an 

abrupt completion

, set 

iteratorRecord

.[[Done]] to 

true

.

iii. 

ReturnIfAbrupt

(

nextValue

).

iv.  Perform ! 

CreateDataPropertyOrThrow

(

A

, ! 

ToString

(

n

)), 

nextValue

).

v.  Set 

n

 to 

n

 + 1.

5.  If 

DestructuringAssignmentTarget

 is neither an 

ObjectLiteral

 nor an 

ArrayLiteral

, then

a.  Return ? 

PutValue

(

lref

A

).

6.  Let 

nestedAssignmentPattern

 be the 

AssignmentPattern

 that is 

covered

 by 

DestructuringAssignmentTarget

.

7.  Return the result of performing 

DestructuringAssignmentEvaluation

 of 

nestedAssignmentPattern

 with 

A

 as the

argument.

With parameters 

value

 and 

propertyName

.

AssignmentElement

 

:

 

DestructuringAssignmentTarget

 

Initializer

opt

1.  If 

DestructuringAssignmentTarget

 is neither an 

ObjectLiteral

 nor an 

ArrayLiteral

, then

a.  Let 

lref

 be the result of evaluating 

DestructuringAssignmentTarget

.

Left to right evaluation order is maintained by evaluating a 

DestructuringAssignmentTarget

 that is

not a destructuring pattern prior to accessing the iterator or evaluating the 

Initializer

.

13.15.5.6  Runtime Semantics: KeyedDestructuringAssignmentEvaluation

354

b. 

ReturnIfAbrupt

(

lref

).

2.  Let 

v

 be ? 

GetV

(

value

propertyName

).

3.  If 

Initializer

 is present and 

v

 is 

undefined

, then

a.  If 

IsAnonymousFunctionDefinition

(

Initializer

) and 

IsIdentifierRef

 of 

DestructuringAssignmentTarget

 are

both 

true

, then

i.  Let 

rhsValue

 be ? 

NamedEvaluation

 of 

Initializer

 with argument 

lref

.[[ReferencedName]].

b.  Else,

i.  Let 

defaultValue

 be the result of evaluating 

Initializer

.

ii.  Let 

rhsValue

 be ? 

GetValue

(

defaultValue

).

4.  Else, let 

rhsValue

 be 

v

.

5.  If 

DestructuringAssignmentTarget

 is an 

ObjectLiteral

 or an 

ArrayLiteral

, then

a.  Let 

assignmentPattern

 be the 

AssignmentPattern

 that is 

covered

 by 

DestructuringAssignmentTarget

.

b.  Return the result of performing 

DestructuringAssignmentEvaluation

 of 

assignmentPattern

 with 

rhsValue

as the argument.

6.  Return ? 

PutValue

(

lref

rhsValue

).

Expression

[In, Yield, Await]

 

:

AssignmentExpression

[?In, ?Yield, ?Await]

Expression

[?In, ?Yield, ?Await]

 

,

 

AssignmentExpression

[?In, ?Yield, ?Await]

Expression

 

:

 

Expression

 

,

 

AssignmentExpression

1.  Let 

lref

 be the result of evaluating 

Expression

.

2.  Perform ? 

GetValue

(

lref

).

3.  Let 

rref

 be the result of evaluating 

AssignmentExpression

.

4.  Return ? 

GetValue

(

rref

).

NOTE

Statement

[Yield, Await, Return]

 

:

BlockStatement

[?Yield, ?Await, ?Return]

VariableStatement

[?Yield, ?Await]

GetValue

 must be called even though its value is not used because it may have observable side-

effects.

13.16  Comma Operator ( 

,,

 )

Syntax

13.16.1  Runtime Semantics: Evaluation

14  ECMAScript Language: Statements and Declarations

Syntax

355

IterationStatement
SwitchStatement

1.  Let 

newLabelSet

 be a new empty 

List

.

2.  Return the result of performing 

LabelledEvaluation

 of this 

BreakableStatement

 with argument 

newLabelSet

.

BlockStatement

[Yield, Await, Return]

 

:

Block

[?Yield, ?Await, ?Return]

Block

[Yield, Await, Return]

 

:

{

 

StatementList

[?Yield, ?Await, ?Return]

opt

 

}

StatementList

[Yield, Await, Return]

 

:

StatementListItem

[?Yield, ?Await, ?Return]

StatementList

[?Yield, ?Await, ?Return]

 

StatementListItem

[?Yield, ?Await, ?Return]

StatementListItem

[Yield, Await, Return]

 

:

Statement

[?Yield, ?Await, ?Return]

Declaration

[?Yield, ?Await]

Block

 

:

 

{

 

StatementList

 

}

It is a Syntax Error if the 

LexicallyDeclaredNames

 of 

StatementList

 contains any duplicate entries.

It is a Syntax Error if any element of the 

LexicallyDeclaredNames

 of 

StatementList

 also occurs in the

VarDeclaredNames

 of 

StatementList

.

Block

 

:

 

{

 

}

1.  Return 

NormalCompletion

(

empty

).

Block

 

:

 

{

 

StatementList

 

}

1.  Let 

oldEnv

 be the 

running execution context

's LexicalEnvironment.

2.  Let 

blockEnv

 be 

NewDeclarativeEnvironment

(

oldEnv

).

3.  Perform 

BlockDeclarationInstantiation

(

StatementList

blockEnv

).

4.  Set the 

running execution context

's LexicalEnvironment to 

blockEnv

.

5.  Let 

blockValue

 be the result of evaluating 

StatementList

.

6.  Set the 

running execution context

's LexicalEnvironment to 

oldEnv

.

7.  Return 

blockValue

.

14.2  Block

Syntax

14.2.1  Static Semantics: Early Errors

14.2.2  Runtime Semantics: Evaluation

357

NOTE 1

StatementList

 

:

 

StatementList

 

StatementListItem

1.  Let 

sl

 be the result of evaluating 

StatementList

.

2. 

ReturnIfAbrupt

(

sl

).

3.  Let 

s

 be the result of evaluating 

StatementListItem

.

4.  Return 

Completion

(

UpdateEmpty

(

s

sl

)).

NOTE 2

NOTE

The abstract operation BlockDeclarationInstantiation takes arguments 

code

 (a 

Parse Node

) and 

env

 (an 

Environment

Record

). 

code

 is the 

Parse Node

 corresponding to the body of the block. 

env

 is the 

Environment Record

 in which

bindings are to be created. It performs the following steps when called:

1. 

Assert

env

 is a 

declarative Environment Record

.

2.  Let 

declarations

 be the 

LexicallyScopedDeclarations

 of 

code

.

3.  For each element 

d

 of 

declarations

, do

a.  For each element 

dn

 of the 

BoundNames

 of 

d

, do

i.  If 

IsConstantDeclaration

 of 

d

 is 

true

, then

1.  Perform ! 

env

.CreateImmutableBinding(

dn

true

).

ii.  Else,

1.  Perform ! 

env

.CreateMutableBinding(

dn

false

). NOTE: This step is replaced in section

B.3.3.6

.

b.  If 

d

 is a 

FunctionDeclaration

, a 

GeneratorDeclaration

, an 

AsyncFunctionDeclaration

, or an 

AsyncGeneratorDeclaration

, then

i.  Let 

fn

 be the sole element of the 

BoundNames

 of 

d

.

ii.  Let 

fo

 be 

InstantiateFunctionObject

 of 

d

 with argument 

env

.

iii.  Perform 

env

.InitializeBinding(

fn

fo

). NOTE: This step is replaced in section 

B.3.3.6

.

No matter how control leaves the 

Block

 the LexicalEnvironment is always restored to its former

state.

The value of a 

StatementList

 is the value of the last value-producing item in the 

StatementList

. For

example, the following calls to the 

eval

eval

 function all return the value 1:

eval

(

"1;;;;;"

)

eval

(

"1;{}"

)

eval

(

"1;var a;"

)

When a 

Block

 or 

CaseBlock

 is evaluated a new 

declarative Environment Record

 is created and

bindings for each block scoped variable, constant, function, or class declared in the block are
instantiated in the 

Environment Record

.

14.2.3  BlockDeclarationInstantiation ( 

code

env

 )

14.3  Declarations and the Variable Statement

358

NOTE

LexicalDeclaration

[In, Yield, Await]

 

:

LetOrConst

 

BindingList

[?In, ?Yield, ?Await]

 

;

LetOrConst

 

:

let

const

BindingList

[In, Yield, Await]

 

:

LexicalBinding

[?In, ?Yield, ?Await]

BindingList

[?In, ?Yield, ?Await]

 

,

 

LexicalBinding

[?In, ?Yield, ?Await]

LexicalBinding

[In, Yield, Await]

 

:

BindingIdentifier

[?Yield, ?Await]

 

Initializer

[?In, ?Yield, ?Await]

opt

BindingPattern

[?Yield, ?Await]

 

Initializer

[?In, ?Yield, ?Await]

LexicalDeclaration

 

:

 

LetOrConst

 

BindingList

 

;

It is a Syntax Error if the 

BoundNames

 of 

BindingList

 contains 

"let"

.

It is a Syntax Error if the 

BoundNames

 of 

BindingList

 contains any duplicate entries.

LexicalBinding

 

:

 

BindingIdentifier

 

Initializer

opt

It is a Syntax Error if 

Initializer

 is not present and 

IsConstantDeclaration

 of the 

LexicalDeclaration

 containing this

LexicalBinding

 is 

true

.

LexicalDeclaration

 

:

 

LetOrConst

 

BindingList

 

;

1.  Let 

next

 be the result of evaluating 

BindingList

.

2. 

ReturnIfAbrupt

(

next

).

3.  Return 

NormalCompletion

(

empty

).

BindingList

 

:

 

BindingList

 

,

 

LexicalBinding

1.  Let 

next

 be the result of evaluating 

BindingList

.

let

let

 and 

const

const

 declarations define variables that are scoped to the 

running execution context

's

LexicalEnvironment. The variables are created when their containing 

Environment Record

 is

instantiated but may not be accessed in any way until the variable's 

LexicalBinding

 is evaluated. A

variable defined by a 

LexicalBinding

 with an 

Initializer

 is assigned the value of its 

Initializer

's 

AssignmentExpression

 when the 

LexicalBinding

 is evaluated, not when the variable is created. If a 

LexicalBinding

 in a 

let

let

 declaration does not have an 

Initializer

 the variable is assigned the value

undefined

 when the 

LexicalBinding

 is evaluated.

14.3.1  Let and Const Declarations

Syntax

14.3.1.1  Static Semantics: Early Errors

14.3.1.2  Runtime Semantics: Evaluation

359

2. 

ReturnIfAbrupt

(

next

).

3.  Return the result of evaluating 

LexicalBinding

.

LexicalBinding

 

:

 

BindingIdentifier

1.  Let 

lhs

 be 

ResolveBinding

(

StringValue

 of 

BindingIdentifier

).

2.  Return 

InitializeReferencedBinding

(

lhs

undefined

).

NOTE

LexicalBinding

 

:

 

BindingIdentifier

 

Initializer

1.  Let 

bindingId

 be 

StringValue

 of 

BindingIdentifier

.

2.  Let 

lhs

 be 

ResolveBinding

(

bindingId

).

3.  If 

IsAnonymousFunctionDefinition

(

Initializer

) is 

true

, then

a.  Let 

value

 be 

NamedEvaluation

 of 

Initializer

 with argument 

bindingId

.

4.  Else,

a.  Let 

rhs

 be the result of evaluating 

Initializer

.

b.  Let 

value

 be ? 

GetValue

(

rhs

).

5.  Return 

InitializeReferencedBinding

(

lhs

value

).

LexicalBinding

 

:

 

BindingPattern

 

Initializer

1.  Let 

rhs

 be the result of evaluating 

Initializer

.

2.  Let 

value

 be ? 

GetValue

(

rhs

).

3.  Let 

env

 be the 

running execution context

's LexicalEnvironment.

4.  Return the result of performing 

BindingInitialization

 for 

BindingPattern

 using 

value

 and 

env

 as the arguments.

NOTE

VariableStatement

[Yield, Await]

 

:

var

 

VariableDeclarationList

[+In, ?Yield, ?Await]

 

;

VariableDeclarationList

[In, Yield, Await]

 

:

VariableDeclaration

[?In, ?Yield, ?Await]

VariableDeclarationList

[?In, ?Yield, ?Await]

 

,

 

VariableDeclaration

[?In, ?Yield, ?Await]

static semantics

 rule ensures that this form of 

LexicalBinding

 never occurs in a 

const

const

declaration.

var

var

 statement declares variables that are scoped to the 

running execution context

's

VariableEnvironment. Var variables are created when their containing 

Environment Record

 is

instantiated and are initialized to 

undefined

 when created. Within the scope of any

VariableEnvironment a common 

BindingIdentifier

 may appear in more than one 

VariableDeclaration

 but those declarations collectively define only one variable. A variable defined

by a 

VariableDeclaration

 with an 

Initializer

 is assigned the value of its 

Initializer

's 

AssignmentExpression

 when the 

VariableDeclaration

 is executed, not when the variable is created.

14.3.2  Variable Statement

Syntax

360

VariableDeclaration

[In, Yield, Await]

 

:

BindingIdentifier

[?Yield, ?Await]

 

Initializer

[?In, ?Yield, ?Await]

opt

BindingPattern

[?Yield, ?Await]

 

Initializer

[?In, ?Yield, ?Await]

VariableStatement

 

:

 

var

 

VariableDeclarationList

 

;

1.  Let 

next

 be the result of evaluating 

VariableDeclarationList

.

2. 

ReturnIfAbrupt

(

next

).

3.  Return 

NormalCompletion

(

empty

).

VariableDeclarationList

 

:

 

VariableDeclarationList

 

,

 

VariableDeclaration

1.  Let 

next

 be the result of evaluating 

VariableDeclarationList

.

2. 

ReturnIfAbrupt

(

next

).

3.  Return the result of evaluating 

VariableDeclaration

.

VariableDeclaration

 

:

 

BindingIdentifier

1.  Return 

NormalCompletion

(

empty

).

VariableDeclaration

 

:

 

BindingIdentifier

 

Initializer

1.  Let 

bindingId

 be 

StringValue

 of 

BindingIdentifier

.

2.  Let 

lhs

 be ? 

ResolveBinding

(

bindingId

).

3.  If 

IsAnonymousFunctionDefinition

(

Initializer

) is 

true

, then

a.  Let 

value

 be 

NamedEvaluation

 of 

Initializer

 with argument 

bindingId

.

4.  Else,

a.  Let 

rhs

 be the result of evaluating 

Initializer

.

b.  Let 

value

 be ? 

GetValue

(

rhs

).

5.  Return ? 

PutValue

(

lhs

value

).

NOTE

VariableDeclaration

 

:

 

BindingPattern

 

Initializer

1.  Let 

rhs

 be the result of evaluating 

Initializer

.

2.  Let 

rval

 be ? 

GetValue

(

rhs

).

3.  Return the result of performing 

BindingInitialization

 for 

BindingPattern

 passing 

rval

 and 

undefined

 as

arguments.

BindingPattern

[Yield, Await]

 

:

If a 

VariableDeclaration

 is nested within a with statement and the 

BindingIdentifier

 in the 

VariableDeclaration

 is the same as a 

property name

 of the binding object of the with statement's

object Environment Record

, then step 

5

 will assign 

value

 to the property instead of assigning to

the VariableEnvironment binding of the 

Identifier

.

14.3.2.1  Runtime Semantics: Evaluation

14.3.3  Destructuring Binding Patterns

Syntax

361

 

 

 

 

 

 

 

Content      ..     42      43      44      45     ..