13 ECMAScript Language: Statements and Declarations

Syntax

Statement[Yield, Return] :
BlockStatement[?Yield, ?Return]
VariableStatement[?Yield]
EmptyStatement
ExpressionStatement[?Yield]
IfStatement[?Yield, ?Return]
BreakableStatement[?Yield, ?Return]
ContinueStatement[?Yield]
BreakStatement[?Yield]
[+Return] ReturnStatement[?Yield]
WithStatement[?Yield, ?Return]
LabelledStatement[?Yield, ?Return]
ThrowStatement[?Yield]
TryStatement[?Yield, ?Return]
DebuggerStatement
Declaration[Yield] :
HoistableDeclaration[?Yield]
ClassDeclaration[?Yield]
LexicalDeclaration[In, ?Yield]
HoistableDeclaration[Yield, Default] :
FunctionDeclaration[?Yield,?Default]
GeneratorDeclaration[?Yield, ?Default]
BreakableStatement[Yield, Return] :
IterationStatement[?Yield, ?Return]
SwitchStatement[?Yield, ?Return]

13.1 Statement Semantics

13.1.1 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.2.2, 13.6.2, 13.7.2.1, 13.7.3.1, 13.7.4.2, 13.7.5.3, 13.11.2, 13.12.2, 13.13.2, 13.15.2, 15.2.1.2.

Statement :
VariableStatement
EmptyStatement
ExpressionStatement
ContinueStatement
BreakStatement
ReturnStatement
ThrowStatement
DebuggerStatement
  1. Return false.

13.1.2 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.2.3, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.11.3, 13.12.3, 13.13.3, 13.15.3, 15.2.1.3.

Statement :
VariableStatement
EmptyStatement
ExpressionStatement
ContinueStatement
ReturnStatement
ThrowStatement
DebuggerStatement
  1. Return false.

13.1.3 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.2.4, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.11.4, 13.12.4, 13.13.4,13.15.4, 15.2.1.4.

Statement :
VariableStatement
EmptyStatement
ExpressionStatement
BreakStatement
ReturnStatement
ThrowStatement
DebuggerStatement
  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 « ».

13.1.4 Static Semantics: DeclarationPart

HoistableDeclaration : FunctionDeclaration
  1. Return FunctionDeclaration.
HoistableDeclaration : GeneratorDeclaration
  1. Return GeneratorDeclaration.
Declaration : ClassDeclaration
  1. Return ClassDeclaration.
Declaration : LexicalDeclaration
  1. Return LexicalDeclaration.

13.1.5 Static Semantics: VarDeclaredNames

See also: 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

Statement :
EmptyStatement
ExpressionStatement
ContinueStatement
BreakStatement
ReturnStatement
ThrowStatement
DebuggerStatement
  1. Return a new empty List.

13.1.6 Static Semantics: VarScopedDeclarations

See also: 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

Statement :
EmptyStatement
ExpressionStatement
ContinueStatement
BreakStatement
ReturnStatement
ThrowStatement
DebuggerStatement
  1. Return a new empty List.

13.1.7 Runtime Semantics: LabelledEvaluation

With argument labelSet.

See also: 13.7.2.6, 13.7.3.6, 13.7.4.7, 13.7.5.11, 13.13.14.

BreakableStatement : IterationStatement
  1. Let stmtResult be the result of performing LabelledEvaluation of IterationStatement with argument labelSet.
  2. If stmtResult.[[type]] is break, then
    1. If stmtResult.[[target]] is empty, then
      1. If stmtResult.[[value]] is empty, let stmtResult be NormalCompletion(undefined).
      2. Else, let stmtResult be NormalCompletion(stmtResult.[[value]]).
  3. Return Completion(stmtResult).
BreakableStatement : SwitchStatement
  1. Let stmtResult be the result of evaluating SwitchStatement.
  2. If stmtResult.[[type]] is break, then
    1. If stmtResult.[[target]] is empty, then
      1. If stmtResult.[[value]] is empty, let stmtResult be NormalCompletion(undefined).
      2. Else, let stmtResult be NormalCompletion(stmtResult.[[value]]).
  3. Return Completion(stmtResult).

NOTE A BreakableStatement is one that can be exited via an unlabelled BreakStatement.

13.1.8 Runtime Semantics: Evaluation

HoistableDeclaration :
GeneratorDeclaration
  1. Return NormalCompletion(empty).
HoistableDeclaration :
FunctionDeclaration
  1. Return the result of evaluating FunctionDeclaration.
BreakableStatement :
IterationStatement
SwitchStatement
  1. Let newLabelSet be a new empty List.
  2. Return the result of performing LabelledEvaluation of this BreakableStatement with argument newLabelSet.

13.2 Block

Syntax

BlockStatement[Yield, Return] :
Block[?Yield, ?Return]
Block[Yield, Return] :
{ StatementList[?Yield, ?Return]opt }
StatementList[Yield, Return] :
StatementListItem[?Yield, ?Return]
StatementList[?Yield, ?Return] StatementListItem[?Yield, ?Return]
StatementListItem[Yield, Return] :
Statement[?Yield, ?Return]
Declaration[?Yield]

13.2.1 Static Semantics: Early Errors

Block : { StatementList }
  • It is a Syntax Error if the LexicallyDeclaredNames of StatementList contains any duplicate entries.

  • It is a Syntax Error if any element of the LexicallyDeclaredNames of StatementList also occurs in the VarDeclaredNames of StatementList.

13.2.2 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.6.2, 13.7.2.1, 13.7.3.1, 13.7.4.2, 13.7.5.3, 13.11.2, 13.12.2, 13.13.2, 13.15.2, 15.2.1.2.

Block : { }
  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.
StatementListItem : Declaration
  1. Return false.

13.2.3 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.11.3, 13.12.3, 13.13.3, 13.15.3, 15.2.1.3.

Block : { }
  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.
StatementListItem : Declaration
  1. Return false.

13.2.4 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.11.4, 13.12.4, 13.13.4,13.15.4, 15.2.1.4.

Block : { }
  1. Return false.
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 « ».
StatementListItem : Declaration
  1. Return false.

13.2.5 Static Semantics: LexicallyDeclaredNames

See also: 13.12.5, 13.13.6, 14.1.13, 14.2.10, 15.1.3, 15.2.1.11.

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.

13.2.6 Static Semantics: LexicallyScopedDeclarations

See also: 13.12.6, 13.13.7, 14.1.14, 14.2.11, 15.1.4, 15.2.1.12, 15.2.3.8.

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 new List containing DeclarationPart of Declaration.

13.2.7 Static Semantics: TopLevelLexicallyDeclaredNames

See also: 13.13.8.

StatementList : StatementList StatementListItem
  1. Let names be TopLevelLexicallyDeclaredNames of StatementList.
  2. Append to names the elements of the TopLevelLexicallyDeclaredNames of StatementListItem.
  3. Return names.
StatementListItem : Statement
  1. Return a new empty List.
StatementListItem : Declaration
  1. If Declaration is Declaration : HoistableDeclaration , then
    1. If HoistableDeclaration is HoistableDeclaration : FunctionDeclaration , return « ».
    2. If HoistableDeclaration is HoistableDeclaration : GeneratorDeclaration , return « ».
  2. Return the BoundNames of Declaration.

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

13.2.8 Static Semantics: TopLevelLexicallyScopedDeclarations

See also: 13.13.9.

Block : { }
  1. Return a new empty List.
StatementList : StatementList StatementListItem
  1. Let declarations be TopLevelLexicallyScopedDeclarations of StatementList.
  2. Append to declarations the elements of the TopLevelLexicallyScopedDeclarations of StatementListItem.
  3. Return declarations.
StatementListItem : Statement
  1. Return a new empty List.
StatementListItem : Declaration
  1. If Declaration is Declaration : HoistableDeclaration , then
    1. If HoistableDeclaration is HoistableDeclaration : FunctionDeclaration , return « ».
    2. If HoistableDeclaration is HoistableDeclaration : GeneratorDeclaration , return « ».
  2. Return a new List containing Declaration.

13.2.9 Static Semantics: TopLevelVarDeclaredNames

See also: 13.13.10.

Block : { }
  1. Return a new empty List.
StatementList : StatementList StatementListItem
  1. Let names be TopLevelVarDeclaredNames of StatementList.
  2. Append to names the elements of the TopLevelVarDeclaredNames of StatementListItem.
  3. Return names.
StatementListItem : Declaration
  1. If Declaration is Declaration : HoistableDeclaration , then
    1. If HoistableDeclaration is HoistableDeclaration : FunctionDeclaration , return the BoundNames of FunctionDeclaration.
    2. If HoistableDeclaration is HoistableDeclaration : GeneratorDeclaration , return the BoundNames of GeneratorDeclaration.
  2. Return a new empty List.
StatementListItem : Statement
  1. If Statement is Statement : LabelledStatement , return TopLevelVarDeclaredNames of Statement.
  2. Return VarDeclaredNames of Statement.

NOTE At the top level of a function or script, inner function declarations are treated like var declarations.

13.2.10 Static Semantics: TopLevelVarScopedDeclarations

See also: 13.13.11.

Block : { }
  1. Return a new empty List.
StatementList : StatementList StatementListItem
  1. Let declarations be TopLevelVarScopedDeclarations of StatementList.
  2. Append to declarations the elements of the TopLevelVarScopedDeclarations of StatementListItem.
  3. Return declarations.
StatementListItem : Statement
  1. If Statement is Statement : LabelledStatement , return TopLevelVarScopedDeclarations of Statement.
  2. Return VarScopedDeclarations of Statement.
StatementListItem : Declaration
  1. If Declaration is Declaration : HoistableDeclaration , then
    1. If HoistableDeclaration is HoistableDeclaration : FunctionDeclaration , return « FunctionDeclaration ».
    2. If HoistableDeclaration is HoistableDeclaration : GeneratorDeclaration , return « GeneratorDeclaration ».
  2. Return a new empty List.

13.2.11 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

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.

13.2.12 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

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.

13.2.13 Runtime Semantics: Evaluation

Block : { }
  1. Return NormalCompletion(empty).
Block : { StatementList }
  1. Let oldEnv be the running execution context’s LexicalEnvironment.
  2. Let blockEnv be NewDeclarativeEnvironment(oldEnv).
  3. Perform BlockDeclarationInstantiation(StatementList, blockEnv).
  4. Set the running execution context’s LexicalEnvironment to blockEnv.
  5. Let blockValue be the result of evaluating StatementList.
  6. Set the running execution context’s LexicalEnvironment to oldEnv.
  7. Return blockValue.

NOTE 1 No matter how control leaves the Block the LexicalEnvironment is always restored to its former state.

