13 ECMAScript Language: Statements and Declarations
Syntax
13.1 Statement Semantics
13.1.1 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Return
false .
13.1.2 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Return
false .
13.1.3 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Return
false .
- Let newIterationSet be a copy of iterationSet with all the elements of labelSet appended.
- Return ContainsUndefinedContinueTarget of
IterationStatement with arguments newIterationSet and « ».
13.1.4 Static Semantics: DeclarationPart
- Return
FunctionDeclaration .
- Return
GeneratorDeclaration .
- Return
AsyncFunctionDeclaration .
- Return
ClassDeclaration .
- Return
LexicalDeclaration .
13.1.5 Static Semantics: VarDeclaredNames
- Return a new empty
List .
13.1.6 Static Semantics: VarScopedDeclarations
- Return a new empty
List .
13.1.7 Runtime Semantics: LabelledEvaluation
With parameter labelSet.
- Let stmtResult be the result of performing LabelledEvaluation of
IterationStatement with argument labelSet. - If stmtResult.[[Type]] is
break , then- If stmtResult.[[Target]] is
empty , then- If stmtResult.[[Value]] is
empty , set stmtResult toNormalCompletion (undefined ). - Else, set stmtResult to
NormalCompletion (stmtResult.[[Value]]).
- If stmtResult.[[Value]] is
- If stmtResult.[[Target]] is
- Return
Completion (stmtResult).
- Let stmtResult be the result of evaluating
SwitchStatement . - If stmtResult.[[Type]] is
break , then- If stmtResult.[[Target]] is
empty , then- If stmtResult.[[Value]] is
empty , set stmtResult toNormalCompletion (undefined ). - Else, set stmtResult to
NormalCompletion (stmtResult.[[Value]]).
- If stmtResult.[[Value]] is
- If stmtResult.[[Target]] is
- Return
Completion (stmtResult).
A
13.1.8 Runtime Semantics: Evaluation
- Return
NormalCompletion (empty ).
- Return
NormalCompletion (empty ).
- Return the result of evaluating
FunctionDeclaration .
- Let newLabelSet be a new empty
List . - Return the result of performing LabelledEvaluation of this
BreakableStatement with argument newLabelSet.
13.2 Block
Syntax
13.2.1 Static Semantics: Early Errors
-
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 ofStatementList .
13.2.2 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Return
false .
- Let hasDuplicates be ContainsDuplicateLabels of
StatementList with argument labelSet. - If hasDuplicates is
true , returntrue . - Return ContainsDuplicateLabels of
StatementListItem with argument labelSet.
- Return
false .
13.2.3 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Return
false .
- Let hasUndefinedLabels be ContainsUndefinedBreakTarget of
StatementList with argument labelSet. - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedBreakTarget of
StatementListItem with argument labelSet.
- Return
false .
13.2.4 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Return
false .
- Let hasUndefinedLabels be ContainsUndefinedContinueTarget of
StatementList with arguments iterationSet and « ». - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedContinueTarget of
StatementListItem with arguments iterationSet and « ».
- Return
false .
13.2.5 Static Semantics: LexicallyDeclaredNames
- Return a new empty
List .
- Let names be LexicallyDeclaredNames of
StatementList . - Append to names the elements of the LexicallyDeclaredNames of
StatementListItem . - Return names.
- If
Statement is , return LexicallyDeclaredNames ofStatement : LabelledStatement LabelledStatement . - Return a new empty
List .
- Return the BoundNames of
Declaration .
13.2.6 Static Semantics: LexicallyScopedDeclarations
- Let declarations be LexicallyScopedDeclarations of
StatementList . - Append to declarations the elements of the LexicallyScopedDeclarations of
StatementListItem . - Return declarations.
- If
Statement is , return LexicallyScopedDeclarations ofStatement : LabelledStatement LabelledStatement . - Return a new empty
List .
- Return a new
List containing DeclarationPart ofDeclaration .
13.2.7 Static Semantics: TopLevelLexicallyDeclaredNames
- Let names be TopLevelLexicallyDeclaredNames of
StatementList . - Append to names the elements of the TopLevelLexicallyDeclaredNames of
StatementListItem . - Return names.
- Return a new empty
List .
- If
Declaration is , thenDeclaration : HoistableDeclaration - Return « ».
- Return the BoundNames of
Declaration .
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
- Return a new empty
List .
- Let declarations be TopLevelLexicallyScopedDeclarations of
StatementList . - Append to declarations the elements of the TopLevelLexicallyScopedDeclarations of
StatementListItem . - Return declarations.
- Return a new empty
List .
- If
Declaration is , thenDeclaration : HoistableDeclaration - Return « ».
- Return a new
List containingDeclaration .
13.2.9 Static Semantics: TopLevelVarDeclaredNames
- Return a new empty
List .
- Let names be TopLevelVarDeclaredNames of
StatementList . - Append to names the elements of the TopLevelVarDeclaredNames of
StatementListItem . - Return names.
- If
Declaration is , thenDeclaration : HoistableDeclaration - Return the BoundNames of
HoistableDeclaration .
- Return the BoundNames of
- Return a new empty
List .
- If
Statement is , return TopLevelVarDeclaredNames ofStatement : LabelledStatement Statement . - Return VarDeclaredNames of
Statement .
At the top level of a function or script, inner function declarations are treated like var declarations.
13.2.10 Static Semantics: TopLevelVarScopedDeclarations
- Return a new empty
List .
- Let declarations be TopLevelVarScopedDeclarations of
StatementList . - Append to declarations the elements of the TopLevelVarScopedDeclarations of
StatementListItem . - Return declarations.
- If
Statement is , return TopLevelVarScopedDeclarations ofStatement : LabelledStatement Statement . - Return VarScopedDeclarations of
Statement .
- If
Declaration is , thenDeclaration : HoistableDeclaration - Let declaration be DeclarationPart of
HoistableDeclaration . - Return « declaration ».
- Let declaration be DeclarationPart of
- Return a new empty
List .
13.2.11 Static Semantics: VarDeclaredNames
13.2.12 Static Semantics: VarScopedDeclarations
- Return a new empty
List .
- Let declarations be VarScopedDeclarations of
StatementList . - Append to declarations the elements of the VarScopedDeclarations of
StatementListItem . - Return declarations.
- Return a new empty
List .
13.2.13 Runtime Semantics: Evaluation
- Return
NormalCompletion (empty ).
- Let oldEnv be the
running execution context 's LexicalEnvironment. - Let blockEnv be
NewDeclarativeEnvironment (oldEnv). - Perform
BlockDeclarationInstantiation (StatementList , blockEnv). Set therunning execution context 's LexicalEnvironment to blockEnv.- Let blockValue be the result of evaluating
StatementList . Set therunning execution context 's LexicalEnvironment to oldEnv.- Return blockValue.
No matter how control leaves the
- Let sl be the result of evaluating
StatementList . ReturnIfAbrupt (sl).- Let s be the result of evaluating
StatementListItem . - Return
Completion (UpdateEmpty (s, sl)).
The value of a eval function all return the value 1:
eval("1;;;;;")
eval("1;{}")
eval("1;var a;")
13.2.14 Runtime Semantics: BlockDeclarationInstantiation( code, env )
When a
BlockDeclarationInstantiation is performed as follows using arguments code and env. code is the
- Let envRec be env's
EnvironmentRecord . Assert : envRec is a declarativeEnvironment Record .- Let declarations be the LexicallyScopedDeclarations of code.
- For each element d in declarations, do
- For each element dn of the BoundNames of d, do
- If IsConstantDeclaration of d is
true , then- Perform ! envRec.CreateImmutableBinding(dn,
true ).
- Perform ! envRec.CreateImmutableBinding(dn,
- Else,
- Perform ! envRec.CreateMutableBinding(dn,
false ).
- Perform ! envRec.CreateMutableBinding(dn,
- If IsConstantDeclaration of d is
- If d is a
FunctionDeclaration , aGeneratorDeclaration , or anAsyncFunctionDeclaration , then- Let fn be the sole element of the BoundNames of d.
- Let fo be the result of performing InstantiateFunctionObject for d with argument env.
- Perform envRec.InitializeBinding(fn, fo).
- For each element dn of the BoundNames of d, do
13.3 Declarations and the Variable Statement
13.3.1 Let and Const Declarations
let and const declarations define variables that are scoped to the let declaration does not have an
Syntax
13.3.1.1 Static Semantics: Early Errors
-
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.
-
It is a Syntax Error if
Initializer is not present and IsConstantDeclaration of theLexicalDeclaration containing thisLexicalBinding istrue .
13.3.1.2 Static Semantics: BoundNames
- Return the BoundNames of
BindingList .
- Let names be the BoundNames of
BindingList . - Append to names the elements of the BoundNames of
LexicalBinding . - Return names.
- Return the BoundNames of
BindingIdentifier .
- Return the BoundNames of
BindingPattern .
13.3.1.3 Static Semantics: IsConstantDeclaration
- Return IsConstantDeclaration of
LetOrConst .
- Return
false .
- Return
true .
13.3.1.4 Runtime Semantics: Evaluation
- Let next be the result of evaluating
BindingList . ReturnIfAbrupt (next).- Return
NormalCompletion (empty ).
- Let next be the result of evaluating
BindingList . ReturnIfAbrupt (next).- Return the result of evaluating
LexicalBinding .
- Let lhs be
ResolveBinding (StringValue ofBindingIdentifier ). - Return
InitializeReferencedBinding (lhs,undefined ).
A static semantics rule ensures that this form of const declaration.
- Let bindingId be StringValue of
BindingIdentifier . - Let lhs be
ResolveBinding (bindingId). - Let rhs be the result of evaluating
Initializer . - Let value be ?
GetValue (rhs). - If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let hasNameProperty be ?
HasOwnProperty (value,"name"). - If hasNameProperty is
false , performSetFunctionName (value, bindingId).
- Let hasNameProperty be ?
- Return
InitializeReferencedBinding (lhs, value).
- Let rhs be the result of evaluating
Initializer . - Let value be ?
GetValue (rhs). - Let env be the
running execution context 's LexicalEnvironment. - Return the result of performing BindingInitialization for
BindingPattern using value and env as the arguments.
13.3.2 Variable Statement
A var statement declares variables that are scoped to the
Syntax
13.3.2.1 Static Semantics: BoundNames
- Let names be BoundNames of
VariableDeclarationList . - Append to names the elements of BoundNames of
VariableDeclaration . - Return names.
- Return the BoundNames of
BindingIdentifier .
- Return the BoundNames of
BindingPattern .
13.3.2.2 Static Semantics: VarDeclaredNames
- Return BoundNames of
VariableDeclarationList .
13.3.2.3 Static Semantics: VarScopedDeclarations
- Return a new
List containingVariableDeclaration .
- Let declarations be VarScopedDeclarations of
VariableDeclarationList . - Append
VariableDeclaration to declarations. - Return declarations.
13.3.2.4 Runtime Semantics: Evaluation
- Let next be the result of evaluating
VariableDeclarationList . ReturnIfAbrupt (next).- Return
NormalCompletion (empty ).
- Let next be the result of evaluating
VariableDeclarationList . ReturnIfAbrupt (next).- Return the result of evaluating
VariableDeclaration .
- Return
NormalCompletion (empty ).
- Let bindingId be StringValue of
BindingIdentifier . - Let lhs be ?
ResolveBinding (bindingId). - Let rhs be the result of evaluating
Initializer . - Let value be ?
GetValue (rhs). - If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let hasNameProperty be ?
HasOwnProperty (value,"name"). - If hasNameProperty is
false , performSetFunctionName (value, bindingId).
- Let hasNameProperty be ?
- Return ?
PutValue (lhs, value).
If a
- Let rhs be the result of evaluating
Initializer . - Let rval be ?
GetValue (rhs). - Return the result of performing BindingInitialization for
BindingPattern passing rval andundefined as arguments.
13.3.3 Destructuring Binding Patterns
Syntax
13.3.3.1 Static Semantics: BoundNames
- Return a new empty
List .
- Return a new empty
List .
- Return the BoundNames of
BindingRestElement .
- Return the BoundNames of
BindingElementList .
- Let names be BoundNames of
BindingElementList . - Append to names the elements of BoundNames of
BindingRestElement . - Return names.
- Let names be BoundNames of
BindingPropertyList . - Append to names the elements of BoundNames of
BindingProperty . - Return names.
- Let names be BoundNames of
BindingElementList . - Append to names the elements of BoundNames of
BindingElisionElement . - Return names.
- Return BoundNames of
BindingElement .
- Return the BoundNames of
BindingElement .
- Return the BoundNames of
BindingIdentifier .
- Return the BoundNames of
BindingPattern .
13.3.3.2 Static Semantics: ContainsExpression
- Return
false .
- Return
false .
- Return ContainsExpression of
BindingRestElement .
- Return ContainsExpression of
BindingElementList .
- Let has be ContainsExpression of
BindingElementList . - If has is
true , returntrue . - Return ContainsExpression of
BindingRestElement .
- Let has be ContainsExpression of
BindingPropertyList . - If has is
true , returntrue . - Return ContainsExpression of
BindingProperty .
- Let has be ContainsExpression of
BindingElementList . - If has is
true , returntrue . - Return ContainsExpression of
BindingElisionElement .
- Return ContainsExpression of
BindingElement .
- Let has be IsComputedPropertyKey of
PropertyName . - If has is
true , returntrue . - Return ContainsExpression of
BindingElement .
- Return
true .
- Return
false .
- Return
true .
- Return
false .
- Return ContainsExpression of
BindingPattern .
13.3.3.3 Static Semantics: HasInitializer
- Return
false .
- Return
true .
- Return
false .
- Return
true .
13.3.3.4 Static Semantics: IsSimpleParameterList
- Return
false .
- Return
false .
- Return
true .
- Return
false .
13.3.3.5 Runtime Semantics: BindingInitialization
With parameters value and environment.
When
- Perform ?
RequireObjectCoercible (value). - Return the result of performing BindingInitialization for
ObjectBindingPattern using value and environment as arguments.
- Let iterator be ?
GetIterator (value). - Let iteratorRecord be
Record {[[Iterator]]: iterator, [[Done]]:false }. - Let result be IteratorBindingInitialization for
ArrayBindingPattern using iteratorRecord and environment as arguments. - If iteratorRecord.[[Done]] is
false , return ?IteratorClose (iterator, result). - Return result.
- Return
NormalCompletion (empty ).
- Let status be the result of performing BindingInitialization for
BindingPropertyList using value and environment as arguments. ReturnIfAbrupt (status).- Return the result of performing BindingInitialization for
BindingProperty using value and environment as arguments.
- Let name be the string that is the only element of BoundNames of
SingleNameBinding . - Return the result of performing KeyedBindingInitialization for
SingleNameBinding using value, environment, and name as the arguments.
- Let P be the result of evaluating
PropertyName . ReturnIfAbrupt (P).- 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.
When
- Return
NormalCompletion (empty ).
- Return the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument.
- If
Elision is present, then- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. ReturnIfAbrupt (status).
- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
- Return the result of performing IteratorBindingInitialization for
BindingRestElement with iteratorRecord and environment as arguments.
- Return the result of performing IteratorBindingInitialization for
BindingElementList with iteratorRecord and environment as arguments.
- Return the result of performing IteratorBindingInitialization for
BindingElementList with iteratorRecord and environment as arguments.
- Let status be the result of performing IteratorBindingInitialization for
BindingElementList with iteratorRecord and environment as arguments. ReturnIfAbrupt (status).- Return the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument.
- Let status be the result of performing IteratorBindingInitialization for
BindingElementList with iteratorRecord and environment as arguments. ReturnIfAbrupt (status).- If
Elision is present, then- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. ReturnIfAbrupt (status).
- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
- Return the result of performing IteratorBindingInitialization for
BindingRestElement with iteratorRecord and environment as arguments.
- Return the result of performing IteratorBindingInitialization for
BindingElisionElement with iteratorRecord and environment as arguments.
- Let status be the result of performing IteratorBindingInitialization for
BindingElementList with iteratorRecord and environment as arguments. ReturnIfAbrupt (status).- Return the result of performing IteratorBindingInitialization for
BindingElisionElement using iteratorRecord and environment as arguments.
- Return the result of performing IteratorBindingInitialization of
BindingElement with iteratorRecord and environment as the arguments.
- Let status be the result of performing IteratorDestructuringAssignmentEvaluation of
Elision with iteratorRecord as the argument. ReturnIfAbrupt (status).- Return the result of performing IteratorBindingInitialization of
BindingElement with iteratorRecord and environment as the arguments.
- Return the result of performing IteratorBindingInitialization for
SingleNameBinding with iteratorRecord and environment as the arguments.
- Let bindingId be StringValue of
BindingIdentifier . - Let lhs be ?
ResolveBinding (bindingId, environment). - If iteratorRecord.[[Done]] is
false , then- Let next be
IteratorStep (iteratorRecord.[[Iterator]]). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue . - Else,
- Let v be
IteratorValue (next). - If v is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (v).
- Let v be
- Let next be
- If iteratorRecord.[[Done]] is
true , let v beundefined . - If
Initializer is present and v isundefined , then- Let defaultValue be the result of evaluating
Initializer . Set v to ?GetValue (defaultValue).- If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let hasNameProperty be ?
HasOwnProperty (v,"name"). - If hasNameProperty is
false , performSetFunctionName (v, bindingId).
- Let hasNameProperty be ?
- Let defaultValue be the result of evaluating
- If environment is
undefined , return ?PutValue (lhs, v). - Return
InitializeReferencedBinding (lhs, v).
- If iteratorRecord.[[Done]] is
false , then- Let next be
IteratorStep (iteratorRecord.[[Iterator]]). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue . - Else,
- Let v be
IteratorValue (next). - If v is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (v).
- Let v be
- Let next be
- If iteratorRecord.[[Done]] is
true , let v beundefined . - If
Initializer is present and v isundefined , then - Return the result of performing BindingInitialization of
BindingPattern with v and environment as the arguments.
- Let lhs be ?
ResolveBinding (StringValue ofBindingIdentifier , environment). - Let A be !
ArrayCreate (0). - Let n be 0.
- Repeat,
- If iteratorRecord.[[Done]] is
false , then- Let next be
IteratorStep (iteratorRecord.[[Iterator]]). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue .
- Let next be
- If iteratorRecord.[[Done]] is
true , then- If environment is
undefined , return ?PutValue (lhs, A). - Return
InitializeReferencedBinding (lhs, A).
- If environment is
- Let nextValue be
IteratorValue (next). - If nextValue is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (nextValue).- Let status be
CreateDataProperty (A, !ToString (n), nextValue). Assert : status istrue .- Increment n by 1.
- If iteratorRecord.[[Done]] is
- Let A be !
ArrayCreate (0). - Let n be 0.
- Repeat,
- If iteratorRecord.[[Done]] is
false , then- Let next be
IteratorStep (iteratorRecord.[[Iterator]]). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue .
- Let next be
- If iteratorRecord.[[Done]] is
true , then- Return the result of performing BindingInitialization of
BindingPattern with A and environment as the arguments.
- Return the result of performing BindingInitialization of
- Let nextValue be
IteratorValue (next). - If nextValue is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (nextValue).- Let status be
CreateDataProperty (A, !ToString (n), nextValue). Assert : status istrue .- Increment n by 1.
- If iteratorRecord.[[Done]] is
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
With parameters value, environment, and propertyName.
When
- Let bindingId be StringValue of
BindingIdentifier . - Let lhs be ?
ResolveBinding (bindingId, environment). - Let v be ?
GetV (value, propertyName). - If
Initializer is present and v isundefined , then- Let defaultValue be the result of evaluating
Initializer . Set v to ?GetValue (defaultValue).- If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let hasNameProperty be ?
HasOwnProperty (v,"name"). - If hasNameProperty is
false , performSetFunctionName (v, bindingId).
- Let hasNameProperty be ?
- Let defaultValue be the result of evaluating
- If environment is
undefined , return ?PutValue (lhs, v). - Return
InitializeReferencedBinding (lhs, v).
13.4 Empty Statement
Syntax
13.4.1 Runtime Semantics: Evaluation
- Return
NormalCompletion (empty ).
13.5 Expression Statement
Syntax
An function or class keywords because that would make it ambiguous with a async function because that would make it ambiguous with an let [ because that would make it ambiguous with a let
13.5.1 Runtime Semantics: Evaluation
- Let exprRef be the result of evaluating
Expression . - Return ?
GetValue (exprRef).
13.6 The if Statement
Syntax
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
-
It is a Syntax Error if
IsLabelledFunction (Statement ) istrue .
It is only necessary to apply this rule if the extension specified in
13.6.2 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Let hasDuplicate be ContainsDuplicateLabels of the first
Statement with argument labelSet. - If hasDuplicate is
true , returntrue . - Return ContainsDuplicateLabels of the second
Statement with argument labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.6.3 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Let hasUndefinedLabels be ContainsUndefinedBreakTarget of the first
Statement with argument labelSet. - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedBreakTarget of the second
Statement with argument labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.6.4 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Let hasUndefinedLabels be ContainsUndefinedContinueTarget of the first
Statement with arguments iterationSet and « ». - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedContinueTarget of the second
Statement with arguments iterationSet and « ».
- Return ContainsUndefinedContinueTarget of
Statement with arguments iterationSet and « ».
13.6.5 Static Semantics: VarDeclaredNames
- Let names be VarDeclaredNames of the first
Statement . - Append to names the elements of the VarDeclaredNames of the second
Statement . - Return names.
- Return the VarDeclaredNames of
Statement .
13.6.6 Static Semantics: VarScopedDeclarations
- Let declarations be VarScopedDeclarations of the first
Statement . - Append to declarations the elements of the VarScopedDeclarations of the second
Statement . - Return declarations.
- Return the VarScopedDeclarations of
Statement .
13.6.7 Runtime Semantics: Evaluation
- Let exprRef be the result of evaluating
Expression . - Let exprValue be
ToBoolean (?GetValue (exprRef)). - If exprValue is
true , then- Let stmtCompletion be the result of evaluating the first
Statement .
- Let stmtCompletion be the result of evaluating the first
- Else,
- Let stmtCompletion be the result of evaluating the second
Statement .
- Let stmtCompletion be the result of evaluating the second
- Return
Completion (UpdateEmpty (stmtCompletion,undefined )).
- Let exprRef be the result of evaluating
Expression . - Let exprValue be
ToBoolean (?GetValue (exprRef)). - If exprValue is
false , then- Return
NormalCompletion (undefined ).
- Return
- Else,
- Let stmtCompletion be the result of evaluating
Statement . - Return
Completion (UpdateEmpty (stmtCompletion,undefined )).
- Let stmtCompletion be the result of evaluating
13.7 Iteration Statements
Syntax
This section is extended by Annex
13.7.1 Semantics
13.7.1.1 Static Semantics: Early Errors
-
It is a Syntax Error if
IsLabelledFunction (Statement ) istrue .
It is only necessary to apply this rule if the extension specified in
13.7.1.2 Runtime Semantics: LoopContinues ( completion, labelSet )
The abstract operation LoopContinues with arguments completion and labelSet is defined by the following steps:
- If completion.[[Type]] is
normal , returntrue . - If completion.[[Type]] is not
continue , returnfalse . - If completion.[[Target]] is
empty , returntrue . - If completion.[[Target]] is an element of labelSet, return
true . - Return
false .
Within the
13.7.2 The do-while Statement
13.7.2.1 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.7.2.2 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.7.2.3 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Return ContainsUndefinedContinueTarget of
Statement with arguments iterationSet and « ».
13.7.2.4 Static Semantics: VarDeclaredNames
- Return the VarDeclaredNames of
Statement .
13.7.2.5 Static Semantics: VarScopedDeclarations
- Return the VarScopedDeclarations of
Statement .
13.7.2.6 Runtime Semantics: LabelledEvaluation
With parameter labelSet.
- Let V be
undefined . - Repeat,
- Let stmtResult be the result of evaluating
Statement . - If
LoopContinues (stmtResult, labelSet) isfalse , returnCompletion (UpdateEmpty (stmtResult, V)). - If stmtResult.[[Value]] is not
empty , set V to stmtResult.[[Value]]. - Let exprRef be the result of evaluating
Expression . - Let exprValue be ?
GetValue (exprRef). - If
ToBoolean (exprValue) isfalse , returnNormalCompletion (V).
- Let stmtResult be the result of evaluating
13.7.3 The while Statement
13.7.3.1 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.7.3.2 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.7.3.3 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Return ContainsUndefinedContinueTarget of
Statement with arguments iterationSet and « ».
13.7.3.4 Static Semantics: VarDeclaredNames
- Return the VarDeclaredNames of
Statement .
13.7.3.5 Static Semantics: VarScopedDeclarations
- Return the VarScopedDeclarations of
Statement .
13.7.3.6 Runtime Semantics: LabelledEvaluation
With parameter labelSet.
- Let V be
undefined . - Repeat,
- Let exprRef be the result of evaluating
Expression . - Let exprValue be ?
GetValue (exprRef). - If
ToBoolean (exprValue) isfalse , returnNormalCompletion (V). - Let stmtResult be the result of evaluating
Statement . - If
LoopContinues (stmtResult, labelSet) isfalse , returnCompletion (UpdateEmpty (stmtResult, V)). - If stmtResult.[[Value]] is not
empty , set V to stmtResult.[[Value]].
- Let exprRef be the result of evaluating
13.7.4 The for Statement
13.7.4.1 Static Semantics: Early Errors
-
It is a Syntax Error if any element of the BoundNames of
LexicalDeclaration also occurs in the VarDeclaredNames ofStatement .
13.7.4.2 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.7.4.3 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.7.4.4 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Return ContainsUndefinedContinueTarget of
Statement with arguments iterationSet and « ».
13.7.4.5 Static Semantics: VarDeclaredNames
- Return the VarDeclaredNames of
Statement .
- Let names be BoundNames of
VariableDeclarationList . - Append to names the elements of the VarDeclaredNames of
Statement . - Return names.
- Return the VarDeclaredNames of
Statement .
13.7.4.6 Static Semantics: VarScopedDeclarations
- Return the VarScopedDeclarations of
Statement .
- Let declarations be VarScopedDeclarations of
VariableDeclarationList . - Append to declarations the elements of the VarScopedDeclarations of
Statement . - Return declarations.
- Return the VarScopedDeclarations of
Statement .
13.7.4.7 Runtime Semantics: LabelledEvaluation
With parameter labelSet.
- If the first
Expression is present, then- Let exprRef be the result of evaluating the first
Expression . - Perform ?
GetValue (exprRef).
- Let exprRef be the result of evaluating the first
- Return ?
ForBodyEvaluation (the secondExpression , the thirdExpression ,Statement , « », labelSet).
- Let varDcl be the result of evaluating
VariableDeclarationList . ReturnIfAbrupt (varDcl).- Return ?
ForBodyEvaluation (the firstExpression , the secondExpression ,Statement , « », labelSet).
- Let oldEnv be the
running execution context 's LexicalEnvironment. - Let loopEnv be
NewDeclarativeEnvironment (oldEnv). - Let loopEnvRec be loopEnv's
EnvironmentRecord . - Let isConst be the result of performing IsConstantDeclaration of
LexicalDeclaration . - Let boundNames be the BoundNames of
LexicalDeclaration . - For each element dn of boundNames, do
- If isConst is
true , then- Perform ! loopEnvRec.CreateImmutableBinding(dn,
true ).
- Perform ! loopEnvRec.CreateImmutableBinding(dn,
- Else,
- Perform ! loopEnvRec.CreateMutableBinding(dn,
false ).
- Perform ! loopEnvRec.CreateMutableBinding(dn,
- If isConst is
Set therunning execution context 's LexicalEnvironment to loopEnv.- Let forDcl be the result of evaluating
LexicalDeclaration . - If forDcl is an
abrupt completion , thenSet therunning execution context 's LexicalEnvironment to oldEnv.- Return
Completion (forDcl).
- If isConst is
false , let perIterationLets be boundNames; otherwise let perIterationLets be « ». - Let bodyResult be
ForBodyEvaluation (the firstExpression , the secondExpression ,Statement , perIterationLets, labelSet). Set therunning execution context 's LexicalEnvironment to oldEnv.- 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:
- Let V be
undefined . - Perform ?
CreatePerIterationEnvironment (perIterationBindings). - Repeat,
- If test is not
[empty] , then- Let testRef be the result of evaluating test.
- Let testValue be ?
GetValue (testRef). - If
ToBoolean (testValue) isfalse , returnNormalCompletion (V).
- Let result be the result of evaluating stmt.
- If
LoopContinues (result, labelSet) isfalse , returnCompletion (UpdateEmpty (result, V)). - If result.[[Value]] is not
empty , set V to result.[[Value]]. - Perform ?
CreatePerIterationEnvironment (perIterationBindings). - If increment is not
[empty] , then- Let incRef be the result of evaluating increment.
- Perform ?
GetValue (incRef).
- If test is not
13.7.4.9 Runtime Semantics: CreatePerIterationEnvironment( perIterationBindings )
The abstract operation CreatePerIterationEnvironment with argument perIterationBindings is performed as follows:
- If perIterationBindings has any elements, then
- Let lastIterationEnv be the
running execution context 's LexicalEnvironment. - Let lastIterationEnvRec be lastIterationEnv's
EnvironmentRecord . - Let outer be lastIterationEnv's outer environment reference.
Assert : outer is notnull .- Let thisIterationEnv be
NewDeclarativeEnvironment (outer). - Let thisIterationEnvRec be thisIterationEnv's
EnvironmentRecord . - For each element bn of perIterationBindings, do
- Perform ! thisIterationEnvRec.CreateMutableBinding(bn,
false ). - Let lastValue be ? lastIterationEnvRec.GetBindingValue(bn,
true ). - Perform thisIterationEnvRec.InitializeBinding(bn, lastValue).
- Perform ! thisIterationEnvRec.CreateMutableBinding(bn,
Set therunning execution context 's LexicalEnvironment to thisIterationEnv.
- Let lastIterationEnv be the
- Return
undefined .
13.7.5 The for-in and for-of Statements
13.7.5.1 Static Semantics: Early Errors
-
It is a Syntax Error if
LeftHandSideExpression is either anObjectLiteral or anArrayLiteral and if the lexical token sequence matched byLeftHandSideExpression cannot be parsed with no tokens left over usingAssignmentPattern as thegoal symbol .
If
-
It is a Syntax Error if IsValidSimpleAssignmentTarget of
LeftHandSideExpression isfalse . -
It is a Syntax Error if the
LeftHandSideExpression is andCoverParenthesizedExpressionAndArrowParameterList : ( Expression ) Expression derives a phrase that would produce a Syntax Error according to these rules if that phrase were substituted forLeftHandSideExpression . This rule is recursively applied.
The last rule means that the other rules are applied even if parentheses surround
-
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 ofStatement . -
It is a Syntax Error if the BoundNames of
ForDeclaration contains any duplicate entries.
13.7.5.2 Static Semantics: BoundNames
- Return the BoundNames of
ForBinding .
13.7.5.3 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
This section is extended by Annex
13.7.5.4 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
This section is extended by Annex
13.7.5.5 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Return ContainsUndefinedContinueTarget of
Statement with arguments iterationSet and « ».
This section is extended by Annex
13.7.5.6 Static Semantics: IsDestructuring
- Return IsDestructuring of
ForBinding .
- Return
false .
- Return
true .
This section is extended by Annex
13.7.5.7 Static Semantics: VarDeclaredNames
- Return the VarDeclaredNames of
Statement .
- Let names be the BoundNames of
ForBinding . - Append to names the elements of the VarDeclaredNames of
Statement . - Return names.
- Return the VarDeclaredNames of
Statement .
- Return the VarDeclaredNames of
Statement .
- Let names be the BoundNames of
ForBinding . - Append to names the elements of the VarDeclaredNames of
Statement . - Return names.
- Return the VarDeclaredNames of
Statement .
This section is extended by Annex
13.7.5.8 Static Semantics: VarScopedDeclarations
- Return the VarScopedDeclarations of
Statement .
- Let declarations be a
List containingForBinding . - Append to declarations the elements of the VarScopedDeclarations of
Statement . - Return declarations.
- Return the VarScopedDeclarations of
Statement .
- Return the VarScopedDeclarations of
Statement .
- Let declarations be a
List containingForBinding . - Append to declarations the elements of the VarScopedDeclarations of
Statement . - Return declarations.
- Return the VarScopedDeclarations of
Statement .
This section is extended by Annex
13.7.5.9 Runtime Semantics: BindingInitialization
With parameters value and environment.
var statements and the formal parameter lists of some non-strict functions (see
- Return the result of performing BindingInitialization for
ForBinding passing value and environment as the arguments.
13.7.5.10 Runtime Semantics: BindingInstantiation
With parameter environment.
- Let envRec be environment's
EnvironmentRecord . Assert : envRec is a declarativeEnvironment Record .- For each element name of the BoundNames of
ForBinding , do- If IsConstantDeclaration of
LetOrConst istrue , then- Perform ! envRec.CreateImmutableBinding(name,
true ).
- Perform ! envRec.CreateImmutableBinding(name,
- Else,
- Perform ! envRec.CreateMutableBinding(name,
false ).
- Perform ! envRec.CreateMutableBinding(name,
- If IsConstantDeclaration of
13.7.5.11 Runtime Semantics: LabelledEvaluation
With parameter labelSet.
- Let keyResult be ?
ForIn/OfHeadEvaluation (« »,Expression ,enumerate ). - Return ?
ForIn/OfBodyEvaluation (LeftHandSideExpression ,Statement , keyResult,enumerate ,assignment , labelSet).
- Let keyResult be ?
ForIn/OfHeadEvaluation (« »,Expression ,enumerate ). - Return ?
ForIn/OfBodyEvaluation (ForBinding ,Statement , keyResult,enumerate ,varBinding , labelSet).
- Let keyResult be the result of performing ?
ForIn/OfHeadEvaluation (BoundNames ofForDeclaration ,Expression ,enumerate ). - Return ?
ForIn/OfBodyEvaluation (ForDeclaration ,Statement , keyResult,enumerate ,lexicalBinding , labelSet).
- Let keyResult be the result of performing ?
ForIn/OfHeadEvaluation (« »,AssignmentExpression ,iterate ). - Return ?
ForIn/OfBodyEvaluation (LeftHandSideExpression ,Statement , keyResult,iterate ,assignment , labelSet).
- Let keyResult be the result of performing ?
ForIn/OfHeadEvaluation (« »,AssignmentExpression ,iterate ). - Return ?
ForIn/OfBodyEvaluation (ForBinding ,Statement , keyResult,iterate ,varBinding , labelSet).
- Let keyResult be the result of performing ?
ForIn/OfHeadEvaluation (BoundNames ofForDeclaration ,AssignmentExpression ,iterate ). - Return ?
ForIn/OfBodyEvaluation (ForDeclaration ,Statement , keyResult,iterate ,lexicalBinding , labelSet).
This section is extended by Annex
13.7.5.12 Runtime Semantics: ForIn/OfHeadEvaluation ( TDZnames, expr, iterationKind )
The abstract operation ForIn/OfHeadEvaluation is called with arguments TDZnames, expr, and iterationKind. The value of iterationKind is either
- Let oldEnv be the
running execution context 's LexicalEnvironment. - If TDZnames is not an empty
List , thenAssert : TDZnames has no duplicate entries.- Let TDZ be
NewDeclarativeEnvironment (oldEnv). - Let TDZEnvRec be TDZ's
EnvironmentRecord . - For each string name in TDZnames, do
- Perform ! TDZEnvRec.CreateMutableBinding(name,
false ).
- Perform ! TDZEnvRec.CreateMutableBinding(name,
Set therunning execution context 's LexicalEnvironment to TDZ.
- Let exprRef be the result of evaluating expr.
Set therunning execution context 's LexicalEnvironment to oldEnv.- Let exprValue be ?
GetValue (exprRef). - If iterationKind is
enumerate , then- If exprValue is
undefined ornull , then- Return
Completion {[[Type]]:break , [[Value]]:empty , [[Target]]:empty }.
- Return
- Let obj be !
ToObject (exprValue). - Return ?
EnumerateObjectProperties (obj).
- If exprValue is
- Else,
Assert : iterationKind isiterate .- Return ?
GetIterator (exprValue).
13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation ( lhs, stmt, iterator, iterationKind, lhsKind, labelSet )
The abstract operation ForIn/OfBodyEvaluation is called with arguments lhs, stmt, iterator, iterationKind, lhsKind, and labelSet. The value of iterationKind is either
- Let oldEnv be the
running execution context 's LexicalEnvironment. - Let V be
undefined . - Let destructuring be IsDestructuring of lhs.
- If destructuring is
true and if lhsKind isassignment , thenAssert : lhs is aLeftHandSideExpression .- Let assignmentPattern be the parse of the source text corresponding to lhs using
AssignmentPattern as thegoal symbol .
- Repeat,
- Let nextResult be ?
IteratorStep (iterator). - If nextResult is
false , returnNormalCompletion (V). - Let nextValue be ?
IteratorValue (nextResult). - If lhsKind is either
assignment orvarBinding , then- If destructuring is
false , then- Let lhsRef be the result of evaluating lhs. (It may be evaluated repeatedly.)
- If destructuring is
- Else,
Assert : lhsKind islexicalBinding .Assert : lhs is aForDeclaration .- Let iterationEnv be
NewDeclarativeEnvironment (oldEnv). - Perform BindingInstantiation for lhs passing iterationEnv as the argument.
Set therunning execution context 's LexicalEnvironment to iterationEnv.- If destructuring is
false , thenAssert : lhs binds a single name.- Let lhsName be the sole element of BoundNames of lhs.
- Let lhsRef be !
ResolveBinding (lhsName).
- If destructuring is
false , then- If lhsRef is an
abrupt completion , then- Let status be lhsRef.
- Else if lhsKind is
lexicalBinding , then- Let status be
InitializeReferencedBinding (lhsRef, nextValue).
- Let status be
- Else,
- Let status be
PutValue (lhsRef, nextValue).
- Let status be
- If lhsRef is an
- Else,
- If lhsKind is
assignment , then- Let status be the result of performing DestructuringAssignmentEvaluation of assignmentPattern using nextValue as the argument.
- Else if lhsKind is
varBinding , thenAssert : lhs is aForBinding .- Let status be the result of performing BindingInitialization for lhs passing nextValue and
undefined as the arguments.
- Else,
- If lhsKind is
- If status is an
abrupt completion , thenSet therunning execution context 's LexicalEnvironment to oldEnv.- If iterationKind is
enumerate , then- Return status.
- Else,
Assert : iterationKind isiterate .- Return ?
IteratorClose (iterator, status).
- Let result be the result of evaluating stmt.
Set therunning execution context 's LexicalEnvironment to oldEnv.- If
LoopContinues (result, labelSet) isfalse , then- If iterationKind is
enumerate , then- Return
Completion (UpdateEmpty (result, V)).
- Return
- Else,
Assert : iterationKind isiterate .- Return ?
IteratorClose (iterator,UpdateEmpty (result, V)).
- If iterationKind is
- If result.[[Value]] is not
empty , set V to result.[[Value]].
- Let nextResult be ?
13.7.5.14 Runtime Semantics: Evaluation
- Let bindingId be StringValue of
BindingIdentifier . - Return ?
ResolveBinding (bindingId).
13.7.5.15 EnumerateObjectProperties ( O )
When the abstract operation EnumerateObjectProperties is called with argument O, the following steps are taken:
Assert :Type (O) is Object.- Return an Iterator object (
25.1.1.2 ) whosenextmethod iterates over all the String-valued keys of enumerable properties of O. The iterator object is never directly accessible to ECMAScript code. The mechanics and order of enumerating the properties is not specified but must conform to the rules specified below.
The iterator's throw and return methods are next method processes object properties to determine whether the property key should be returned as an iterator value. Returned property keys do not include keys that are Symbols. Properties of the target object may be deleted during enumeration. A property that is deleted before it is processed by the iterator's next method is ignored. If new properties are added to the target object during enumeration, the newly added properties are not guaranteed to be processed in the active enumeration. A property name will be returned by the iterator's next method at most once in any enumeration.
Enumerating the properties of the target object includes enumerating properties of its prototype, and the prototype of the prototype, and so on, recursively; but a property of a prototype is not processed if it has the same name as a property that has already been processed by the iterator's next method. The values of [[Enumerable]] attributes are not considered when determining if a property of a prototype object has already been processed. The enumerable property names of prototype objects must be obtained by invoking EnumerateObjectProperties passing the prototype object as the argument. EnumerateObjectProperties must obtain the own property keys of the target object by calling its [[OwnPropertyKeys]] internal method. Property attributes of the target object must be obtained by calling its [[GetOwnProperty]] internal method.
The following is an informative definition of an ECMAScript generator function that conforms to these rules:
function* EnumerateObjectProperties(obj) {
const visited = new Set();
for (const key of Reflect.ownKeys(obj)) {
if (typeof key === "symbol") continue;
const desc = Reflect.getOwnPropertyDescriptor(obj, key);
if (desc && !visited.has(key)) {
visited.add(key);
if (desc.enumerable) yield key;
}
}
const proto = Reflect.getPrototypeOf(obj);
if (proto === null) return;
for (const protoKey of EnumerateObjectProperties(proto)) {
if (!visited.has(protoKey)) yield protoKey;
}
}
13.8 The continue Statement
Syntax
13.8.1 Static Semantics: Early Errors
-
It is a Syntax Error if this
ContinueStatement is not nested, directly or indirectly (but not crossing function boundaries), within anIterationStatement .
13.8.2 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Return
false .
- If the StringValue of
LabelIdentifier is not an element of iterationSet, returntrue . - Return
false .
13.8.3 Runtime Semantics: Evaluation
- Return
Completion {[[Type]]:continue , [[Value]]:empty , [[Target]]:empty }.
- Let label be the StringValue of
LabelIdentifier . - Return
Completion {[[Type]]:continue , [[Value]]:empty , [[Target]]: label }.
13.9 The break Statement
Syntax
13.9.1 Static Semantics: Early Errors
-
It is a Syntax Error if this
BreakStatement is not nested, directly or indirectly (but not crossing function boundaries), within anIterationStatement or aSwitchStatement .
13.9.2 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Return
false .
- If the StringValue of
LabelIdentifier is not an element of labelSet, returntrue . - Return
false .
13.9.3 Runtime Semantics: Evaluation
- Return
Completion {[[Type]]:break , [[Value]]:empty , [[Target]]:empty }.
- Let label be the StringValue of
LabelIdentifier . - Return
Completion {[[Type]]:break , [[Value]]:empty , [[Target]]: label }.
13.10 The return Statement
Syntax
A return statement causes a function to cease execution and return a value to the caller. If
13.10.1 Runtime Semantics: Evaluation
- Return
Completion {[[Type]]:return , [[Value]]:undefined , [[Target]]:empty }.
- Let exprRef be the result of evaluating
Expression . - Let exprValue be ?
GetValue (exprRef). - Return
Completion {[[Type]]:return , [[Value]]: exprValue, [[Target]]:empty }.
13.11 The with Statement
Syntax
The with statement adds an object
13.11.1 Static Semantics: Early Errors
-
It is a Syntax Error if the code that matches this production is contained in
strict mode code . -
It is a Syntax Error if
IsLabelledFunction (Statement ) istrue .
It is only necessary to apply the second rule if the extension specified in
13.11.2 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.11.3 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.11.4 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Return ContainsUndefinedContinueTarget of
Statement with arguments iterationSet and « ».
13.11.5 Static Semantics: VarDeclaredNames
- Return the VarDeclaredNames of
Statement .
13.11.6 Static Semantics: VarScopedDeclarations
- Return the VarScopedDeclarations of
Statement .
13.11.7 Runtime Semantics: Evaluation
- Let val be the result of evaluating
Expression . - Let obj be ?
ToObject (?GetValue (val)). - Let oldEnv be the
running execution context 's LexicalEnvironment. - Let newEnv be
NewObjectEnvironment (obj, oldEnv). Set the withEnvironment flag of newEnv'sEnvironmentRecord totrue .Set therunning execution context 's LexicalEnvironment to newEnv.- Let C be the result of evaluating
Statement . Set therunning execution context 's LexicalEnvironment to oldEnv.- Return
Completion (UpdateEmpty (C,undefined )).
No matter how control leaves the embedded
13.12 The switch Statement
Syntax
13.12.1 Static Semantics: Early Errors
-
It is a Syntax Error if the LexicallyDeclaredNames of
CaseBlock contains any duplicate entries. -
It is a Syntax Error if any element of the LexicallyDeclaredNames of
CaseBlock also occurs in the VarDeclaredNames ofCaseBlock .
13.12.2 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Return ContainsDuplicateLabels of
CaseBlock with argument labelSet.
- Return
false .
- If the first
CaseClauses is present, then- Let hasDuplicates be ContainsDuplicateLabels of the first
CaseClauses with argument labelSet. - If hasDuplicates is
true , returntrue .
- Let hasDuplicates be ContainsDuplicateLabels of the first
- Let hasDuplicates be ContainsDuplicateLabels of
DefaultClause with argument labelSet. - If hasDuplicates is
true , returntrue . - If the second
CaseClauses is not present, returnfalse . - Return ContainsDuplicateLabels of the second
CaseClauses with argument labelSet.
- Let hasDuplicates be ContainsDuplicateLabels of
CaseClauses with argument labelSet. - If hasDuplicates is
true , returntrue . - Return ContainsDuplicateLabels of
CaseClause with argument labelSet.
- If the
StatementList is present, return ContainsDuplicateLabels ofStatementList with argument labelSet. - Return
false .
- If the
StatementList is present, return ContainsDuplicateLabels ofStatementList with argument labelSet. - Return
false .
13.12.3 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Return ContainsUndefinedBreakTarget of
CaseBlock with argument labelSet.
- Return
false .
- If the first
CaseClauses is present, then- Let hasUndefinedLabels be ContainsUndefinedBreakTarget of the first
CaseClauses with argument labelSet. - If hasUndefinedLabels is
true , returntrue .
- Let hasUndefinedLabels be ContainsUndefinedBreakTarget of the first
- Let hasUndefinedLabels be ContainsUndefinedBreakTarget of
DefaultClause with argument labelSet. - If hasUndefinedLabels is
true , returntrue . - If the second
CaseClauses is not present, returnfalse . - Return ContainsUndefinedBreakTarget of the second
CaseClauses with argument labelSet.
- Let hasUndefinedLabels be ContainsUndefinedBreakTarget of
CaseClauses with argument labelSet. - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedBreakTarget of
CaseClause with argument labelSet.
- If the
StatementList is present, return ContainsUndefinedBreakTarget ofStatementList with argument labelSet. - Return
false .
- If the
StatementList is present, return ContainsUndefinedBreakTarget ofStatementList with argument labelSet. - Return
false .
13.12.4 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Return ContainsUndefinedContinueTarget of
CaseBlock with arguments iterationSet and « ».
- Return
false .
- If the first
CaseClauses is present, then- Let hasUndefinedLabels be ContainsUndefinedContinueTarget of the first
CaseClauses with arguments iterationSet and « ». - If hasUndefinedLabels is
true , returntrue .
- Let hasUndefinedLabels be ContainsUndefinedContinueTarget of the first
- Let hasUndefinedLabels be ContainsUndefinedContinueTarget of
DefaultClause with arguments iterationSet and « ». - If hasUndefinedLabels is
true , returntrue . - If the second
CaseClauses is not present, returnfalse . - Return ContainsUndefinedContinueTarget of the second
CaseClauses with arguments iterationSet and « ».
- Let hasUndefinedLabels be ContainsUndefinedContinueTarget of
CaseClauses with arguments iterationSet and « ». - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedContinueTarget of
CaseClause with arguments iterationSet and « ».
- If the
StatementList is present, return ContainsUndefinedContinueTarget ofStatementList with arguments iterationSet and « ». - Return
false .
- If the
StatementList is present, return ContainsUndefinedContinueTarget ofStatementList with arguments iterationSet and « ». - Return
false .
13.12.5 Static Semantics: LexicallyDeclaredNames
- Return a new empty
List .
- If the first
CaseClauses is present, let names be the LexicallyDeclaredNames of the firstCaseClauses . - Else, let names be a new empty
List . - Append to names the elements of the LexicallyDeclaredNames of the
DefaultClause . - If the second
CaseClauses is not present, return names. - Return the result of appending to names the elements of the LexicallyDeclaredNames of the second
CaseClauses .
- Let names be LexicallyDeclaredNames of
CaseClauses . - Append to names the elements of the LexicallyDeclaredNames of
CaseClause . - Return names.
- If the
StatementList is present, return the LexicallyDeclaredNames ofStatementList . - Return a new empty
List .
- If the
StatementList is present, return the LexicallyDeclaredNames ofStatementList . - Return a new empty
List .
13.12.6 Static Semantics: LexicallyScopedDeclarations
- Return a new empty
List .
- If the first
CaseClauses is present, let declarations be the LexicallyScopedDeclarations of the firstCaseClauses . - Else, let declarations be a new empty
List . - Append to declarations the elements of the LexicallyScopedDeclarations of the
DefaultClause . - If the second
CaseClauses is not present, return declarations. - Return the result of appending to declarations the elements of the LexicallyScopedDeclarations of the second
CaseClauses .
- Let declarations be LexicallyScopedDeclarations of
CaseClauses . - Append to declarations the elements of the LexicallyScopedDeclarations of
CaseClause . - Return declarations.
- If the
StatementList is present, return the LexicallyScopedDeclarations ofStatementList . - Return a new empty
List .
- If the
StatementList is present, return the LexicallyScopedDeclarations ofStatementList . - Return a new empty
List .
13.12.7 Static Semantics: VarDeclaredNames
- Return the VarDeclaredNames of
CaseBlock .
- Return a new empty
List .
- If the first
CaseClauses is present, let names be the VarDeclaredNames of the firstCaseClauses . - Else, let names be a new empty
List . - Append to names the elements of the VarDeclaredNames of the
DefaultClause . - If the second
CaseClauses is not present, return names. - Return the result of appending to names the elements of the VarDeclaredNames of the second
CaseClauses .
- Let names be VarDeclaredNames of
CaseClauses . - Append to names the elements of the VarDeclaredNames of
CaseClause . - Return names.
- If the
StatementList is present, return the VarDeclaredNames ofStatementList . - Return a new empty
List .
- If the
StatementList is present, return the VarDeclaredNames ofStatementList . - Return a new empty
List .
13.12.8 Static Semantics: VarScopedDeclarations
- Return the VarScopedDeclarations of
CaseBlock .
- Return a new empty
List .
- If the first
CaseClauses is present, let declarations be the VarScopedDeclarations of the firstCaseClauses . - Else, let declarations be a new empty
List . - Append to declarations the elements of the VarScopedDeclarations of the
DefaultClause . - If the second
CaseClauses is not present, return declarations. - Return the result of appending to declarations the elements of the VarScopedDeclarations of the second
CaseClauses .
- Let declarations be VarScopedDeclarations of
CaseClauses . - Append to declarations the elements of the VarScopedDeclarations of
CaseClause . - Return declarations.
- If the
StatementList is present, return the VarScopedDeclarations ofStatementList . - Return a new empty
List .
- If the
StatementList is present, return the VarScopedDeclarations ofStatementList . - Return a new empty
List .
13.12.9 Runtime Semantics: CaseBlockEvaluation
With parameter input.
- Return
NormalCompletion (undefined ).
- Let V be
undefined . - Let A be the
List ofCaseClause items inCaseClauses , in source text order. - Let found be
false . - For each
CaseClause C in A, do- If found is
false , then- Let clauseSelector be the result of CaseSelectorEvaluation of C.
ReturnIfAbrupt (clauseSelector).Set found to the result of performingStrict Equality Comparison input === clauseSelector.
- If found is
true , then- Let R be the result of evaluating C.
- If R.[[Value]] is not
empty , set V to R.[[Value]]. - If R is an
abrupt completion , returnCompletion (UpdateEmpty (R, V)).
- If found is
- Return
NormalCompletion (V).
- Let V be
undefined . - If the first
CaseClauses is present, then- Let A be the
List ofCaseClause items in the firstCaseClauses , in source text order.
- Let A be the
- Else,
- Let A be « ».
- Let found be
false . - For each
CaseClause C in A, do- If found is
false , then- Let clauseSelector be the result of CaseSelectorEvaluation of C.
ReturnIfAbrupt (clauseSelector).Set found to the result of performingStrict Equality Comparison input === clauseSelector.
- If found is
true , then- Let R be the result of evaluating C.
- If R.[[Value]] is not
empty , set V to R.[[Value]]. - If R is an
abrupt completion , returnCompletion (UpdateEmpty (R, V)).
- If found is
- Let foundInB be
false . - If the second
CaseClauses is present, then- Let B be the
List ofCaseClause items in the secondCaseClauses , in source text order.
- Let B be the
- Else,
- Let B be « ».
- If found is
false , then- For each
CaseClause C in B, do- If foundInB is
false , then- Let clauseSelector be the result of CaseSelectorEvaluation of C.
ReturnIfAbrupt (clauseSelector).Set foundInB to the result of performingStrict Equality Comparison input === clauseSelector.
- If foundInB is
true , then- Let R be the result of evaluating
CaseClause C. - If R.[[Value]] is not
empty , set V to R.[[Value]]. - If R is an
abrupt completion , returnCompletion (UpdateEmpty (R, V)).
- Let R be the result of evaluating
- If foundInB is
- For each
- If foundInB is
true , returnNormalCompletion (V). - Let R be the result of evaluating
DefaultClause . - If R.[[Value]] is not
empty , set V to R.[[Value]]. - If R is an
abrupt completion , returnCompletion (UpdateEmpty (R, V)). - For each
CaseClause C in B (NOTE: this is another complete iteration of the secondCaseClauses ), do- Let R be the result of evaluating
CaseClause C. - If R.[[Value]] is not
empty , set V to R.[[Value]]. - If R is an
abrupt completion , returnCompletion (UpdateEmpty (R, V)).
- Let R be the result of evaluating
- Return
NormalCompletion (V).
13.12.10 Runtime Semantics: CaseSelectorEvaluation
- Let exprRef be the result of evaluating
Expression . - Return ?
GetValue (exprRef).
CaseSelectorEvaluation does not execute the associated
13.12.11 Runtime Semantics: Evaluation
- Let exprRef be the result of evaluating
Expression . - Let switchValue be ?
GetValue (exprRef). - Let oldEnv be the
running execution context 's LexicalEnvironment. - Let blockEnv be
NewDeclarativeEnvironment (oldEnv). - Perform
BlockDeclarationInstantiation (CaseBlock , blockEnv). Set therunning execution context 's LexicalEnvironment to blockEnv.- Let R be the result of performing CaseBlockEvaluation of
CaseBlock with argument switchValue. Set therunning execution context 's LexicalEnvironment to oldEnv.- Return R.
No matter how control leaves the
- Return
NormalCompletion (empty ).
- Return the result of evaluating
StatementList .
- Return
NormalCompletion (empty ).
- Return the result of evaluating
StatementList .
13.13 Labelled Statements
Syntax
A break and continue statements. ECMAScript has no goto statement. A
13.13.1 Static Semantics: Early Errors
- It is a Syntax Error if any source text matches this rule.
An alternative definition for this rule is provided in
13.13.2 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Let label be the StringValue of
LabelIdentifier . - If label is an element of labelSet, return
true . - Let newLabelSet be a copy of labelSet with label appended.
- Return ContainsDuplicateLabels of
LabelledItem with argument newLabelSet.
- Return
false .
13.13.3 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Let label be the StringValue of
LabelIdentifier . - Let newLabelSet be a copy of labelSet with label appended.
- Return ContainsUndefinedBreakTarget of
LabelledItem with argument newLabelSet.
- Return
false .
13.13.4 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Let label be the StringValue of
LabelIdentifier . - Let newLabelSet be a copy of labelSet with label appended.
- Return ContainsUndefinedContinueTarget of
LabelledItem with arguments iterationSet and newLabelSet.
- Return
false .
13.13.5 Static Semantics: IsLabelledFunction ( stmt )
The abstract operation IsLabelledFunction with argument stmt performs the following steps:
- If stmt is not a
LabelledStatement , returnfalse . - Let item be the
LabelledItem of stmt. - If item is
, returnLabelledItem : FunctionDeclaration true . - Let subStmt be the
Statement of item. - Return IsLabelledFunction(subStmt).
13.13.6 Static Semantics: LexicallyDeclaredNames
- Return the LexicallyDeclaredNames of
LabelledItem .
- Return a new empty
List .
- Return BoundNames of
FunctionDeclaration .
13.13.7 Static Semantics: LexicallyScopedDeclarations
13.13.8 Static Semantics: TopLevelLexicallyDeclaredNames
13.13.9 Static Semantics: TopLevelLexicallyScopedDeclarations
13.13.10 Static Semantics: TopLevelVarDeclaredNames
- Return the TopLevelVarDeclaredNames of
LabelledItem .
- If
Statement is , return TopLevelVarDeclaredNames ofStatement : LabelledStatement Statement . - Return VarDeclaredNames of
Statement .
- Return BoundNames of
FunctionDeclaration .
13.13.11 Static Semantics: TopLevelVarScopedDeclarations
- Return the TopLevelVarScopedDeclarations of
LabelledItem .
- If
Statement is , return TopLevelVarScopedDeclarations ofStatement : LabelledStatement Statement . - Return VarScopedDeclarations of
Statement .
- Return a new
List containingFunctionDeclaration .
13.13.12 Static Semantics: VarDeclaredNames
- Return the VarDeclaredNames of
LabelledItem .
- Return a new empty
List .
13.13.13 Static Semantics: VarScopedDeclarations
- Return the VarScopedDeclarations of
LabelledItem .
- Return a new empty
List .
13.13.14 Runtime Semantics: LabelledEvaluation
With parameter labelSet.
- Let label be the StringValue of
LabelIdentifier . - Append label as an element of labelSet.
- Let stmtResult be LabelledEvaluation of
LabelledItem with argument labelSet. - If stmtResult.[[Type]] is
break andSameValue (stmtResult.[[Target]], label) istrue , thenSet stmtResult toNormalCompletion (stmtResult.[[Value]]).
- Return
Completion (stmtResult).
- If
Statement is either aLabelledStatement or aBreakableStatement , then- Return LabelledEvaluation of
Statement with argument labelSet.
- Return LabelledEvaluation of
- Else,
- Return the result of evaluating
Statement .
- Return the result of evaluating
- Return the result of evaluating
FunctionDeclaration .
13.13.15 Runtime Semantics: Evaluation
- Let newLabelSet be a new empty
List . - Return LabelledEvaluation of this
LabelledStatement with argument newLabelSet.
13.14 The throw Statement
Syntax
13.14.1 Runtime Semantics: Evaluation
- Let exprRef be the result of evaluating
Expression . - Let exprValue be ?
GetValue (exprRef). - Return
Completion {[[Type]]:throw , [[Value]]: exprValue, [[Target]]:empty }.
13.15 The try Statement
Syntax
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
13.15.1 Static Semantics: Early Errors
-
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 ofBlock . -
It is a Syntax Error if any element of the BoundNames of
CatchParameter also occurs in the VarDeclaredNames ofBlock .
An alternative static semantics for this production is given in
13.15.2 Static Semantics: ContainsDuplicateLabels
With parameter labelSet.
- Let hasDuplicates be ContainsDuplicateLabels of
Block with argument labelSet. - If hasDuplicates is
true , returntrue . - Return ContainsDuplicateLabels of
Catch with argument labelSet.
- Let hasDuplicates be ContainsDuplicateLabels of
Block with argument labelSet. - If hasDuplicates is
true , returntrue . - Return ContainsDuplicateLabels of
Finally with argument labelSet.
- Let hasDuplicates be ContainsDuplicateLabels of
Block with argument labelSet. - If hasDuplicates is
true , returntrue . - Let hasDuplicates be ContainsDuplicateLabels of
Catch with argument labelSet. - If hasDuplicates is
true , returntrue . - Return ContainsDuplicateLabels of
Finally with argument labelSet.
- Return ContainsDuplicateLabels of
Block with argument labelSet.
13.15.3 Static Semantics: ContainsUndefinedBreakTarget
With parameter labelSet.
- Let hasUndefinedLabels be ContainsUndefinedBreakTarget of
Block with argument labelSet. - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedBreakTarget of
Catch with argument labelSet.
- Let hasUndefinedLabels be ContainsUndefinedBreakTarget of
Block with argument labelSet. - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedBreakTarget of
Finally with argument labelSet.
- Let hasUndefinedLabels be ContainsUndefinedBreakTarget of
Block with argument labelSet. - If hasUndefinedLabels is
true , returntrue . - Let hasUndefinedLabels be ContainsUndefinedBreakTarget of
Catch with argument labelSet. - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedBreakTarget of
Finally with argument labelSet.
- Return ContainsUndefinedBreakTarget of
Block with argument labelSet.
13.15.4 Static Semantics: ContainsUndefinedContinueTarget
With parameters iterationSet and labelSet.
- Let hasUndefinedLabels be ContainsUndefinedContinueTarget of
Block with arguments iterationSet and « ». - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedContinueTarget of
Catch with arguments iterationSet and « ».
- Let hasUndefinedLabels be ContainsUndefinedContinueTarget of
Block with arguments iterationSet and « ». - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedContinueTarget of
Finally with arguments iterationSet and « ».
- Let hasUndefinedLabels be ContainsUndefinedContinueTarget of
Block with arguments iterationSet and « ». - If hasUndefinedLabels is
true , returntrue . - Let hasUndefinedLabels be ContainsUndefinedContinueTarget of
Catch with arguments iterationSet and « ». - If hasUndefinedLabels is
true , returntrue . - Return ContainsUndefinedContinueTarget of
Finally with arguments iterationSet and « ».
- Return ContainsUndefinedContinueTarget of
Block with arguments iterationSet and « ».
13.15.5 Static Semantics: VarDeclaredNames
- Let names be VarDeclaredNames of
Block . - Append to names the elements of the VarDeclaredNames of
Catch . - Return names.
- Let names be VarDeclaredNames of
Block . - Append to names the elements of the VarDeclaredNames of
Finally . - Return names.
- Let names be VarDeclaredNames of
Block . - Append to names the elements of the VarDeclaredNames of
Catch . - Append to names the elements of the VarDeclaredNames of
Finally . - Return names.
- Return the VarDeclaredNames of
Block .
13.15.6 Static Semantics: VarScopedDeclarations
- Let declarations be VarScopedDeclarations of
Block . - Append to declarations the elements of the VarScopedDeclarations of
Catch . - Return declarations.
- Let declarations be VarScopedDeclarations of
Block . - Append to declarations the elements of the VarScopedDeclarations of
Finally . - Return declarations.
- Let declarations be VarScopedDeclarations of
Block . - Append to declarations the elements of the VarScopedDeclarations of
Catch . - Append to declarations the elements of the VarScopedDeclarations of
Finally . - Return declarations.
- Return the VarScopedDeclarations of
Block .
13.15.7 Runtime Semantics: CatchClauseEvaluation
With parameter thrownValue.
- Let oldEnv be the
running execution context 's LexicalEnvironment. - Let catchEnv be
NewDeclarativeEnvironment (oldEnv). - Let catchEnvRec be catchEnv's
EnvironmentRecord . - For each element argName of the BoundNames of
CatchParameter , do- Perform ! catchEnvRec.CreateMutableBinding(argName,
false ).
- Perform ! catchEnvRec.CreateMutableBinding(argName,
Set therunning execution context 's LexicalEnvironment to catchEnv.- Let status be the result of performing BindingInitialization for
CatchParameter passing thrownValue and catchEnv as arguments. - If status is an
abrupt completion , thenSet therunning execution context 's LexicalEnvironment to oldEnv.- Return
Completion (status).
- Let B be the result of evaluating
Block . Set therunning execution context 's LexicalEnvironment to oldEnv.- Return
Completion (B).
No matter how control leaves the
13.15.8 Runtime Semantics: Evaluation
- Let B be the result of evaluating
Block . - If B.[[Type]] is
throw , let C be CatchClauseEvaluation ofCatch with parameter B.[[Value]]. - Else, let C be B.
- Return
Completion (UpdateEmpty (C,undefined )).
- Let B be the result of evaluating
Block . - Let F be the result of evaluating
Finally . - If F.[[Type]] is
normal , set F to B. - Return
Completion (UpdateEmpty (F,undefined )).
- Let B be the result of evaluating
Block . - If B.[[Type]] is
throw , let C be CatchClauseEvaluation ofCatch with parameter B.[[Value]]. - Else, let C be B.
- Let F be the result of evaluating
Finally . - If F.[[Type]] is
normal , set F to C. - Return
Completion (UpdateEmpty (F,undefined )).
13.16 The debugger Statement
Syntax
13.16.1 Runtime Semantics: Evaluation
Evaluating a
- If an implementation-defined debugging facility is available and enabled, then
- Perform an implementation-defined debugging action.
- Let result be an implementation-defined
Completion value.
- Else,
- Let result be
NormalCompletion (empty ).
- Let result be
- Return result.