Stage 3 Draft / June 28, 2021

ECMAScript class static initialization blocks

Introduction

This proposal defines new syntax to perform privleged static initialization of a class.

See the proposal repository for background material and discussion.

1 ECMAScript Data Types and Values

1.1 ECMAScript Specification Types

1.1.1 ClassStaticBlockDefinition Records

A ClassStaticBlockDefinition Record is a Record value used to encapsulate the executable code for a class static initialization block.

ClassStaticBlockDefinition Records have the fields listed in Table 1.

Table 1: ClassStaticBlockDefinition Record Fields
Field Name Value Meaning
[[BodyFunction]] An function object. The function object to be called during static initialization of a class.

2 Abstract Operations

2.1 Operations on Objects

2.1.1 EvaluateStaticBlock ( receiver , blockRecord )

The abstract operation EvaluateStaticBlock takes arguments receiver (an Object) and blockRecord (a ClassStaticBlockDefinition Record). It performs the following steps when called:

  1. Assert: Type(receiver) is Object.
  2. Assert: blockRecord is a ClassStaticBlockDefinition Record.
  3. Perform ? Call(blockRecord.[[BodyFunction]], receiver).

3 Syntax-Directed Operations

In addition to those defined in this section, specialized syntax-directed operations are defined throughout this specification.

3.1 Scope Analysis

3.1.1 Static Semantics: LexicallyDeclaredNames

Block : { }
  1. Return a new empty List.
StatementList : StatementList StatementListItem
  1. Let names be LexicallyDeclaredNames of StatementList.
  2. Append to names the elements of the LexicallyDeclaredNames of StatementListItem.
  3. Return names.
StatementListItem : Statement
  1. If Statement is Statement : LabelledStatement , return LexicallyDeclaredNames of LabelledStatement.
  2. Return a new empty List.
StatementListItem : Declaration
  1. Return the BoundNames of Declaration.
CaseBlock : { }
  1. Return a new empty List.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, let names be the LexicallyDeclaredNames of the first CaseClauses.
  2. Else, let names be a new empty List.
  3. Append to names the elements of the LexicallyDeclaredNames of DefaultClause.
  4. If the second CaseClauses is not present, return names.
  5. Return the result of appending to names the elements of the LexicallyDeclaredNames of the second CaseClauses.
CaseClauses : CaseClauses CaseClause
  1. Let names be LexicallyDeclaredNames of CaseClauses.
  2. Append to names the elements of the LexicallyDeclaredNames of CaseClause.
  3. Return names.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return the LexicallyDeclaredNames of StatementList.
  2. Return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the LexicallyDeclaredNames of StatementList.
  2. Return a new empty List.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the LexicallyDeclaredNames of LabelledItem.
LabelledItem : Statement
  1. Return a new empty List.
LabelledItem : FunctionDeclaration
  1. Return BoundNames of FunctionDeclaration.
FunctionStatementList : [empty]
  1. Return a new empty List.
FunctionStatementList : StatementList
  1. Return TopLevelLexicallyDeclaredNames of StatementList.
ClassStaticBlockStatementList : [empty]
  1. Return a new empty List.
ClassStaticBlockStatementList : StatementList
  1. Return the TopLevelLexicallyDeclaredNames of StatementList.
ConciseBody : ExpressionBody
  1. Return a new empty List.
AsyncConciseBody : ExpressionBody
  1. Return a new empty List.
ScriptBody : StatementList
  1. Return TopLevelLexicallyDeclaredNames of StatementList.
Note 1

At the top level of a Script, function declarations are treated like var declarations rather than like lexical declarations.

Note 2

The LexicallyDeclaredNames of a Module includes the names of all of its imported bindings.

ModuleItemList : ModuleItemList ModuleItem
  1. Let names be LexicallyDeclaredNames of ModuleItemList.
  2. Append to names the elements of the LexicallyDeclaredNames of ModuleItem.
  3. Return names.
ModuleItem : ImportDeclaration
  1. Return the BoundNames of ImportDeclaration.
ModuleItem : ExportDeclaration
  1. If ExportDeclaration is export VariableStatement, return a new empty List.
  2. Return the BoundNames of ExportDeclaration.
ModuleItem : StatementListItem
  1. Return LexicallyDeclaredNames of StatementListItem.
Note 3

At the top level of a Module, function declarations are treated like lexical declarations rather than like var declarations.

3.1.2 Static Semantics: LexicallyScopedDeclarations

StatementList : StatementList StatementListItem
  1. Let declarations be LexicallyScopedDeclarations of StatementList.
  2. Append to declarations the elements of the LexicallyScopedDeclarations of StatementListItem.
  3. Return declarations.
StatementListItem : Statement
  1. If Statement is Statement : LabelledStatement , return LexicallyScopedDeclarations of LabelledStatement.
  2. Return a new empty List.
StatementListItem : Declaration
  1. Return a List whose sole element is DeclarationPart of Declaration.
CaseBlock : { }
  1. Return a new empty List.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, let declarations be the LexicallyScopedDeclarations of the first CaseClauses.
  2. Else, let declarations be a new empty List.
  3. Append to declarations the elements of the LexicallyScopedDeclarations of DefaultClause.
  4. If the second CaseClauses is not present, return declarations.
  5. Return the result of appending to declarations the elements of the LexicallyScopedDeclarations of the second CaseClauses.
CaseClauses : CaseClauses CaseClause
  1. Let declarations be LexicallyScopedDeclarations of CaseClauses.
  2. Append to declarations the elements of the LexicallyScopedDeclarations of CaseClause.
  3. Return declarations.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return the LexicallyScopedDeclarations of StatementList.
  2. Return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the LexicallyScopedDeclarations of StatementList.
  2. Return a new empty List.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the LexicallyScopedDeclarations of LabelledItem.
LabelledItem : Statement
  1. Return a new empty List.
LabelledItem : FunctionDeclaration
  1. Return a List whose sole element is FunctionDeclaration.
FunctionStatementList : [empty]
  1. Return a new empty List.
FunctionStatementList : StatementList
  1. Return the TopLevelLexicallyScopedDeclarations of StatementList.
ClassStaticBlockStatementList : [empty]
  1. Return a new empty List.