StatementList : StatementList StatementListItem
  1. Let sl be the result of evaluating StatementList.
  2. ReturnIfAbrupt(sl).
  3. Let s be the result of evaluating StatementListItem.
  4. Return Completion(UpdateEmpty(s, sl.[[value]])).

NOTE 2 The value of a StatementList is the value of the last value producing item in the StatementList. For example, the following calls to the eval function all return the value 1:

eval("1;;;;;")

eval("1;{}")

eval("1;var a;")

13.2.14 Runtime Semantics: BlockDeclarationInstantiation( code, env )

NOTE When a Block or CaseBlock production is evaluated a new declarative Environment Record is created and bindings for each block scoped variable, constant, function, generator function, or class declared in the block are instantiated in the Environment Record.

BlockDeclarationInstantiation is performed as follows using arguments code and env. code is the grammar production corresponding to the body of the block. env is the declarative Environment Record in which bindings are to be created.

  1. Let declarations be the LexicallyScopedDeclarations of code.
  2. For each element d in declarations do
    1. For each element dn of the BoundNames of d do
      1. If IsConstantDeclaration of d is true, then
        1. Let status be env.CreateImmutableBinding(dn, true).
      2. Else,
        1. Let status be env.CreateMutableBinding(dn, false).
      3. Assert: status is never an abrupt completion.
    2. If d is a GeneratorDeclaration production or a FunctionDeclaration production, then
      1. Let fn be the sole element of the BoundNames of d
      2. Let fo be the result of performing InstantiateFunctionObject for d with argument env.
      3. Perform env.InitializeBinding(fn, fo).

13.3 Declarations and the Variable Statement

13.3.1 Let and Const Declarations

NOTE let and const declarations define variables that are scoped to the running execution context’s LexicalEnvironment. The variables are created when their containing Lexical Environment is instantiated but may not be accessed in any way until the variable’s LexicalBinding is evaluated. A variable defined by a LexicalBinding with an Initializer is assigned the value of its Initializer’s AssignmentExpression when the LexicalBinding is evaluated, not when the variable is created. If a LexicalBinding in a let declaration does not have an Initializer the variable is assigned the value undefined when the LexicalBinding is evaluated.

Syntax

LexicalDeclaration[In, Yield] :
LetOrConst BindingList[?In, ?Yield] ;
LetOrConst :
let
const
BindingList[In, Yield] :
LexicalBinding[?In, ?Yield]
BindingList[?In, ?Yield] , LexicalBinding[?In, ?Yield]
LexicalBinding[In, Yield] :
BindingIdentifier[?Yield] Initializer[?In, ?Yield]opt
BindingPattern[?Yield] Initializer[?In, ?Yield]

13.3.1.1 Static Semantics: Early Errors

LexicalDeclaration : LetOrConst BindingList ;
  • It is a Syntax Error if the BoundNames of BindingList contains "let".
  • It is a Syntax Error if the BoundNames of BindingList contains any duplicate entries.
LexicalBinding : BindingIdentifier Initializeropt
  • It is a Syntax Error if Initializer is not present and IsConstantDeclaration of the LexicalDeclaration containing this production is true.

13.3.1.2 Static Semantics: BoundNames

See also: 12.1.2, 13.3.2.1, 13.3.3.1, 13.7.5.2, 14.1.3, 14.2.2, 14.4.2, 14.5.2, 15.2.2.2, 15.2.3.2.

LexicalDeclaration : LetOrConst BindingList ;
  1. Return the BoundNames of BindingList.
BindingList : BindingList , LexicalBinding
  1. Let names be the BoundNames of BindingList.
  2. Append to names the elements of the BoundNames of LexicalBinding.
  3. Return names.
LexicalBinding : BindingIdentifier Initializeropt
  1. Return the BoundNames of BindingIdentifier.
LexicalBinding : BindingPattern Initializer
  1. Return the BoundNames of BindingPattern.

13.3.1.3 Static Semantics: IsConstantDeclaration

See also: 14.1.10, 14.4.8, 14.5.7, 15.2.3.7.

LexicalDeclaration : LetOrConst BindingList ;
  1. Return IsConstantDeclaration of LetOrConst.
LetOrConst : let
  1. Return false.
LetOrConst : const
  1. Return true.

13.3.1.4 Runtime Semantics: Evaluation

LexicalDeclaration : LetOrConst BindingList ;
  1. Let next be the result of evaluating BindingList.
  2. ReturnIfAbrupt(next).
  3. Return NormalCompletion(empty).
BindingList : BindingList , LexicalBinding
  1. Let next be the result of evaluating BindingList.
  2. ReturnIfAbrupt(next).
  3. Return the result of evaluating LexicalBinding.
LexicalBinding : BindingIdentifier
  1. Let lhs be ResolveBinding(StringValue of BindingIdentifier).
  2. Return InitializeReferencedBinding(lhs, undefined).

NOTE A static semantics rule ensures that this form of LexicalBinding never occurs in a const declaration.

LexicalBinding : BindingIdentifier Initializer
  1. Let bindingId be StringValue of BindingIdentifier.
  2. Let lhs be ResolveBinding(bindingId).
  3. Let rhs be the result of evaluating Initializer.
  4. Let value be GetValue(rhs).
  5. ReturnIfAbrupt(value).
  6. If IsAnonymousFunctionDefinition(Initializer) is true, then
    1. Let hasNameProperty be HasOwnProperty(value, "name").
    2. ReturnIfAbrupt(hasNameProperty).
    3. If hasNameProperty is false, perform SetFunctionName(value, bindingId).
  7. Return InitializeReferencedBinding(lhs, value).
LexicalBinding : BindingPattern Initializer
  1. Let rhs be the result of evaluating Initializer.
  2. Let value be GetValue(rhs).
  3. ReturnIfAbrupt(value).
  4. Let env be the running execution context’s LexicalEnvironment.
  5. Return the result of performing BindingInitialization for BindingPattern using value and env as the arguments.

13.3.2 Variable Statement

NOTE A var statement declares variables that are scoped to the running execution context’s VariableEnvironment. Var variables are created when their containing Lexical Environment is instantiated and are initialized to undefined when created. Within the scope of any VariableEnvironment a common BindingIdentifier may appear in more than one VariableDeclaration but those declarations collective define only one variable. A variable defined by a VariableDeclaration with an Initializer is assigned the value of its Initializer’s AssignmentExpression when the VariableDeclaration is executed, not when the variable is created.

Syntax

VariableStatement[Yield] :
var VariableDeclarationList[In, ?Yield] ;
VariableDeclarationList[In, Yield] :
VariableDeclaration[?In, ?Yield]
VariableDeclarationList[?In, ?Yield] , VariableDeclaration[?In, ?Yield]
VariableDeclaration[In, Yield] :
BindingIdentifier[?Yield] Initializer[?In, ?Yield]opt
BindingPattern[?Yield] Initializer[?In, ?Yield]

13.3.2.1 Static Semantics: BoundNames

See also: 12.1.2, 13.3.1.2, 13.3.3.1, 13.7.5.2, 14.1.3, 14.2.2, 14.4.2, 14.5.2, 15.2.2.2, 15.2.3.2.

VariableDeclarationList : VariableDeclarationList , VariableDeclaration
  1. Let names be BoundNames of VariableDeclarationList.
  2. Append to names the elements of BoundNames of VariableDeclaration.
  3. Return names.
VariableDeclaration : BindingIdentifier Initializeropt
  1. Return the BoundNames of BindingIdentifier.
VariableDeclaration : BindingPattern Initializer
  1. Return the BoundNames of BindingPattern.

13.3.2.2 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

VariableStatement : var VariableDeclarationList ;
  1. Return BoundNames of VariableDeclarationList.

13.3.2.3 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

VariableDeclarationList : VariableDeclaration
  1. Return a new List containing VariableDeclaration.
VariableDeclarationList : VariableDeclarationList , VariableDeclaration
  1. Let declarations be VarScopedDeclarations of VariableDeclarationList.
  2. Append VariableDeclaration to declarations.
  3. Return declarations.

13.3.2.4 Runtime Semantics: Evaluation

VariableStatement : var VariableDeclarationList ;
  1. Let next be the result of evaluating VariableDeclarationList.
  2. ReturnIfAbrupt(next).
  3. Return NormalCompletion( empty).
VariableDeclarationList : VariableDeclarationList , VariableDeclaration
  1. Let next be the result of evaluating VariableDeclarationList.
  2. ReturnIfAbrupt(next).
  3. Return the result of evaluating VariableDeclaration.
VariableDeclaration : BindingIdentifier
  1. Return NormalCompletion(empty).
VariableDeclaration : BindingIdentifier Initializer
  1. Let bindingId be StringValue of BindingIdentifier.
  2. Let lhs be ResolveBinding(bindingId)
  3. ReturnIfAbrupt(lhs).
  4. Let rhs be the result of evaluating Initializer.
  5. Let value be GetValue(rhs).
  6. ReturnIfAbrupt(value).
  7. If IsAnonymousFunctionDefinition(Initializer) is true, then
    1. Let hasNameProperty be HasOwnProperty(value, "name").
    2. ReturnIfAbrupt(hasNameProperty).
    3. If hasNameProperty is false, perform SetFunctionName(value, bindingId).
  8. Return PutValue(lhs, value).

NOTE If a VariableDeclaration is nested within a with statement and the BindingIdentifier in the VariableDeclaration is the same as a property name of the binding object of the with statement’s object Environment Record, then step 7 will assign value to the property instead of assigning to the VariableEnvironment binding of the Identifier.

VariableDeclaration : BindingPattern Initializer
  1. Let rhs be the result of evaluating Initializer.
  2. Let rval be GetValue(rhs).
  3. ReturnIfAbrupt(rval).
  4. Return the result of performing BindingInitialization for BindingPattern passing rval and undefined as arguments.

13.3.3 Destructuring Binding Patterns

Syntax

BindingPattern[Yield] :
ObjectBindingPattern[?Yield]
ArrayBindingPattern[?Yield]
ObjectBindingPattern[Yield] :
{ }
{ BindingPropertyList[?Yield] }
{ BindingPropertyList[?Yield] , }
ArrayBindingPattern[Yield] :
[ Elisionopt BindingRestElement[?Yield]opt ]
[ BindingElementList[?Yield] ]
[ BindingElementList[?Yield] , Elisionopt BindingRestElement[?Yield]opt ]
BindingPropertyList[Yield] :
BindingProperty[?Yield]
BindingPropertyList[?Yield] , BindingProperty[?Yield]
BindingElementList[Yield] :
BindingElisionElement[?Yield]
BindingElementList[?Yield] , BindingElisionElement[?Yield]
BindingElisionElement[Yield] :
Elisionopt BindingElement[?Yield]
BindingProperty[Yield] :
SingleNameBinding[?Yield]
PropertyName[?Yield] : BindingElement[?Yield]
BindingElement[Yield ] :
SingleNameBinding[?Yield]
BindingPattern[?Yield] Initializer[In, ?Yield]opt
SingleNameBinding[Yield] :
BindingIdentifier[?Yield] Initializer[In, ?Yield]opt
BindingRestElement[Yield] :
... BindingIdentifier[?Yield]

