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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     24      25      26      27     ..

 

 

 

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

 

 

3.  Set 

value

.[[SourceText]] to the source text matched by 

ClassDeclaration

.

4.  Let 

env

 be the 

running execution context

's LexicalEnvironment.

5.  Perform ? 

InitializeBoundName

(

className

value

env

).

6.  Return 

value

.

ClassDeclaration

 

:

 

class

 

ClassTail

1.  Let 

value

 be ? 

ClassDefinitionEvaluation

 of 

ClassTail

 with arguments 

undefined

 and 

"default"

.

2.  Set 

value

.[[SourceText]] to the source text matched by 

ClassDeclaration

.

3.  Return 

value

.

NOTE

ClassDeclaration

 

:

 

class

 

BindingIdentifier

 

ClassTail

1.  Perform ? 

BindingClassDeclarationEvaluation

 of this 

ClassDeclaration

.

2.  Return 

NormalCompletion

(

empty

).

NOTE

ClassExpression

 

:

 

class

 

ClassTail

1.  Let 

value

 be ? 

ClassDefinitionEvaluation

 of 

ClassTail

 with arguments 

undefined

 and 

""

.

2.  Set 

value

.[[SourceText]] to the source text matched by 

ClassExpression

.

3.  Return 

value

.

ClassExpression

 

:

 

class

 

BindingIdentifier

 

ClassTail

1.  Let 

className

 be 

StringValue

 of 

BindingIdentifier

.

2.  Let 

value

 be ? 

ClassDefinitionEvaluation

 of 

ClassTail

 with arguments 

className

 and 

className

.

3.  Set 

value

.[[SourceText]] to the source text matched by 

ClassExpression

.

4.  Return 

value

.

AsyncFunctionDeclaration

[Yield, Await, Default]

 

:

async

 [no 

LineTerminator

 here]  

function

 

BindingIdentifier

[?Yield, ?Await]

 

(

FormalParameters

[~Yield, +Await]

 

)

 

{

 

AsyncFunctionBody

 

}

[+Default]

 

async

 [no 

LineTerminator

 here]  

function

 

(

 

FormalParameters

[~Yield, +Await]

 

)

 

{

AsyncFunctionBody

 

}

ClassDeclaration

 

:

 

class

 

ClassTail

 only occurs as part of an 

ExportDeclaration

 and establishing its

binding is handled as part of the evaluation action for that production. See 

16.2.3.7

.

ClassDeclaration

 

:

 

class

 

ClassTail

 only occurs as part of an 

ExportDeclaration

 and is never directly

evaluated.

15.7.9  Runtime Semantics: Evaluation

15.8  Async Function Definitions

Syntax

416

AsyncFunctionExpression

 

:

async

 [no 

LineTerminator

 here]  

function

 

BindingIdentifier

[~Yield, +Await]

opt

 

(

FormalParameters

[~Yield, +Await]

 

)

 

{

 

AsyncFunctionBody

 

}

AsyncMethod

[Yield, Await]

 

:

async

 [no 

LineTerminator

 here]  

PropertyName

[?Yield, ?Await]

 

(

 

UniqueFormalParameters

[~Yield, +Await]

)

 

{

 

AsyncFunctionBody

 

}

AsyncFunctionBody

 

:

FunctionBody

[~Yield, +Await]

AwaitExpression

[Yield]

 

:

await

 

UnaryExpression

[?Yield, +Await]

NOTE 1

NOTE 2

AsyncMethod

 

:

 

async

 

PropertyName

 