ClassStaticBlockStatementList : StatementList
  1. Return the TopLevelLexicallyScopedDeclarations of StatementList.
ConciseBody : ExpressionBody
  1. Return a new empty List.
AsyncConciseBody : ExpressionBody
  1. Return a new empty List.
ScriptBody : StatementList
  1. Return TopLevelLexicallyScopedDeclarations of StatementList.
Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItemList ModuleItem
  1. Let declarations be LexicallyScopedDeclarations of ModuleItemList.
  2. Append to declarations the elements of the LexicallyScopedDeclarations of ModuleItem.
  3. Return declarations.
ModuleItem : ImportDeclaration
  1. Return a new empty List.
ExportDeclaration : export ExportFromClause FromClause ; export NamedExports ; export VariableStatement
  1. Return a new empty List.
ExportDeclaration : export Declaration
  1. Return a List whose sole element is DeclarationPart of Declaration.
ExportDeclaration : export default HoistableDeclaration
  1. Return a List whose sole element is DeclarationPart of HoistableDeclaration.
ExportDeclaration : export default ClassDeclaration
  1. Return a List whose sole element is ClassDeclaration.
ExportDeclaration : export default AssignmentExpression ;
  1. Return a List whose sole element is this ExportDeclaration.

3.1.3 Static Semantics: VarDeclaredNames

Statement : EmptyStatement ExpressionStatement ContinueStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement
  1. Return a new empty List.
Block : { }
  1. Return a new empty List.
StatementList : StatementList StatementListItem
  1. Let names be VarDeclaredNames of StatementList.
  2. Append to names the elements of the VarDeclaredNames of StatementListItem.
  3. Return names.
StatementListItem : Declaration
  1. Return a new empty List.
VariableStatement : var VariableDeclarationList ;
  1. Return BoundNames of VariableDeclarationList.
IfStatement : if ( Expression ) Statement else Statement
  1. Let names be VarDeclaredNames of the first Statement.
  2. Append to names the elements of the VarDeclaredNames of the second Statement.
  3. Return names.
IfStatement : if ( Expression ) Statement
  1. Return the VarDeclaredNames of Statement.
DoWhileStatement : do Statement while ( Expression ) ;
  1. Return the VarDeclaredNames of Statement.
WhileStatement : while ( Expression ) Statement
  1. Return the VarDeclaredNames of Statement.
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. Return the VarDeclaredNames of Statement.
ForStatement : for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
  1. Let names be BoundNames of VariableDeclarationList.
  2. Append to names the elements of the VarDeclaredNames of Statement.
  3. Return names.
ForStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return the VarDeclaredNames of Statement.
ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( ForDeclaration in Expression ) Statement for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement for await ( LeftHandSideExpression of AssignmentExpression ) Statement for await ( ForDeclaration of AssignmentExpression ) Statement
  1. Return the VarDeclaredNames of Statement.