13.3.3.1 Static Semantics: BoundNames

See also: 12.1.2, 13.3.1.2, 13.3.2.1, 13.7.5.2, 14.1.3, 14.2.2, 14.4.2, 14.5.2, 15.2.2.2, 15.2.3.2.

ObjectBindingPattern : { }
  1. Return an empty List.
ArrayBindingPattern : [ Elisionopt ]
  1. Return an empty List.
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. Return the BoundNames of BindingRestElement.
ArrayBindingPattern : [ BindingElementList , Elisionopt ]
  1. Return the BoundNames of BindingElementList.
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. Let names be BoundNames of BindingElementList.
  2. Append to names the elements of BoundNames of BindingRestElement.
  3. Return names.
BindingPropertyList : BindingPropertyList , BindingProperty
  1. Let names be BoundNames of BindingPropertyList.
  2. Append to names the elements of BoundNames of BindingProperty.
  3. Return names.
BindingElementList : BindingElementList , BindingElisionElement
  1. Let names be BoundNames of BindingElementList.
  2. Append to names the elements of BoundNames of BindingElisionElement.
  3. Return names.
BindingElisionElement : Elisionopt BindingElement
  1. Return BoundNames of BindingElement.
BindingProperty : PropertyName : BindingElement
  1. Return the BoundNames of BindingElement.
SingleNameBinding : BindingIdentifier Initializeropt
  1. Return the BoundNames of BindingIdentifier.
BindingElement : BindingPattern Initializeropt
  1. Return the BoundNames of BindingPattern.

13.3.3.2 Static Semantics: ContainsExpression

See also: 14.1.5, 14.2.4.

ObjectBindingPattern : { }
  1. Return false.
ArrayBindingPattern : [ Elisionopt ]
  1. Return false.
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. Return false.
ArrayBindingPattern : [ BindingElementList , Elisionopt ]
  1. Return ContainsExpression of BindingElementList.
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. Return ContainsExpression of BindingElementList.
BindingPropertyList : BindingPropertyList , BindingProperty
  1. Let has be ContainsExpression of BindingPropertyList.
  2. If has is true, return true.
  3. Return ContainsExpression of BindingProperty.
BindingElementList : BindingElementList , BindingElisionElement
  1. Let has be ContainsExpression of BindingElementList.
  2. If has is true, return true.
  3. Return ContainsExpression of BindingElisionElement.
BindingElisionElement : Elisionopt BindingElement
  1. Return ContainsExpression of BindingElement.
BindingProperty : PropertyName : BindingElement
  1. Let has be IsComputedPropertyKey of PropertyName.
  2. If has is true, return true.
  3. Return the ContainsExpression of BindingElement.
BindingElement : BindingPattern Initializer
  1. Return true.
SingleNameBinding : BindingIdentifier
  1. Return false.
SingleNameBinding : BindingIdentifier Initializer
  1. Return true.

13.3.3.3 Static Semantics: HasInitializer

See also: 14.1.7, 14.2.6.

BindingElement : BindingPattern
  1. Return false.
BindingElement : BindingPattern Initializer
  1. Return true.
SingleNameBinding : BindingIdentifier
  1. Return false.
SingleNameBinding : BindingIdentifier Initializer
  1. Return true.

13.3.3.4 Static Semantics: IsSimpleParameterList

See also: 14.1.12, 14.2.8.

BindingElement : BindingPattern
  1. Return false.
BindingElement : BindingPattern Initializer
  1. Return false.
SingleNameBinding : BindingIdentifier
  1. Return true.
SingleNameBinding : BindingIdentifier Initializer
  1. Return false.

13.3.3.5 Runtime Semantics: BindingInitialization

With parameters value and environment.

See also: 12.1.5, 13.7.5.9.

NOTE When undefined is passed for environment it indicates that a PutValue operation should be used to assign the initialization value. This is the case for formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order to deal with the possibility of multiple parameters with the same name.

BindingPattern : ObjectBindingPattern
  1. Let valid be RequireObjectCoercible(value).
  2. ReturnIfAbrupt(valid).
  3. Return the result of performing BindingInitialization for ObjectBindingPattern using value and environment as arguments.
BindingPattern : ArrayBindingPattern
  1. Let iterator be GetIterator(value).
  2. ReturnIfAbrupt(iterator).
  3. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}.
  4. Let result be IteratorBindingInitialization for ArrayBindingPattern using iteratorRecord, and environment as arguments.
  5. If iteratorRecord.[[done]] is false, return IteratorClose(iterator, result).
  6. Return result.
ObjectBindingPattern : { }
  1. Return NormalCompletion(empty).
BindingPropertyList : BindingPropertyList , BindingProperty
  1. Let status be the result of performing BindingInitialization for BindingPropertyList using value and environment as arguments.
  2. ReturnIfAbrupt(status).
  3. Return the result of performing BindingInitialization for BindingProperty using value and environment as arguments.
BindingProperty : SingleNameBinding
  1. Let name be the string that is the only element of BoundNames of SingleNameBinding.
  2. Return the result of performing KeyedBindingInitialization for SingleNameBinding using value, environment, and name as the arguments.
BindingProperty : PropertyName : BindingElement
  1. Let P be the result of evaluating PropertyName
  2. ReturnIfAbrupt(P).
  3. Return the result of performing KeyedBindingInitialization for BindingElement using value, environment, and P as arguments.

13.3.3.6 Runtime Semantics: IteratorBindingInitialization

With parameters iteratorRecord, and environment.

See also: 14.1.18, 14.2.14.

NOTE When undefined is passed for environment it indicates that a PutValue operation should be used to assign the initialization value. This is the case for formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order to deal with the possibility of multiple parameters with the same name.

ArrayBindingPattern : [ ]
  1. Return NormalCompletion(empty).
ArrayBindingPattern : [ Elision ]
  1. Return the result of performing IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord as the argument.
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. If Elision is present, then
    1. Let status be the result of performing IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord as the argument.
    2. ReturnIfAbrupt(status).
  2. Return the result of performing IteratorBindingInitialization for BindingRestElement with iteratorRecord and environment as arguments.
ArrayBindingPattern : [ BindingElementList ]
  1. Return the result of performing IteratorBindingInitialization for BindingElementList with iteratorRecord and environment as arguments.
ArrayBindingPattern : [ BindingElementList , ]
  1. Return the result of performing IteratorBindingInitialization for BindingElementList with iteratorRecord and environment as arguments.
ArrayBindingPattern : [ BindingElementList , Elision ]
  1. Let status be the result of performing IteratorBindingInitialization for BindingElementList with iteratorRecord and environment as arguments.
  2. ReturnIfAbrupt(status).
  3. Return the result of performing IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord as the argument.
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. Let status be the result of performing IteratorBindingInitialization for BindingElementList with iteratorRecord and environment as arguments.
  2. ReturnIfAbrupt(status).
  3. If Elision is present, then
    1. Let status be the result of performing IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord as the argument.
    2. ReturnIfAbrupt(status).
  4. Return the result of performing IteratorBindingInitialization for BindingRestElement with iteratorRecord and environment as arguments.
BindingElementList : BindingElisionElement
  1. Return the result of performing IteratorBindingInitialization for BindingElisionElement with iteratorRecord and environment as arguments.
BindingElementList : BindingElementList , BindingElisionElement
  1. Let status be the result of performing IteratorBindingInitialization for BindingElementList with iteratorRecord and environment as arguments.
  2. ReturnIfAbrupt(status).
  3. Return the result of performing IteratorBindingInitialization for BindingElisionElement using iteratorRecord and environment as arguments.
BindingElisionElement : BindingElement
  1. Return the result of performing IteratorBindingInitialization of BindingElement with iteratorRecord and environment as the arguments.
BindingElisionElement : Elision BindingElement
  1. Let status be the result of performing IteratorDestructuringAssignmentEvaluation of Elision with iteratorRecord as the argument.
  2. ReturnIfAbrupt(status).
  3. Return the result of performing IteratorBindingInitialization of BindingElement with iteratorRecord and environment as the arguments.
BindingElement : SingleNameBinding
  1. Return the result of performing IteratorBindingInitialization for SingleNameBinding with iteratorRecord and environment as the arguments.
SingleNameBinding : BindingIdentifier Initializeropt
  1. Let bindingId be StringValue of BindingIdentifier.
  2. Let lhs be ResolveBinding(bindingId, environment).
  3. ReturnIfAbrupt(lhs).
  4. If iteratorRecord.[[done]] is false, then
    1. Let next be IteratorStep(iteratorRecord.[[iterator]]).
    2. If next is an abrupt completion, set iteratorRecord.[[done]] to true.
    3. ReturnIfAbrupt(next).
    4. If next is false, set iteratorRecord.[[done]] to true.
    5. Else,
      1. Let v be IteratorValue(next).
      2. If v is an abrupt completion, set iteratorRecord.[[done]] to true.
      3. ReturnIfAbrupt(v).
  5. If iteratorRecord.[[done]] is true, let v be undefined.
  6. If Initializer is present and v is undefined, then
    1. Let defaultValue be the result of evaluating Initializer.
    2. Let v be GetValue(defaultValue).
    3. ReturnIfAbrupt(v).
    4. If IsAnonymousFunctionDefinition(Initializer) is true, then
      1. Let hasNameProperty be HasOwnProperty(v, "name").
      2. ReturnIfAbrupt(hasNameProperty).
      3. If hasNameProperty is false, perform SetFunctionName(v, bindingId).
  7. If environment is undefined, return PutValue(lhs, v).
  8. Return InitializeReferencedBinding(lhs, v).
BindingElement : BindingPattern Initializeropt
  1. If iteratorRecord.[[done]] is false, then
    1. Let next be IteratorStep(iteratorRecord.[[iterator]]).
    2. If next is an abrupt completion, set iteratorRecord.[[done]] to true.
    3. ReturnIfAbrupt(next).
    4. If next is false, set iteratorRecord.[[done]] to true.
    5. Else
      1. Let v be IteratorValue(next).
      2. If v is an abrupt completion, set iteratorRecord.[[done]] to true.
      3. ReturnIfAbrupt(v).
  2. If iteratorRecord.[[done]] is true, let v be undefined.
  3. If Initializer is present and v is undefined, then
    1. Let defaultValue be the result of evaluating Initializer.
    2. Let v be GetValue(defaultValue).
    3. ReturnIfAbrupt(v).
  4. Return the result of performing BindingInitialization of BindingPattern with v and environment as the arguments.
