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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     43      44      45      46     ..

 

 

 

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

 

 

ObjectBindingPattern

[?Yield, ?Await]

ArrayBindingPattern

[?Yield, ?Await]

ObjectBindingPattern

[Yield, Await]

 

:

{

 

}

{

 

BindingRestProperty

[?Yield, ?Await]

 

}

{

 

BindingPropertyList

[?Yield, ?Await]

 

}

{

 

BindingPropertyList

[?Yield, ?Await]

 

,

 

BindingRestProperty

[?Yield, ?Await]

opt

 

}

ArrayBindingPattern

[Yield, Await]

 

:

[

 

Elision

opt

 

BindingRestElement

[?Yield, ?Await]

opt

 

]

[

 

BindingElementList

[?Yield, ?Await]

 

]

[

 

BindingElementList

[?Yield, ?Await]

 

,

 

Elision

opt

 

BindingRestElement

[?Yield, ?Await]

opt

 

]

BindingRestProperty

[Yield, Await]

 

:

...

 

BindingIdentifier

[?Yield, ?Await]

BindingPropertyList

[Yield, Await]

 

:

BindingProperty

[?Yield, ?Await]

BindingPropertyList

[?Yield, ?Await]

 

,

 

BindingProperty

[?Yield, ?Await]

BindingElementList

[Yield, Await]

 

:

BindingElisionElement

[?Yield, ?Await]

BindingElementList

[?Yield, ?Await]

 

,

 

BindingElisionElement

[?Yield, ?Await]

BindingElisionElement

[Yield, Await]

 

:

Elision

opt

 

BindingElement

[?Yield, ?Await]

BindingProperty

[Yield, Await]

 

:

SingleNameBinding

[?Yield, ?Await]

PropertyName

[?Yield, ?Await]

 

:

 

BindingElement

[?Yield, ?Await]

BindingElement

[Yield, Await]

 

:

SingleNameBinding

[?Yield, ?Await]

BindingPattern

[?Yield, ?Await]

 

Initializer

[+In, ?Yield, ?Await]

opt

SingleNameBinding

[Yield, Await]

 

:

BindingIdentifier

[?Yield, ?Await]

 

Initializer

[+In, ?Yield, ?Await]

opt

BindingRestElement

[Yield, Await]

 

:

...

 

BindingIdentifier

[?Yield, ?Await]

...

 

BindingPattern

[?Yield, ?Await]

With parameters 

value

 and 

environment

.

14.3.3.1  Runtime Semantics: PropertyBindingInitialization

362

NOTE

BindingPropertyList

 

:

 

BindingPropertyList

 

,

 

BindingProperty

1.  Let 

boundNames

 be ? 

PropertyBindingInitialization

 of 

BindingPropertyList

 with arguments 

value

 and

environment

.

2.  Let 

nextNames

 be ? 

PropertyBindingInitialization

 of 

BindingProperty

 with arguments 

value

 and 

environment

.

3.  Append each item in 

nextNames

 to the end of 

boundNames

.

4.  Return 

boundNames

.

BindingProperty

 

:

 

SingleNameBinding

1.  Let 

name

 be the string that is the only element of 

BoundNames

 of 

SingleNameBinding

.

2.  Perform ? 

KeyedBindingInitialization

 for 

SingleNameBinding

 using 

value

environment

, and 

name

 as the

arguments.

3.  Return a 

List

 whose sole element is 

name

.

BindingProperty

 

:

 

PropertyName

 

:

 

BindingElement

1.  Let 

P

 be the result of evaluating 

PropertyName

.

2. 

ReturnIfAbrupt

(

P

).

3.  Perform ? 

KeyedBindingInitialization

 of 

BindingElement

 with 

value

environment

, and 

P

 as the arguments.

4.  Return a 

List

 whose sole element is 

P

.

With parameters 

value

environment

, and 

excludedNames

.

BindingRestProperty

 

:

 

...

 

BindingIdentifier

1.  Let 

lhs

 be ? 

ResolveBinding

(

StringValue

 of 

BindingIdentifier

environment

).

2.  Let 

restObj

 be ! 

OrdinaryObjectCreate

(

%Object.prototype%

).

3.  Perform ? 

CopyDataProperties

(

restObj

value

excludedNames

).

4.  If 

environment

 is 

undefined

, return 

PutValue

(

lhs

restObj

).

5.  Return 

InitializeReferencedBinding

(

lhs

restObj

).

With parameters 

value

environment

, and 

propertyName

.

NOTE

BindingElement

 

:

 

BindingPattern

 

Initializer

opt

1.  Let 

v

 be ? 

GetV

(

value

propertyName

).

2.  If 

Initializer

 is present and 

v

 is 

undefined

, then

These collect a list of all bound property names rather than just empty completion.

When 

undefined

 is passed for 

environment

 it indicates that a 

PutValue

 operation should be used

to assign the initialization value. This is the case for formal parameter lists of non-strict functions.
In that case the formal parameter bindings are preinitialized in order to deal with the possibility
of multiple parameters with the same name.

14.3.3.2  Runtime Semantics: RestBindingInitialization

14.3.3.3  Runtime Semantics: KeyedBindingInitialization

363

a.  Let 

defaultValue

 be the result of evaluating 

Initializer

.

b.  Set 

v

 to ? 

GetValue

(

defaultValue

).

3.  Return the result of performing 

BindingInitialization

 for 

BindingPattern

 passing 

v

 and 

environment

 as

arguments.

SingleNameBinding

 

:

 