ForInOfStatement : for ( var ForBinding in Expression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement
  1. Let names be the BoundNames of ForBinding.
  2. Append to names the elements of the VarDeclaredNames of Statement.
  3. Return names.
Note

This section is extended by Annex B.3.6.

WithStatement : with ( Expression ) Statement
  1. Return the VarDeclaredNames of Statement.
SwitchStatement : switch ( Expression ) CaseBlock
  1. Return the VarDeclaredNames of CaseBlock.
CaseBlock : { }
  1. Return a new empty List.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, let names be the VarDeclaredNames of the first CaseClauses.
  2. Else, let names be a new empty List.
  3. Append to names the elements of the VarDeclaredNames of DefaultClause.
  4. If the second CaseClauses is not present, return names.
  5. Return the result of appending to names the elements of the VarDeclaredNames of the second CaseClauses.
CaseClauses : CaseClauses CaseClause
  1. Let names be VarDeclaredNames of CaseClauses.
  2. Append to names the elements of the VarDeclaredNames of CaseClause.
  3. Return names.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return the VarDeclaredNames of StatementList.
  2. Return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the VarDeclaredNames of StatementList.
  2. Return a new empty List.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the VarDeclaredNames of LabelledItem.
LabelledItem : FunctionDeclaration
  1. Return a new empty List.
TryStatement : try Block Catch
  1. Let names be VarDeclaredNames of Block.
  2. Append to names the elements of the VarDeclaredNames of Catch.
  3. Return names.
TryStatement : try Block Finally
  1. Let names be VarDeclaredNames of Block.
  2. Append to names the elements of the VarDeclaredNames of Finally.
  3. Return names.
TryStatement : try Block Catch Finally
  1. Let names be VarDeclaredNames of Block.
  2. Append to names the elements of the VarDeclaredNames of Catch.
  3. Append to names the elements of the VarDeclaredNames of Finally.
  4. Return names.
Catch : catch ( CatchParameter ) Block
  1. Return the VarDeclaredNames of Block.
FunctionStatementList : [empty]
  1. Return a new empty List.
FunctionStatementList : StatementList
  1. Return TopLevelVarDeclaredNames of StatementList.
ClassStaticBlockStatementList : [empty]
  1. Return a new empty List.
ClassStaticBlockStatementList : StatementList
  1. Return the TopLevelVarDeclaredNames of StatementList.
ConciseBody : ExpressionBody
  1. Return a new empty List.
AsyncConciseBody : ExpressionBody
  1. Return a new empty List.
ScriptBody : StatementList
  1. Return TopLevelVarDeclaredNames of StatementList.
Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItemList ModuleItem
  1. Let names be VarDeclaredNames of ModuleItemList.
  2. Append to names the elements of the VarDeclaredNames of ModuleItem.
  3. Return names.
ModuleItem : ImportDeclaration
  1. Return a new empty List.
ModuleItem : ExportDeclaration
  1. If ExportDeclaration is export VariableStatement, return BoundNames of ExportDeclaration.
  2. Return a new empty List.

3.1.4 Static Semantics: VarScopedDeclarations

Statement : EmptyStatement ExpressionStatement ContinueStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement
  1. Return a new empty List.
Block : { }
  1. Return a new empty List.
StatementList : StatementList StatementListItem
  1. Let declarations be VarScopedDeclarations of StatementList.
  2. Append to declarations the elements of the VarScopedDeclarations of StatementListItem.
  3. Return declarations.
StatementListItem : Declaration
  1. Return a new empty List.
VariableDeclarationList : VariableDeclaration
  1. Return a List whose sole element is VariableDeclaration.
VariableDeclarationList : VariableDeclarationList , VariableDeclaration
  1. Let declarations be VarScopedDeclarations of VariableDeclarationList.
  2. Append VariableDeclaration to declarations.
  3. Return declarations.
IfStatement : if ( Expression ) Statement else Statement
  1. Let declarations be VarScopedDeclarations of the first Statement.
  2. Append to declarations the elements of the VarScopedDeclarations of the second Statement.
  3. Return declarations.
IfStatement : if ( Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.
DoWhileStatement : do Statement while ( Expression ) ;
  1. Return the VarScopedDeclarations of Statement.
WhileStatement : while ( Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. Return the VarScopedDeclarations of Statement.
ForStatement : for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
  1. Let declarations be VarScopedDeclarations of VariableDeclarationList.
  2. Append to declarations the elements of the VarScopedDeclarations of Statement.
  3. Return declarations.
ForStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return the VarScopedDeclarations of Statement.
ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( ForDeclaration in Expression ) Statement for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement for await ( LeftHandSideExpression of AssignmentExpression ) Statement for await ( ForDeclaration of AssignmentExpression ) Statement
  1. Return the VarScopedDeclarations of Statement.
ForInOfStatement : for ( var ForBinding in Expression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement
  1. Let declarations be a List whose sole element is ForBinding.
  2. Append to declarations the elements of the VarScopedDeclarations of Statement.
  3. Return declarations.
Note

This section is extended by Annex B.3.6.

WithStatement : with ( Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.
SwitchStatement : switch ( Expression ) CaseBlock
  1. Return the VarScopedDeclarations of CaseBlock.
CaseBlock : { }
  1. Return a new empty List.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, let declarations be the VarScopedDeclarations of the first CaseClauses.
  2. Else, let declarations be a new empty List.
  3. Append to declarations the elements of the VarScopedDeclarations of DefaultClause.
  4. If the second CaseClauses is not present, return declarations.
  5. Return the result of appending to declarations the elements of the VarScopedDeclarations of the second CaseClauses.
CaseClauses : CaseClauses CaseClause
  1. Let declarations be VarScopedDeclarations of CaseClauses.
  2. Append to declarations the elements of the VarScopedDeclarations of CaseClause.
  3. Return declarations.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return the VarScopedDeclarations of StatementList.
  2. Return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the VarScopedDeclarations of StatementList.
  2. Return a new empty List.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the VarScopedDeclarations of LabelledItem.
LabelledItem : FunctionDeclaration
  1. Return a new empty List.
TryStatement : try Block Catch
  1. Let declarations be VarScopedDeclarations of Block.
  2. Append to declarations the elements of the VarScopedDeclarations of Catch.
  3. Return declarations.
TryStatement : try Block Finally
  1. Let declarations be VarScopedDeclarations of Block.
  2. Append to declarations the elements of the VarScopedDeclarations of Finally.
  3. Return declarations.
TryStatement : try Block Catch Finally
  1. Let declarations be VarScopedDeclarations of Block.
  2. Append to declarations the elements of the VarScopedDeclarations of Catch.
  3. Append to declarations the elements of the VarScopedDeclarations of Finally.
  4. Return declarations.
Catch : catch ( CatchParameter ) Block
  1. Return the VarScopedDeclarations of Block.
FunctionStatementList : [empty]
  1. Return a new empty List.
FunctionStatementList : StatementList
  1. Return the TopLevelVarScopedDeclarations of StatementList.
ClassStaticBlockStatementList : [empty]
  1. Return a new empty List.
ClassStaticBlockStatementList : StatementList
  1. Return the TopLevelVarScopedDeclarations of StatementList.
ConciseBody : ExpressionBody
  1. Return a new empty List.
AsyncConciseBody : ExpressionBody
  1. Return a new empty List.
ScriptBody : StatementList
  1. Return TopLevelVarScopedDeclarations of StatementList.
Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItemList ModuleItem
  1. Let declarations be VarScopedDeclarations of ModuleItemList.
  2. Append to declarations the elements of the VarScopedDeclarations of ModuleItem.
  3. Return declarations.
ModuleItem : ImportDeclaration
  1. Return a new empty List.
ModuleItem : ExportDeclaration
  1. If ExportDeclaration is export VariableStatement, return VarScopedDeclarations of VariableStatement.
  2. Return a new empty List.

3.2 Labels

3.2.1 Static Semantics: ContainsDuplicateLabels

With parameter labelSet.

Statement : VariableStatement EmptyStatement ExpressionStatement ContinueStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement Block : { } StatementListItem : Declaration
  1. Return false.
StatementList : StatementList StatementListItem
  1. Let hasDuplicates be ContainsDuplicateLabels of StatementList with argument labelSet.
  2. If hasDuplicates is true, return true.
  3. Return ContainsDuplicateLabels of StatementListItem with argument labelSet.
IfStatement : if ( Expression ) Statement else Statement
  1. Let hasDuplicate be ContainsDuplicateLabels of the first Statement with argument labelSet.
  2. If hasDuplicate is true, return true.
  3. Return ContainsDuplicateLabels of the second Statement with argument labelSet.
IfStatement : if ( Expression ) Statement
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.
DoWhileStatement : do Statement while ( Expression ) ;
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.
WhileStatement : while ( Expression ) Statement
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.
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
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.
Note

This section is extended by Annex B.3.6.

WithStatement : with ( Expression ) Statement
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.
SwitchStatement : switch ( Expression ) CaseBlock
  1. Return ContainsDuplicateLabels of CaseBlock with argument labelSet.
CaseBlock : { }
  1. Return false.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, then
    1. Let hasDuplicates be ContainsDuplicateLabels of the first CaseClauses with argument labelSet.
    2. If hasDuplicates is true, return true.
  2. Let hasDuplicates be ContainsDuplicateLabels of DefaultClause with argument labelSet.
  3. If hasDuplicates is true, return true.
  4. If the second CaseClauses is not present, return false.
  5. Return ContainsDuplicateLabels of the second CaseClauses with argument labelSet.
CaseClauses : CaseClauses CaseClause
  1. Let hasDuplicates be ContainsDuplicateLabels of CaseClauses with argument labelSet.
  2. If hasDuplicates is true, return true.
  3. Return ContainsDuplicateLabels of CaseClause with argument labelSet.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return ContainsDuplicateLabels of StatementList with argument labelSet.
  2. Return false.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return ContainsDuplicateLabels of StatementList with argument labelSet.
  2. Return false.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Let label be the StringValue of LabelIdentifier.
  2. If label is an element of labelSet, return true.
  3. Let newLabelSet be a copy of labelSet with label appended.
  4. Return ContainsDuplicateLabels of LabelledItem with argument newLabelSet.
LabelledItem : FunctionDeclaration
  1. Return false.
TryStatement : try Block Catch
  1. Let hasDuplicates be ContainsDuplicateLabels of Block with argument labelSet.
  2. If hasDuplicates is true, return true.
  3. Return ContainsDuplicateLabels of Catch with argument labelSet.
TryStatement : try Block Finally
  1. Let hasDuplicates be ContainsDuplicateLabels of Block with argument labelSet.
  2. If hasDuplicates is true, return true.
  3. Return ContainsDuplicateLabels of Finally with argument labelSet.
TryStatement : try Block Catch Finally
  1. Let hasDuplicates be ContainsDuplicateLabels of Block with argument labelSet.
  2. If hasDuplicates is true, return true.
  3. Let hasDuplicates be ContainsDuplicateLabels of Catch with argument labelSet.
  4. If hasDuplicates is true, return true.
  5. Return ContainsDuplicateLabels of Finally with argument labelSet.
Catch : catch ( CatchParameter ) Block
  1. Return ContainsDuplicateLabels of Block with argument labelSet.
FunctionStatementList : [empty]
  1. Return false.
ClassStaticBlockStatementList : [empty]
  1. Return false.
ModuleItemList : ModuleItemList ModuleItem
  1. Let hasDuplicates be ContainsDuplicateLabels of ModuleItemList with argument labelSet.
  2. If hasDuplicates is true, return true.
  3. Return ContainsDuplicateLabels of ModuleItem with argument labelSet.
ModuleItem : ImportDeclaration ExportDeclaration
  1. Return false.

3.2.2 Static Semantics: ContainsUndefinedBreakTarget

With parameter labelSet.

Statement : VariableStatement EmptyStatement ExpressionStatement ContinueStatement ReturnStatement ThrowStatement DebuggerStatement Block : { } StatementListItem : Declaration
  1. Return false.
StatementList : StatementList StatementListItem
  1. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of StatementList with argument labelSet.
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedBreakTarget of StatementListItem with argument labelSet.
IfStatement : if ( Expression ) Statement else Statement
  1. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of the first Statement with argument labelSet.
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedBreakTarget of the second Statement with argument labelSet.
IfStatement : if ( Expression ) Statement
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.
DoWhileStatement : do Statement while ( Expression ) ;
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.
WhileStatement : while ( Expression ) Statement
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.
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
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.
Note

This section is extended by Annex B.3.6.

BreakStatement : break ;
  1. Return false.
BreakStatement : break LabelIdentifier ;
  1. If the StringValue of LabelIdentifier is not an element of labelSet, return true.
  2. Return false.
WithStatement : with ( Expression ) Statement
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.
SwitchStatement : switch ( Expression ) CaseBlock
  1. Return ContainsUndefinedBreakTarget of CaseBlock with argument labelSet.
CaseBlock : { }
  1. Return false.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, then
    1. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of the first CaseClauses with argument labelSet.
    2. If hasUndefinedLabels is true, return true.
  2. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of DefaultClause with argument labelSet.
  3. If hasUndefinedLabels is true, return true.
  4. If the second CaseClauses is not present, return false.
  5. Return ContainsUndefinedBreakTarget of the second CaseClauses with argument labelSet.
CaseClauses : CaseClauses CaseClause
  1. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of CaseClauses with argument labelSet.
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedBreakTarget of CaseClause with argument labelSet.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return ContainsUndefinedBreakTarget of StatementList with argument labelSet.
  2. Return false.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return ContainsUndefinedBreakTarget of StatementList with argument labelSet.
  2. Return false.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Let label be the StringValue of LabelIdentifier.
  2. Let newLabelSet be a copy of labelSet with label appended.
  3. Return ContainsUndefinedBreakTarget of LabelledItem with argument newLabelSet.
LabelledItem : FunctionDeclaration
  1. Return false.
TryStatement : try Block Catch
  1. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of Block with argument labelSet.
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedBreakTarget of Catch with argument labelSet.
TryStatement : try Block Finally
  1. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of Block with argument labelSet.
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedBreakTarget of Finally with argument labelSet.
TryStatement : try Block Catch Finally
  1. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of Block with argument labelSet.
  2. If hasUndefinedLabels is true, return true.
  3. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of Catch with argument labelSet.
  4. If hasUndefinedLabels is true, return true.
  5. Return ContainsUndefinedBreakTarget of Finally with argument labelSet.
Catch : catch ( CatchParameter ) Block
  1. Return ContainsUndefinedBreakTarget of Block with argument labelSet.
FunctionStatementList : [empty]
  1. Return false.
ClassStaticBlockStatementList : [empty]
  1. Return false.
ModuleItemList : ModuleItemList ModuleItem
  1. Let hasUndefinedLabels be ContainsUndefinedBreakTarget of ModuleItemList with argument labelSet.
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedBreakTarget of ModuleItem with argument labelSet.
ModuleItem : ImportDeclaration ExportDeclaration
  1. Return false.

3.2.3 Static Semantics: ContainsUndefinedContinueTarget

With parameters iterationSet and labelSet.

Statement : VariableStatement EmptyStatement ExpressionStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement Block : { } StatementListItem : Declaration
  1. Return false.
BreakableStatement : IterationStatement
  1. Let newIterationSet be a copy of iterationSet with all the elements of labelSet appended.
  2. Return ContainsUndefinedContinueTarget of IterationStatement with arguments newIterationSet and « ».
StatementList : StatementList StatementListItem
  1. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of StatementList with arguments iterationSet and « ».
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedContinueTarget of StatementListItem with arguments iterationSet and « ».
IfStatement : if ( Expression ) Statement else Statement
  1. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of the first Statement with arguments iterationSet and « ».
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedContinueTarget of the second Statement with arguments iterationSet and « ».
IfStatement : if ( Expression ) Statement
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».
DoWhileStatement : do Statement while ( Expression ) ;
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».
WhileStatement : while ( Expression ) Statement
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».
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
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».
Note

This section is extended by Annex B.3.6.

ContinueStatement : continue ;
  1. Return false.
ContinueStatement : continue LabelIdentifier ;
  1. If the StringValue of LabelIdentifier is not an element of iterationSet, return true.
  2. Return false.
WithStatement : with ( Expression ) Statement
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».
SwitchStatement : switch ( Expression ) CaseBlock
  1. Return ContainsUndefinedContinueTarget of CaseBlock with arguments iterationSet and « ».
CaseBlock : { }
  1. Return false.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, then
    1. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of the first CaseClauses with arguments iterationSet and « ».
    2. If hasUndefinedLabels is true, return true.
  2. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of DefaultClause with arguments iterationSet and « ».
  3. If hasUndefinedLabels is true, return true.
  4. If the second CaseClauses is not present, return false.
  5. Return ContainsUndefinedContinueTarget of the second CaseClauses with arguments iterationSet and « ».
CaseClauses : CaseClauses CaseClause
  1. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of CaseClauses with arguments iterationSet and « ».
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedContinueTarget of CaseClause with arguments iterationSet and « ».
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return ContainsUndefinedContinueTarget of StatementList with arguments iterationSet and « ».
  2. Return false.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return ContainsUndefinedContinueTarget of StatementList with arguments iterationSet and « ».
  2. Return false.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Let label be the StringValue of LabelIdentifier.
  2. Let newLabelSet be a copy of labelSet with label appended.
  3. Return ContainsUndefinedContinueTarget of LabelledItem with arguments iterationSet and newLabelSet.
LabelledItem : FunctionDeclaration
  1. Return false.
TryStatement : try Block Catch
  1. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of Block with arguments iterationSet and « ».
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedContinueTarget of Catch with arguments iterationSet and « ».
TryStatement : try Block Finally
  1. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of Block with arguments iterationSet and « ».
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedContinueTarget of Finally with arguments iterationSet and « ».
TryStatement : try Block Catch Finally
  1. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of Block with arguments iterationSet and « ».
  2. If hasUndefinedLabels is true, return true.
  3. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of Catch with arguments iterationSet and « ».
  4. If hasUndefinedLabels is true, return true.
  5. Return ContainsUndefinedContinueTarget of Finally with arguments iterationSet and « ».
Catch : catch ( CatchParameter ) Block
  1. Return ContainsUndefinedContinueTarget of Block with arguments iterationSet and « ».
FunctionStatementList : [empty]
  1. Return false.
ClassStaticBlockStatementList : [empty]
  1. Return false.
ModuleItemList : ModuleItemList ModuleItem
  1. Let hasUndefinedLabels be ContainsUndefinedContinueTarget of ModuleItemList with arguments iterationSet and « ».
  2. If hasUndefinedLabels is true, return true.
  3. Return ContainsUndefinedContinueTarget of ModuleItem with arguments iterationSet and « ».
ModuleItem : ImportDeclaration ExportDeclaration
  1. Return false.

3.3 Contains

3.3.1 Static Semantics: Contains

With parameter symbol.

Every grammar production alternative in this specification which is not listed below implicitly has the following default definition of Contains:

  1. For each child node child of this Parse Node, do
    1. If child is an instance of symbol, return true.
    2. If child is an instance of a nonterminal, then
      1. Let contained be the result of child Contains symbol.
      2. If contained is true, return true.
  2. Return false.
FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } function ( FormalParameters ) { FunctionBody } FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody } GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody } AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. Return false.
Note 1

Static semantic rules that depend upon substructure generally do not look into function definitions.

ClassTail : ClassHeritageopt { ClassBody }
  1. If symbol is ClassBody, return true.
  2. If symbol is ClassHeritage, then
    1. If ClassHeritage is present, return true; otherwise return false.
  3. Let inHeritage be ClassHeritage Contains symbol.
  4. If inHeritage is true, return true.
  5. Return the result of ComputedPropertyContains for ClassBody with argument symbol.
Note 2

Static semantic rules that depend upon substructure generally do not look into class bodies except for PropertyNames.

ClassStaticBlock : static { ClassStaticBlockBody }
  1. Return false.
Note 3

Static semantic rules that depend upon substructure generally do not look into static initialization blocks.

ArrowFunction : ArrowParameters => ConciseBody
  1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super or this, return false.
  2. If ArrowParameters Contains symbol is true, return true.
  3. Return ConciseBody Contains symbol.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. Let formals be CoveredFormalsList of CoverParenthesizedExpressionAndArrowParameterList.
  2. Return formals Contains symbol.
AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super, or this, return false.
  2. Return AsyncConciseBody Contains symbol.
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super, or this, return false.
  2. Let head be CoveredAsyncArrowHead of CoverCallExpressionAndAsyncArrowHead.
  3. If head Contains symbol is true, return true.
  4. Return AsyncConciseBody Contains symbol.
Note 4

Contains is used to detect new.target, this, and super usage within an ArrowFunction or AsyncArrowFunction.

PropertyDefinition : MethodDefinition
  1. If symbol is MethodDefinition, return true.
  2. Return the result of ComputedPropertyContains for MethodDefinition with argument symbol.
LiteralPropertyName : IdentifierName
  1. Return false.
MemberExpression : MemberExpression . IdentifierName
  1. If MemberExpression Contains symbol is true, return true.
  2. Return false.
SuperProperty : super . IdentifierName
  1. If symbol is the ReservedWord super, return true.
  2. Return false.
CallExpression : CallExpression . IdentifierName
  1. If CallExpression Contains symbol is true, return true.
  2. Return false.
OptionalChain : ?. IdentifierName
  1. Return false.
OptionalChain : OptionalChain . IdentifierName
  1. If OptionalChain Contains symbol is true, return true.
  2. Return false.

3.3.2 Static Semantics: ComputedPropertyContains

With parameter symbol.

PropertyName : LiteralPropertyName
  1. Return false.
PropertyName : ComputedPropertyName
  1. Return the result of ComputedPropertyName Contains symbol.
MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } get PropertyName ( ) { FunctionBody } set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. Return the result of ComputedPropertyContains for PropertyName with argument symbol.
GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody }
  1. Return the result of ComputedPropertyContains for PropertyName with argument symbol.
AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. Return the result of ComputedPropertyContains for PropertyName with argument symbol.
ClassElementList : ClassElementList ClassElement
  1. Let inList be ComputedPropertyContains of ClassElementList with argument symbol.
  2. If inList is true, return true.
  3. Return the result of ComputedPropertyContains for ClassElement with argument symbol.
ClassElement : ClassStaticBlock
  1. Return false.
ClassElement : ;
  1. Return false.
AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. Return the result of ComputedPropertyContains for PropertyName with argument symbol.

3.4 Miscellaneous

These operations are used in multiple places throughout the specification.

3.4.1 Static Semantics: PropName

PropertyDefinition : IdentifierReference
  1. Return StringValue of IdentifierReference.
PropertyDefinition : ... AssignmentExpression
  1. Return empty.
PropertyDefinition : PropertyName : AssignmentExpression
  1. Return PropName of PropertyName.
LiteralPropertyName : IdentifierName
  1. Return StringValue of IdentifierName.
LiteralPropertyName : StringLiteral
  1. Return the SV of StringLiteral.
LiteralPropertyName : NumericLiteral
  1. Let nbr be the NumericValue of NumericLiteral.
  2. Return ! ToString(nbr).
ComputedPropertyName : [ AssignmentExpression ]
  1. Return empty.