BindingRestElement : ... BindingIdentifier
  1. Let lhs be ResolveBinding(StringValue of BindingIdentifier, environment).
  2. ReturnIfAbrupt(lhs).
  3. Let A be ArrayCreate(0).
  4. Let n=0.
  5. Repeat,
    1. If iteratorRecord.[[done]] is false,
      1. Let next be IteratorStep(iteratorRecord.[[iterator]]).
      2. If next is an abrupt completion, set iteratorRecord.[[done]] to true.
      3. ReturnIfAbrupt(next).
      4. If next is false, set iteratorRecord.[[done]] to true.
    2. If iteratorRecord.[[done]] is true, then
      1. If environment is undefined, return PutValue(lhs, A).
      2. Return InitializeReferencedBinding(lhs, A).
    3. Let nextValue be IteratorValue(next).
    4. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to true.
    5. ReturnIfAbrupt(nextValue).
    6. Let status be CreateDataProperty(A, ToString (n), nextValue).
    7. Assert: status is true.
    8. Increment n by 1.

13.3.3.7 Runtime Semantics: KeyedBindingInitialization

With parameters value, environment, and propertyName.

NOTE When undefined is passed for environment it indicates that a PutValue operation should be used to assign the initialization value. This is the case for formal parameter lists of non-strict functions. In that case the formal parameter bindings are preinitialized in order to deal with the possibility of multiple parameters with the same name.

BindingElement : BindingPattern Initializeropt
  1. Let v be GetV(value, propertyName).
  2. ReturnIfAbrupt(v).
  3. If Initializer is present and v is undefined, then
    1. Let defaultValue be the result of evaluating Initializer.
    2. Let v be GetValue(defaultValue).
    3. ReturnIfAbrupt(v).
  4. Return the result of performing BindingInitialization for BindingPattern passing v and environment as arguments.
SingleNameBinding : BindingIdentifier Initializeropt
  1. Let bindingId be StringValue of BindingIdentifier.
  2. Let lhs be ResolveBinding(bindingId, environment).
  3. ReturnIfAbrupt(lhs).
  4. Let v be GetV(value, propertyName).
  5. ReturnIfAbrupt(v).
  6. If Initializer is present and v is undefined, then
    1. Let defaultValue be the result of evaluating Initializer.
    2. Let v be GetValue(defaultValue).
    3. ReturnIfAbrupt(v).
    4. If IsAnonymousFunctionDefinition(Initializer) is true, then
      1. Let hasNameProperty be HasOwnProperty(v, "name").
      2. ReturnIfAbrupt(hasNameProperty).
      3. If hasNameProperty is false, perform SetFunctionName(v, bindingId).
  7. If environment is undefined, return PutValue(lhs, v).
  8. Return InitializeReferencedBinding(lhs, v).

13.4 Empty Statement

Syntax

EmptyStatement :
;

13.4.1 Runtime Semantics: Evaluation

EmptyStatement : ;
  1. Return NormalCompletion(empty).

13.5 Expression Statement

Syntax