(

 

UniqueFormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

It is a Syntax Error if 

FunctionBodyContainsUseStrict

 of 

AsyncFunctionBody

 is 

true

 and 

IsSimpleParameterList

of 

UniqueFormalParameters

 is 

false

.

It is a Syntax Error if 

HasDirectSuper

 of 

AsyncMethod

 is 

true

.

It is a Syntax Error if 

UniqueFormalParameters

 

Contains

 

AwaitExpression

 is 

true

.

It is a Syntax Error if any element of the 

BoundNames

 of 

UniqueFormalParameters

 also occurs in the

LexicallyDeclaredNames

 of 

AsyncFunctionBody

.

AsyncFunctionDeclaration

 

:

await

await

 is parsed as an 

AwaitExpression

 when the 

[Await]

 parameter is present. The 

[Await]

parameter is present in the following contexts:

In an 

AsyncFunctionBody

.

In the 

FormalParameters

 of an 

AsyncFunctionDeclaration

AsyncFunctionExpression

AsyncGeneratorDeclaration

, or 

AsyncGeneratorExpression

AwaitExpression

 in this position is

a Syntax error via 

static semantics

.

When 

Module

 is the syntactic 

goal symbol

 and the 

[Await]

 parameter is absent, 

await

await

 is parsed

as a 

keyword

 and will be a Syntax error. When 

Script

 is the syntactic 

goal symbol

await

await

 may be

parsed as an identifier when the 

[Await]

 parameter is absent. This includes the following contexts:

Anywhere outside of an 

AsyncFunctionBody

 or 

FormalParameters

 of an 

AsyncFunctionDeclaration

AsyncFunctionExpression

AsyncGeneratorDeclaration

, or 

AsyncGeneratorExpression

.

In the 

BindingIdentifier

 of a 

FunctionExpression

GeneratorExpression

, or 

AsyncGeneratorExpression

.

Unlike 

YieldExpression

, it is a Syntax Error to omit the operand of an 

AwaitExpression

. You must

await something.

15.8.1  Static Semantics: Early Errors

417

async

 

function

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

async

 

function

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

AsyncFunctionExpression

 

:

async

 

function

 

BindingIdentifier

opt

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

It is a Syntax Error if 

FunctionBodyContainsUseStrict

 of 

AsyncFunctionBody

 is 

true

 and 

IsSimpleParameterList

of 

FormalParameters

 is 

false

.

It is a Syntax Error if 

FormalParameters

 

Contains

 

AwaitExpression

 is 

true

.

If the source code matching 

FormalParameters

 is 

strict mode code

, the Early Error rules for

UniqueFormalParameters

 

:

 

FormalParameters

 are applied.

If 

BindingIdentifier

 is present and the source code matching 

BindingIdentifier

 is 

strict mode code

, it is a Syntax

Error if the 

StringValue

 of 

BindingIdentifier

 is 

"eval"

 or 

"arguments"

.

It is a Syntax Error if any element of the 

BoundNames

 of 

FormalParameters

 also occurs in the

LexicallyDeclaredNames

 of 

AsyncFunctionBody

.

It is a Syntax Error if 

FormalParameters

 

Contains

 

SuperProperty

 is 

true

.

It is a Syntax Error if 

AsyncFunctionBody

 

Contains

 

SuperProperty

 is 

true

.

It is a Syntax Error if 

FormalParameters

 

Contains

 

SuperCall

 is 

true

.

It is a Syntax Error if 

AsyncFunctionBody

 

Contains

 

SuperCall

 is 

true

.

With parameter 

scope

.

AsyncFunctionDeclaration

 

:

 

async

 

function

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

1.  Let 

name

 be 

StringValue

 of 

BindingIdentifier

.

2.  Let 

sourceText

 be the source text matched by 

AsyncFunctionDeclaration

.

3.  Let 

F

 be ! 

OrdinaryFunctionCreate

(

%AsyncFunction.prototype%

sourceText

FormalParameters

AsyncFunctionBody

non-lexical-this

scope

).

4.  Perform ! 

SetFunctionName

(

F

name

).

5.  Return 

F

.

AsyncFunctionDeclaration

 

:

 

async

 

function

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

1.  Let 

sourceText

 be the source text matched by 

AsyncFunctionDeclaration

.

2.  Let 

F

 be ! 

OrdinaryFunctionCreate

(

%AsyncFunction.prototype%

sourceText

FormalParameters

AsyncFunctionBody

non-lexical-this

scope

).

3.  Perform ! 

SetFunctionName

(

F

"default"

).

4.  Return 

F

.

With optional parameter 

name

.

AsyncFunctionExpression

 

:

 

async

 

function

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

1.  If 

name

 is not present, set 

name

 to 

""

.

2.  Let 

scope

 be the LexicalEnvironment of the 

running execution context

.

3.  Let 

sourceText

 be the source text matched by 

AsyncFunctionExpression

.

15.8.2  Runtime Semantics: InstantiateAsyncFunctionObject

15.8.3  Runtime Semantics: InstantiateAsyncFunctionExpression

418

4.  Let 

closure

 be ! 

OrdinaryFunctionCreate

(

%AsyncFunction.prototype%

sourceText

FormalParameters

AsyncFunctionBody

non-lexical-this

scope

).

5.  Perform 

SetFunctionName

(

closure

name

).

6.  Return 

closure

.

AsyncFunctionExpression

 

:

 

async

 

function

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

1. 

Assert

name

 is not present.

2.  Set 

name

 to 

StringValue

 of 

BindingIdentifier

.

3.  Let 

scope

 be the LexicalEnvironment of the 

running execution context

.

4.  Let 

funcEnv

 be ! 

NewDeclarativeEnvironment

(

scope

).

5.  Perform ! 

funcEnv

.CreateImmutableBinding(

name

false

).

6.  Let 

sourceText

 be the source text matched by 

AsyncFunctionExpression

.

7.  Let 

closure

 be ! 

OrdinaryFunctionCreate

(

%AsyncFunction.prototype%

sourceText

FormalParameters

AsyncFunctionBody

non-lexical-this

funcEnv

).

8.  Perform ! 

SetFunctionName

(

closure

name

).

9.  Perform ! 

funcEnv

.InitializeBinding(

name

closure

).

10.  Return 

closure

.

NOTE

With parameters 

functionObject

 and 

argumentsList

 (a 

List

).

AsyncFunctionBody

 

:

 

FunctionBody

1.  Let 

promiseCapability

 be ! 

NewPromiseCapability

(

%Promise%

).

2.  Let 

declResult

 be 

FunctionDeclarationInstantiation

(

functionObject

argumentsList

).

3.  If 

declResult

 is not an 

abrupt completion

, then

a.  Perform ! 

AsyncFunctionStart

(

promiseCapability

FunctionBody

).

4.  Else,

a.  Perform ! 

Call

(

promiseCapability

.[[Reject]], 

undefined

, « 

declResult

.[[Value]] »).

5.  Return 

Completion

 { [[Type]]: 

return

, [[Value]]: 

promiseCapability

.[[Promise]], [[Target]]: 

empty

 }.

AsyncFunctionDeclaration

 

:

 

async

 

function

 

BindingIdentifier

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

1.  Return 

NormalCompletion

(

empty

).

AsyncFunctionDeclaration

 

:

 

async

 

function

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

1.  Return 

NormalCompletion

(

empty

).

AsyncFunctionExpression

 

:

async

 

function

 

BindingIdentifier

opt

 

(

 

FormalParameters

 

)

 

{

 

AsyncFunctionBody

 

}

The 

BindingIdentifier

 in an 

AsyncFunctionExpression

 can be referenced from inside the 

AsyncFunctionExpression

's 

AsyncFunctionBody

 to allow the function to call itself recursively.

However, unlike in a 

FunctionDeclaration

, the 

BindingIdentifier

 in a 

AsyncFunctionExpression

 cannot

be referenced from and does not affect the scope enclosing the 

AsyncFunctionExpression

.

15.8.4  Runtime Semantics: EvaluateAsyncFunctionBody

15.8.5  Runtime Semantics: Evaluation

419

1.  Return 

InstantiateAsyncFunctionExpression

 of 

AsyncFunctionExpression

.

AwaitExpression

 

:

 

await

 

UnaryExpression

1.  Let 

exprRef

 be the result of evaluating 

UnaryExpression

.

2.  Let 

value

 be ? 

GetValue

(

exprRef

).

3.  Return ? 

Await

(

value

).

AsyncArrowFunction

[In, Yield, Await]

 

:

async

 [no 

LineTerminator

 here]  

AsyncArrowBindingIdentifier

[?Yield]

 [no 

LineTerminator

 here]  

=>

AsyncConciseBody

[?In]

CoverCallExpressionAndAsyncArrowHead

[?Yield, ?Await]

 [no 

LineTerminator

 here]  

=>

AsyncConciseBody

[?In]

AsyncConciseBody

[In]

 

:

[lookahead 

 

{

 

ExpressionBody

[?In, +Await]

{

 

AsyncFunctionBody

 

}

AsyncArrowBindingIdentifier

[Yield]

 

:

BindingIdentifier

[?Yield, +Await]

CoverCallExpressionAndAsyncArrowHead

[Yield, Await]

 

:

MemberExpression

[?Yield, ?Await]

 

Arguments

[?Yield, ?Await]

When processing an instance of the production 

AsyncArrowFunction

 

:

 

CoverCallExpressionAndAsyncArrowHead

 

=>

 

AsyncConciseBody

 

the interpretation of 

CoverCallExpressionAndAsyncArrowHead

 is refined using the following grammar:

AsyncArrowHead

 

:

async

 [no 

LineTerminator

 here]  

ArrowFormalParameters

[~Yield, +Await]

AsyncArrowFunction

 

:

 

async

 

AsyncArrowBindingIdentifier

 

=>

 

AsyncConciseBody

It is a Syntax Error if any element of the 

BoundNames

 of 

AsyncArrowBindingIdentifier

 also occurs in the

LexicallyDeclaredNames

 of 

AsyncConciseBody

.

AsyncArrowFunction

 

:

 

CoverCallExpressionAndAsyncArrowHead

 

=>

 

AsyncConciseBody

It is a Syntax Error if 

CoverCallExpressionAndAsyncArrowHead

 

Contains

 

YieldExpression

 is 

true

.

It is a Syntax Error if 

CoverCallExpressionAndAsyncArrowHead

 

Contains

 

AwaitExpression

 is 

true

.

15.9  Async Arrow Function Definitions

Syntax

Supplemental Syntax

15.9.1  Static Semantics: Early Errors

420

It is a Syntax Error if 

CoverCallExpressionAndAsyncArrowHead

 is not 

covering

 an 

AsyncArrowHead

.

It is a Syntax Error if any element of the 

BoundNames

 of 

CoverCallExpressionAndAsyncArrowHead

 also occurs in

the 

LexicallyDeclaredNames

 of 

AsyncConciseBody

.

It is a Syntax Error if 

AsyncConciseBodyContainsUseStrict

 of 

AsyncConciseBody

 is 

true

 and

IsSimpleParameterList

 of 

CoverCallExpressionAndAsyncArrowHead

 is 

false

.

All Early Error rules for 

AsyncArrowHead

 and its derived productions apply to 

CoveredAsyncArrowHead

 of 

CoverCallExpressionAndAsyncArrowHead

.

CoverCallExpressionAndAsyncArrowHead

 

:

 

MemberExpression

 

Arguments

1.  Return the 

AsyncArrowHead

 that is 

covered

 by 

CoverCallExpressionAndAsyncArrowHead

.

AsyncConciseBody

 

:

 

ExpressionBody

1.  Return 

false

.

AsyncConciseBody

 

:

 

{

 

AsyncFunctionBody

 

}

1.  Return 

FunctionBodyContainsUseStrict

 of 

AsyncFunctionBody

.

With parameters 

functionObject

 and 

argumentsList

 (a 

List

).

AsyncConciseBody

 

:

 

ExpressionBody

1.  Let 

promiseCapability

 be ! 

NewPromiseCapability

(

%Promise%

).

2.  Let 

declResult

 be 

FunctionDeclarationInstantiation

(

functionObject

argumentsList

).

3.  If 

declResult

 is not an 

abrupt completion

, then

a.  Perform ! 

AsyncFunctionStart

(

promiseCapability

ExpressionBody

).

4.  Else,

a.  Perform ! 

Call

(

promiseCapability

.[[Reject]], 

undefined

, « 

declResult

.[[Value]] »).

5.  Return 

Completion

 { [[Type]]: 

return

, [[Value]]: 

promiseCapability

.[[Promise]], [[Target]]: 

empty

 }.

With optional parameter 

name

.

AsyncArrowFunction

 

:

 

async

 

AsyncArrowBindingIdentifier

 

=>

 

AsyncConciseBody

1.  If 

name

 is not present, set 

name

 to 

""

.

2.  Let 

scope

 be the LexicalEnvironment of the 

running execution context

.

3.  Let 

sourceText

 be the source text matched by 

AsyncArrowFunction

.

4.  Let 

parameters

 be 

AsyncArrowBindingIdentifier

.

5.  Let 

closure

 be ! 

OrdinaryFunctionCreate

(

%AsyncFunction.prototype%

sourceText

parameters

AsyncConciseBody

,

lexical-this

scope

).

6.  Perform 

SetFunctionName

(

closure

name

).

15.9.2  Static Semantics: CoveredAsyncArrowHead

15.9.3  Static Semantics: AsyncConciseBodyContainsUseStrict

15.9.4  Runtime Semantics: EvaluateAsyncConciseBody

15.9.5  Runtime Semantics: InstantiateAsyncArrowFunctionExpression

421

7.  Return 

closure

.

AsyncArrowFunction

 

:

 

CoverCallExpressionAndAsyncArrowHead

 

=>

 

AsyncConciseBody

1.  If 

name

 is not present, set 

name

 to 

""

.

2.  Let 

scope

 be the LexicalEnvironment of the 

running execution context

.

3.  Let 

sourceText

 be the source text matched by 

AsyncArrowFunction

.

4.  Let 

head

 be 

CoveredAsyncArrowHead

 of 

CoverCallExpressionAndAsyncArrowHead

.

5.  Let 

parameters

 be the 

ArrowFormalParameters

 of 

head

.

6.  Let 

closure

 be ! 

OrdinaryFunctionCreate

(

%AsyncFunction.prototype%

sourceText

parameters

AsyncConciseBody

,

lexical-this

scope

).

7.  Perform 

SetFunctionName

(

closure

name

).

8.  Return 

closure

.

AsyncArrowFunction

 

:

async

 

AsyncArrowBindingIdentifier

 

=>

 

AsyncConciseBody

CoverCallExpressionAndAsyncArrowHead

 

=>

 

AsyncConciseBody

1.  Return 

InstantiateAsyncArrowFunctionExpression

 of 

AsyncArrowFunction

.

The abstract operation IsInTailPosition takes argument 

call

. It performs the following steps when called:

1. 

Assert

call

 is a 

Parse Node

.

2.  If the source code matching 

call

 is 

non-strict code

, return 

false

.

3.  If 

call

 is not contained within a 

FunctionBody

ConciseBody

, or 

AsyncConciseBody

, return 

false

.

4.  Let 

body

 be the 

FunctionBody

ConciseBody

, or 

AsyncConciseBody

 that most closely contains 

call

.

5.  If 

body

 is the 

FunctionBody

 of a 

GeneratorBody

, return 

false

.

6.  If 

body

 is the 

FunctionBody

 of an 

AsyncFunctionBody

, return 

false

.

7.  If 

body

 is the 

FunctionBody

 of an 

AsyncGeneratorBody

, return 

false

.

8.  If 

body

 is an 

AsyncConciseBody

, return 

false

.

9.  Return the result of 

HasCallInTailPosition

 of 

body

 with argument 

call

.

NOTE

With parameter 

call

.

Tail Position calls are only defined in 

strict mode code

 because of a common non-standard

language extension (see 

10.2.4

) that enables observation of the chain of caller contexts.

15.9.6  Runtime Semantics: Evaluation

15.10  Tail Position Calls

15.10.1  Static Semantics: IsInTailPosition ( 

call

 )

15.10.2  Static Semantics: HasCallInTailPosition

422

NOTE

StatementList

 

:

 

StatementList

 

StatementListItem

1.  Let 

has

 be 

HasCallInTailPosition

 of 

StatementList

 with argument 

call

.

2.  If 

has

 is 

true

, return 

true

.

3.  Return 

HasCallInTailPosition

 of 

StatementListItem

 with argument 

call

.

FunctionStatementList

 

:

  [empty]

StatementListItem

 

:

 

Declaration

Statement

 

:

VariableStatement
EmptyStatement
ExpressionStatement
ContinueStatement
BreakStatement
ThrowStatement
DebuggerStatement

Block

 

:

 

{

 

}

ReturnStatement

 

:

 

return

 

;

LabelledItem

 

:

 

FunctionDeclaration

ForInOfStatement

 

:

for

 

(

 

LeftHandSideExpression

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

(

 

var

 

ForBinding

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

(

 

ForDeclaration

 

of

 

AssignmentExpression

 

)

 

Statement

CaseBlock

 

:

 

{

 

}

1.  Return 

false

.

IfStatement

 

:

 

if

 

(

 

Expression

 

)

 

Statement

 

else

 

Statement

1.  Let 

has

 be 

HasCallInTailPosition

 of the first 

Statement

 with argument 

call

.

2.  If 

has

 is 

true

, return 

true

.

3.  Return 

HasCallInTailPosition

 of the second 

Statement

 with argument 

call

.

IfStatement

 

:

 

if

 

(

 

Expression

 

)

 

Statement

DoWhileStatement

 

:

 

do

 

Statement

 

while

 

(

 

Expression

 

)

 

;

WhileStatement

 

:

 

while

 

(

 

Expression

 

)

 

Statement

ForStatement

 

:

for

 

(

 

Expression

opt

 

;

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

for

 

(

 

var

 

VariableDeclarationList

 

;

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

for

 

(

 

LexicalDeclaration

 

Expression

opt

 

;

 

Expression

opt

 

)

 

Statement

ForInOfStatement

 

:

for

 

(

 

LeftHandSideExpression

 

in

 

Expression

 

)

 

Statement

for

 

(

 

var

 

ForBinding

 

in

 

Expression

 

)

 

Statement

call

 is a 

Parse Node

 that represents a specific range of source text. When the following algorithms

compare 

call

 to another 

Parse Node

, it is a test of whether they represent the same source text.

15.10.2.1  Statement Rules

423

for

 

(

 

ForDeclaration

 

in

 

Expression

 

)

 

Statement

for

 

await

 

(

 

LeftHandSideExpression

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

await

 

(

 

var

 

ForBinding

 

of

 

AssignmentExpression

 

)

 

Statement

for

 

await

 

(

 

ForDeclaration

 

of

 

AssignmentExpression

 

)

 

Statement

WithStatement

 

:

 

with

 

(

 

Expression

 

)

 

Statement

1.  Return 

HasCallInTailPosition

 of 

Statement

 with argument 

call

.

LabelledStatement

 

:

LabelIdentifier

 

:

 

LabelledItem

1.  Return 

HasCallInTailPosition

 of 

LabelledItem

 with argument 

call

.

ReturnStatement

 

:

 

return

 

Expression

 

;

1.  Return 

HasCallInTailPosition

 of 

Expression

 with argument 

call

.

SwitchStatement

 

:

 

switch

 

(

 

Expression

 

)

 

CaseBlock

1.  Return 

HasCallInTailPosition

 of 

CaseBlock

 with argument 

call

.

CaseBlock

 

:

 

{

 

CaseClauses

opt

 

DefaultClause

 

CaseClauses

opt

 

}

1.  Let 

has

 be 

false

.

2.  If the first 

CaseClauses

 is present, let 

has

 be 

HasCallInTailPosition

 of the first 

CaseClauses

 with argument 

call

.

3.  If 

has

 is 

true

, return 

true

.

4.  Let 

has

 be 

HasCallInTailPosition

 of 

DefaultClause

 with argument 

call

.

5.  If 

has

 is 

true

, return 

true

.

6.  If the second 

CaseClauses

 is present, let 

has

 be 

HasCallInTailPosition

 of the second 

CaseClauses

 with argument

call

.

7.  Return 

has

.

CaseClauses

 

:

 

CaseClauses

 

CaseClause

1.  Let 

has

 be 

HasCallInTailPosition

 of 

CaseClauses

 with argument 

call

.

2.  If 

has

 is 

true

, return 

true

.

3.  Return 

HasCallInTailPosition

 of 

CaseClause

 with argument 

call

.

CaseClause

 

:

 

case

 

Expression

 

:

 

StatementList

opt

DefaultClause

 

:

 

default

 

:

 

StatementList

opt

1.  If 

StatementList

 is present, return 

HasCallInTailPosition

 of 

StatementList

 with argument 

call

.

2.  Return 

false

.

TryStatement

 

:

 

try

 

Block

 

Catch

1.  Return 

HasCallInTailPosition

 of 

Catch

 with argument 

call

.

TryStatement

 

:

 

try

 

Block

 

Finally

TryStatement

 

:

 

try

 

Block

 

Catch

 

Finally

1.  Return 

HasCallInTailPosition

 of 

Finally

 with argument 

call

.

424

Catch

 

:

 

catch

 

(

 

CatchParameter

 

)

 

Block

1.  Return 

HasCallInTailPosition

 of 

Block

 with argument 

call

.

NOTE

AssignmentExpression

 

:

YieldExpression
ArrowFunction
AsyncArrowFunction
LeftHandSideExpression

 

=

 

AssignmentExpression

LeftHandSideExpression

 

AssignmentOperator

 

AssignmentExpression

LeftHandSideExpression

 

&&=

 

AssignmentExpression

LeftHandSideExpression

 

||=

 

AssignmentExpression

LeftHandSideExpression

 

??=

 

AssignmentExpression

BitwiseANDExpression

 

:

 

BitwiseANDExpression

 

&

 

EqualityExpression

BitwiseXORExpression

 

:

 

BitwiseXORExpression

 

^

 

BitwiseANDExpression

BitwiseORExpression

 

:

 

BitwiseORExpression

 

|

 

BitwiseXORExpression

EqualityExpression

 

:

EqualityExpression

 

==

 

RelationalExpression

EqualityExpression

 

!=

 

RelationalExpression

EqualityExpression

 

===

 

RelationalExpression

EqualityExpression

 

!==

 

RelationalExpression

RelationalExpression

 

:

RelationalExpression

 

<

 

ShiftExpression

RelationalExpression

 

>

 

ShiftExpression

RelationalExpression

 

<=

 

ShiftExpression

RelationalExpression

 

>=

 

ShiftExpression

RelationalExpression

 

instanceof

 

ShiftExpression

RelationalExpression

 

in

 

ShiftExpression

ShiftExpression

 

:

ShiftExpression

 

<<

 

AdditiveExpression

ShiftExpression

 

>>

 

AdditiveExpression

ShiftExpression

 

>>>

 

AdditiveExpression

AdditiveExpression

 

:

AdditiveExpression

 

+

 

MultiplicativeExpression

AdditiveExpression

 

-

 

MultiplicativeExpression

MultiplicativeExpression

 

:

MultiplicativeExpression

 

MultiplicativeOperator

 

ExponentiationExpression

ExponentiationExpression

 

:

UpdateExpression

 

**

 

ExponentiationExpression

A potential tail position call that is immediately followed by return 

GetValue

 of the call result is

also a possible tail position call. A function call cannot return a 

Reference Record

, so such a

GetValue

 operation will always return the same value as the actual function call result.

15.10.2.2  Expression Rules

425

1.  Return 

HasCallInTailPosition

 of 

AssignmentExpression

 with argument 

call

.

ConditionalExpression

 

:

 

ShortCircuitExpression

 

?

 

AssignmentExpression

 

:

 

AssignmentExpression

1.  Let 

has

 be 

HasCallInTailPosition

 of the first 

AssignmentExpression

 with argument 

call

.

2.  If 

has

 is 

true

, return 

true

.

3.  Return 

HasCallInTailPosition

 of the second 

AssignmentExpression

 with argument 

call

.

LogicalANDExpression

 

:

 

LogicalANDExpression

 

&&

 

BitwiseORExpression

1.  Return 

HasCallInTailPosition

 of 

BitwiseORExpression

 with argument 

call

.

LogicalORExpression

 

:

 

LogicalORExpression

 

||

 

LogicalANDExpression

1.  Return 

HasCallInTailPosition

 of 

LogicalANDExpression

 with argument 

call

.

CoalesceExpression

 

:

 

CoalesceExpressionHead

 

??

 

BitwiseORExpression

1.  Return 

HasCallInTailPosition

 of 

BitwiseORExpression

 with argument 

call

.

CallExpression

 

:

CoverCallExpressionAndAsyncArrowHead
CallExpression

 

Arguments

CallExpression

 

TemplateLiteral

1.  If this 

CallExpression

 is 

call

, return 

true

.

2.  Return 

false

.

OptionalExpression

 

:

MemberExpression

 

OptionalChain

CallExpression

 

OptionalChain

OptionalExpression

 

OptionalChain

1.  Return 

HasCallInTailPosition

 of 

OptionalChain

 with argument 

call

.

OptionalChain

 

:

?.

 

[

 

Expression

 

]

?.

 

IdentifierName

OptionalChain

 

[

 

Expression

 

]

OptionalChain

 

.

 

IdentifierName

1.  Return 

false

.

OptionalChain

 

:

?.

 

Arguments

OptionalChain

 

Arguments

1.  If this 

OptionalChain

 is 

call

, return 

true

.

2.  Return 

false

.

MemberExpression

 

:

MemberExpression

 

TemplateLiteral

427

1.  If this 

MemberExpression

 is 

call

, return 

true

.

2.  Return 

false

.

PrimaryExpression

 

:

 

CoverParenthesizedExpressionAndArrowParameterList

1.  Let 

expr

 be 

CoveredParenthesizedExpression

 of 

CoverParenthesizedExpressionAndArrowParameterList

.

2.  Return 

HasCallInTailPosition

 of 

expr

 with argument 

call

.

ParenthesizedExpression

 

:

(

 

Expression

 

)

1.  Return 

HasCallInTailPosition

 of 

Expression

 with argument 

call

.

The abstract operation PrepareForTailCall takes no arguments. It performs the following steps when called:

1.  Let 

leafContext

 be the 

running execution context

.

2.  Suspend 

leafContext

.

3.  Pop 

leafContext

 from the 

execution context stack

. The 

execution context

 now on the top of the stack becomes the

running execution context

.

4. 

Assert

leafContext

 has no further use. It will never be activated as the 

running execution context

.

A tail position call must either release any transient internal resources associated with the currently executing function

execution context

 before invoking the target function or reuse those resources in support of the target function.

NOTE

Script

 

:

ScriptBody

opt

ScriptBody

 

:

StatementList

[~Yield, ~Await, ~Return]

Script

 

:

 

ScriptBody

For example, a tail position call should only grow an implementation's activation record stack by
the amount that the size of the target function's activation record exceeds the size of the calling
function's activation record. If the target function's activation record is smaller, then the total size
of the stack should decrease.

15.10.3  PrepareForTailCall ( )

16  ECMAScript Language: Scripts and Modules

16.1  Scripts

Syntax

16.1.1  Static Semantics: Early Errors

428

It is a Syntax Error if the 

LexicallyDeclaredNames

 of 

ScriptBody

 contains any duplicate entries.

It is a Syntax Error if any element of the 

LexicallyDeclaredNames

 of 

ScriptBody

 also occurs in the

VarDeclaredNames

 of 

ScriptBody

.

ScriptBody

 

:

 

StatementList

It is a Syntax Error if 

StatementList

 

Contains

 

super

super

 unless the source code containing 

super

super

 is eval code that

is being processed by a 

direct eval

. Additional 

early error

 rules for 

super

super

 within 

direct eval

 are defined in

19.2.1.1

.

It is a Syntax Error if 

StatementList

 

Contains

 

NewTarget

 unless the source code containing 

NewTarget

 is eval code

that is being processed by a 

direct eval

. Additional 

early error

 rules for 

NewTarget

 in 

direct eval

 are defined in

19.2.1.1

.

It is a Syntax Error if 

ContainsDuplicateLabels

 of 

StatementList

 with argument « » is 

true

.

It is a Syntax Error if 

ContainsUndefinedBreakTarget

 of 

StatementList

 with argument « » is 

true

.

It is a Syntax Error if 

ContainsUndefinedContinueTarget

 of 

StatementList

 with arguments « » and « » is 

true

.

Script

 

:

 

ScriptBody

opt

1.  If 

ScriptBody

 is present and the 

Directive Prologue

 of 

ScriptBody

 contains a 

Use Strict Directive

, return 

true

;

otherwise, return 

false

.

Script

 

:

  [empty]

1.  Return 

NormalCompletion

(

undefined

).

Script Record

 encapsulates information about a script being evaluated. Each script record contains the fields listed in

Table 39

.

Table 39: 

Script Record

 Fields

Field Name

Value Type

Meaning

[[Realm]]

Realm Record

 |

undefined

The 

realm

 within which this script was created. 

undefined

 if not yet

assigned.

[[Environment]]

Environment
Record

 |

undefined

The 

Environment Record

 containing the top level bindings for this

script. This field is set when the script is instantiated.

[[ECMAScriptCode]] a 

Parse Node

The result of parsing the source text of this script using 

Script

 as the

goal symbol

.

[[HostDefined]]

Any, default value
is 

empty

.

Field reserved for use by 

host

 environments that need to associate

additional information with a script.

16.1.2  Static Semantics: IsStrict

16.1.3  Runtime Semantics: Evaluation

16.1.4  Script Records

429

The abstract operation ParseScript takes arguments 

sourceText

realm

, and 

hostDefined

. It creates a 

Script Record

 based

upon the result of parsing 

sourceText

 as a 

Script

. It performs the following steps when called:

1. 

Assert

sourceText

 is an ECMAScript source text (see clause 

11

).

2.  Let 

body

 be 

ParseText

(

sourceText

Script

).

3.  If 

body

 is a 

List

 of errors, return 

body

.

4.  Return 

Script Record

 { [[Realm]]: 

realm

, [[Environment]]: 

undefined

, [[ECMAScriptCode]]: 

body

,

[[HostDefined]]: 

hostDefined

 }.

NOTE

The abstract operation ScriptEvaluation takes argument 

scriptRecord

. It performs the following steps when called:

1.  Let 

globalEnv

 be 

scriptRecord

.[[Realm]].[[GlobalEnv]].

2.  Let 

scriptContext

 be a new ECMAScript code 

execution context

.

3.  Set the Function of 

scriptContext

 to 

null

.

4.  Set the 

Realm

 of 

scriptContext

 to 

scriptRecord

.[[Realm]].

5.  Set the ScriptOrModule of 

scriptContext

 to 

scriptRecord

.

6.  Set the VariableEnvironment of 

scriptContext

 to 

globalEnv

.

7.  Set the LexicalEnvironment of 

scriptContext

 to 

globalEnv

.

8.  Suspend the currently 

running execution context

.

9.  Push 

scriptContext

 onto the 

execution context stack

scriptContext

 is now the 

running execution context

.

10.  Let 

scriptBody

 be 

scriptRecord

.[[ECMAScriptCode]].

11.  Let 

result

 be 

GlobalDeclarationInstantiation

(

scriptBody

globalEnv

).

12.  If 

result

.[[Type]] is 

normal

, then

a.  Set 

result

 to the result of evaluating 

scriptBody

.

13.  If 

result

.[[Type]] is 

normal

 and 

result

.[[Value]] is 

empty

, then

a.  Set 

result

 to 

NormalCompletion

(

undefined

).

14.  Suspend 

scriptContext

 and remove it from the 

execution context stack

.

15. 

Assert

: The 

execution context stack

 is not empty.

16.  Resume the context that is now on the top of the 

execution context stack

 as the 

running execution context

.

17.  Return 

Completion

(

result

).

NOTE 1

The abstract operation GlobalDeclarationInstantiation takes arguments 

script

 (a 

Parse Node

 for 

ScriptBody

) and 

env

 (an

Environment Record

). 

script

 is the 

ScriptBody

 for which the 

execution context

 is being established. 

env

 is the global

An implementation may parse script source text and analyse it for Early Error conditions prior to
evaluation of ParseScript for that script source text. However, the reporting of any errors must be
deferred until the point where this specification actually performs ParseScript upon that source
text.

When an 

execution context

 is established for evaluating scripts, declarations are instantiated in

the current global environment. Each global binding declared in the code is instantiated.

16.1.5  ParseScript ( 

sourceText

realm

hostDefined

 )

16.1.6  ScriptEvaluation ( 

scriptRecord

 )

16.1.7  GlobalDeclarationInstantiation ( 

script

env

 )

430

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

1. 

Assert

env

 is a 

global Environment Record

.

2.  Let 

lexNames

 be the 

LexicallyDeclaredNames

 of 

script

.

3.  Let 

varNames

 be the 

VarDeclaredNames

 of 

script

.

4.  For each element 

name

 of 

lexNames

, do

a.  If 

env

.HasVarDeclaration(

name

) is 

true

, throw a 

SyntaxError

 exception.

b.  If 

env

.HasLexicalDeclaration(

name

) is 

true

, throw a 

SyntaxError

 exception.

c.  Let 

hasRestrictedGlobal

 be ? 

env

.HasRestrictedGlobalProperty(

name

).

d.  If 

hasRestrictedGlobal

 is 

true

, throw a 

SyntaxError

 exception.

5.  For each element 

name

 of 

varNames

, do

a.  If 

env

.HasLexicalDeclaration(

name

) is 

true

, throw a 

SyntaxError

 exception.

6.  Let 

varDeclarations

 be the 

VarScopedDeclarations

 of 

script

.

7.  Let 

functionsToInitialize

 be a new empty 

List

.

8.  Let 

declaredFunctionNames

 be a new empty 

List

.

9.  For each element 

d

 of 

varDeclarations

, in reverse 

List

 order, do

a.  If 

d

 is neither a 

VariableDeclaration

 nor a 

ForBinding

 nor a 

BindingIdentifier

, then

i. 

Assert

d

 is either a 

FunctionDeclaration

, a 

GeneratorDeclaration

, an 

AsyncFunctionDeclaration

, or an 

AsyncGeneratorDeclaration

.

ii.  NOTE: If there are multiple function declarations for the same name, the last declaration is used.

iii.  Let 

fn

 be the sole element of the 

BoundNames

 of 

d

.

iv.  If 

fn

 is not an element of 

declaredFunctionNames

, then

1.  Let 

fnDefinable

 be ? 

env

.CanDeclareGlobalFunction(

fn

).

2.  If 

fnDefinable

 is 

false

, throw a 

TypeError

 exception.

3.  Append 

fn

 to 

declaredFunctionNames

.

4.  Insert 

d

 as the first element of 

functionsToInitialize

.

10.  Let 

declaredVarNames

 be a new empty 

List

.

11.  For each element 

d

 of 

varDeclarations

, do

a.  If 

d

 is a 

VariableDeclaration

, a 

ForBinding

, or a 

BindingIdentifier

, then

i.  For each String 

vn

 of the 

BoundNames

 of 

d

, do

1.  If 

vn

 is not an element of 

declaredFunctionNames

, then

a.  Let 

vnDefinable

 be ? 

env

.CanDeclareGlobalVar(

vn

).

b.  If 

vnDefinable

 is 

false

, throw a 

TypeError

 exception.

c.  If 

vn

 is not an element of 

declaredVarNames

, then

i.  Append 

vn

 to 

declaredVarNames

.

12.  NOTE: No abnormal terminations occur after this algorithm step if the 

global object

 is an 

ordinary object

.

However, if the 

global object

 is a 

Proxy exotic object

 it may exhibit behaviours that cause abnormal

terminations in some of the following steps.

13.  NOTE: Annex 

B.3.3.2

 adds additional steps at this point.

14.  Let 

lexDeclarations

 be the 

LexicallyScopedDeclarations

 of 

script

.

15.  For each element 

d

 of 

lexDeclarations

, do

a.  NOTE: Lexically declared names are only instantiated here but not initialized.

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

).

16.  For each 

Parse Node

 

f

 of 

functionsToInitialize

, do

431

 

 

 

 

 

 

 

Content      ..     24      25      26      27     ..