MethodDefinition : PropertyName ( UniqueFormalParameters ) { FunctionBody } get PropertyName ( ) { FunctionBody } set PropertyName ( PropertySetParameterList ) { FunctionBody }
  1. Return PropName of PropertyName.
GeneratorMethod : * PropertyName ( UniqueFormalParameters ) { GeneratorBody }
  1. Return PropName of PropertyName.
AsyncGeneratorMethod : async * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. Return PropName of PropertyName.
ClassElement : ClassStaticBlock
  1. Return empty.
ClassElement : ;
  1. Return empty.
AsyncMethod : async PropertyName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. Return PropName of PropertyName.

4 Ordinary and Exotic Objects Behaviours

4.1 ECMAScript Function Objects

4.1.1 [[Call]] ( thisArgument, argumentsList )

4.1.1.1 Runtime Semantics: EvaluateBody

With parameters functionObject and argumentsList (a List).

FunctionBody : FunctionStatementList
  1. Return ? EvaluateFunctionBody of FunctionBody with arguments functionObject and argumentsList.
ConciseBody : ExpressionBody
  1. Return ? EvaluateConciseBody of ConciseBody with arguments functionObject and argumentsList.
GeneratorBody : FunctionBody
  1. Return ? EvaluateGeneratorBody of GeneratorBody with arguments functionObject and argumentsList.