ExpressionStatement[Yield] :
[lookahead ∉ {{, function, class, let [}] Expression[In, ?Yield] ;

NOTE An ExpressionStatement cannot start with a U+007B (LEFT CURLY BRACKET) because that might make it ambiguous with a Block. Also, an ExpressionStatement cannot start with the function or class keywords because that would make it ambiguous with a FunctionDeclaration, a GeneratorDeclaration, or a ClassDeclaration. An ExpressionStatement cannot start with the two token sequence let [ because that would make it ambiguous with a let LexicalDeclaration whose first LexicalBinding was an ArrayBindingPattern.

13.5.1 Runtime Semantics: Evaluation

ExpressionStatement : Expression ;
  1. Let exprRef be the result of evaluating Expression.
  2. Return GetValue(exprRef).

13.6 The if Statement

Syntax

IfStatement[Yield, Return] :
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return] else Statement[?Yield, ?Return]
if ( Expression[In, ?Yield] ) Statement[?Yield, ?Return]

Each else for which the choice of associated if is ambiguous shall be associated with the nearest possible if that would otherwise have no corresponding else.

13.6.1 Static Semantics: Early Errors

IfStatement :
if ( Expression ) Statement else Statement
if ( Expression ) Statement

NOTE It is only necessary to apply this rule if the extension specified in B.3.2 is implemented.

13.6.2 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.2.2, 13.7.2.1, 13.7.3.1, 13.7.4.2, 13.7.5.3, 13.11.2, 13.12.2, 13.13.2, 13.15.2, 15.2.1.2.

IfStatement : if ( Expression ) Statement else Statement
  1. Let hasUndefinedLabels be ContainsDuplicateLabels of the first Statement with argument labelSet.
  2. If hasUndefinedLabels 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.

13.6.3 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.11.3, 13.12.3, 13.13.3, 13.15.3, 15.2.1.3.

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.

13.6.4 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.11.4, 13.12.4, 13.13.4,13.15.4, 15.2.1.4.

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 « ».

13.6.5 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

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.

13.6.6 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

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.

13.6.7 Runtime Semantics: Evaluation

IfStatement : if ( Expression ) Statement else Statement
  1. Let exprRef be the result of evaluating Expression.
  2. Let exprValue be ToBoolean(GetValue(exprRef)).
  3. ReturnIfAbrupt(exprValue).
  4. If exprValue is true, then
    1. Let stmtCompletion be the result of evaluating the first Statement.
  5. Else,
    1. Let stmtCompletion be the result of evaluating the second Statement.
  6. ReturnIfAbrupt(stmtCompletion).
  7. If stmtCompletion.[[value]] is not empty, return stmtCompletion.
  8. Return NormalCompletion(undefined).
IfStatement : if ( Expression ) Statement
  1. Let exprRef be the result of evaluating Expression.
  2. Let exprValue be ToBoolean(GetValue(exprRef)).
  3. ReturnIfAbrupt(exprValue).
  4. If exprValue is false, then
    1. Return NormalCompletion(undefined).
  5. Else,
    1. Let stmtCompletion be the result of evaluating Statement.
    2. ReturnIfAbrupt(stmtCompletion).
    3. If stmtCompletion.[[value]] is not empty, return stmtCompletion.
    4. Return NormalCompletion(undefined).

13.7 Iteration Statements

Syntax

IterationStatement[Yield, Return] :
do Statement[?Yield, ?Return] while ( Expression[In, ?Yield] ) ;
while ( Expression[In, ?Yield] ) Statement[?Yield, ?Return]
for ( [lookahead ∉ {let [}] Expression[?Yield]opt ; Expression[In, ?Yield]opt ; Expression[In, ?Yield]opt ) Statement[?Yield, ?Return]
for ( var VariableDeclarationList[?Yield] ; Expression[In, ?Yield]opt ; Expression[In, ?Yield]opt ) Statement[?Yield, ?Return]
for ( LexicalDeclaration[?Yield] Expression[In, ?Yield]opt ; Expression[In, ?Yield]opt ) Statement[?Yield, ?Return]
for ( [lookahead ∉ {let [}] LeftHandSideExpression[?Yield] in Expression[In, ?Yield] ) Statement[?Yield, ?Return]
for ( var ForBinding[?Yield] in Expression[In, ?Yield] ) Statement[?Yield, ?Return]
for ( ForDeclaration[?Yield] in Expression[In, ?Yield] ) Statement[?Yield, ?Return]
for ( [lookahead ≠ let ] LeftHandSideExpression[?Yield] of AssignmentExpression[In, ?Yield] ) Statement[?Yield, ?Return]
for ( var ForBinding[?Yield] of AssignmentExpression[In, ?Yield] ) Statement[?Yield, ?Return]
for ( ForDeclaration[?Yield] of AssignmentExpression[In, ?Yield] ) Statement[?Yield, ?Return]
ForDeclaration[Yield] :
LetOrConst ForBinding[?Yield]
ForBinding[Yield] :
BindingIdentifier[?Yield]
BindingPattern[?Yield]

13.7.1 Semantics

13.7.1.1 Static Semantics: Early Errors

IterationStatement :
do Statement while ( Expression ) ;
while ( Expression ) Statement
for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
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

NOTE It is only necessary to apply this rule if the extension specified in B.3.2 is implemented.

13.7.1.2 Runtime Semantics: LoopContinues(completion, labelSet)

The abstract operation LoopContinues with arguments completion and labelSet is defined by the following steps:

  1. If completion.[[type]] is normal, return true.
  2. If completion.[[type]] is not continue, return false.
  3. If completion.[[target]] is empty, return true.
  4. If completion.[[target]] is an element of labelSet, return true.
  5. Return false.

NOTE Within the Statement part of an IterationStatement a ContinueStatement may be used to begin a new iteration.

13.7.2 The do-while Statement

13.7.2.1 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.2.2, 13.6.2, 13.7.3.1, 13.7.4.2, 13.7.5.3, 13.11.2, 13.12.2, 13.13.2, 13.15.2, 15.2.1.2.

IterationStatement : do Statement while ( Expression ) ;
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.

13.7.2.2 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.6.3, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.11.3, 13.12.3, 13.13.3, 13.15.3, 15.2.1.3.

IterationStatement : do Statement while ( Expression ) ;
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.

13.7.2.3 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.6.4, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.11.4, 13.12.4, 13.13.4,13.15.4, 15.2.1.4.

IterationStatement : do Statement while ( Expression ) ;
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».

13.7.2.4 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

IterationStatement : do Statement while ( Expression ) ;
  1. Return the VarDeclaredNames of Statement.

13.7.2.5 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

IterationStatement : do Statement while ( Expression ) ;
  1. Return the VarScopedDeclarations of Statement.

13.7.2.6 Runtime Semantics: LabelledEvaluation

With argument labelSet.

See also: 13.1.7, 13.7.3.6, 13.7.4.7, 13.7.5.11, 13.13.14.

IterationStatement : do Statement while ( Expression ) ;
  1. Let V = undefined.
  2. Repeat
    1. Let stmt be the result of evaluating Statement.
    2. If LoopContinues(stmt, labelSet) is false, return Completion(UpdateEmpty(stmt, V)).
    3. If stmt.[[value]] is not empty, let V = stmt.[[value]].
    4. Let exprRef be the result of evaluating Expression.
    5. Let exprValue be GetValue(exprRef).
    6. ReturnIfAbrupt(exprValue).
    7. If ToBoolean(exprValue) is false, return NormalCompletion(V).

13.7.3 The while Statement

13.7.3.1 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.2.2, 13.6.2, 13.7.2.1, 13.7.4.2, 13.7.5.3, 13.11.2, 13.12.2, 13.13.2, 13.15.2, 15.2.1.2.

IterationStatement : while ( Expression ) Statement
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.

13.7.3.2 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.6.3, 13.7.2.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.11.3, 13.12.3, 13.13.3, 13.15.3, 15.2.1.3.

IterationStatement : while ( Expression ) Statement
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.

13.7.3.3 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.6.4, 13.7.2.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.11.4, 13.12.4, 13.13.4,13.15.4, 15.2.1.4.

IterationStatement : while ( Expression ) Statement
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».

13.7.3.4 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

IterationStatement : while ( Expression ) Statement
  1. Return the VarDeclaredNames of Statement.

13.7.3.5 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

IterationStatement : while ( Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.

13.7.3.6 Runtime Semantics: LabelledEvaluation

With argument labelSet.

See also: 13.1.7, 13.7.2.6, 13.7.4.7, 13.7.5.11, 13.13.14.

IterationStatement : while ( Expression ) Statement
  1. Let V = undefined.
  2. Repeat
    1. Let exprRef be the result of evaluating Expression.
    2. Let exprValue be GetValue(exprRef).
    3. ReturnIfAbrupt(exprValue).
    4. If ToBoolean(exprValue) is false, return NormalCompletion(V).
    5. Let stmt be the result of evaluating Statement.
    6. If LoopContinues (stmt, labelSet) is false, return Completion(UpdateEmpty(stmt, V)).
    7. If stmt.[[value]] is not empty, let V = stmt.[[value]].

13.7.4 The for Statement

13.7.4.1 Static Semantics: Early Errors

IterationStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  • It is a Syntax Error if any element of the BoundNames of LexicalDeclaration also occurs in the VarDeclaredNames of Statement.

13.7.4.2 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.2.2, 13.6.2, 13.7.2.1, 13.7.3.1, 13.7.5.3, 13.11.2, 13.12.2, 13.13.2, 13.15.2, 15.2.1.2.

IterationStatement :
for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.

13.7.4.3 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.5.4, 13.9.2, 13.11.3, 13.12.3, 13.13.3, 13.15.3, 15.2.1.3.

IterationStatement :
for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.

13.7.4.4 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.5.5, 13.8.2, 13.11.4, 13.12.4, 13.13.4,13.15.4, 15.2.1.4.

IterationStatement :
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 « ».

13.7.4.5 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

IterationStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. Return the VarDeclaredNames of Statement.
IterationStatement : 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.
IterationStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return the VarDeclaredNames of Statement.

13.7.4.6 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

IterationStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. Return the VarScopedDeclarations of Statement.
IterationStatement : 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.
IterationStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return the VarScopedDeclarations of Statement.

13.7.4.7 Runtime Semantics: LabelledEvaluation

With argument labelSet.

See also: 13.1.7, 13.7.2.6, 13.7.3.6, 13.7.5.11, 13.13.14.

IterationStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. If the first Expression is present, then
    1. Let exprRef be the result of evaluating the first Expression.
    2. Let exprValue be GetValue(exprRef).
    3. ReturnIfAbrupt(exprValue).
  2. Return ForBodyEvaluation(the second Expression, the third Expression, Statement, « », labelSet).
IterationStatement : for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
  1. Let varDcl be the result of evaluating VariableDeclarationList.
  2. ReturnIfAbrupt(varDcl).
  3. Return ForBodyEvaluation(the first Expression, the second Expression, Statement, « », labelSet).
IterationStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Let oldEnv be the running execution context’s LexicalEnvironment.
  2. Let loopEnv be NewDeclarativeEnvironment(oldEnv).
  3. Let isConst be the result of performing IsConstantDeclaration of LexicalDeclaration.
  4. Let boundNames be the BoundNames of LexicalDeclaration.
  5. For each element dn of boundNames do
    1. If isConst is true, then
      1. Perform loopEnv.CreateImmutableBinding(dn, true).
    2. Else,
      1. Perform loopEnv.CreateMutableBinding(dn, false).
      2. Assert: The above call to CreateMutableBinding will never return an abrupt completion.
  6. Set the running execution context’s LexicalEnvironment to loopEnv.
  7. Let forDcl be the result of evaluating LexicalDeclaration.
  8. If forDcl is an abrupt completion, then
    1. Set the running execution context’s LexicalEnvironment to oldEnv.
    2. Return Completion(forDcl).
  9. If isConst is false, let perIterationLets be boundNames otherwise let perIterationLets be « ».
  10. Let bodyResult be ForBodyEvaluation(the first Expression, the second Expression, Statement, perIterationLets, labelSet).
  11. Set the running execution context’s LexicalEnvironment to oldEnv.
  12. Return Completion(bodyResult).

13.7.4.8 Runtime Semantics: ForBodyEvaluation( test, increment, stmt, perIterationBindings, labelSet )

The abstract operation ForBodyEvaluation with arguments test, increment, stmt, perIterationBindings, and labelSet is performed as follows:

  1. Let V = undefined.
  2. Let status be CreatePerIterationEnvironment(perIterationBindings).
  3. ReturnIfAbrupt(status).
  4. Repeat
    1. If test is not [empty], then
      1. Let testRef be the result of evaluating test.
      2. Let testValue be GetValue(testRef).
      3. ReturnIfAbrupt(testValue).
      4. If ToBoolean(testValue) is false, return NormalCompletion(V).
    2. Let result be the result of evaluating stmt.
    3. If LoopContinues(result, labelSet) is false, return Completion(UpdateEmpty(result, V)).
    4. If result.[[value]] is not empty, let V = result.[[value]].
    5. Let status be CreatePerIterationEnvironment(perIterationBindings).
    6. ReturnIfAbrupt(status).
    7. If increment is not [empty], then
      1. Let incRef be the result of evaluating increment.
      2. Let incValue be GetValue(incRef).
      3. ReturnIfAbrupt(incValue).

13.7.4.9 Runtime Semantics: CreatePerIterationEnvironment( perIterationBindings )

The abstract operation CreatePerIterationEnvironment with argument perIterationBindings is performed as follows:

  1. If perIterationBindings has any elements, then
    1. Let lastIterationEnv be the running execution context’s LexicalEnvironment.
    2. Let outer be lastIterationEnv’s outer environment reference.
    3. Assert: outer is not null.
    4. Let thisIterationEnv be NewDeclarativeEnvironment(outer).
    5. For each element bn of perIterationBindings do,
      1. Let status be thisIterationEnv.CreateMutableBinding(bn, false).
      2. Assert: status is never an abrupt completion.
      3. Let lastValue be lastIterationEnv.GetBindingValue(bn, true).
      4. ReturnIfAbrupt(lastValue).
      5. Perform thisIterationEnv.InitializeBinding(bn, lastValue).
    6. Set the running execution context’s LexicalEnvironment to thisIterationEnv.
  2. Return undefined

13.7.5 The for-in and for-of Statements

13.7.5.1 Static Semantics: Early Errors

IterationStatement :
for ( LeftHandSideExpression in Expression ) Statement
for ( LeftHandSideExpression of AssignmentExpression ) Statement
  • It is a Syntax Error if LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if the lexical token sequence matched by LeftHandSideExpression cannot be parsed with no tokens left over using AssignmentPattern as the goal symbol.

If LeftHandSideExpression is either an ObjectLiteral or an ArrayLiteral and if the lexical token sequence matched by LeftHandSideExpression can be parsed with no tokens left over using AssignmentPattern as the goal symbol then the following rules are not applied. Instead, the Early Error rules for AssignmentPattern are used.

  • It is a Syntax Error if IsValidSimpleAssignmentTarget of LeftHandSideExpression is false.

  • It is a Syntax Error if the LeftHandSideExpression is CoverParenthesizedExpressionAndArrowParameterList : ( Expression ) and Expression derives a production that would produce a Syntax Error according to these rules if that production is substituted for LeftHandSideExpression. This rule is recursively applied.

NOTE The last rule means that the other rules are applied even if parentheses surround Expression.

IterationStatement :
for ( ForDeclaration in Expression ) Statement
for ( ForDeclaration of AssignmentExpression ) Statement
  • It is a Syntax Error if the BoundNames of ForDeclaration contains "let".

  • It is a Syntax Error if any element of the BoundNames of ForDeclaration also occurs in the VarDeclaredNames of Statement.

  • It is a Syntax Error if the BoundNames of ForDeclaration contains any duplicate entries.

13.7.5.2 Static Semantics: BoundNames

See also: 12.1.2, 13.3.1.2, 13.3.2.1, 13.3.3.1, 14.1.3, 14.2.2, 14.4.2, 14.5.2, 15.2.2.2, 15.2.3.2.

ForDeclaration : LetOrConst ForBinding
  1. Return the BoundNames of ForBinding.

13.7.5.3 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.2.2, 13.6.2, 13.7.2.1, 13.7.3.1, 13.7.4.2, 13.11.2, 13.12.2, 13.13.2, 13.15.2, 15.2.1.2.

IterationStatement :
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
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.

13.7.5.4 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.9.2, 13.11.3, 13.12.3, 13.13.3, 13.15.3, 15.2.1.3.

IterationStatement :
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
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.

13.7.5.5 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.8.2, 13.11.4, 13.12.4, 13.13.4,13.15.4, 15.2.1.4.

IterationStatement :
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
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».

13.7.5.6 Static Semantics: IsDestructuring

See also: 12.3.1.3.

ForDeclaration : LetOrConst ForBinding
  1. Return IsDestructuring of ForBinding.
ForBinding : BindingIdentifier
  1. Return false.
ForBinding : BindingPattern
  1. Return true.

13.7.5.7 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

IterationStatement : for ( LeftHandSideExpression in Expression ) Statement
  1. Return the VarDeclaredNames of Statement.
IterationStatement : for ( var ForBinding in Expression ) Statement
  1. Let names be the BoundNames of ForBinding.
  2. Append to names the elements of the VarDeclaredNames of Statement.
  3. Return names.
IterationStatement : for ( ForDeclaration in Expression ) Statement
  1. Return the VarDeclaredNames of Statement.
IterationStatement : for ( LeftHandSideExpression of AssignmentExpression ) Statement
  1. Return the VarDeclaredNames of Statement.
IterationStatement : for ( 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.
IterationStatement : for ( ForDeclaration of AssignmentExpression ) Statement
  1. Return the VarDeclaredNames of Statement.

13.7.5.8 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.11.6, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

IterationStatement : for ( LeftHandSideExpression in Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.
IterationStatement : for ( var ForBinding in Expression ) Statement
  1. Let declarations be a List containing ForBinding.
  2. Append to declarations the elements of the VarScopedDeclarations of Statement.
  3. Return declarations.
IterationStatement : for ( ForDeclaration in Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.
IterationStatement : for ( LeftHandSideExpression of AssignmentExpression ) Statement
  1. Return the VarScopedDeclarations of Statement.
IterationStatement : for ( var ForBinding of AssignmentExpression ) Statement
  1. Let declarations be a List containing ForBinding.
  2. Append to declarations the elements of the VarScopedDeclarations of Statement.
  3. Return declarations.
IterationStatement : for ( ForDeclaration of AssignmentExpression ) Statement
  1. Return the VarScopedDeclarations of Statement.

13.7.5.9 Runtime Semantics: BindingInitialization

With arguments value and environment.

See also: 12.1.5, 13.3.3.5.

NOTE undefined is passed for environment to indicate that a PutValue operation should be used to assign the initialization value. This is the case for var statements and the formal parameter lists of some non-strict functions (see 9.2.12). In those cases a lexical binding is hoisted and preinitialized prior to evaluation of its initializer.

ForDeclaration : LetOrConst ForBinding
  1. Return the result of performing BindingInitialization for ForBinding passing value and environment as the arguments.

13.7.5.10 Runtime Semantics: BindingInstantiation

With argument environment.

ForDeclaration : LetOrConst ForBinding
  1. For each element name of the BoundNames of ForBinding do
    1. If IsConstantDeclaration of LetOrConst is true, then
      1. Perform environment.CreateImmutableBinding(name, true).
    2. Else,
      1. Perform environment.CreateMutableBinding(name).
      2. Assert: The above call to CreateMutableBinding will never return an abrupt completion.

13.7.5.11 Runtime Semantics: LabelledEvaluation

With argument labelSet.

See also: 13.1.7, 13.7.2.6, 13.7.3.6, 13.7.4.7, 13.13.14.

IterationStatement : for ( LeftHandSideExpression in Expression ) Statement
  1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate).
  2. ReturnIfAbrupt(keyResult).
  3. Return ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, keyResult, assignment, labelSet).
IterationStatement : for ( var ForBinding in Expression ) Statement
  1. Let keyResult be ForIn/OfHeadEvaluation( « », Expression, enumerate).
  2. ReturnIfAbrupt(keyResult).
  3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, varBinding, labelSet).
IterationStatement : for ( ForDeclaration in Expression ) Statement
  1. Let keyResult be the result of performing ForIn/OfHeadEvaluation(BoundNames of ForDeclaration, Expression, enumerate).
  2. ReturnIfAbrupt(keyResult).
  3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, lexicalBinding, labelSet).
IterationStatement : for ( LeftHandSideExpression of AssignmentExpression ) Statement
  1. Let keyResult be the result of performing ForIn/OfHeadEvaluation( « », AssignmentExpression, iterate).
  2. ReturnIfAbrupt(keyResult).
  3. Return ForIn/OfBodyEvaluation(LeftHandSideExpression, Statement, keyResult, assignment, labelSet).
IterationStatement : for ( var ForBinding of AssignmentExpression ) Statement
  1. Let keyResult be the result of performing ForIn/OfHeadEvaluation( « », AssignmentExpression, iterate).
  2. ReturnIfAbrupt(keyResult).
  3. Return ForIn/OfBodyEvaluation(ForBinding, Statement, keyResult, varBinding, labelSet).
IterationStatement : for ( ForDeclaration of AssignmentExpression ) Statement
  1. Let keyResult be the result of performing ForIn/OfHeadEvaluation( BoundNames of ForDeclaration, AssignmentExpression, iterate).
  2. ReturnIfAbrupt(keyResult).
  3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, lexicalBinding, labelSet).

13.7.5.12 Runtime Semantics: ForIn/OfHeadEvaluation ( TDZnames, expr, iterationKind, labelSet)

The abstract operation ForIn/OfHeadEvaluation is called with arguments TDZnames, expr, and iterationKind. The value of iterationKind is either enumerate or iterate.

  1. Let oldEnv be the running execution context’s LexicalEnvironment.
  2. If TDZnames is not an empty List, then
    1. Assert: TDZnames has no duplicate entries.
    2. Let TDZ be NewDeclarativeEnvironment(oldEnv).
    3. For each string name in TDZnames, do
      1. Let status be TDZ.CreateMutableBinding(name, false).
      2. Assert: status is never an abrupt completion.
    4. Set the running execution context’s LexicalEnvironment to TDZ.
  3. Let exprRef be the result of evaluating the production that is expr.
  4. Set the running execution context’s LexicalEnvironment to oldEnv.
  5. Let exprValue be GetValue(exprRef).
  6. ReturnIfAbrupt(exprValue).
  7. If iterationKind is enumerate, then
    1. If exprValue.[[value]] is null or undefined, then
      1. Return Completion{[[type]]: break, [[value]]: empty, [[target]]: empty}.
    2. Let obj be ToObject(exprValue).
    3. Return obj.[[Enumerate]]().
  8. Else,
    1. Assert: iterationKind is iterate.
    2. Return GetIterator(exprValue).

13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation ( lhs, stmt, iterator, lhsKind, labelSet )

The abstract operation ForIn/OfBodyEvaluation is called with arguments lhs, stmt, iterator, lhsKind, and labelSet. The value of lhsKind is either assignment, varBinding or lexicalBinding.

  1. Let oldEnv be the running execution context’s LexicalEnvironment.
  2. Let V = undefined .
  3. Let destructuring be IsDestructuring of lhs.
  4. If destructuring is true and if lhsKind is assignment, then
    1. Assert: lhs is a LeftHandSideExpression.
    2. Let assignmentPattern be the parse of the source text corresponding to lhs using AssignmentPattern as the goal symbol.
  5. Repeat
    1. Let nextResult be IteratorStep(iterator).
    2. ReturnIfAbrupt(nextResult).
    3. If nextResult is false, return NormalCompletion(V).
    4. Let nextValue be IteratorValue(nextResult).
    5. ReturnIfAbrupt(nextValue).
    6. If lhsKind is either assignment or varBinding, then
      1. If destructuring is false, then
        1. Let lhsRef be the result of evaluating lhs ( it may be evaluated repeatedly).
    7. Else
      1. Assert: lhsKind is lexicalBinding.
      2. Assert: lhs is a ForDeclaration.
      3. Let iterationEnv be NewDeclarativeEnvironment(oldEnv).
      4. Perform BindingInstantiation for lhs passing iterationEnv as the argument.
      5. Set the running execution context’s LexicalEnvironment to iterationEnv.
      6. If destructuring is false, then
        1. Assert: lhs binds a single name.
        2. Let lhsName be the sole element of BoundNames of lhs.
        3. Let lhsRef be ResolveBinding(lhsName).
        4. Assert: lhsRef is not an abrupt completion.
    8. If destructuring is false, then
      1. If lhsRef is an abrupt completion, then
        1. Let status be lhsRef.
      2. Else if lhsKind is lexicalBinding, then
        1. Let status be InitializeReferencedBinding(lhsRef, nextValue).
      3. Else,
        1. Let status be PutValue(lhsRef, nextValue).
    9. Else,
      1. If lhsKind is assignment, then
        1. Let status be the result of performing DestructuringAssignmentEvaluation of assignmentPattern using nextValue as the argument.
      2. Else if lhsKind is varBinding, then
        1. Assert: lhs is a ForBinding.
        2. Let status be the result of performing BindingInitialization for lhs passing nextValue and undefined as the arguments.
      3. Else,
        1. Assert: lhsKind is lexicalBinding.
        2. Assert: lhs is a ForDeclaration.
        3. Let status be the result of performing BindingInitialization for lhs passing nextValue and iterationEnv as arguments.
    10. If status is an abrupt completion, then
      1. Set the running execution context’s LexicalEnvironment to oldEnv.
      2. Return IteratorClose(iterator, status).
    11. Let result be the result of evaluating stmt.
    12. Set the running execution context’s LexicalEnvironment to oldEnv.
    13. If LoopContinues(result, labelSet) is false, return IteratorClose(iterator, UpdateEmpty(result, V)).
    14. If result.[[value]] is not empty, let V be result.[[value]].

13.7.5.14 Runtime Semantics: Evaluation

ForBinding : BindingIdentifier
  1. Let bindingId be StringValue of BindingIdentifier.
  2. Return ResolveBinding(bindingId)

13.8 The continue Statement

Syntax

ContinueStatement[Yield] :
continue ;
continue [no LineTerminator here] LabelIdentifier[?Yield] ;

13.8.1 Static Semantics: Early Errors

ContinueStatement : continue ;

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

13.8.2 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.11.4, 13.12.4, 13.13.4,13.15.4, 15.2.1.4.

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.

13.8.3 Runtime Semantics: Evaluation

ContinueStatement : continue ;
  1. Return Completion{[[type]]: continue, [[value]]: empty, [[target]]: empty}.
ContinueStatement : continue LabelIdentifier ;
  1. Let label be the StringValue of LabelIdentifier.
  2. Return Completion{[[type]]: continue, [[value]]: empty, [[target]]: label }.

13.9 The break Statement

Syntax

BreakStatement[Yield] :
break ;
break [no LineTerminator here] LabelIdentifier[?Yield] ;

13.9.1 Static Semantics: Early Errors

BreakStatement : break ;
  • It is a Syntax Error if this production is not nested, directly or indirectly (but not crossing function boundaries), within an IterationStatement or a SwitchStatement.

13.9.2 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.11.3, 13.12.3, 13.13.3, 13.15.3, 15.2.1.3.

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.

13.9.3 Runtime Semantics: Evaluation

BreakStatement : break ;
  1. Return Completion{[[type]]: break, [[value]]: empty, [[target]]: empty}.
BreakStatement : break LabelIdentifier ;
  1. Let label be the StringValue of LabelIdentifier.
  2. Return Completion{[[type]]: break, [[value]]: empty, [[target]]: label }.

13.10 The return Statement

Syntax

ReturnStatement[Yield] :
return ;
return [no LineTerminator here] Expression[In, ?Yield] ;

NOTE A return statement causes a function to cease execution and return a value to the caller. If Expression is omitted, the return value is undefined. Otherwise, the return value is the value of Expression.

13.10.1 Runtime Semantics: Evaluation

ReturnStatement : return ;
  1. Return Completion{[[type]]: return, [[value]]: undefined, [[target]]: empty}.
ReturnStatement : return Expression ;
  1. Let exprRef be the result of evaluating Expression.
  2. Let exprValue be GetValue(exprRef).
  3. ReturnIfAbrupt(exprValue).
  4. Return Completion{[[type]]: return, [[value]]: exprValue, [[target]]: empty}.

13.11 The with Statement

Syntax

WithStatement[Yield, Return] :
with ( Expression[In, ?Yield] ) Statement[?Yield, ?Return]

NOTE The with statement adds an object Environment Record for a computed object to the lexical environment of the running execution context. It then executes a statement using this augmented lexical environment. Finally, it restores the original lexical environment.

13.11.1 Static Semantics: Early Errors

WithStatement : with ( Expression ) Statement
  • It is a Syntax Error if the code that matches this production is contained in strict code.
  • It is a Syntax Error if IsLabelledFunction(Statement) is true.

NOTE It is only necessary to apply the second rule if the extension specified in B.3.2 is implemented.

13.11.2 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.2.2, 13.6.2, 13.7.2.1, 13.7.3.1, 13.7.4.2, 13.7.5.3, 13.12.2, 13.13.2, 13.15.2, 15.2.1.2.

WithStatement : with ( Expression ) Statement
  1. Return ContainsDuplicateLabels of Statement with argument labelSet.

13.11.3 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.12.3, 13.13.3, 13.15.3, 15.2.1.3.

WithStatement : with ( Expression ) Statement
  1. Return ContainsUndefinedBreakTarget of Statement with argument labelSet.

13.11.4 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.12.4, 13.13.4,13.15.4, 15.2.1.4.

WithStatement : with ( Expression ) Statement
  1. Return ContainsUndefinedContinueTarget of Statement with arguments iterationSet and « ».

13.11.5 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.12.7, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

WithStatement : with ( Expression ) Statement
  1. Return the VarDeclaredNames of Statement.

13.11.6 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.12.8, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

WithStatement : with ( Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.

13.11.7 Runtime Semantics: Evaluation

WithStatement : with ( Expression ) Statement
  1. Let val be the result of evaluating Expression.
  2. Let obj be ToObject(GetValue(val)).
  3. ReturnIfAbrupt(obj).
  4. Let oldEnv be the running execution context’s LexicalEnvironment.
  5. Let newEnv be NewObjectEnvironment(obj, oldEnv).
  6. Set the withEnvironment flag of newEnv’s EnvironmentRecord to true.
  7. Set the running execution context’s LexicalEnvironment to newEnv.
  8. Let C be the result of evaluating Statement.
  9. Set the running execution context’s Lexical Environment to oldEnv.
  10. If C.[[type]] is normal and C.[[value]] is empty, return NormalCompletion(undefined).
  11. Return Completion(C).

NOTE No matter how control leaves the embedded Statement, whether normally or by some form of abrupt completion or exception, the LexicalEnvironment is always restored to its former state.

13.12 The switch Statement

Syntax

SwitchStatement[Yield, Return] :
switch ( Expression[In, ?Yield] ) CaseBlock[?Yield, ?Return]
CaseBlock[Yield, Return] :
{ CaseClauses[?Yield, ?Return]opt }
{ CaseClauses[?Yield, ?Return]opt DefaultClause[?Yield, ?Return] CaseClauses[?Yield, ?Return]opt }
CaseClauses[Yield, Return] :
CaseClause[?Yield, ?Return]
CaseClauses[?Yield, ?Return] CaseClause[?Yield, ?Return]
CaseClause[Yield, Return] :
case Expression[In, ?Yield] : StatementList[?Yield, ?Return]opt
DefaultClause[Yield, Return] :
default : StatementList[?Yield, ?Return]opt

13.12.1 Static Semantics: Early Errors

CaseBlock : { CaseClauses }
  • It is a Syntax Error if the LexicallyDeclaredNames of CaseClauses contains any duplicate entries.

  • It is a Syntax Error if any element of the LexicallyDeclaredNames of CaseClauses also occurs in the VarDeclaredNames of CaseClauses.

13.12.2 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.2.2, 13.6.2, 13.7.2.1, 13.7.3.1, 13.7.4.2, 13.7.5.3, 13.11.2, 13.13.2, 13.15.2, 15.2.1.2.

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. Else return false.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return ContainsDuplicateLabels of StatementList with argument labelSet.
  2. Else return false.

13.12.3 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.11.3, 13.13.3, 13.15.3, 15.2.1.3.

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. Else return false.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return ContainsUndefinedBreakTarget of StatementList with argument labelSet.
  2. Else return false.

13.12.4 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.11.4, 13.13.4,13.15.4, 15.2.1.4.

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. Else return false.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return ContainsUndefinedContinueTarget of StatementList with arguments iterationSet and « ».
  2. Else return false.

13.12.5 Static Semantics: LexicallyDeclaredNames

See also: 13.2.5, 13.13.6, 14.1.13, 14.2.10, 15.1.3, 15.2.1.11.

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 the DefaultClause.
  4. If the second CaseClauses is not present, return names.
  5. Else 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. Else return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the LexicallyDeclaredNames of StatementList.
  2. Else return a new empty List.

13.12.6 Static Semantics: LexicallyScopedDeclarations

See also: 13.2.6, 13.13.7, 14.1.14, 14.2.11, 15.1.4, 15.2.1.12, 15.2.3.8.

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 the DefaultClause.
  4. If the second CaseClauses is not present, return declarations.
  5. Else 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. Else return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the LexicallyScopedDeclarations of StatementList.
  2. Else return a new empty List.

13.12.7 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.13.12, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

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 the DefaultClause.
  4. If the second CaseClauses is not present, return names.
  5. Else 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. Else return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the VarDeclaredNames of StatementList.
  2. Else return a new empty List.

13.12.8 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.13.13, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

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 the DefaultClause.
  4. If the second CaseClauses is not present, return declarations.
  5. Else 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. Else return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the VarScopedDeclarations of StatementList.
  2. Else return a new empty List.

13.12.9 Runtime Semantics: CaseBlockEvaluation

With argument input.

CaseBlock : { }
  1. Return NormalCompletion(undefined).
CaseBlock : { CaseClauses }
  1. Let V = undefined.
  2. Let A be the List of CaseClause items in CaseClauses, in source text order.
  3. Let found be false.
  4. Repeat for each CaseClause C in A,
    1. If found is false, then
      1. Let clauseSelector be the result of CaseSelectorEvaluation of C.
      2. If clauseSelector is an abrupt completion, then
        1. If clauseSelector.[[value]] is empty, return Completion{[[type]]: clauseSelector.[[type]], [[value]]: undefined, [[target]]: clauseSelector.[[target]]}.
        2. Else, return Completion(clauseSelector).
      3. Let found be the result of performing Strict Equality Comparison input === clauseSelector.[[value]].
    2. If found is true, then
      1. Let R be the result of evaluating C.
      2. If R.[[value]] is not empty, let V = R.[[value]].
      3. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)).
  5. Return NormalCompletion(V).
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. Let V = undefined.
  2. Let A be the list of CaseClause items in the first CaseClauses, in source text order. If the first CaseClauses is not present A is « ».
  3. Let found be false.
  4. Repeat for each CaseClause C in A
    1. If found is false, then
      1. Let clauseSelector be the result of CaseSelectorEvaluation of C.
      2. If clauseSelector is an abrupt completion, then
        1. If clauseSelector.[[value]] is empty, return Completion{[[type]]: clauseSelector.[[type]], [[value]]: undefined, [[target]]: clauseSelector.[[target]]}.
        2. Else, return Completion(clauseSelector).
      3. Let found be the result of performing Strict Equality Comparison input === clauseSelector.[[value]].
    2. If found is true, then
      1. Let R be the result of evaluating C.
      2. If R.[[value]] is not empty, let V = R.[[value]].
      3. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)).
  5. Let foundInB be false.
  6. Let B be the List containing the CaseClause items in the second CaseClauses, in source text order. If the second CaseClauses is not present B is « ».
  7. If found is false, then
    1. Repeat for each CaseClause C in B
      1. If foundInB is false, then
        1. Let clauseSelector be the result of CaseSelectorEvaluation of C.
        2. If clauseSelector is an abrupt completion, then
          1. If clauseSelector.[[value]] is empty, return Completion{[[type]]: clauseSelector.[[type]], [[value]]: undefined, [[target]]: clauseSelector.[[target]]}.
          2. Else, return Completion(clauseSelector).
        3. Let foundInB be the result of performing Strict Equality Comparison input === clauseSelector.[[value]].
      2. If foundInB is true, then
        1. Let R be the result of evaluating CaseClause C.
        2. If R.[[value]] is not empty, let V = R.[[value]].
        3. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)).
  8. If foundInB is true, return NormalCompletion(V).
  9. Let R be the result of evaluating DefaultClause.
  10. If R.[[value]] is not empty, let V = R.[[value]].
  11. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)).
  12. Repeat for each CaseClause C in B (NOTE this is another complete iteration of the second CaseClauses)
    1. Let R be the result of evaluating CaseClause C.
    2. If R.[[value]] is not empty, let V = R.[[value]].
    3. If R is an abrupt completion, return Completion(UpdateEmpty(R, V)).
  13. Return NormalCompletion(V).

