13 ECMAScript Language: Statements and Declarations
Syntax
13.1 Statement Semantics
13.1.1 Static Semantics: ContainsDuplicateLabels
With argument labelSet.
- Return
false .
13.1.2 Static Semantics: ContainsUndefinedBreakTarget
With argument labelSet.
- Return
false .
13.1.3 Static Semantics: ContainsUndefinedContinueTarget
With arguments 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
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 argument 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 , let stmtResult beNormalCompletion (undefined ). - Else, let stmtResult be
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 , let stmtResult beNormalCompletion (undefined ). - Else, let stmtResult be
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 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 argument 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 argument 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 arguments 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 - If
HoistableDeclaration is , return « ».HoistableDeclaration : FunctionDeclaration - If
HoistableDeclaration is , return « ».HoistableDeclaration : GeneratorDeclaration
- If
- 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 - If
HoistableDeclaration is , return « ».HoistableDeclaration : FunctionDeclaration - If
HoistableDeclaration is , return « ».HoistableDeclaration : GeneratorDeclaration
- If
- 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 - If
HoistableDeclaration is , return the BoundNames ofHoistableDeclaration : FunctionDeclaration FunctionDeclaration . - If
HoistableDeclaration is , return the BoundNames ofHoistableDeclaration : GeneratorDeclaration GeneratorDeclaration .
- If
- 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 - If
HoistableDeclaration is , return «HoistableDeclaration : FunctionDeclaration FunctionDeclaration ». - If
HoistableDeclaration is , return «HoistableDeclaration : GeneratorDeclaration GeneratorDeclaration ».
- If
- 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 the running
execution context 's LexicalEnvironment to blockEnv. - Let blockValue be the result of evaluating
StatementList . - Set the running
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.[[value]])).
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 grammar production corresponding to the body of the block. env is the declarative
- 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- Let status be env.CreateImmutableBinding(dn,
true ).
- Let status be env.CreateImmutableBinding(dn,
- Else,
- Let status be env.CreateMutableBinding(dn,
false ).
- Let status be env.CreateMutableBinding(dn,
- Assert: status is never an
abrupt completion .
- If IsConstantDeclaration of d is
- If d is a
GeneratorDeclaration production or aFunctionDeclaration production, 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 env.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 running 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 this production 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). ReturnIfAbrupt (value).- If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let hasNameProperty be
HasOwnProperty (value,"name"). ReturnIfAbrupt (hasNameProperty).- 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). ReturnIfAbrupt (value).- 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 running
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) ReturnIfAbrupt (lhs).- Let rhs be the result of evaluating
Initializer . - Let value be
GetValue (rhs). ReturnIfAbrupt (value).- If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let hasNameProperty be
HasOwnProperty (value,"name"). ReturnIfAbrupt (hasNameProperty).- 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). ReturnIfAbrupt (rval).- 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 an empty
List .
- Return an 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
false .
- Return ContainsExpression of
BindingElementList .
- Return ContainsExpression of
BindingElementList .
- 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 the ContainsExpression of
BindingElement .
- Return
true .
- Return
false .
- Return
true .
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
- Let valid be
RequireObjectCoercible (value). ReturnIfAbrupt (valid).- Return the result of performing BindingInitialization for
ObjectBindingPattern using value and environment as arguments.
- Let iterator be
GetIterator (value). ReturnIfAbrupt (iterator).- 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 , returnIteratorClose (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). ReturnIfAbrupt (lhs).- 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 . - Let v be
GetValue (defaultValue). ReturnIfAbrupt (v).- If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let hasNameProperty be
HasOwnProperty (v,"name"). ReturnIfAbrupt (hasNameProperty).- If hasNameProperty is
false , performSetFunctionName (v, bindingId).
- Let hasNameProperty be
- Let defaultValue be the result of evaluating
- If environment is
undefined , returnPutValue (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- Let defaultValue be the result of evaluating
Initializer . - Let v be
GetValue (defaultValue). ReturnIfAbrupt (v).
- Let defaultValue be the result of evaluating
- Return the result of performing BindingInitialization of
BindingPattern with v and environment as the arguments.
- Let lhs be
ResolveBinding (StringValue ofBindingIdentifier , environment). ReturnIfAbrupt (lhs).- Let A be
ArrayCreate (0). - Let n=0.
- Repeat,
- If iteratorRecord.[[done]] is
false ,- 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 , returnPutValue (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 is
true . - Increment n by 1.
- If iteratorRecord.[[done]] is
13.3.3.7 Runtime Semantics: KeyedBindingInitialization
With parameters value, environment, and propertyName.
When
- Let v be
GetV (value, propertyName). ReturnIfAbrupt (v).- If
Initializer is present and v isundefined , then- Let defaultValue be the result of evaluating
Initializer . - Let v be
GetValue (defaultValue). ReturnIfAbrupt (v).
- Let defaultValue be the result of evaluating
- Return the result of performing BindingInitialization for
BindingPattern passing v and environment as arguments.
- Let bindingId be StringValue of
BindingIdentifier . - Let lhs be
ResolveBinding (bindingId, environment). ReturnIfAbrupt (lhs).- Let v be
GetV (value, propertyName). ReturnIfAbrupt (v).- If
Initializer is present and v isundefined , then- Let defaultValue be the result of evaluating
Initializer . - Let v be
GetValue (defaultValue). ReturnIfAbrupt (v).- If
IsAnonymousFunctionDefinition (Initializer ) istrue , then- Let hasNameProperty be
HasOwnProperty (v,"name"). ReturnIfAbrupt (hasNameProperty).- If hasNameProperty is
false , performSetFunctionName (v, bindingId).
- Let hasNameProperty be
- Let defaultValue be the result of evaluating
- If environment is
undefined , returnPutValue (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 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 argument labelSet.
- Let hasUndefinedLabels be ContainsDuplicateLabels of the first
Statement with argument labelSet. - If hasUndefinedLabels 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 argument 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 arguments 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)). ReturnIfAbrupt (exprValue).- 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
ReturnIfAbrupt (stmtCompletion).- If stmtCompletion.[[value]] is not
empty , return stmtCompletion. - Return
NormalCompletion (undefined ).
- Let exprRef be the result of evaluating
Expression . - Let exprValue be
ToBoolean (GetValue (exprRef)). ReturnIfAbrupt (exprValue).- If exprValue is
false , then- Return
NormalCompletion (undefined ).
- Return
- Else,
- Let stmtCompletion be the result of evaluating
Statement . ReturnIfAbrupt (stmtCompletion).- If stmtCompletion.[[value]] is not
empty , return stmtCompletion. - Return
NormalCompletion (undefined ).
- Let stmtCompletion be the result of evaluating
13.7 Iteration Statements
Syntax
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 argument labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.7.2.2 Static Semantics: ContainsUndefinedBreakTarget
With argument labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.7.2.3 Static Semantics: ContainsUndefinedContinueTarget
With arguments 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 argument labelSet.
- Let V =
undefined . - Repeat
- Let stmt be the result of evaluating
Statement . - If
LoopContinues (stmt, labelSet) isfalse , returnCompletion (UpdateEmpty (stmt, V)). - If stmt.[[value]] is not
empty , let V = stmt.[[value]]. - Let exprRef be the result of evaluating
Expression . - Let exprValue be
GetValue (exprRef). ReturnIfAbrupt (exprValue).- If
ToBoolean (exprValue) isfalse , returnNormalCompletion (V).
- Let stmt be the result of evaluating
13.7.3 The while Statement
13.7.3.1 Static Semantics: ContainsDuplicateLabels
With argument labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.7.3.2 Static Semantics: ContainsUndefinedBreakTarget
With argument labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.7.3.3 Static Semantics: ContainsUndefinedContinueTarget
With arguments 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 argument labelSet.
- Let V =
undefined . - Repeat
- Let exprRef be the result of evaluating
Expression . - Let exprValue be
GetValue (exprRef). ReturnIfAbrupt (exprValue).- If
ToBoolean (exprValue) isfalse , returnNormalCompletion (V). - Let stmt be the result of evaluating
Statement . - If
LoopContinues (stmt, labelSet) isfalse , returnCompletion (UpdateEmpty (stmt, V)). - If stmt.[[value]] is not
empty , let V = stmt.[[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 argument labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.7.4.3 Static Semantics: ContainsUndefinedBreakTarget
With argument labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.7.4.4 Static Semantics: ContainsUndefinedContinueTarget
With arguments 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 argument labelSet.
- If the first
Expression is present, then- Let exprRef be the result of evaluating the first
Expression . - Let exprValue be
GetValue (exprRef). ReturnIfAbrupt (exprValue).
- 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 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 loopEnv.CreateImmutableBinding(dn,
true ).
- Perform loopEnv.CreateImmutableBinding(dn,
- Else,
- Perform loopEnv.CreateMutableBinding(dn,
false ). - Assert: The above call to CreateMutableBinding will never return an
abrupt completion .
- Perform loopEnv.CreateMutableBinding(dn,
- If isConst is
- Set the running
execution context 's LexicalEnvironment to loopEnv. - Let forDcl be the result of evaluating
LexicalDeclaration . - If forDcl is an
abrupt completion , then- Set the running
execution context 's LexicalEnvironment to oldEnv. - Return
Completion (forDcl).
- Set the running
- If isConst is
false , let perIterationLets be boundNames otherwise let perIterationLets be « ». - Let bodyResult be
ForBodyEvaluation (the firstExpression , the secondExpression ,Statement , perIterationLets, labelSet). - Set the running
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 =
undefined . - Let status be
CreatePerIterationEnvironment (perIterationBindings). ReturnIfAbrupt (status).- Repeat
- If test is not
[empty] , then- Let testRef be the result of evaluating test.
- Let testValue be
GetValue (testRef). ReturnIfAbrupt (testValue).- 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 , let V = result.[[value]]. - Let status be
CreatePerIterationEnvironment (perIterationBindings). ReturnIfAbrupt (status).- If increment is not
[empty] , then- Let incRef be the result of evaluating increment.
- Let incValue be
GetValue (incRef). ReturnIfAbrupt (incValue).
- 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 outer be lastIterationEnv's outer environment reference.
- Assert: outer is not
null . - Let thisIterationEnv be
NewDeclarativeEnvironment (outer). - For each element bn of perIterationBindings do,
- Let status be thisIterationEnv.CreateMutableBinding(bn,
false ). - Assert: status is never an
abrupt completion . - Let lastValue be lastIterationEnv.GetBindingValue(bn,
true ). ReturnIfAbrupt (lastValue).- Perform thisIterationEnv.InitializeBinding(bn, lastValue).
- Let status be thisIterationEnv.CreateMutableBinding(bn,
- Set the running
execution context 's LexicalEnvironment to thisIterationEnv.
- Let lastIterationEnv be the running
- 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 the goal 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 production that would produce a Syntax Error according to these rules if that production is 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 argument labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.7.5.4 Static Semantics: ContainsUndefinedBreakTarget
With argument labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.7.5.5 Static Semantics: ContainsUndefinedContinueTarget
With arguments iterationSet and labelSet.
- Return ContainsUndefinedContinueTarget of
Statement with arguments iterationSet and « ».
13.7.5.6 Static Semantics: IsDestructuring
- Return IsDestructuring of
ForBinding .
- Return
false .
- Return
true .
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 .
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 .
13.7.5.9 Runtime Semantics: BindingInitialization
With arguments 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 argument environment.
- For each element name of the BoundNames of
ForBinding do- If IsConstantDeclaration of
LetOrConst istrue , then- Perform environment.CreateImmutableBinding(name,
true ).
- Perform environment.CreateImmutableBinding(name,
- Else,
- Perform environment.CreateMutableBinding(name).
- Assert: The above call to CreateMutableBinding will never return an
abrupt completion .
- If IsConstantDeclaration of
13.7.5.11 Runtime Semantics: LabelledEvaluation
With argument labelSet.
- Let keyResult be
ForIn/OfHeadEvaluation ( « »,Expression ,enumerate ). ReturnIfAbrupt (keyResult).- Return
ForIn/OfBodyEvaluation (LeftHandSideExpression ,Statement , keyResult,assignment , labelSet).
- Let keyResult be
ForIn/OfHeadEvaluation ( « »,Expression ,enumerate ). ReturnIfAbrupt (keyResult).- Return
ForIn/OfBodyEvaluation (ForBinding ,Statement , keyResult,varBinding , labelSet).
- Let keyResult be the result of performing
ForIn/OfHeadEvaluation (BoundNames ofForDeclaration ,Expression ,enumerate ). ReturnIfAbrupt (keyResult).- Return
ForIn/OfBodyEvaluation (ForDeclaration ,Statement , keyResult,lexicalBinding , labelSet).
- Let keyResult be the result of performing
ForIn/OfHeadEvaluation ( « »,AssignmentExpression ,iterate ). ReturnIfAbrupt (keyResult).- Return
ForIn/OfBodyEvaluation (LeftHandSideExpression ,Statement , keyResult,assignment , labelSet).
- Let keyResult be the result of performing
ForIn/OfHeadEvaluation ( « »,AssignmentExpression ,iterate ). ReturnIfAbrupt (keyResult).- Return
ForIn/OfBodyEvaluation (ForBinding ,Statement , keyResult,varBinding , labelSet).
- Let keyResult be the result of performing
ForIn/OfHeadEvaluation ( BoundNames ofForDeclaration ,AssignmentExpression ,iterate ). ReturnIfAbrupt (keyResult).- Return
ForIn/OfBodyEvaluation (ForDeclaration ,Statement , keyResult,lexicalBinding , labelSet).
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 , then- Assert: TDZnames has no duplicate entries.
- Let TDZ be
NewDeclarativeEnvironment (oldEnv). - For each string name in TDZnames, do
- Let status be TDZ.CreateMutableBinding(name,
false ). - Assert: status is never an
abrupt completion .
- Let status be TDZ.CreateMutableBinding(name,
- Set the running
execution context 's LexicalEnvironment to TDZ.
- Let exprRef be the result of evaluating the production that is expr.
- Set the running
execution context 's LexicalEnvironment to oldEnv. - Let exprValue be
GetValue (exprRef). ReturnIfAbrupt (exprValue).- If iterationKind is
enumerate , then- If exprValue.[[value]] is
null orundefined , then- Return
Completion {[[type]]:break , [[value]]:empty , [[target]]:empty }.
- Return
- Let obj be
ToObject (exprValue). - Return obj.[[Enumerate]]().
- If exprValue.[[value]] is
- Else,
- Assert: iterationKind is
iterate . - Return
GetIterator (exprValue).
- Assert: iterationKind is
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
- Let oldEnv be the running
execution context 's LexicalEnvironment. - Let V =
undefined . - Let destructuring be IsDestructuring of lhs.
- If destructuring is
true and if lhsKind isassignment , then- Assert: lhs is a
LeftHandSideExpression . - Let assignmentPattern be the parse of the source text corresponding to lhs using
AssignmentPattern as the goal symbol.
- Assert: lhs is a
- Repeat
- Let nextResult be
IteratorStep (iterator). ReturnIfAbrupt (nextResult).- If nextResult is
false , returnNormalCompletion (V). - Let nextValue be
IteratorValue (nextResult). ReturnIfAbrupt (nextValue).- 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 is
lexicalBinding . - Assert: lhs is a
ForDeclaration . - Let iterationEnv be
NewDeclarativeEnvironment (oldEnv). - Perform BindingInstantiation for lhs passing iterationEnv as the argument.
- Set the running
execution context 's LexicalEnvironment to iterationEnv. - If destructuring is
false , then- Assert: lhs binds a single name.
- Let lhsName be the sole element of BoundNames of lhs.
- Let lhsRef be
ResolveBinding (lhsName). - Assert: lhsRef is not an
abrupt completion .
- Assert: lhsKind is
- 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 , then- Assert: lhs is a
ForBinding . - Let status be the result of performing BindingInitialization for lhs passing nextValue and
undefined as the arguments.
- Assert: lhs is a
- Else,
- Assert: lhsKind is
lexicalBinding . - Assert: lhs is a
ForDeclaration . - Let status be the result of performing BindingInitialization for lhs passing nextValue and iterationEnv as arguments.
- Assert: lhsKind is
- If lhsKind is
- If status is an
abrupt completion , then- Set the running
execution context 's LexicalEnvironment to oldEnv. - Return
IteratorClose (iterator, status).
- Set the running
- Let result be the result of evaluating stmt.
- Set the running
execution context 's LexicalEnvironment to oldEnv. - If
LoopContinues (result, labelSet) isfalse , returnIteratorClose (iterator,UpdateEmpty (result, V)). - If result.[[value]] is not
empty , let V be result.[[value]].
- Let nextResult be
13.7.5.14 Runtime Semantics: Evaluation
- Let bindingId be StringValue of
BindingIdentifier . - Return
ResolveBinding (bindingId)
13.8 The continue Statement
Syntax
13.8.1 Static Semantics: Early Errors
-
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.
- 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 production is not nested, directly or indirectly (but not crossing function boundaries), within an
IterationStatement or aSwitchStatement .
13.9.2 Static Semantics: ContainsUndefinedBreakTarget
With argument 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). ReturnIfAbrupt (exprValue).- 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 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 argument labelSet.
- Return ContainsDuplicateLabels of
Statement with argument labelSet.
13.11.3 Static Semantics: ContainsUndefinedBreakTarget
With argument labelSet.
- Return ContainsUndefinedBreakTarget of
Statement with argument labelSet.
13.11.4 Static Semantics: ContainsUndefinedContinueTarget
With arguments 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)). ReturnIfAbrupt (obj).- Let oldEnv be the running
execution context 's LexicalEnvironment. - Let newEnv be
NewObjectEnvironment (obj, oldEnv). - Set the withEnvironment flag of newEnv's
EnvironmentRecord totrue . - Set the running
execution context 's LexicalEnvironment to newEnv. - Let C be the result of evaluating
Statement . - Set the running
execution context 'sLexical Environment to oldEnv. - If C.[[type]] is
normal and C.[[value]] isempty , returnNormalCompletion (undefined ). - Return
Completion (C).
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
CaseClauses contains any duplicate entries. -
It is a Syntax Error if any element of the LexicallyDeclaredNames of
CaseClauses also occurs in the VarDeclaredNames ofCaseClauses .
13.12.2 Static Semantics: ContainsDuplicateLabels
With argument 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. - Else return
false .
- If the
StatementList is present, return ContainsDuplicateLabels ofStatementList with argument labelSet. - Else return
false .
13.12.3 Static Semantics: ContainsUndefinedBreakTarget
With argument 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. - Else return
false .
- If the
StatementList is present, return ContainsUndefinedBreakTarget ofStatementList with argument labelSet. - Else return
false .
13.12.4 Static Semantics: ContainsUndefinedContinueTarget
With arguments 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 « ». - Else return
false .
- If the
StatementList is present, return ContainsUndefinedContinueTarget ofStatementList with arguments iterationSet and « ». - Else 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. - Else 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 . - Else return a new empty
List .
- If the
StatementList is present, return the LexicallyDeclaredNames ofStatementList . - Else 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. - Else 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 . - Else return a new empty
List .
- If the
StatementList is present, return the LexicallyScopedDeclarations ofStatementList . - Else 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. - Else 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 . - Else return a new empty
List .
- If the
StatementList is present, return the VarDeclaredNames ofStatementList . - Else 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. - Else 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 . - Else return a new empty
List .
- If the
StatementList is present, return the VarScopedDeclarations ofStatementList . - Else return a new empty
List .
13.12.9 Runtime Semantics: CaseBlockEvaluation
With argument input.
- Return
NormalCompletion (undefined ).
- Let V =
undefined . - Let A be the
List ofCaseClause items inCaseClauses , in source text order. - Let found be
false . - Repeat for each
CaseClause C in A,- If found is
false , then- Let clauseSelector be the result of CaseSelectorEvaluation of C.
- If clauseSelector is an
abrupt completion , then- If clauseSelector.[[value]] is
empty , returnCompletion {[[type]]: clauseSelector.[[type]], [[value]]:undefined , [[target]]: clauseSelector.[[target]]}. - Else, return
Completion (clauseSelector).
- If clauseSelector.[[value]] is
- Let found be the result of performing
Strict Equality Comparison input === clauseSelector.[[value]].
- If found is
true , then- Let R be the result of evaluating C.
- If R.[[value]] is not
empty , let V = R.[[value]]. - If R is an
abrupt completion , returnCompletion (UpdateEmpty (R, V)).
- If found is
- Return
NormalCompletion (V).
- Let V =
undefined . - Let A be the list of
CaseClause items in the firstCaseClauses , in source text order. If the firstCaseClauses is not present A is « ». - Let found be
false . - Repeat for each
CaseClause C in A- If found is
false , then- Let clauseSelector be the result of CaseSelectorEvaluation of C.
- If clauseSelector is an
abrupt completion , then- If clauseSelector.[[value]] is
empty , returnCompletion {[[type]]: clauseSelector.[[type]], [[value]]:undefined , [[target]]: clauseSelector.[[target]]}. - Else, return
Completion (clauseSelector).
- If clauseSelector.[[value]] is
- Let found be the result of performing
Strict Equality Comparison input === clauseSelector.[[value]].
- If found is
true , then- Let R be the result of evaluating C.
- If R.[[value]] is not
empty , let V = R.[[value]]. - If R is an
abrupt completion , returnCompletion (UpdateEmpty (R, V)).
- If found is
- Let foundInB be
false . - Let B be the
List containing theCaseClause items in the secondCaseClauses , in source text order. If the secondCaseClauses is not present B is « ». - If found is
false , then- Repeat for each
CaseClause C in B- If foundInB is
false , then- Let clauseSelector be the result of CaseSelectorEvaluation of C.
- If clauseSelector is an
abrupt completion , then- If clauseSelector.[[value]] is
empty , returnCompletion {[[type]]: clauseSelector.[[type]], [[value]]:undefined , [[target]]: clauseSelector.[[target]]}. - Else, return
Completion (clauseSelector).
- If clauseSelector.[[value]] is
- Let foundInB be the result of performing
Strict Equality Comparison input === clauseSelector.[[value]].
- If foundInB is
true , then- Let R be the result of evaluating
CaseClause C. - If R.[[value]] is not
empty , let V = R.[[value]]. - If R is an
abrupt completion , returnCompletion (UpdateEmpty (R, V)).
- Let R be the result of evaluating
- If foundInB is
- Repeat for each
- If foundInB is
true , returnNormalCompletion (V). - Let R be the result of evaluating
DefaultClause . - If R.[[value]] is not
empty , let V = R.[[value]]. - If R is an
abrupt completion , returnCompletion (UpdateEmpty (R, V)). - Repeat for each
CaseClause C in B (NOTE this is another complete iteration of the secondCaseClauses )- Let R be the result of evaluating
CaseClause C. - If R.[[value]] is not
empty , let V = 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). ReturnIfAbrupt (switchValue).- Let oldEnv be the running
execution context 's LexicalEnvironment. - Let blockEnv be
NewDeclarativeEnvironment (oldEnv). - Perform
BlockDeclarationInstantiation (CaseBlock , blockEnv). - Set the running
execution context 's LexicalEnvironment to blockEnv. - Let R be the result of performing CaseBlockEvaluation of
CaseBlock with argument switchValue. - Set the running
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 argument 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 argument 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 arguments 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 component of stmt. - If item is
, returnLabelledItem : FunctionDeclaration true . - Let subStmt be the
Statement component 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 argument 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), then- Let stmtResult be
NormalCompletion (stmtResult.[[value]]).
- Let stmtResult be
- 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
LabelledItem 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). ReturnIfAbrupt (exprValue).- 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 argument 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 argument 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 arguments 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). - For each element argName of the BoundNames of
CatchParameter , do- Perform catchEnv.CreateMutableBinding(argName).
- Assert: The above call to CreateMutableBinding will never return an
abrupt completion .
- Set the running
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 , then- Set the running
execution context 's LexicalEnvironment to oldEnv. - Return
Completion (status).
- Set the running
- Let B be the result of evaluating
Block . - Set the running
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 , then- Let C be CatchClauseEvaluation of
Catch with parameter B.[[value]].
- Let C be CatchClauseEvaluation of
- Else B.[[type]] is not
throw ,- Let C be B.
- If C.[[type]] is
return , or C.[[type]] isthrow , returnCompletion (C). - If C.[[value]] is not
empty , returnCompletion (C). - Return
Completion {[[type]]: C.[[type]], [[value]]:undefined , [[target]]: C.[[target]]}.
- Let B be the result of evaluating
Block . - Let F be the result of evaluating
Finally . - If F.[[type]] is
normal , let F be B. - If F.[[type]] is
return , or F.[[type]] isthrow , returnCompletion (F). - If F.[[value]] is not
empty , returnCompletion (F). - Return
Completion {[[type]]: F.[[type]], [[value]]:undefined , [[target]]: F.[[target]]}.
- Let B be the result of evaluating
Block . - If B.[[type]] is
throw , then- Let C be CatchClauseEvaluation of
Catch with parameter B.[[value]].
- Let C be CatchClauseEvaluation of
- Else B.[[type]] is not
throw , let C be B. - Let F be the result of evaluating
Finally . - If F.[[type]] is
normal , let F be C. - If F.[[type]] is
return , or F.[[type]] isthrow , returnCompletion (F). - If F.[[value]] is not
empty , returnNormalCompletion (F.[[value]]). - Return
Completion {[[type]]: F.[[type]], [[value]]:undefined , [[target]]: F.[[target]]}.
13.16 The debugger statement
Syntax
13.16.1 Runtime Semantics: Evaluation
Evaluating the
- 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.