AsyncGeneratorBody : FunctionBody
  1. Return ? EvaluateAsyncGeneratorBody of AsyncGeneratorBody with arguments functionObject and argumentsList.
AsyncFunctionBody : FunctionBody
  1. Return ? EvaluateAsyncFunctionBody of AsyncFunctionBody with arguments functionObject and argumentsList.
AsyncConciseBody : ExpressionBody
  1. Return ? EvaluateAsyncConciseBody of AsyncConciseBody with arguments functionObject and argumentsList.
Initializer : = AssignmentExpression
  1. Assert: argumentsList is empty.
  2. Assert: functionObject.[[ClassFieldInitializerName]] is not empty.
  3. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then
    1. Let value be NamedEvaluation of Initializer with argument functionObject.[[ClassFieldInitializerName]].
  4. Else,
    1. Let rhs be the result of evaluating AssignmentExpression.
    2. Let value be ? GetValue(rhs).
  5. Return Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty }.
Note

Even though field initializers constitute a function boundary, calling FunctionDeclarationInstantiation does not have any observable effect and so is omitted.

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. Assert: argumentsList is empty.
  2. Return ? EvaluateClassStaticBlockBody of ClassStaticBlockBody with argument functionObject.

5 ECMAScript Language: Statements and Declarations

5.1 The continue Statement

5.1.1 Static Semantics: Early Errors

ContinueStatement : continue ; ContinueStatement : continue LabelIdentifier ;
  • It is a Syntax Error if this ContinueStatement is not nested, directly or indirectly (but not crossing function or static initialization block boundaries), within an IterationStatement.

5.2 The break Statement

5.2.1 Static Semantics: Early Errors

BreakStatement : break ;

6 ECMAScript Language: Functions and Classes

6.1 Class Definitions

Syntax

ClassElement[Yield, Await] : MethodDefinition[?Yield, ?Await] static MethodDefinition[?Yield, ?Await] FieldDefinition[?Yield, ?Await] ; static FieldDefinition[?Yield, ?Await] ; ClassStaticBlock ; ClassStaticBlock : static { ClassStaticBlockBody } ClassStaticBlockBody : ClassStaticBlockStatementList ClassStaticBlockStatementList : StatementList[~Yield, +Await, ~Return]opt

6.1.1 Static Semantics: Early Errors

ClassStaticBlockBody : ClassStaticBlockStatementList

6.1.2 Static Semantics: ClassElementKind

ClassElement : MethodDefinition
  1. If PropName of MethodDefinition is "constructor", return ConstructorMethod.
  2. Return NonConstructorMethod.
ClassElement : static MethodDefinition FieldDefinition ; static FieldDefinition ;
  1. Return NonConstructorMethod.
ClassElement : ClassStaticBlock
  1. Return NonConstructorMethod.
ClassElement : ;
  1. Return empty.

6.1.3 Static Semantics: IsStatic

ClassElement : MethodDefinition
  1. Return false.
ClassElement : static MethodDefinition
  1. Return true.
ClassElement : FieldDefinition ;
  1. Return false.
ClassElement : static FieldDefinition ;
  1. Return true.
ClassElement : ClassStaticBlock
  1. Return true.
ClassElement : ;
  1. Return false.

6.1.4 Static Semantics: PrivateBoundIdentifiers