13.12.10 Runtime Semantics: CaseSelectorEvaluation

CaseClause : case Expression : StatementListopt
  1. Let exprRef be the result of evaluating Expression.
  2. Return GetValue(exprRef).

NOTE CaseSelectorEvaluation does not execute the associated StatementList. It simply evaluates the Expression and returns the value, which the CaseBlock algorithm uses to determine which StatementList to start executing.

13.12.11 Runtime Semantics: Evaluation

SwitchStatement : switch ( Expression ) CaseBlock
  1. Let exprRef be the result of evaluating Expression.
  2. Let switchValue be GetValue(exprRef).
  3. ReturnIfAbrupt(switchValue).
  4. Let oldEnv be the running execution context’s LexicalEnvironment.
  5. Let blockEnv be NewDeclarativeEnvironment(oldEnv).
  6. Perform BlockDeclarationInstantiation(CaseBlock, blockEnv).
  7. Set the running execution context’s LexicalEnvironment to blockEnv.
  8. Let R be the result of performing CaseBlockEvaluation of CaseBlock with argument switchValue.
  9. Set the running execution context’s LexicalEnvironment to oldEnv.
  10. Return R.

NOTE No matter how control leaves the SwitchStatement the LexicalEnvironment is always restored to its former state.

CaseClause : case Expression :
  1. Return NormalCompletion(empty).