BindingIdentifier

 

Initializer

opt

1.  Let 

bindingId

 be 

StringValue

 of 

BindingIdentifier

.

2.  Let 

lhs

 be ? 

ResolveBinding

(

bindingId

environment

).

3.  Let 

v

 be ? 

GetV

(

value

propertyName

).

4.  If 

Initializer

 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 

bindingId

.

b.  Else,

i.  Let 

defaultValue

 be the result of evaluating 

Initializer

.

ii.  Set 

v

 to ? 

GetValue

(

defaultValue

).

5.  If 

environment

 is 

undefined

, return ? 

PutValue

(

lhs

v

).

6.  Return 

InitializeReferencedBinding

(

lhs

v

).

EmptyStatement

 

:

;

EmptyStatement

 

:

 

;

1.  Return 

NormalCompletion

(

empty

).

ExpressionStatement

[Yield, Await]

 

:

[lookahead 

 { 

{

function

async

 [no 

LineTerminator

 here]  

function

class

let

 

[

 }]

Expression

[+In, ?Yield, ?Await]

 

;

14.4  Empty Statement

Syntax

14.4.1  Runtime Semantics: Evaluation

14.5  Expression Statement

Syntax

364

NOTE

ExpressionStatement

 

:

 

Expression

 

;

1.  Let 

exprRef

 be the result of evaluating 

Expression

.

2.  Return ? 

GetValue

(

exprRef

).

IfStatement

[Yield, Await, Return]

 

:

if

 

(

 

Expression

[+In, ?Yield, ?Await]

 

)

 

Statement

[?Yield, ?Await, ?Return]

 

else

Statement

[?Yield, ?Await, ?Return]

if

 

(

 

Expression

[+In, ?Yield, ?Await]

 

)

 

Statement

[?Yield, ?Await, ?Return]

 [lookahead 

 

else

]

NOTE

IfStatement

 

:

if

 

(

 

Expression

 

)

 

Statement

 

else

 

Statement

if

 

(

 

Expression

 

)

 

Statement

It is a Syntax Error if 

IsLabelledFunction

(

Statement

) is 

true

.

NOTE

IfStatement

 

:

 

if

 

(

 

Expression

 

)

 

Statement

 

else

 

Statement

1.  Let 

exprRef

 be the result of evaluating 

Expression

.

2.  Let 

exprValue

 be ! 

ToBoolean

(? 

GetValue

(

exprRef

)).

3.  If 

exprValue

 is 

true

, then

An 

ExpressionStatement

 cannot start with a U+007B (LEFT CURLY BRACKET) because that might

make it ambiguous with a 

Block

. An 

ExpressionStatement

 cannot start with the 

function

function

 or

class

class

 keywords because that would make it ambiguous with a 

FunctionDeclaration

, a 

GeneratorDeclaration

, or a 

ClassDeclaration

. An 

ExpressionStatement

 cannot start with

async function

async function

 because that would make it ambiguous with an 

AsyncFunctionDeclaration

or a 

AsyncGeneratorDeclaration

. An 

ExpressionStatement

 cannot start with the two token sequence

let [

let [

 because that would make it ambiguous with a 

let

let

 

LexicalDeclaration

 whose first 

LexicalBinding

 was an 

ArrayBindingPattern

.

The lookahead-restriction [lookahead 

 

else

else

] resolves the classic "dangling else" problem in the

usual way. That is, when the choice of associated 

if

if

 is otherwise ambiguous, the 

else

else

 is

associated with the nearest (innermost) of the candidate 

if

if

s

It is only necessary to apply this rule if the extension specified in 

B.3.2

 is implemented.

14.5.1  Runtime Semantics: Evaluation

14.6  The 

if

if

 Statement

Syntax

14.6.1  Static Semantics: Early Errors

14.6.2  Runtime Semantics: Evaluation

365

a.  Let 

stmtCompletion

 be the result of evaluating the first 

Statement

.

4.  Else,

a.  Let 

stmtCompletion

 be the result of evaluating the second 

Statement

.

5.  Return 

Completion

(

UpdateEmpty

(

stmtCompletion

undefined

)).

IfStatement

 

:

 

if

 

(

 

Expression

 

)

 

Statement

1.  Let 

exprRef

 be the result of evaluating 

Expression

.

2.  Let 

exprValue

 be ! 

ToBoolean

(? 

GetValue

(

exprRef

)).

3.  If 

exprValue

 is 

false

, then

a.  Return 

NormalCompletion

(

undefined

).

4.  Else,

a.  Let 

stmtCompletion

 be the result of evaluating 

Statement

.

b.  Return 

Completion

(

UpdateEmpty

(

stmtCompletion

undefined

)).

IterationStatement

[Yield, Await, Return]

 

:

DoWhileStatement

[?Yield, ?Await, ?Return]

WhileStatement

[?Yield, ?Await, ?Return]

ForStatement

[?Yield, ?Await, ?Return]

ForInOfStatement

[?Yield, ?Await, ?Return]

The abstract operation LoopContinues takes arguments 

completion

 and 

labelSet

. It performs the following steps when

called:

1.  If 

completion

.[[Type]] is 

normal

, return 

true

.

2.  If 

completion

.[[Type]] is not 

continue

, return 

false

.

3.  If 

completion

.[[Target]] is 

empty

, return 

true

.

4.  If 

completion

.[[Target]] is an element of 

labelSet

, return 

true

.

5.  Return 

false

.

NOTE

With parameter 

labelSet

.

IterationStatement

 

:

 

DoWhileStatement

Within the 

Statement

 part of an 

IterationStatement

 a 

ContinueStatement

 may be used to begin a new

iteration.

14.7  Iteration Statements

Syntax

14.7.1  Semantics

14.7.1.1  LoopContinues ( 

completion

labelSet

 )

14.7.1.2  Runtime Semantics: LoopEvaluation

366

1.  Return ? 

DoWhileLoopEvaluation

 of 

DoWhileStatement

 with argument 

labelSet

.

IterationStatement

 

:

 

WhileStatement

1.  Return ? 

WhileLoopEvaluation

 of 

WhileStatement

 with argument 

labelSet

.

IterationStatement

 

:

 

ForStatement

1.  Return ? 

ForLoopEvaluation

 of 

ForStatement

 with argument 

labelSet

.

IterationStatement

 

:

 

ForInOfStatement

1.  Return ? 

ForInOfLoopEvaluation

 of 

ForInOfStatement

 with argument 

labelSet

.

DoWhileStatement

[Yield, Await, Return]

 

:

do

 

Statement

[?Yield, ?Await, ?Return]

 

while

 

(

 

Expression

[+In, ?Yield, ?Await]

 

)

 

;

DoWhileStatement

 

:

 

do

 

Statement

 

while

 

(

 

Expression

 

)

 

;

It is a Syntax Error if 

IsLabelledFunction

(

Statement

) is 

true

.

NOTE

With parameter 

labelSet

.

DoWhileStatement

 

:

 

do

 

Statement

 

while

 

(

 

Expression

 

)

 

;

1.  Let 

V

 be 

undefined

.

2.  Repeat,

a.  Let 

stmtResult

 be the result of evaluating 

Statement

.

b.  If 

LoopContinues

(

stmtResult

labelSet

) is 

false

, return 

Completion

(

UpdateEmpty

(

stmtResult

V

)).

c.  If 

stmtResult

.[[Value]] is not 

empty

, set 

V

 to 

stmtResult

.[[Value]].

d.  Let 

exprRef

 be the result of evaluating 

Expression

.

e.  Let 

exprValue

 be ? 

GetValue

(

exprRef

).

f.  If ! 

ToBoolean

(

exprValue

) is 

false

, return 

NormalCompletion

(

V

).

WhileStatement

[Yield, Await, Return]

 

:

while

 

(

 

Expression

[+In, ?Yield, ?Await]

 

)

 

Statement

[?Yield, ?Await, ?Return]

It is only necessary to apply this rule if the extension specified in 

B.3.2

 is implemented.

14.7.2  The 

do

do

-

while

while

 Statement

Syntax

14.7.2.1  Static Semantics: Early Errors

14.7.2.2  Runtime Semantics: DoWhileLoopEvaluation

14.7.3  The 

while

while

 Statement

Syntax

367

WhileStatement

 

:

 

while

 

(

 

Expression

 

)

 

Statement

It is a Syntax Error if 

IsLabelledFunction

(

Statement

) is 

true

.

NOTE

With parameter 

labelSet

.

WhileStatement

 

:

 

while

 

(

 

Expression

 

)

 

Statement

1.  Let 

V

 be 

undefined

.

2.  Repeat,

a.  Let 

exprRef

 be the result of evaluating 

Expression

.

b.  Let 

exprValue

 be ? 

GetValue

(

exprRef

).

c.  If ! 

ToBoolean

(

exprValue

) is 

false

, return 

NormalCompletion

(

V

).

d.  Let 

stmtResult

 be the result of evaluating 

Statement

.

e.  If 

LoopContinues

(

stmtResult

labelSet

) is 

false

, return 

Completion

(

UpdateEmpty

(

stmtResult

V

)).

f.  If 

stmtResult

.[[Value]] is not 

empty

, set 

V

 to 

stmtResult

.[[Value]].

ForStatement

[Yield, Await, Return]

 

:

for

 

(

 [lookahead 

 

let

 

[

]  

Expression

[~In, ?Yield, ?Await]

opt

 

;

 

Expression

[+In, ?Yield, ?Await]

opt

 

;

Expression

[+In, ?Yield, ?Await]

opt

 

)

 

Statement

[?Yield, ?Await, ?Return]

for

 

(

 

var

 

VariableDeclarationList

[~In, ?Yield, ?Await]

 

;

 

Expression

[+In, ?Yield, ?Await]

opt

 

;

Expression

[+In, ?Yield, ?Await]

opt

 

)

 

Statement

[?Yield, ?Await, ?Return]

for

 

(

 

LexicalDeclaration

[~In, ?Yield, ?Await]

 

Expression

[+In, ?Yield, ?Await]

opt

 

;

Expression

[+In, ?Yield, ?Await]

opt

 

)

 

Statement

[?Yield, ?Await, ?Return]

ForStatement

 

:

for

 

(

 

Expression

opt

 

;

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

for

 

(

 

var

 

VariableDeclarationList

 

;

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

for

 

(

 

LexicalDeclaration

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

It is a Syntax Error if 

IsLabelledFunction

(

Statement

) is 

true

.

NOTE

ForStatement

 

:

 

for

 

(

 

LexicalDeclaration

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

It is only necessary to apply this rule if the extension specified in 

B.3.2

 is implemented.

It is only necessary to apply this rule if the extension specified in 

B.3.2

 is implemented.

14.7.3.1  Static Semantics: Early Errors

14.7.3.2  Runtime Semantics: WhileLoopEvaluation

14.7.4  The 

for

for

 Statement

Syntax

14.7.4.1  Static Semantics: Early Errors

368

It is a Syntax Error if any element of the 

BoundNames

 of 

LexicalDeclaration

 also occurs in the

VarDeclaredNames

 of 

Statement

.

With parameter 

labelSet

.

ForStatement

 

:

 

for

 

(

 

Expression

opt

 

;

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

1.  If the first 

Expression

 is present, then

a.  Let 

exprRef

 be the result of evaluating the first 

Expression

.

b.  Perform ? 

GetValue

(

exprRef

).

2.  Return ? 

ForBodyEvaluation

(the second 

Expression

, the third 

Expression

Statement

, « », 

labelSet

).

ForStatement

 

:

 

for

 

(

 

var

 

VariableDeclarationList

 

;

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

1.  Let 

varDcl

 be the result of evaluating 

VariableDeclarationList

.

2. 

ReturnIfAbrupt

(

varDcl

).

3.  Return ? 

ForBodyEvaluation

(the first 

Expression

, the second 

Expression

Statement

, « », 

labelSet

).

ForStatement

 

:

 

for

 

(

 

LexicalDeclaration

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

1.  Let 

oldEnv

 be the 

running execution context

's LexicalEnvironment.

2.  Let 

loopEnv

 be 

NewDeclarativeEnvironment

(

oldEnv

).

3.  Let 

isConst

 be 

IsConstantDeclaration

 of 

LexicalDeclaration

.

4.  Let 

boundNames

 be the 

BoundNames

 of 

LexicalDeclaration

.

5.  For each element 

dn

 of 

boundNames

, do

a.  If 

isConst

 is 

true

, then

i.  Perform ! 

loopEnv

.CreateImmutableBinding(

dn

true

).

b.  Else,

i.  Perform ! 

loopEnv

.CreateMutableBinding(

dn

false

).

6.  Set the 

running execution context

's LexicalEnvironment to 

loopEnv

.

7.  Let 

forDcl

 be the result of evaluating 

LexicalDeclaration

.

8.  If 

forDcl

 is an 

abrupt completion

, then

a.  Set the 

running execution context

's LexicalEnvironment to 

oldEnv

.

b.  Return 

Completion

(

forDcl

).

9.  If 

isConst

 is 

false

, let 

perIterationLets

 be 

boundNames

; otherwise let 

perIterationLets

 be « ».

10.  Let 

bodyResult

 be 

ForBodyEvaluation

(the first 

Expression

, the second 

Expression

Statement

perIterationLets

,

labelSet

).

11.  Set the 

running execution context

's LexicalEnvironment to 

oldEnv

.

12.  Return 

Completion

(

bodyResult

).

The abstract operation ForBodyEvaluation takes arguments 

test

increment

stmt

perIterationBindings

, and 

labelSet

. It

performs the following steps when called:

1.  Let 

V

 be 

undefined

.

2.  Perform ? 

CreatePerIterationEnvironment

(

perIterationBindings

).

3.  Repeat,

14.7.4.2  Runtime Semantics: ForLoopEvaluation

14.7.4.3  ForBodyEvaluation ( 

test

increment

stmt

perIterationBindings

labelSet

 )

369

a.  If 

test

 is not 

[empty]

, then

i.  Let 

testRef

 be the result of evaluating 

test

.

ii.  Let 

testValue

 be ? 

GetValue

(

testRef

).

iii.  If ! 

ToBoolean

(

testValue

) is 

false

, return 

NormalCompletion

(

V

).

b.  Let 

result

 be the result of evaluating 

stmt

.

c.  If 

LoopContinues

(

result

labelSet

) is 

false

, return 

Completion

(

UpdateEmpty

(

result

V

)).

d.  If 

result

.[[Value]] is not 

empty

, set 

V

 to 

result

.[[Value]].

e.  Perform ? 

CreatePerIterationEnvironment

(

perIterationBindings

).

f.  If 

increment

 is not 

[empty]

, then

i.  Let 

incRef

 be the result of evaluating 

increment

.

ii.  Perform ? 

GetValue

(

incRef

).

The abstract operation CreatePerIterationEnvironment takes argument 

perIterationBindings

. It performs the following

steps when called:

1.  If 

perIterationBindings

 has any elements, then

a.  Let 

lastIterationEnv

 be the 

running execution context

's LexicalEnvironment.

b.  Let 

outer

 be 

lastIterationEnv

.[[OuterEnv]].

c. 

Assert

outer

 is not 

null

.

d.  Let 

thisIterationEnv

 be 

NewDeclarativeEnvironment

(

outer

).

e.  For each element 

bn

 of 

perIterationBindings

, do

i.  Perform ! 

thisIterationEnv

.CreateMutableBinding(

bn

false

).

ii.  Let 

lastValue

 be ? 

lastIterationEnv

.GetBindingValue(

bn

true

).

iii.  Perform 

thisIterationEnv

.InitializeBinding(

bn

lastValue

).

f.  Set the 

running execution context

's LexicalEnvironment to 

thisIterationEnv

.

2.  Return 

undefined

.

ForInOfStatement

[Yield, Await, Return]

 

:

for

 

(

 [lookahead 

 

let

 

[

]  

LeftHandSideExpression

[?Yield, ?Await]

 

in

 

Expression

[+In, ?Yield, ?Await]

 

)

Statement

[?Yield, ?Await, ?Return]

for

 

(

 

var

 

ForBinding

[?Yield, ?Await]

 

in

 

Expression

[+In, ?Yield, ?Await]

 

)

Statement

[?Yield, ?Await, ?Return]

for

 

(

 

ForDeclaration

[?Yield, ?Await]

 

in

 

Expression

[+In, ?Yield, ?Await]

 

)

Statement

[?Yield, ?Await, ?Return]

for

 

(

 [lookahead 

 { 

let

async

 

of

 }]  

LeftHandSideExpression

[?Yield, ?Await]

 

of

AssignmentExpression

[+In, ?Yield, ?Await]

 

)

 

Statement

[?Yield, ?Await, ?Return]

for

 

(

 

var

 

ForBinding

[?Yield, ?Await]

 

of

 

AssignmentExpression

[+In, ?Yield, ?Await]

 

)

Statement

[?Yield, ?Await, ?Return]

for

 

(

 

ForDeclaration

[?Yield, ?Await]

 

of

 

AssignmentExpression

[+In, ?Yield, ?Await]

 

)

Statement

[?Yield, ?Await, ?Return]

14.7.4.4  CreatePerIterationEnvironment ( 

perIterationBindings

 )

14.7.5  The 

for

for

-

in

in

for

for

-

of

of

, and 

for

for

-

await

await

-

of

of

 Statements

Syntax

370

[+Await]

 

for

 

await

 

(

 [lookahead 

 

let

 

LeftHandSideExpression

[?Yield, ?Await]

 

of

AssignmentExpression

[+In, ?Yield, ?Await]

 

)

 

Statement

[?Yield, ?Await, ?Return]

[+Await]

 

for

 

await

 

(

 

var

 

ForBinding

[?Yield, ?Await]

 

of

 

AssignmentExpression

[+In, ?Yield, ?Await]

 

)

Statement

[?Yield, ?Await, ?Return]

[+Await]

 

for

 

await

 

(

 

ForDeclaration

[?Yield, ?Await]

 

of

 

AssignmentExpression

[+In, ?Yield, ?Await]

 

)

Statement

[?Yield, ?Await, ?Return]

ForDeclaration

[Yield, Await]

 

:

LetOrConst

 

ForBinding

[?Yield, ?Await]

ForBinding

[Yield, Await]

 

:

BindingIdentifier

[?Yield, ?Await]

BindingPattern

[?Yield, ?Await]

NOTE

ForInOfStatement

 

:

for

 

(

 

LeftHandSideExpression

 

in

 

Expression

 

)

 

Statement

for

 

(

 

var

 

ForBinding

 

in

 

Expression

 

)

 

Statement

for

 

(

 

ForDeclaration

 

in

 

Expression

 

)

 

Statement

for

 

(

 

LeftHandSideExpression

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

(

 

var

 

ForBinding

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

(

 

ForDeclaration

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

await

 

(

 

LeftHandSideExpression

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

await

 

(

 

var

 

ForBinding

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

await

 

(

 

ForDeclaration

 

of

 

AssignmentExpression

 

)

 

Statement

It is a Syntax Error if 

IsLabelledFunction

(

Statement

) is 

true

.

NOTE

ForInOfStatement

 

:

for

 

(

 

LeftHandSideExpression

 

in

 

Expression

 

)

 

Statement

for

 

(

 

LeftHandSideExpression

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

await

 

(

 

LeftHandSideExpression

 

of

 

AssignmentExpression

 

)

 

Statement

If 

LeftHandSideExpression

 is either 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

.

This section is extended by Annex 

B.3.6

.

It is only necessary to apply this rule if the extension specified in 

B.3.2

 is implemented.

14.7.5.1  Static Semantics: Early Errors

371

ForInOfStatement

 

:

for

 

(

 

ForDeclaration

 

in

 

Expression

 

)

 

Statement

for

 

(

 

ForDeclaration

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

await

 

(

 

ForDeclaration

 

of

 

AssignmentExpression

 

)

 

Statement

It is a Syntax Error if the 

BoundNames

 of 

ForDeclaration

 contains 

"let"

.

It is a Syntax Error if any element of the 

BoundNames

 of 

ForDeclaration

 also occurs in the 

VarDeclaredNames

 of

Statement

.

It is a Syntax Error if the 

BoundNames

 of 

ForDeclaration

 contains any duplicate entries.

MemberExpression

 

:

 

PrimaryExpression

1.  If 

PrimaryExpression

 is either an 

ObjectLiteral

 or an 

ArrayLiteral

, return 

true

.

2.  Return 

false

.

MemberExpression

 

:

MemberExpression

 

[

 

Expression

 

]

MemberExpression

 

.

 

IdentifierName

MemberExpression

 

TemplateLiteral

SuperProperty
MetaProperty

new

 

MemberExpression

 

Arguments

NewExpression

 

:

new

 

NewExpression

LeftHandSideExpression

 

:

CallExpression
OptionalExpression

1.  Return 

false

.

ForDeclaration

 

:

 

LetOrConst

 

ForBinding

1.  Return 

IsDestructuring

 of 

ForBinding

.

ForBinding

 

:

 

BindingIdentifier

1.  Return 

false

.

ForBinding

 

:

 

BindingPattern

1.  Return 

true

.

NOTE

With parameters 

value

 and 

environment

.

This section is extended by Annex 

B.3.6

.

14.7.5.2  Static Semantics: IsDestructuring

14.7.5.3  Runtime Semantics: ForDeclarationBindingInitialization

372

NOTE

ForDeclaration

 

:

 

LetOrConst

 

ForBinding

1.  Return the result of performing 

BindingInitialization

 for 

ForBinding

 passing 

value

 and 

environment

 as the

arguments.

With parameter 

environment

.

ForDeclaration

 

:

 

LetOrConst

 

ForBinding

1. 

Assert

environment

 is a 

declarative Environment Record

.

2.  For each element 

name

 of the 

BoundNames

 of 

ForBinding

, do

a.  If 

IsConstantDeclaration

 of 

LetOrConst

 is 

true

, then

i.  Perform ! 

environment

.CreateImmutableBinding(

name

true

).

b.  Else,

i.  Perform ! 

environment

.CreateMutableBinding(

name

false

).

With parameter 

labelSet

.

ForInOfStatement

 

:

 

for

 

(

 

LeftHandSideExpression

 

in

 

Expression

 

)

 

Statement

1.  Let 

keyResult

 be ? 

ForIn/OfHeadEvaluation

(« », 

Expression

enumerate

).

2.  Return ? 

ForIn/OfBodyEvaluation

(

LeftHandSideExpression

Statement

keyResult

enumerate

assignment

,

labelSet

).

ForInOfStatement

 

:

 

for

 

(

 

var

 

ForBinding

 

in

 

Expression

 

)

 

Statement

1.  Let 

keyResult

 be ? 

ForIn/OfHeadEvaluation

(« », 

Expression

enumerate

).

2.  Return ? 

ForIn/OfBodyEvaluation

(

ForBinding

Statement

keyResult

enumerate

varBinding

labelSet

).

ForInOfStatement

 

:

 

for

 

(

 

ForDeclaration

 

in

 

Expression

 

)

 

Statement

1.  Let 

keyResult

 be ? 

ForIn/OfHeadEvaluation

(

BoundNames

 of 

ForDeclaration

Expression

enumerate

).

2.  Return ? 

ForIn/OfBodyEvaluation

(

ForDeclaration

Statement

keyResult

enumerate

lexicalBinding

labelSet

).

ForInOfStatement

 

:

 

for

 

(

 

LeftHandSideExpression

 

of

 

AssignmentExpression

 

)

 

Statement

1.  Let 

keyResult

 be ? 

ForIn/OfHeadEvaluation

(« », 

AssignmentExpression

iterate

).

2.  Return ? 

ForIn/OfBodyEvaluation

(

LeftHandSideExpression

Statement

keyResult

iterate

assignment

labelSet

).

ForInOfStatement

 

:

 

for

 

(

 

var

 

ForBinding

 

of

 

AssignmentExpression

 

)

 

Statement

1.  Let 

keyResult

 be ? 

ForIn/OfHeadEvaluation

(« », 

AssignmentExpression

iterate

).

undefined

 is passed for 

environment

 to indicate that a 

PutValue

 operation should be used to

assign the initialization value. This is the case for 

var

var

 statements and the formal parameter lists

of some non-strict functions (see 

10.2.10

). In those cases a lexical binding is hoisted and

preinitialized prior to evaluation of its initializer.

14.7.5.4  Runtime Semantics: ForDeclarationBindingInstantiation

14.7.5.5  Runtime Semantics: ForInOfLoopEvaluation

373

2.  Return ? 

ForIn/OfBodyEvaluation

(

ForBinding

Statement

keyResult

iterate

varBinding

labelSet

).

ForInOfStatement

 

:

 

for

 

(

 

ForDeclaration

 

of

 

AssignmentExpression

 

)

 

Statement

1.  Let 

keyResult

 be ? 

ForIn/OfHeadEvaluation

(

BoundNames

 of 

ForDeclaration

AssignmentExpression

iterate

).

2.  Return ? 

ForIn/OfBodyEvaluation

(

ForDeclaration

Statement

keyResult

iterate

lexicalBinding

labelSet

).

ForInOfStatement

 

:

 

for

 

await

 

(

 

LeftHandSideExpression

 

of

 

AssignmentExpression

 

)

 

Statement

1.  Let 

keyResult

 be ? 

ForIn/OfHeadEvaluation

(« », 

AssignmentExpression

async-iterate

).

2.  Return ? 

ForIn/OfBodyEvaluation

(

LeftHandSideExpression

Statement

keyResult

iterate

assignment

labelSet

,

async

).

ForInOfStatement

 

:

 

for

 

await

 

(

 

var

 

ForBinding

 

of

 

AssignmentExpression

 

)

 

Statement

1.  Let 

keyResult

 be ? 

ForIn/OfHeadEvaluation

(« », 

AssignmentExpression

async-iterate

).

2.  Return ? 

ForIn/OfBodyEvaluation

(

ForBinding

Statement

keyResult

iterate

varBinding

labelSet

async

).

ForInOfStatement

 

:

 

for

 

await

 

(

 

ForDeclaration

 

of

 

AssignmentExpression

 

)

 

Statement

1.  Let 

keyResult

 be ? 

ForIn/OfHeadEvaluation

(

BoundNames

 of 

ForDeclaration

AssignmentExpression

async-

iterate

).

2.  Return ? 

ForIn/OfBodyEvaluation

(

ForDeclaration

Statement

keyResult

iterate

lexicalBinding

labelSet

async

).

NOTE

The abstract operation ForIn/OfHeadEvaluation takes arguments 

uninitializedBoundNames

expr

, and 

iterationKind

(either 

enumerate

iterate

, or 

async-iterate

). It performs the following steps when called:

1.  Let 

oldEnv

 be the 

running execution context

's LexicalEnvironment.

2.  If 

uninitializedBoundNames

 is not an empty 

List

, then

a. 

Assert

uninitializedBoundNames

 has no duplicate entries.

b.  Let 

newEnv

 be 

NewDeclarativeEnvironment

(

oldEnv

).

c.  For each String 

name

 of 

uninitializedBoundNames

, do

i.  Perform ! 

newEnv

.CreateMutableBinding(

name

false

).

d.  Set the 

running execution context

's LexicalEnvironment to 

newEnv

.

3.  Let 

exprRef

 be the result of evaluating 

expr

.

4.  Set the 

running execution context

's LexicalEnvironment to 

oldEnv

.

5.  Let 

exprValue

 be ? 

GetValue

(

exprRef

).

6.  If 

iterationKind

 is 

enumerate

, then

a.  If 

exprValue

 is 

undefined

 or 

null

, then

i.  Return 

Completion

 { [[Type]]: 

break

, [[Value]]: 

empty

, [[Target]]: 

empty

 }.

b.  Let 

obj

 be ! 

ToObject

(

exprValue

).

c.  Let 

iterator

 be ? 

EnumerateObjectProperties

(

obj

).

d.  Let 

nextMethod

 be ! 

GetV

(

iterator

"next"

).

e.  Return the 

Record

 { [[Iterator]]: 

iterator

, [[NextMethod]]: 

nextMethod

, [[Done]]: 

false

 }.

7.  Else,

This section is extended by Annex 

B.3.6

.

14.7.5.6  ForIn/OfHeadEvaluation ( 

uninitializedBoundNames

expr

iterationKind

 )

374

a. 

Assert

iterationKind

 is 

iterate

 or 

async-iterate

.

b.  If 

iterationKind

 is 

async-iterate

, let 

iteratorHint

 be 

async

.

c.  Else, let 

iteratorHint

 be 

sync

.

d.  Return ? 

GetIterator

(

exprValue

iteratorHint

).

The abstract operation ForIn/OfBodyEvaluation takes arguments 

lhs

stmt

iteratorRecord

iterationKind

lhsKind

 (either

assignment

varBinding

 or 

lexicalBinding

), and 

labelSet

 and optional argument 

iteratorKind

 (either 

sync

 or 

async

). It

performs the following steps when called:

1.  If 

iteratorKind

 is not present, set 

iteratorKind

 to 

sync

.

2.  Let 

oldEnv

 be the 

running execution context

's LexicalEnvironment.

3.  Let 

V

 be 

undefined

.

4.  Let 

destructuring

 be 

IsDestructuring

 of 

lhs

.

5.  If 

destructuring

 is 

true

 and if 

lhsKind

 is 

assignment

, then

a. 

Assert

lhs

 is a 

LeftHandSideExpression

.

b.  Let 

assignmentPattern

 be the 

AssignmentPattern

 that is 

covered

 by 

lhs

.

6.  Repeat,

a.  Let 

nextResult

 be ? 

Call

(

iteratorRecord

.[[NextMethod]], 

iteratorRecord

.[[Iterator]]).

b.  If 

iteratorKind

 is 

async

, set 

nextResult

 to ? 

Await

(

nextResult

).

c.  If 

Type

(

nextResult

) is not Object, throw a 

TypeError

 exception.

d.  Let 

done

 be ? 

IteratorComplete

(

nextResult

).

e.  If 

done

 is 

true

, return 

NormalCompletion

(

V

).

f.  Let 

nextValue

 be ? 

IteratorValue

(

nextResult

).

g.  If 

lhsKind

 is either 

assignment

 or 

varBinding

, then

i.  If 

destructuring

 is 

false

, then

1.  Let 

lhsRef

 be the result of evaluating 

lhs

. (It may be evaluated repeatedly.)

h.  Else,

i. 

Assert

lhsKind

 is 

lexicalBinding

.

ii. 

Assert

lhs

 is a 

ForDeclaration

.

iii.  Let 

iterationEnv

 be 

NewDeclarativeEnvironment

(

oldEnv

).

iv.  Perform 

ForDeclarationBindingInstantiation

 for 

lhs

 passing 

iterationEnv

 as the argument.

v.  Set the 

running execution context

's LexicalEnvironment to 

iterationEnv

.

vi.  If 

destructuring

 is 

false

, then

1. 

Assert

lhs

 binds a single name.

2.  Let 

lhsName

 be the sole element of 

BoundNames

 of 

lhs

.

3.  Let 

lhsRef

 be ! 

ResolveBinding

(

lhsName

).

i.  If 

destructuring

 is 

false

, then

i.  If 

lhsRef

 is an 

abrupt completion

, then

1.  Let 

status

 be 

lhsRef

.

ii.  Else if 

lhsKind

 is 

lexicalBinding

, then

1.  Let 

status

 be 

InitializeReferencedBinding

(

lhsRef

nextValue

).

iii.  Else,

1.  Let 

status

 be 

PutValue

(

lhsRef

nextValue

).

j.  Else,

i.  If 

lhsKind

 is 

assignment

, then

14.7.5.7  ForIn/OfBodyEvaluation ( 

lhs

stmt

iteratorRecord

iterationKind

lhsKind

labelSet

 [ ,

iteratorKind

 ] )

375

1.  Let 

status

 be 

DestructuringAssignmentEvaluation

 of 

assignmentPattern

 with argument

nextValue

.

ii.  Else if 

lhsKind

 is 

varBinding

, then

1. 

Assert

lhs

 is a 

ForBinding

.

2.  Let 

status

 be 

BindingInitialization

 of 

lhs

 with arguments 

nextValue

 and 

undefined

.

iii.  Else,

1. 

Assert

lhsKind

 is 

lexicalBinding

.

2. 

Assert

lhs

 is a 

ForDeclaration

.

3.  Let 

status

 be 

ForDeclarationBindingInitialization

 of 

lhs

 with arguments 

nextValue

 and

iterationEnv

.

k.  If 

status

 is an 

abrupt completion

, then

i.  Set the 

running execution context

's LexicalEnvironment to 

oldEnv

.

ii.  If 

iteratorKind

 is 

async

, return ? 

AsyncIteratorClose

(

iteratorRecord

status

).

iii.  If 

iterationKind

 is 

enumerate

, then

1.  Return 

status

.

iv.  Else,

1. 

Assert

iterationKind

 is 

iterate

.

2.  Return ? 

IteratorClose

(

iteratorRecord

status

).

l.  Let 

result

 be the result of evaluating 

stmt

.

m.  Set the 

running execution context

's LexicalEnvironment to 

oldEnv

.

n.  If 

LoopContinues

(

result

labelSet

) is 

false

, then

i.  If 

iterationKind

 is 

enumerate

, then

1.  Return 

Completion

(

UpdateEmpty

(

result

V

)).

ii.  Else,

1. 

Assert

iterationKind

 is 

iterate

.

2.  Set 

status

 to 

UpdateEmpty

(

result

V

).

3.  If 

iteratorKind

 is 

async

, return ? 

AsyncIteratorClose

(

iteratorRecord

status

).

4.  Return ? 

IteratorClose

(

iteratorRecord

status

).

o.  If 

result

.[[Value]] is not 

empty

, set 

V

 to 

result

.[[Value]].

ForBinding

 

:

 

BindingIdentifier

1.  Let 

bindingId

 be 

StringValue

 of 

BindingIdentifier

.

2.  Return ? 

ResolveBinding

(

bindingId

).

The abstract operation EnumerateObjectProperties takes argument 

O

. It performs the following steps when called:

1. 

Assert

Type

(

O

) is Object.

2.  Return an Iterator object (

27.1.1.2

) whose 

next

next

 method iterates over all the String-valued keys of enumerable

properties of 

O

. The iterator object is never directly accessible to ECMAScript code. The mechanics and order of

enumerating the properties is not specified but must conform to the rules specified below.

The iterator's 

throw

throw

 and 

return

return

 methods are 

null

 and are never invoked. The iterator's 

next

next

 method processes

object properties to determine whether the property key should be returned as an iterator value. Returned property
keys do not include keys that are Symbols. Properties of the target object may be deleted during enumeration. A

14.7.5.8  Runtime Semantics: Evaluation

14.7.5.9  EnumerateObjectProperties ( 

O

 )

376

property that is deleted before it is processed by the iterator's 

next

next

 method is ignored. If new properties are added to

the target object during enumeration, the newly added properties are not guaranteed to be processed in the active
enumeration. A 

property name

 will be returned by the iterator's 

next

next

 method at most once in any enumeration.

Enumerating the properties of the target object includes enumerating properties of its prototype, and the prototype of
the prototype, and so on, recursively; but a property of a prototype is not processed if it has the same name as a
property that has already been processed by the iterator's 

next

next

 method. The values of [[Enumerable]] attributes are

not considered when determining if a property of a prototype object has already been processed. The enumerable
property names of prototype objects must be obtained by invoking EnumerateObjectProperties passing the prototype
object as the argument. EnumerateObjectProperties must obtain the own property keys of the target object by calling
its [[OwnPropertyKeys]] internal method. Property attributes of the target object must be obtained by calling its
[[GetOwnProperty]] internal method.

In addition, if neither 

O

 nor any object in its prototype chain is a 

Proxy exotic object

Integer-Indexed exotic object

,

module namespace exotic object

, or implementation provided 

exotic object

, then the iterator must behave as would

the iterator given by 

CreateForInIterator

(

O

) until one of the following occurs:

the value of the [[Prototype]] internal slot of 

O

 or an object in its prototype chain changes,

a property is removed from 

O

 or an object in its prototype chain,

a property is added to an object in 

O

's prototype chain, or

the value of the [[Enumerable]] attribute of a property of 

O

 or an object in its prototype chain changes.

NOTE 1

ECMAScript implementations are not required to implement the algorithm in 

14.7.5.10.2.1

directly. They may choose any implementation whose behaviour will not deviate from that
algorithm unless one of the constraints in the previous paragraph is violated.

The following is an informative definition of an ECMAScript generator function that conforms to
these rules:

function

EnumerateObjectProperties

(obj) {

  

const

 visited = 

new

 

Set

();

  

for

 (

const

 key 

of

 

Reflect

.ownKeys(obj)) {

    

if

 (

typeof

 key === 

"symbol"

continue

;

    

const

 desc = 

Reflect

.getOwnPropertyDescriptor(obj, key);

    

if

 (desc) {

      visited.add(key);
      

if

 (desc.enumerable) 

yield

 key;

    }
  }
  

const

 proto = 

Reflect

.getPrototypeOf(obj);

  

if

 (proto === 

null

return

;

  

for

 (

const

 protoKey 

of

 EnumerateObjectProperties(proto)) {

    

if

 (!visited.has(protoKey)) 

yield

 protoKey;

  }
}

377

 

 

 

 

 

 

 

Content      ..     43      44      45      46     ..