FieldDefinition : ClassElementName Initializeropt
  1. Return PrivateBoundIdentifiers of ClassElementName.
ClassElementName : PrivateIdentifier
  1. Return a List whose sole element is the StringValue of PrivateIdentifier.
ClassElementName : PropertyName ClassElement : ClassStaticBlock ClassElement : ;
  1. Return a new empty List.
ClassElementList : ClassElementList ClassElement
  1. Let names be PrivateBoundIdentifiers of ClassElementList.
  2. Append to names the elements of PrivateBoundIdentifiers of ClassElement.
  3. Return names.
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody } GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. Return PrivateBoundIdentifiers of ClassElementName.

6.1.5 Static Semantics: ContainsAwait

Every grammar production alternative in this specification which is not listed below implicitly has the following default definition of ContainsAwait:

  1. For each child node child of this Parse Node, do
    1. If child is an instance of a nonterminal, then
      1. If ContainsAwait for child is true, return true.
  2. Return false.
FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } function ( FormalParameters ) { FunctionBody } FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody } GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody } AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. Return false.
Note 1

Static semantic rules that depend upon substructure generally do not look into function definitions.

ClassTail : ClassHeritageopt { ClassBody }
  1. If ClassHeritage is present, then
    1. If ContainsAwait for ClassHeritage is true, return true.
  2. Return the result of ComputedPropertyContainsAwait for ClassBody.
Note 2

Static semantic rules that depend upon substructure generally do not look into class bodies except for PropertyNames.

ArrowFunction : ArrowParameters => ConciseBody AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. Return false.
Note 3

Static semantic rules that depend upon substructure containing await do not need to look into arrow functions.

UnaryExpression : AwaitExpression
  1. Return true.
ForInOfStatement : for await ( LeftHandSideExpression of AssignmentExpression ) Statement ForInOfStatement : for await ( var ForBinding of AssignmentExpression ) Statement ForInOfStatement : for await ( ForDeclaration of AssignmentExpression ) Statement
  1. Return true.

6.1.6 Static Semantics: ComputedPropertyContainsAwait

ClassElementName : PrivateIdentifier PropertyName : LiteralPropertyName
  1. Return false.
PropertyName : ComputedPropertyName
  1. Return the result of ContainsAwait for ComputedPropertyName.
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. Return the result of ComputedPropertyContainsAwait for ClassElementName.
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. Return the result of ComputedPropertyContainsAwait for ClassElementName.
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. Return the result of ComputedPropertyContainsAwait for ClassElementName.
ClassElementList : ClassElementList ClassElement
  1. Let ComputedPropertyContainsAwait for ClassElementList is true, return true.
  2. Return the result of ComputedPropertyContainsAwait for ClassElement.
ClassElement : ClassStaticBlock ClassElement : ;
  1. Return false.
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. Return the result of ComputedPropertyContainsAwait for ClassElementName.
FieldDefinition : ClassElementName Initializeropt
  1. Return the result of ComputedPropertyContainsAwait for ClassElementName.

6.1.7 Runtime Semantics: ClassStaticBlockDefinitionEvaluation

With parameter homeObject.

ClassStaticBlock : static { ClassStaticBlockBody }
  1. Let lex be the running execution context's LexicalEnvironment.
  2. Let privateScope be the running execution context's PrivateEnvironment.
  3. Let sourceText be the empty sequence of Unicode code points.
  4. Let formalParameters be an instance of the production FormalParameters : [empty] .
  5. Let bodyFunction be OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameters, ClassStaticBlockBody, non-lexical-this, lex, privateScope).
  6. Perform MakeMethod(bodyFunction, homeObject).
  7. Return the ClassStaticBlockDefinition Record { [[BodyFunction]]: bodyFunction }.
Note
The function created for bodyFunction is never directly accessible to ECMAScript code.

6.1.8 Runtime Semantics: EvaluateClassStaticBlockBody

With parameter functionObject.

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. Perform ? FunctionDeclarationInstantiation(functionObject, « »).
  2. Return the result of evaluating ClassStaticBlockStatementList.

6.1.9 Runtime Semantics: ClassElementEvaluation

With parameters object and enumerable.

ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ;
  1. Return ClassFieldDefinitionEvaluation of FieldDefinition with argument object.
ClassElement : MethodDefinition ClassElement : static MethodDefinition
  1. Return MethodDefinitionEvaluation of MethodDefinition with arguments object and enumerable.
ClassElement : ClassStaticBlock
  1. Return ClassStaticBlockDefinitionEvaluation of ClassStaticBlock with argument object.
ClassElement : ;
  1. Return.

6.1.10 Runtime Semantics: ClassDefinitionEvaluation

With parameters classBinding and className.

Note

For ease of specification, private methods and accessors are included alongside private fields in the [[PrivateElements]] slot of class instances. However, any given object has either all or none of the private methods and accessors defined by a given class. This feature has been designed so that implementations may choose to implement private methods and accessors using a strategy which does not require tracking each method or accessor individually.

For example, an implementation could directly associate instance private methods with their corresponding Private Name and track, for each object, which class constructors have run with that object as their this value. Looking up an instance private method on an object then consists of checking that the class constructor which defines the method has been used to initialize the object, then returning the method associated with the Private Name.

This differs from private fields: because field initializers can throw during class instantiation, an individual object may have some proper subset of the private fields of a given class, and so private fields must in general be tracked individually.