CaseClause : case Expression : StatementList
  1. Return the result of evaluating StatementList.
DefaultClause : default :
  1. Return NormalCompletion(empty).
DefaultClause : default : StatementList
  1. Return the result of evaluating StatementList.

13.13 Labelled Statements

Syntax

LabelledStatement[Yield, Return] :
LabelIdentifier[?Yield] : LabelledItem[?Yield, ?Return]
LabelledItem[Yield, Return] :
Statement[?Yield, ?Return]
FunctionDeclaration[?Yield]

NOTE A Statement may be prefixed by a label. Labelled statements are only used in conjunction with labelled break and continue statements. ECMAScript has no goto statement. A Statement can be part of a LabelledStatement, which itself can be part of a LabelledStatement, and so on. The labels introduced this way are collectively referred to as the “current label set” when describing the semantics of individual statements. A LabelledStatement has no semantic meaning other than the introduction of a label to a label set.

13.13.1 Static Semantics: Early Errors

LabelledItem : FunctionDeclaration
  • It is a Syntax Error if any source text matches this rule.

NOTE An alternative definition for this rule is provided in B.3.2.

13.13.2 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.2.2, 13.6.2, 13.7.2.1, 13.7.3.1, 13.7.4.2, 13.7.5.3, 13.11.2, 13.12.2, 13.15.2, 15.2.1.2.

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.