ClassTail : ClassHeritageopt { ClassBodyopt }
  1. Let env be the LexicalEnvironment of the running execution context.
  2. Let classScope be NewDeclarativeEnvironment(env).
  3. If classBinding is not undefined, then
    1. Perform classScope.CreateImmutableBinding(classBinding, true).
  4. Let outerPrivateEnvironment be the running execution context's PrivateEnvironment.
  5. Let classPrivateEnvironment be NewPrivateEnvironment(outerPrivateEnvironment).
  6. If ClassBodyopt is present, then
    1. For each String dn of the PrivateBoundIdentifiers of ClassBodyopt, do
      1. If classPrivateEnvironment.[[Names]] contains a Private Name whose [[Description]] is dn, then
        1. Assert: This is only possible for getter/setter pairs.
      2. Else,
        1. Let name be a new Private Name whose [[Description]] value is dn.
        2. Append name to classPrivateEnvironment.[[Names]].
  7. If ClassHeritageopt is not present, then
    1. Let protoParent be %Object.prototype%.
    2. Let constructorParent be %Function.prototype%.
  8. Else,
    1. Set the running execution context's LexicalEnvironment to classScope.
    2. NOTE: The running execution context's PrivateEnvironment is outerPrivateEnvironment when evaluating ClassHeritage.
    3. Let superclassRef be the result of evaluating ClassHeritage.
    4. Set the running execution context's LexicalEnvironment to env.
    5. Let superclass be ? GetValue(superclassRef).
    6. If superclass is null, then
      1. Let protoParent be null.
      2. Let constructorParent be %Function.prototype%.
    7. Else if IsConstructor(superclass) is false, throw a TypeError exception.
    8. Else,
      1. Let protoParent be ? Get(superclass, "prototype").
      2. If Type(protoParent) is neither Object nor Null, throw a TypeError exception.
      3. Let constructorParent be superclass.
  9. Let proto be ! OrdinaryObjectCreate(protoParent).
  10. If ClassBodyopt is not present, let constructor be empty.
  11. Else, let constructor be ConstructorMethod of ClassBody.
  12. Set the running execution context's LexicalEnvironment to classScope.
  13. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
  14. If constructor is empty, then
    1. Let steps be the algorithm steps defined in .
    2. Let F be ! CreateBuiltinFunction(steps, 0, className, « [[ConstructorKind]], [[SourceText]] », empty, constructorParent).
  15. Else,
    1. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent.
    2. Let F be constructorInfo.[[Closure]].
    3. Perform ! MakeClassConstructor(F).
    4. Perform ! SetFunctionName(F, className).
  16. Perform ! MakeConstructor(F, false, proto).
  17. If ClassHeritageopt is present, set F.[[ConstructorKind]] to derived.
  18. Perform ! CreateMethodProperty(proto, "constructor", F).
  19. If ClassBodyopt is not present, let elements be a new empty List.
  20. Else, let elements be NonConstructorElements of ClassBody.
  21. Let instancePrivateMethods be a new empty List.
  22. Let staticPrivateMethods be a new empty List.
  23. Let instanceFields be a new empty List.
  24. Let staticFieldsstaticElements be a new empty List.
  25. For each ClassElement e of elements, do
    1. If IsStatic of e is false, then
      1. Let fieldelement be ClassElementEvaluation of e with arguments proto and false.
    2. Else,
      1. Let fieldelement be ClassElementEvaluation of e with arguments F and false.
    3. If fieldelement is an abrupt completion, then
      1. Set the running execution context's LexicalEnvironment to lex.
      2. Set the running execution context's PrivateEnvironment to outerPrivateEnvironment.
      3. Return Completion(fieldelement).
    4. Set fieldelement to fieldelement.[[Value]].
    5. If fieldelement is a PrivateElement, then
      1. Assert: fieldelement.[[Kind]] is either method or accessor.
      2. If IsStatic of e is false, let container be instancePrivateMethods.
      3. Else, let container be staticPrivateMethods.
      4. If container contains a PrivateElement whose [[Key]] is fieldelement.[[Key]], then
        1. Let existing be that PrivateElement.
        2. Assert: fieldelement.[[Kind]] and existing.[[Kind]] are both accessor.
        3. If fieldelement.[[Get]] is undefined, then
          1. Let combined be PrivateElement { [[Key]]: fieldelement.[[Key]], [[Kind]]: accessor, [[Get]]: existing.[[Get]], [[Set]]: fieldelement.[[Set]] }.
        4. Else,
          1. Let combined be PrivateElement { [[Key]]: fieldelement.[[Key]], [[Kind]]: accessor, [[Get]]: fieldelement.[[Get]], [[Set]]: existing.[[Set]] }.
        5. Replace existing in container with combined.
      5. Else,
        1. Append fieldelement to container.
    6. Else if fieldelement is a ClassFieldDefinition Record, then
      1. If IsStatic of e is false, append fieldelement to instanceFields.
      2. Else, append fieldelement to staticFieldsstaticElements.
    7. If element is a ClassStaticBlockDefinition Record, then
      1. Append element to staticElements.
  26. Set the running execution context's LexicalEnvironment to lex.
  27. If classBinding is not undefined, then
    1. Perform classScopeEnvRec.InitializeBinding(classBinding, F).
  28. Set F.[[Fields]] to instanceFields.
  29. For each PrivateElement method of staticPrivateMethods, do
    1. Perform ! PrivateMethodOrAccessorAdd(method, F).
  30. For each element fieldRecordelementRecord of staticFieldsstaticElements, do
    1. Let result be DefineField(F, fieldRecord).
    2. If elementRecord is a ClassFieldDefinition Record, then
      1. Let result be DefineField(F, elementRecord).
    3. Else,
      1. Assert: elementRecord is a ClassStaticBlockDefinition Record.
      2. Let result be EvaluateStaticBlock(F, elementRecord).
    4. If result is an abrupt completion, then
      1. Set the running execution context's PrivateEnvironment to outerPrivateEnvironment.
      2. Return result.
  31. Set the running execution context's PrivateEnvironment to outerPrivateEnvironment.
  32. Return F.

6.1.11 Runtime Semantics: Evaluation

ClassDeclaration : class BindingIdentifier ClassTail
  1. Perform ? BindingClassDeclarationEvaluation of this ClassDeclaration.
  2. Return NormalCompletion(empty).
Note

ClassDeclaration : class ClassTail only occurs as part of an ExportDeclaration and is never directly evaluated.

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.
ClassElementName : PrivateIdentifier
  1. Let privateIdentifier be StringValue of PrivateIdentifier.
  2. Let privateEnvRec be the running execution context's PrivateEnvironment.
  3. Let names be privateEnvRec.[[Names]].
  4. Assert: Exactly one element of names is a Private Name whose [[Description]] is privateIdentifier.
  5. Let privateName be the Private Name in names whose [[Description]] is privateIdentifier.
  6. Return privateName.
ClassStaticBlockStatementList : [empty]
  1. Return NormalCompletion(undefined).

A Copyright & Software License

Copyright Notice

© 2021 Ron Buckton, Ecma International

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.