13.13.3 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.11.3, 13.12.3, 13.15.3, 15.2.1.3.

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.

13.13.4 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.11.4, 13.12.4, 13.15.4, 15.2.1.4.

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.

13.13.5 Static Semantics: IsLabelledFunction ( stmt )

The abstract operation IsLabelledFunction with argument stmt performs the following steps:

  1. If stmt is not a LabelledStatement, return false.
  2. Let item be the LabelledItem component of stmt.
  3. If item is LabelledItem : FunctionDeclaration , return true.
  4. Let subStmt be the Statement component of item.
  5. Return IsLabelledFunction(subStmt).

13.13.6 Static Semantics: LexicallyDeclaredNames

See also: 13.2.5, 13.12.5, 14.1.13, 14.2.10, 15.1.3, 15.2.1.11.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the LexicallyDeclaredNames of LabelledItem.
LabelledItem : Statement
  1. Return a new empty List.
LabelledItem : FunctionDeclaration
  1. Return BoundNames of FunctionDeclaration.

13.13.7 Static Semantics: LexicallyScopedDeclarations

See also: 13.2.6, 13.12.6, 14.1.14, 14.2.11, 15.1.4, 15.2.1.12, 15.2.3.8.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the LexicallyScopedDeclarations of LabelledItem.
LabelledItem : Statement
  1. Return a new empty List.
LabelledItem : FunctionDeclaration
  1. Return a new List containing FunctionDeclaration.

13.13.8 Static Semantics: TopLevelLexicallyDeclaredNames

See also: 13.2.7.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Return a new empty List.

13.13.9 Static Semantics: TopLevelLexicallyScopedDeclarations

See also: 13.2.8.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Return a new empty List.

13.13.10 Static Semantics: TopLevelVarDeclaredNames

See also: 13.2.9.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the TopLevelVarDeclaredNames of LabelledItem.
LabelledItem : Statement
  1. If Statement is Statement : LabelledStatement , return TopLevelVarDeclaredNames of Statement.
  2. Return VarDeclaredNames of Statement.
LabelledItem : FunctionDeclaration
  1. Return BoundNames of FunctionDeclaration.

13.13.11 Static Semantics: TopLevelVarScopedDeclarations

See also: 13.2.10.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the TopLevelVarScopedDeclarations of LabelledItem.
LabelledItem : Statement
  1. If Statement is Statement : LabelledStatement , return TopLevelVarScopedDeclarations of Statement.
  2. Return VarScopedDeclarations of Statement.
LabelledItem : FunctionDeclaration
  1. Return a new List containing FunctionDeclaration.

13.13.12 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.15.5, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the VarDeclaredNames of LabelledItem.
LabelledItem : FunctionDeclaration
  1. Return a new empty List.

13.13.13 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.15.6, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the VarScopedDeclarations of LabelledItem.
LabelledItem : FunctionDeclaration
  1. Return a new empty List.

13.13.14 Runtime Semantics: LabelledEvaluation

With argument labelSet.

See also: 13.1.7, 13.7.2.6, 13.7.3.6, 13.7.4.7, 13.7.5.11.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Let label be the StringValue of LabelIdentifier.
  2. Append label as an element of labelSet.
  3. Let stmtResult be LabelledEvaluation of LabelledItem with argument labelSet.
  4. If stmtResult.[[type]] is break and SameValue(stmtResult.[[target]], label), then
    1. Let stmtResult be NormalCompletion(stmtResult.[[value]]).
  5. Return Completion(stmtResult).
LabelledItem : Statement
  1. If Statement is either a LabelledStatement or a BreakableStatement, then
    1. Return LabelledEvaluation of Statement with argument labelSet.
  2. Else,
    1. Return the result of evaluating Statement.

LabelledItem : FunctionDeclaration

  1. Return the result of evaluating FunctionDeclaration.

13.13.15 Runtime Semantics: Evaluation

LabelledStatement : LabelIdentifier : LabelledItem
  1. Let newLabelSet be a new empty List.
  2. Return LabelledEvaluation of LabelledItem with argument newLabelSet.

13.14 The throw Statement

Syntax

ThrowStatement[Yield] :
throw [no LineTerminator here] Expression[In, ?Yield] ;

13.14.1 Runtime Semantics: Evaluation

ThrowStatement : throw Expression ;
  1. Let exprRef be the result of evaluating Expression.
  2. Let exprValue be GetValue(exprRef).
  3. ReturnIfAbrupt(exprValue).
  4. Return Completion{[[type]]: throw, [[value]]: exprValue, [[target]]: empty}.

13.15 The try Statement

Syntax

TryStatement[Yield, Return] :
try Block[?Yield, ?Return] Catch[?Yield, ?Return]
try Block[?Yield, ?Return] Finally[?Yield, ?Return]
try Block[?Yield, ?Return] Catch[?Yield, ?Return] Finally[?Yield, ?Return]
Catch[Yield, Return] :
catch ( CatchParameter[?Yield] ) Block[?Yield, ?Return]
Finally[Yield, Return] :
finally Block[?Yield, ?Return]
CatchParameter[Yield] :
BindingIdentifier[?Yield]
BindingPattern[?Yield]

NOTE The try statement encloses a block of code in which an exceptional condition can occur, such as a runtime error or a throw statement. The catch clause provides the exception-handling code. When a catch clause catches an exception, its CatchParameter is bound to that exception.

13.15.1 Static Semantics: Early Errors

Catch : catch ( CatchParameter ) Block
  • It is a Syntax Error if BoundNames of CatchParameter contains any duplicate elements.

  • It is a Syntax Error if any element of the BoundNames of CatchParameter also occurs in the LexicallyDeclaredNames of Block.

  • It is a Syntax Error if any element of the BoundNames of CatchParameter also occurs in the VarDeclaredNames of Block.

NOTE An alternative static semantics for this production is given in B.3.5.

13.15.2 Static Semantics: ContainsDuplicateLabels

With argument labelSet.

See also: 13.1.1, 13.2.2, 13.6.2, 13.7.2.1, 13.7.3.1, 13.7.4.2, 13.7.5.3, 13.11.2, 13.12.2, 13.13.2, 15.2.1.2.

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.

13.15.3 Static Semantics: ContainsUndefinedBreakTarget

With argument labelSet.

See also: 13.1.2, 13.2.3, 13.6.3, 13.7.2.2, 13.7.3.2, 13.7.4.3, 13.7.5.4, 13.9.2, 13.11.3, 13.12.3, 13.13.3, 15.2.1.3.

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.

13.15.4 Static Semantics: ContainsUndefinedContinueTarget

With arguments iterationSet and labelSet.

See also: 13.1.3, 13.2.4, 13.6.4, 13.7.2.3, 13.7.3.3, 13.7.4.4, 13.7.5.5, 13.8.2, 13.11.4, 13.12.4, 13.13.4, 15.2.1.4.

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 « ».

13.15.5 Static Semantics: VarDeclaredNames

See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 14.1.15, 14.2.12, 15.1.5, 15.2.1.13.

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.

13.15.6 Static Semantics: VarScopedDeclarations

See also: 13.1.6, 13.2.12, 13.3.2.3, 13.6.6, 13.7.2.5, 13.7.3.5, 13.7.4.6, 13.7.5.8, 13.11.6, 13.12.8, 13.13.13, 14.1.16, 14.2.13, 15.1.6, 15.2.1.14.

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.

13.15.7 Runtime Semantics: CatchClauseEvaluation

with parameter thrownValue

Catch : catch ( CatchParameter ) Block
  1. Let oldEnv be the running execution context’s LexicalEnvironment.
  2. Let catchEnv be NewDeclarativeEnvironment(oldEnv).
  3. For each element argName of the BoundNames of CatchParameter, do
    1. Perform catchEnv.CreateMutableBinding(argName).
    2. Assert: The above call to CreateMutableBinding will never return an abrupt completion.
  4. Set the running execution context’s LexicalEnvironment to catchEnv.
  5. Let status be the result of performing BindingInitialization for CatchParameter passing thrownValue and catchEnv as arguments.
  6. If status is an abrupt completion, then
    1. Set the running execution context’s LexicalEnvironment to oldEnv.
    2. Return Completion(status).
  7. Let B be the result of evaluating Block.
  8. Set the running execution context’s LexicalEnvironment to oldEnv.
  9. Return Completion(B).

NOTE No matter how control leaves the Block the LexicalEnvironment is always restored to its former state.

13.15.8 Runtime Semantics: Evaluation

TryStatement : try Block Catch
  1. Let B be the result of evaluating Block.
  2. If B.[[type]] is throw, then
    1. Let C be CatchClauseEvaluation of Catch with parameter B.[[value]].
  3. Else B.[[type]] is not throw,
    1. Let C be B.
  4. If C.[[type]] is return, or C.[[type]] is throw, return Completion(C).
  5. If C.[[value]] is not empty, return Completion(C).
  6. Return Completion{[[type]]: C.[[type]], [[value]]: undefined, [[target]]: C.[[target]]}.
TryStatement : try Block Finally
  1. Let B be the result of evaluating Block.
  2. Let F be the result of evaluating Finally.
  3. If F.[[type]] is normal, let F be B.
  4. If F.[[type]] is return, or F.[[type]] is throw, return Completion(F).
  5. If F.[[value]] is not empty, return Completion(F).
  6. Return Completion{[[type]]: F.[[type]], [[value]]: undefined, [[target]]: F.[[target]]}.
TryStatement : try Block Catch Finally
  1. Let B be the result of evaluating Block.
  2. If B.[[type]] is throw, then
    1. Let C be CatchClauseEvaluation of Catch with parameter B.[[value]].
  3. Else B.[[type]] is not throw, let C be B.
  4. Let F be the result of evaluating Finally.
  5. If F.[[type]] is normal, let F be C.
  6. If F.[[type]] is return, or F.[[type]] is throw, return Completion(F).
  7. If F.[[value]] is not empty, return NormalCompletion(F.[[value]]).
  8. Return Completion{[[type]]: F.[[type]], [[value]]: undefined, [[target]]: F.[[target]]}.

13.16 The debugger statement

Syntax

DebuggerStatement :
debugger ;

13.16.1 Runtime Semantics: Evaluation

NOTE Evaluating the DebuggerStatement production may allow an implementation to cause a breakpoint when run under a debugger. If a debugger is not present or active this statement has no observable effect.

DebuggerStatement : debugger ;
  1. If an implementation defined debugging facility is available and enabled, then
    1. Perform an implementation defined debugging action.
    2. Let result be an implementation defined Completion value.
  2. Else
    1. Let result be NormalCompletion(empty).
  3. Return result.