15 ECMAScript Language: Functions and Classes
15.1 Parameter Lists
Syntax
15.1.1 Static Semantics: Early Errors
-
It is a Syntax Error if
BoundNames ofFormalParameters contains any duplicate elements.
-
It is a Syntax Error if
IsSimpleParameterList ofFormalParameterList isfalse andBoundNames ofFormalParameterList contains any duplicate elements.
Multiple occurrences of the same
15.1.2 Static Semantics: ContainsExpression
- Return
false .
- Return ContainsExpression of
BindingPropertyList .
- 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 ofPropertyName . - If has is
true , returntrue . - Return ContainsExpression of
BindingElement .
- Return
true .
- Return
false .
- Return
true .
- Return
false .
- Return ContainsExpression of
BindingPattern .
- Return
false .
- If ContainsExpression of
FormalParameterList istrue , returntrue . - Return ContainsExpression of
FunctionRestParameter .
- If ContainsExpression of
FormalParameterList istrue , returntrue . - Return ContainsExpression of
FormalParameter .
- Return
false .
- Let formals be
CoveredFormalsList ofCoverParenthesizedExpressionAndArrowParameterList . - Return ContainsExpression of formals.
- Return
false .
15.1.3 Static Semantics: IsSimpleParameterList
- Return
false .
- Return
false .
- Return
true .
- Return
false .
- Return
true .
- Return
false .
- Return
false .
- If IsSimpleParameterList of
FormalParameterList isfalse , returnfalse . - Return IsSimpleParameterList of
FormalParameter .
- Return IsSimpleParameterList of
BindingElement .
- Return
true .
- Let formals be
CoveredFormalsList ofCoverParenthesizedExpressionAndArrowParameterList . - Return IsSimpleParameterList of formals.
- Return
true .
- Let head be
CoveredAsyncArrowHead ofCoverCallExpressionAndAsyncArrowHead . - Return IsSimpleParameterList of head.
15.1.4 Static Semantics: HasInitializer
- Return
false .
- Return
true .
- Return
false .
- Return
true .
- If HasInitializer of
FormalParameterList istrue , returntrue . - Return HasInitializer of
FormalParameter .
15.1.5 Static Semantics: ExpectedArgumentCount
- Return 0.
- Return ExpectedArgumentCount of
FormalParameterList .
The ExpectedArgumentCount of a
- If
HasInitializer ofFormalParameter istrue , return 0. - Return 1.
- Let count be ExpectedArgumentCount of
FormalParameterList . - If
HasInitializer ofFormalParameterList istrue orHasInitializer ofFormalParameter istrue , return count. - Return count + 1.
- Return 1.
- Let formals be
CoveredFormalsList ofCoverParenthesizedExpressionAndArrowParameterList . - Return ExpectedArgumentCount of formals.
- If
HasInitializer ofFormalParameter istrue , return 0. - Return 1.
- Return 1.
15.2 Function Definitions
Syntax
15.2.1 Static Semantics: Early Errors
-
If the source code matching
FormalParameters isstrict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters -
If
BindingIdentifier is present and the source code matchingBindingIdentifier isstrict mode code , it is a Syntax Error if theStringValue ofBindingIdentifier is"eval" or"arguments" . -
It is a Syntax Error if
FunctionBodyContainsUseStrict ofFunctionBody istrue andIsSimpleParameterList ofFormalParameters isfalse . -
It is a Syntax Error if any element of the
BoundNames ofFormalParameters also occurs in theLexicallyDeclaredNames ofFunctionBody . -
It is a Syntax Error if
FormalParameters Contains SuperProperty istrue . -
It is a Syntax Error if
FunctionBody Contains SuperProperty istrue . -
It is a Syntax Error if
FormalParameters Contains SuperCall istrue . -
It is a Syntax Error if
FunctionBody Contains SuperCall istrue .
The
-
It is a Syntax Error if the
LexicallyDeclaredNames ofFunctionStatementList contains any duplicate entries. -
It is a Syntax Error if any element of the
LexicallyDeclaredNames ofFunctionStatementList also occurs in theVarDeclaredNames ofFunctionStatementList . -
It is a Syntax Error if
ContainsDuplicateLabels ofFunctionStatementList with argument « » istrue . -
It is a Syntax Error if
ContainsUndefinedBreakTarget ofFunctionStatementList with argument « » istrue . -
It is a Syntax Error if
ContainsUndefinedContinueTarget ofFunctionStatementList with arguments « » and « » istrue .
15.2.2 Static Semantics: FunctionBodyContainsUseStrict
- If the
Directive Prologue ofFunctionBody contains aUse Strict Directive , returntrue ; otherwise, returnfalse .
15.2.3 Runtime Semantics: EvaluateFunctionBody
With parameters functionObject and argumentsList (a
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Return the result of evaluating
FunctionStatementList .
15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject
With parameter scope.
- Let name be
StringValue ofBindingIdentifier . - Let sourceText be the
source text matched by FunctionDeclaration . - Let F be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , scope). - Perform
SetFunctionName (F, name). - Perform
MakeConstructor (F). - Return F.
- Let sourceText be the
source text matched by FunctionDeclaration . - Let F be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , scope). - Perform
SetFunctionName (F,"default" ). - Perform
MakeConstructor (F). - Return F.
An anonymous export default declaration, and its function code is therefore always
15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression
With optional parameter name.
- If name is not present, set name to
"" . - Let scope be the LexicalEnvironment of the
running execution context . - Let sourceText be the
source text matched by FunctionExpression . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , scope). - Perform
SetFunctionName (closure, name). - Perform
MakeConstructor (closure). - Return closure.
Assert : name is not present.Set name toStringValue ofBindingIdentifier .- Let scope be the
running execution context 's LexicalEnvironment. - Let funcEnv be
NewDeclarativeEnvironment (scope). - Perform funcEnv.CreateImmutableBinding(name,
false ). - Let sourceText be the
source text matched by FunctionExpression . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , funcEnv). - Perform
SetFunctionName (closure, name). - Perform
MakeConstructor (closure). - Perform funcEnv.InitializeBinding(name, closure).
- Return closure.
The
15.2.6 Runtime Semantics: Evaluation
- Return
NormalCompletion (empty ).
An alternative semantics is provided in
- Return
NormalCompletion (empty ).
A
- Return
NormalCompletion (undefined ).
15.3 Arrow Function Definitions
Syntax
Supplemental Syntax
When processing an instance of the production
the interpretation of
15.3.1 Static Semantics: Early Errors
-
It is a Syntax Error if
ArrowParameters Contains YieldExpression istrue . -
It is a Syntax Error if
ArrowParameters Contains AwaitExpression istrue . -
It is a Syntax Error if
ConciseBodyContainsUseStrict ofConciseBody istrue andIsSimpleParameterList ofArrowParameters isfalse . -
It is a Syntax Error if any element of the
BoundNames ofArrowParameters also occurs in theLexicallyDeclaredNames ofConciseBody .
-
It is a Syntax Error if
CoverParenthesizedExpressionAndArrowParameterList is notcovering anArrowFormalParameters . -
All
early error rules forArrowFormalParameters and its derived productions also apply toCoveredFormalsList ofCoverParenthesizedExpressionAndArrowParameterList .
15.3.2 Static Semantics: ConciseBodyContainsUseStrict
- Return
false .
- Return
FunctionBodyContainsUseStrict ofFunctionBody .
15.3.3 Static Semantics: CoveredFormalsList
- Return this
ArrowParameters .
- Return the
ArrowFormalParameters that iscovered byCoverParenthesizedExpressionAndArrowParameterList .
15.3.4 Runtime Semantics: EvaluateConciseBody
With parameters functionObject and argumentsList (a
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Return the result of evaluating
ExpressionBody .
15.3.5 Runtime Semantics: InstantiateArrowFunctionExpression
With optional parameter name.
- If name is not present, set name to
"" . - Let scope be the LexicalEnvironment of the
running execution context . - Let sourceText be the
source text matched by ArrowFunction . - Let parameters be
CoveredFormalsList ofArrowParameters . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText, parameters,ConciseBody ,lexical-this , scope). - Perform
SetFunctionName (closure, name). - Return closure.
An arguments, super, this, or new.target. Any reference to arguments, super, this, or new.target within an super, the super is always contained within a non-super is accessible via the scope that is captured by the
15.3.6 Runtime Semantics: Evaluation
- Return
InstantiateArrowFunctionExpression ofArrowFunction .
- Let exprRef be the result of evaluating
AssignmentExpression . - Let exprValue be ?
GetValue (exprRef). - Return
Completion { [[Type]]:return , [[Value]]: exprValue, [[Target]]:empty }.
15.4 Method Definitions
Syntax
15.4.1 Static Semantics: Early Errors
-
It is a Syntax Error if
FunctionBodyContainsUseStrict ofFunctionBody istrue andIsSimpleParameterList ofUniqueFormalParameters isfalse . -
It is a Syntax Error if any element of the
BoundNames ofUniqueFormalParameters also occurs in theLexicallyDeclaredNames ofFunctionBody .
-
It is a Syntax Error if
BoundNames ofPropertySetParameterList contains any duplicate elements. -
It is a Syntax Error if
FunctionBodyContainsUseStrict ofFunctionBody istrue andIsSimpleParameterList ofPropertySetParameterList isfalse . -
It is a Syntax Error if any element of the
BoundNames ofPropertySetParameterList also occurs in theLexicallyDeclaredNames ofFunctionBody .
15.4.2 Static Semantics: HasDirectSuper
- If
UniqueFormalParameters Contains SuperCall istrue , returntrue . - Return
FunctionBody Contains SuperCall .
- Return
FunctionBody Contains SuperCall .
- If
PropertySetParameterList Contains SuperCall istrue , returntrue . - Return
FunctionBody Contains SuperCall .
- If
UniqueFormalParameters Contains SuperCall istrue , returntrue . - Return
GeneratorBody Contains SuperCall .
- If
UniqueFormalParameters Contains SuperCall istrue , returntrue . - Return
AsyncGeneratorBody Contains SuperCall .
- If
UniqueFormalParameters Contains SuperCall istrue , returntrue . - Return
AsyncFunctionBody Contains SuperCall .
15.4.3 Static Semantics: SpecialMethod
- Return
false .
- Return
true .
15.4.4 Runtime Semantics: DefineMethod
With parameter object and optional parameter functionPrototype.
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- Let scope be the
running execution context 's LexicalEnvironment. - If functionPrototype is present, then
- Let prototype be functionPrototype.
- Else,
- Let prototype be
%Function.prototype% .
- Let prototype be
- Let sourceText be the
source text matched by MethodDefinition . - Let closure be
OrdinaryFunctionCreate (prototype, sourceText,UniqueFormalParameters ,FunctionBody ,non-lexical-this , scope). - Perform
MakeMethod (closure, object). - Return the
Record { [[Key]]: propKey, [[Closure]]: closure }.
15.4.5 Runtime Semantics: MethodDefinitionEvaluation
With parameters object and enumerable.
- Let methodDef be ?
DefineMethod ofMethodDefinition with argument object. - Perform
SetFunctionName (methodDef.[[Closure]], methodDef.[[Key]]). - Let desc be the PropertyDescriptor { [[Value]]: methodDef.[[Closure]], [[Writable]]:
true , [[Enumerable]]: enumerable, [[Configurable]]:true }. - Return ?
DefinePropertyOrThrow (object, methodDef.[[Key]], desc).
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- Let scope be the
running execution context 's LexicalEnvironment. - Let sourceText be the
source text matched by MethodDefinition . - Let formalParameterList be an instance of the production
.FormalParameters : [empty] - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText, formalParameterList,FunctionBody ,non-lexical-this , scope). - Perform
MakeMethod (closure, object). - Perform
SetFunctionName (closure, propKey,"get" ). - Let desc be the PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]:
true }. - Return ?
DefinePropertyOrThrow (object, propKey, desc).
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- Let scope be the
running execution context 's LexicalEnvironment. - Let sourceText be the
source text matched by MethodDefinition . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,PropertySetParameterList ,FunctionBody ,non-lexical-this , scope). - Perform
MakeMethod (closure, object). - Perform
SetFunctionName (closure, propKey,"set" ). - Let desc be the PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]:
true }. - Return ?
DefinePropertyOrThrow (object, propKey, desc).
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- Let scope be the
running execution context 's LexicalEnvironment. - Let sourceText be the
source text matched by GeneratorMethod . - Let closure be
OrdinaryFunctionCreate (%GeneratorFunction.prototype% , sourceText,UniqueFormalParameters ,GeneratorBody ,non-lexical-this , scope). - Perform
MakeMethod (closure, object). - Perform
SetFunctionName (closure, propKey). - Let prototype be !
OrdinaryObjectCreate (%GeneratorFunction.prototype.prototype% ). - Perform
DefinePropertyOrThrow (closure,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]:
true , [[Enumerable]]: enumerable, [[Configurable]]:true }. - Return ?
DefinePropertyOrThrow (object, propKey, desc).
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- Let scope be the
running execution context 's LexicalEnvironment. - Let sourceText be the
source text matched by AsyncGeneratorMethod . - Let closure be !
OrdinaryFunctionCreate (%AsyncGeneratorFunction.prototype% , sourceText,UniqueFormalParameters ,AsyncGeneratorBody ,non-lexical-this , scope). - Perform !
MakeMethod (closure, object). - Perform !
SetFunctionName (closure, propKey). - Let prototype be !
OrdinaryObjectCreate (%AsyncGeneratorFunction.prototype.prototype% ). - Perform !
DefinePropertyOrThrow (closure,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Let desc be PropertyDescriptor { [[Value]]: closure, [[Writable]]:
true , [[Enumerable]]: enumerable, [[Configurable]]:true }. - Return ?
DefinePropertyOrThrow (object, propKey, desc).
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- Let scope be the LexicalEnvironment of the
running execution context . - Let sourceText be the
source text matched by AsyncMethod . - Let closure be !
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText,UniqueFormalParameters ,AsyncFunctionBody ,non-lexical-this , scope). - Perform !
MakeMethod (closure, object). - Perform !
SetFunctionName (closure, propKey). - Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]:
true , [[Enumerable]]: enumerable, [[Configurable]]:true }. - Return ?
DefinePropertyOrThrow (object, propKey, desc).
15.5 Generator Function Definitions
Syntax
The syntactic context immediately following yield requires use of the
15.5.1 Static Semantics: Early Errors
-
It is a Syntax Error if
HasDirectSuper ofGeneratorMethod istrue . -
It is a Syntax Error if
UniqueFormalParameters Contains YieldExpression istrue . -
It is a Syntax Error if
FunctionBodyContainsUseStrict ofGeneratorBody istrue andIsSimpleParameterList ofUniqueFormalParameters isfalse . -
It is a Syntax Error if any element of the
BoundNames ofUniqueFormalParameters also occurs in theLexicallyDeclaredNames ofGeneratorBody .
-
If the source code matching
FormalParameters isstrict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters -
If
BindingIdentifier is present and the source code matchingBindingIdentifier isstrict mode code , it is a Syntax Error if theStringValue ofBindingIdentifier is"eval" or"arguments" . -
It is a Syntax Error if
FunctionBodyContainsUseStrict ofGeneratorBody istrue andIsSimpleParameterList ofFormalParameters isfalse . -
It is a Syntax Error if any element of the
BoundNames ofFormalParameters also occurs in theLexicallyDeclaredNames ofGeneratorBody . -
It is a Syntax Error if
FormalParameters Contains YieldExpression istrue . -
It is a Syntax Error if
FormalParameters Contains SuperProperty istrue . -
It is a Syntax Error if
GeneratorBody Contains SuperProperty istrue . -
It is a Syntax Error if
FormalParameters Contains SuperCall istrue . -
It is a Syntax Error if
GeneratorBody Contains SuperCall istrue .
15.5.2 Runtime Semantics: EvaluateGeneratorBody
With parameters functionObject and argumentsList (a
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Let G be ?
OrdinaryCreateFromConstructor (functionObject," , « [[GeneratorState]], [[GeneratorContext]], [[GeneratorBrand]] »).%GeneratorFunction.prototype.prototype% " Set G.[[GeneratorBrand]] toempty .- Perform
GeneratorStart (G,FunctionBody ). - Return
Completion { [[Type]]:return , [[Value]]: G, [[Target]]:empty }.
15.5.3 Runtime Semantics: InstantiateGeneratorFunctionObject
With parameter scope.
- Let name be
StringValue ofBindingIdentifier . - Let sourceText be the
source text matched by GeneratorDeclaration . - Let F be
OrdinaryFunctionCreate (%GeneratorFunction.prototype% , sourceText,FormalParameters ,GeneratorBody ,non-lexical-this , scope). - Perform
SetFunctionName (F, name). - Let prototype be !
OrdinaryObjectCreate (%GeneratorFunction.prototype.prototype% ). - Perform
DefinePropertyOrThrow (F,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Return F.
- Let sourceText be the
source text matched by GeneratorDeclaration . - Let F be
OrdinaryFunctionCreate (%GeneratorFunction.prototype% , sourceText,FormalParameters ,GeneratorBody ,non-lexical-this , scope). - Perform
SetFunctionName (F,"default" ). - Let prototype be !
OrdinaryObjectCreate (%GeneratorFunction.prototype.prototype% ). - Perform
DefinePropertyOrThrow (F,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Return F.
An anonymous export default declaration, and its function code is therefore always
15.5.4 Runtime Semantics: InstantiateGeneratorFunctionExpression
With optional parameter name.
- If name is not present, set name to
"" . - Let scope be the LexicalEnvironment of the
running execution context . - Let sourceText be the
source text matched by GeneratorExpression . - Let closure be
OrdinaryFunctionCreate (%GeneratorFunction.prototype% , sourceText,FormalParameters ,GeneratorBody ,non-lexical-this , scope). - Perform
SetFunctionName (closure, name). - Let prototype be !
OrdinaryObjectCreate (%GeneratorFunction.prototype.prototype% ). - Perform
DefinePropertyOrThrow (closure,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Return closure.
Assert : name is not present.Set name toStringValue ofBindingIdentifier .- Let scope be the
running execution context 's LexicalEnvironment. - Let funcEnv be
NewDeclarativeEnvironment (scope). - Perform funcEnv.CreateImmutableBinding(name,
false ). - Let sourceText be the
source text matched by GeneratorExpression . - Let closure be
OrdinaryFunctionCreate (%GeneratorFunction.prototype% , sourceText,FormalParameters ,GeneratorBody ,non-lexical-this , funcEnv). - Perform
SetFunctionName (closure, name). - Let prototype be !
OrdinaryObjectCreate (%GeneratorFunction.prototype.prototype% ). - Perform
DefinePropertyOrThrow (closure,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform funcEnv.InitializeBinding(name, closure).
- Return closure.
The
15.5.5 Runtime Semantics: Evaluation
- Return ?
Yield (undefined ).
- Let exprRef be the result of evaluating
AssignmentExpression . - Let value be ?
GetValue (exprRef). - Return ?
Yield (value).
- Let generatorKind be !
GetGeneratorKind (). - Let exprRef be the result of evaluating
AssignmentExpression . - Let value be ?
GetValue (exprRef). - Let iteratorRecord be ?
GetIterator (value, generatorKind). - Let iterator be iteratorRecord.[[Iterator]].
- Let received be
NormalCompletion (undefined ). - Repeat,
- If received.[[Type]] is
normal , then- Let innerResult be ?
Call (iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] »). - If generatorKind is
async , set innerResult to ?Await (innerResult). - If
Type (innerResult) is not Object, throw aTypeError exception. - Let done be ?
IteratorComplete (innerResult). - If done is
true , then- Return ?
IteratorValue (innerResult).
- Return ?
- If generatorKind is
async , set received toAsyncGeneratorYield (?IteratorValue (innerResult)). - Else, set received to
GeneratorYield (innerResult).
- Let innerResult be ?
- Else if received.[[Type]] is
throw , then- Let throw be ?
GetMethod (iterator,"throw" ). - If throw is not
undefined , then- Let innerResult be ?
Call (throw, iterator, « received.[[Value]] »). - If generatorKind is
async , set innerResult to ?Await (innerResult). - NOTE: Exceptions from the inner iterator
throwmethod are propagated. Normal completions from an innerthrowmethod are processed similarly to an innernext. - If
Type (innerResult) is not Object, throw aTypeError exception. - Let done be ?
IteratorComplete (innerResult). - If done is
true , then- Return ?
IteratorValue (innerResult).
- Return ?
- If generatorKind is
async , set received toAsyncGeneratorYield (?IteratorValue (innerResult)). - Else, set received to
GeneratorYield (innerResult).
- Let innerResult be ?
- Else,
- NOTE: If iterator does not have a
throwmethod, this throw is going to terminate theyield*loop. But first we need to give iterator a chance to clean up. - Let closeCompletion be
Completion { [[Type]]:normal , [[Value]]:empty , [[Target]]:empty }. - If generatorKind is
async , perform ?AsyncIteratorClose (iteratorRecord, closeCompletion). - Else, perform ?
IteratorClose (iteratorRecord, closeCompletion). - NOTE: The next step throws a
TypeError to indicate that there was ayield*protocol violation: iterator does not have athrowmethod. - Throw a
TypeError exception.
- NOTE: If iterator does not have a
- Let throw be ?
- Else,
Assert : received.[[Type]] isreturn .- Let return be ?
GetMethod (iterator,"return" ). - If return is
undefined , then- If generatorKind is
async , set received.[[Value]] to ?Await (received.[[Value]]). - Return
Completion (received).
- If generatorKind is
- Let innerReturnResult be ?
Call (return, iterator, « received.[[Value]] »). - If generatorKind is
async , set innerReturnResult to ?Await (innerReturnResult). - If
Type (innerReturnResult) is not Object, throw aTypeError exception. - Let done be ?
IteratorComplete (innerReturnResult). - If done is
true , then- Let value be ?
IteratorValue (innerReturnResult). - Return
Completion { [[Type]]:return , [[Value]]: value, [[Target]]:empty }.
- Let value be ?
- If generatorKind is
async , set received toAsyncGeneratorYield (?IteratorValue (innerReturnResult)). - Else, set received to
GeneratorYield (innerReturnResult).
- If received.[[Type]] is
15.6 Async Generator Function Definitions
Syntax
15.6.1 Static Semantics: Early Errors
- It is a Syntax Error if
HasDirectSuper ofAsyncGeneratorMethod istrue . - It is a Syntax Error if
UniqueFormalParameters Contains YieldExpression istrue . - It is a Syntax Error if
UniqueFormalParameters Contains AwaitExpression istrue . - It is a Syntax Error if
FunctionBodyContainsUseStrict ofAsyncGeneratorBody istrue andIsSimpleParameterList ofUniqueFormalParameters isfalse . - It is a Syntax Error if any element of the
BoundNames ofUniqueFormalParameters also occurs in theLexicallyDeclaredNames ofAsyncGeneratorBody .
- If the source code matching
FormalParameters isstrict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters - If
BindingIdentifier is present and the source code matchingBindingIdentifier isstrict mode code , it is a Syntax Error if theStringValue ofBindingIdentifier is"eval" or"arguments" . - It is a Syntax Error if
FunctionBodyContainsUseStrict ofAsyncGeneratorBody istrue andIsSimpleParameterList ofFormalParameters isfalse . - It is a Syntax Error if any element of the
BoundNames ofFormalParameters also occurs in theLexicallyDeclaredNames ofAsyncGeneratorBody . - It is a Syntax Error if
FormalParameters Contains YieldExpression istrue . - It is a Syntax Error if
FormalParameters Contains AwaitExpression istrue . - It is a Syntax Error if
FormalParameters Contains SuperProperty istrue . - It is a Syntax Error if
AsyncGeneratorBody Contains SuperProperty istrue . - It is a Syntax Error if
FormalParameters Contains SuperCall istrue . - It is a Syntax Error if
AsyncGeneratorBody Contains SuperCall istrue .
15.6.2 Runtime Semantics: EvaluateAsyncGeneratorBody
With parameters functionObject and argumentsList (a
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Let generator be ?
OrdinaryCreateFromConstructor (functionObject," , « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]], [[GeneratorBrand]] »).%AsyncGeneratorFunction.prototype.prototype% " Set generator.[[GeneratorBrand]] toempty .- Perform !
AsyncGeneratorStart (generator,FunctionBody ). - Return
Completion { [[Type]]:return , [[Value]]: generator, [[Target]]:empty }.
15.6.3 Runtime Semantics: InstantiateAsyncGeneratorFunctionObject
With parameter scope.
- Let name be
StringValue ofBindingIdentifier . - Let sourceText be the
source text matched by AsyncGeneratorDeclaration . - Let F be !
OrdinaryFunctionCreate (%AsyncGeneratorFunction.prototype% , sourceText,FormalParameters ,AsyncGeneratorBody ,non-lexical-this , scope). - Perform !
SetFunctionName (F, name). - Let prototype be !
OrdinaryObjectCreate (%AsyncGeneratorFunction.prototype.prototype% ). - Perform !
DefinePropertyOrThrow (F,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Return F.
- Let sourceText be the
source text matched by AsyncGeneratorDeclaration . - Let F be
OrdinaryFunctionCreate (%AsyncGeneratorFunction.prototype% , sourceText,FormalParameters ,AsyncGeneratorBody ,non-lexical-this , scope). - Perform
SetFunctionName (F,"default" ). - Let prototype be !
OrdinaryObjectCreate (%AsyncGeneratorFunction.prototype.prototype% ). - Perform
DefinePropertyOrThrow (F,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Return F.
An anonymous export default declaration.
15.6.4 Runtime Semantics: InstantiateAsyncGeneratorFunctionExpression
With optional parameter name.
- If name is not present, set name to
"" . - Let scope be the LexicalEnvironment of the
running execution context . - Let sourceText be the
source text matched by AsyncGeneratorExpression . - Let closure be !
OrdinaryFunctionCreate (%AsyncGeneratorFunction.prototype% , sourceText,FormalParameters ,AsyncGeneratorBody ,non-lexical-this , scope). - Perform
SetFunctionName (closure, name). - Let prototype be !
OrdinaryObjectCreate (%AsyncGeneratorFunction.prototype.prototype% ). - Perform !
DefinePropertyOrThrow (closure,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Return closure.
Assert : name is not present.Set name toStringValue ofBindingIdentifier .- Let scope be the
running execution context 's LexicalEnvironment. - Let funcEnv be !
NewDeclarativeEnvironment (scope). - Perform ! funcEnv.CreateImmutableBinding(name,
false ). - Let sourceText be the
source text matched by AsyncGeneratorExpression . - Let closure be !
OrdinaryFunctionCreate (%AsyncGeneratorFunction.prototype% , sourceText,FormalParameters ,AsyncGeneratorBody ,non-lexical-this , funcEnv). - Perform !
SetFunctionName (closure, name). - Let prototype be !
OrdinaryObjectCreate (%AsyncGeneratorFunction.prototype.prototype% ). - Perform !
DefinePropertyOrThrow (closure,"prototype" , PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform ! funcEnv.InitializeBinding(name, closure).
- Return closure.
The
15.6.5 Runtime Semantics: Evaluation
15.7 Class Definitions
Syntax
A class definition is always
15.7.1 Static Semantics: Early Errors
-
It is a Syntax Error if
ClassHeritage is not present and the following algorithm evaluates totrue :- Let constructor be
ConstructorMethod ofClassBody . - If constructor is
empty , returnfalse . - Return
HasDirectSuper of constructor.
- Let constructor be
-
It is a Syntax Error if
PrototypePropertyNameList ofClassElementList contains more than one occurrence of"constructor" .
-
It is a Syntax Error if
PropName ofMethodDefinition is not"constructor" andHasDirectSuper ofMethodDefinition istrue . -
It is a Syntax Error if
PropName ofMethodDefinition is"constructor" andSpecialMethod ofMethodDefinition istrue .
-
It is a Syntax Error if
HasDirectSuper ofMethodDefinition istrue . -
It is a Syntax Error if
PropName ofMethodDefinition is"prototype" .
15.7.2 Static Semantics: ClassElementKind
- If
PropName ofMethodDefinition is"constructor" , returnConstructorMethod . - Return
NonConstructorMethod .
- Return
NonConstructorMethod .
- Return
empty .
15.7.3 Static Semantics: ConstructorMethod
- If
ClassElementKind ofClassElement isConstructorMethod , returnClassElement . - Return
empty .
- Let head be ConstructorMethod of
ClassElementList . - If head is not
empty , return head. - If
ClassElementKind ofClassElement isConstructorMethod , returnClassElement . - Return
empty .
Early Error rules ensure that there is only one method definition named
15.7.4 Static Semantics: IsStatic
- Return
false .
- Return
true .
- Return
false .
15.7.5 Static Semantics: NonConstructorMethodDefinitions
- If
ClassElementKind ofClassElement isNonConstructorMethod , then- Return a
List whose sole element isClassElement .
- Return a
- Return a new empty
List .
- Let list be NonConstructorMethodDefinitions of
ClassElementList . - If
ClassElementKind ofClassElement isNonConstructorMethod , then- Append
ClassElement to the end of list.
- Append
- Return list.
15.7.6 Static Semantics: PrototypePropertyNameList
- If
PropName ofClassElement isempty , return a new emptyList . - If
IsStatic ofClassElement istrue , return a new emptyList . - Return a
List whose sole element isPropName ofClassElement .
- Let list be PrototypePropertyNameList of
ClassElementList . - If
PropName ofClassElement isempty , return list. - If
IsStatic ofClassElement istrue , return list. - Append
PropName ofClassElement to the end of list. - Return list.
15.7.7 Runtime Semantics: ClassDefinitionEvaluation
With parameters classBinding and className.
- Let env be the LexicalEnvironment of the
running execution context . - Let classScope be
NewDeclarativeEnvironment (env). - If classBinding is not
undefined , then- Perform classScope.CreateImmutableBinding(classBinding,
true ).
- Perform classScope.CreateImmutableBinding(classBinding,
- If
ClassHeritage_opt is not present, then- Let protoParent be
%Object.prototype% . - Let constructorParent be
%Function.prototype% .
- Let protoParent be
- Else,
Set therunning execution context 's LexicalEnvironment to classScope.- Let superclassRef be the result of evaluating
ClassHeritage . Set therunning execution context 's LexicalEnvironment to env.- Let superclass be ?
GetValue (superclassRef). - If superclass is
null , then- Let protoParent be
null . - Let constructorParent be
%Function.prototype% .
- Let protoParent be
- Else if
IsConstructor (superclass) isfalse , throw aTypeError exception. - Else,
- Let proto be !
OrdinaryObjectCreate (protoParent). - If
ClassBody_opt is not present, let constructor beempty . - Else, let constructor be
ConstructorMethod ofClassBody . Set therunning execution context 's LexicalEnvironment to classScope.- If constructor is
empty , then- Let steps be the algorithm steps defined in
Default Constructor Functions . - Let F be !
CreateBuiltinFunction (steps, 0, className, « [[ConstructorKind]], [[SourceText]] »,empty , constructorParent).
- Let steps be the algorithm steps defined in
- Else,
- Let constructorInfo be !
DefineMethod of constructor with arguments proto and constructorParent. - Let F be constructorInfo.[[Closure]].
- Perform !
MakeClassConstructor (F). - Perform !
SetFunctionName (F, className).
- Let constructorInfo be !
- Perform !
MakeConstructor (F,false , proto). - If
ClassHeritage_opt is present, set F.[[ConstructorKind]] toderived . - Perform !
CreateMethodProperty (proto,"constructor" , F). - If
ClassBody_opt is not present, let methods be a new emptyList . - Else, let methods be
NonConstructorMethodDefinitions ofClassBody . - For each
ClassElement m of methods, do- If
IsStatic of m isfalse , then- Let status be
PropertyDefinitionEvaluation of m with arguments proto andfalse .
- Let status be
- Else,
- Let status be
PropertyDefinitionEvaluation of m with arguments F andfalse .
- Let status be
- If status is an
abrupt completion , thenSet therunning execution context 's LexicalEnvironment to env.- Return
Completion (status).
- If
Set therunning execution context 's LexicalEnvironment to env.- If classBinding is not
undefined , then- Perform classScope.InitializeBinding(classBinding, F).
- Return F.
15.7.7.1 Default Constructor Functions
When a Default
- If NewTarget is
undefined , throw aTypeError exception. - Let F be the
active function object . - If F.[[ConstructorKind]] is
derived , then- NOTE: This branch behaves similarly to
constructor(...args) { super(...args); }. The most notable distinction is that while the aforementioned ECMAScript source text observably calls the @@iterator method on%Array.prototype%, a DefaultConstructor Function does not. - Let func be ! F.[[GetPrototypeOf]]().
- If
IsConstructor (func) isfalse , throw aTypeError exception. - Return ?
Construct (func, args, NewTarget).
- NOTE: This branch behaves similarly to
- Else,
- NOTE: This branch behaves similarly to
constructor() {}. - Return ?
OrdinaryCreateFromConstructor (NewTarget," ).%Object.prototype% "
- NOTE: This branch behaves similarly to
The
15.7.8 Runtime Semantics: BindingClassDeclarationEvaluation
- Let className be
StringValue ofBindingIdentifier . - Let value be ?
ClassDefinitionEvaluation ofClassTail with arguments className and className. Set value.[[SourceText]] to thesource text matched by ClassDeclaration .- Let env be the
running execution context 's LexicalEnvironment. - Perform ?
InitializeBoundName (className, value, env). - Return value.
- Let value be ?
ClassDefinitionEvaluation ofClassTail with argumentsundefined and"default" . Set value.[[SourceText]] to thesource text matched by ClassDeclaration .- Return value.
15.7.9 Runtime Semantics: Evaluation
- Perform ?
BindingClassDeclarationEvaluation of thisClassDeclaration . - Return
NormalCompletion (empty ).
- Let value be ?
ClassDefinitionEvaluation ofClassTail with argumentsundefined and"" . Set value.[[SourceText]] to thesource text matched by ClassExpression .- Return value.
- Let className be
StringValue ofBindingIdentifier . - Let value be ?
ClassDefinitionEvaluation ofClassTail with arguments className and className. Set value.[[SourceText]] to thesource text matched by ClassExpression .- Return value.
15.8 Async Function Definitions
Syntax
await is parsed as an
- In an
AsyncFunctionBody . - In the
FormalParameters of anAsyncFunctionDeclaration ,AsyncFunctionExpression ,AsyncGeneratorDeclaration , orAsyncGeneratorExpression .AwaitExpression in this position is a Syntax error viastatic semantics .
When await is parsed as a await may be parsed as an identifier when the [Await] parameter is absent. This includes the following contexts:
- Anywhere outside of an
AsyncFunctionBody orFormalParameters of anAsyncFunctionDeclaration ,AsyncFunctionExpression ,AsyncGeneratorDeclaration , orAsyncGeneratorExpression . - In the
BindingIdentifier of aFunctionExpression ,GeneratorExpression , orAsyncGeneratorExpression .
Unlike
15.8.1 Static Semantics: Early Errors
- It is a Syntax Error if
FunctionBodyContainsUseStrict ofAsyncFunctionBody istrue andIsSimpleParameterList ofUniqueFormalParameters isfalse . - It is a Syntax Error if
HasDirectSuper ofAsyncMethod istrue . - It is a Syntax Error if
UniqueFormalParameters Contains AwaitExpression istrue . - It is a Syntax Error if any element of the
BoundNames ofUniqueFormalParameters also occurs in theLexicallyDeclaredNames ofAsyncFunctionBody .
- It is a Syntax Error if
FunctionBodyContainsUseStrict ofAsyncFunctionBody istrue andIsSimpleParameterList ofFormalParameters isfalse . - It is a Syntax Error if
FormalParameters Contains AwaitExpression istrue . - If the source code matching
FormalParameters isstrict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters - If
BindingIdentifier is present and the source code matchingBindingIdentifier isstrict mode code , it is a Syntax Error if theStringValue ofBindingIdentifier is"eval" or"arguments" . - It is a Syntax Error if any element of the
BoundNames ofFormalParameters also occurs in theLexicallyDeclaredNames ofAsyncFunctionBody . - It is a Syntax Error if
FormalParameters Contains SuperProperty istrue . - It is a Syntax Error if
AsyncFunctionBody Contains SuperProperty istrue . - It is a Syntax Error if
FormalParameters Contains SuperCall istrue . - It is a Syntax Error if
AsyncFunctionBody Contains SuperCall istrue .
15.8.2 Runtime Semantics: InstantiateAsyncFunctionObject
With parameter scope.
- Let name be
StringValue ofBindingIdentifier . - Let sourceText be the
source text matched by AsyncFunctionDeclaration . - Let F be !
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText,FormalParameters ,AsyncFunctionBody ,non-lexical-this , scope). - Perform !
SetFunctionName (F, name). - Return F.
- Let sourceText be the
source text matched by AsyncFunctionDeclaration . - Let F be !
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText,FormalParameters ,AsyncFunctionBody ,non-lexical-this , scope). - Perform !
SetFunctionName (F,"default" ). - Return F.
15.8.3 Runtime Semantics: InstantiateAsyncFunctionExpression
With optional parameter name.
- If name is not present, set name to
"" . - Let scope be the LexicalEnvironment of the
running execution context . - Let sourceText be the
source text matched by AsyncFunctionExpression . - Let closure be !
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText,FormalParameters ,AsyncFunctionBody ,non-lexical-this , scope). - Perform
SetFunctionName (closure, name). - Return closure.
Assert : name is not present.Set name toStringValue ofBindingIdentifier .- Let scope be the LexicalEnvironment of the
running execution context . - Let funcEnv be !
NewDeclarativeEnvironment (scope). - Perform ! funcEnv.CreateImmutableBinding(name,
false ). - Let sourceText be the
source text matched by AsyncFunctionExpression . - Let closure be !
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText,FormalParameters ,AsyncFunctionBody ,non-lexical-this , funcEnv). - Perform !
SetFunctionName (closure, name). - Perform ! funcEnv.InitializeBinding(name, closure).
- Return closure.
The
15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody
With parameters functionObject and argumentsList (a
- Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let declResult be
FunctionDeclarationInstantiation (functionObject, argumentsList). - If declResult is not an
abrupt completion , then- Perform !
AsyncFunctionStart (promiseCapability,FunctionBody ).
- Perform !
- Else,
- Perform !
Call (promiseCapability.[[Reject]],undefined , « declResult.[[Value]] »).
- Perform !
- Return
Completion { [[Type]]:return , [[Value]]: promiseCapability.[[Promise]], [[Target]]:empty }.
15.8.5 Runtime Semantics: Evaluation
- Return
NormalCompletion (empty ).
- Return
NormalCompletion (empty ).
- Let exprRef be the result of evaluating
UnaryExpression . - Let value be ?
GetValue (exprRef). - Return ?
Await (value).
15.9 Async Arrow Function Definitions
Syntax
Supplemental Syntax
When processing an instance of the production
the interpretation of
15.9.1 Static Semantics: Early Errors
- It is a Syntax Error if any element of the
BoundNames ofAsyncArrowBindingIdentifier also occurs in theLexicallyDeclaredNames ofAsyncConciseBody .
- It is a Syntax Error if
CoverCallExpressionAndAsyncArrowHead Contains YieldExpression istrue . - It is a Syntax Error if
CoverCallExpressionAndAsyncArrowHead Contains AwaitExpression istrue . - It is a Syntax Error if
CoverCallExpressionAndAsyncArrowHead is notcovering anAsyncArrowHead . - It is a Syntax Error if any element of the
BoundNames ofCoverCallExpressionAndAsyncArrowHead also occurs in theLexicallyDeclaredNames ofAsyncConciseBody . - It is a Syntax Error if
AsyncConciseBodyContainsUseStrict ofAsyncConciseBody istrue andIsSimpleParameterList ofCoverCallExpressionAndAsyncArrowHead isfalse . - All Early Error rules for
AsyncArrowHead and its derived productions apply toCoveredAsyncArrowHead ofCoverCallExpressionAndAsyncArrowHead .
15.9.2 Static Semantics: CoveredAsyncArrowHead
- Return the
AsyncArrowHead that iscovered byCoverCallExpressionAndAsyncArrowHead .
15.9.3 Static Semantics: AsyncConciseBodyContainsUseStrict
- Return
false .
- Return
FunctionBodyContainsUseStrict ofAsyncFunctionBody .
15.9.4 Runtime Semantics: EvaluateAsyncConciseBody
With parameters functionObject and argumentsList (a
- Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let declResult be
FunctionDeclarationInstantiation (functionObject, argumentsList). - If declResult is not an
abrupt completion , then- Perform !
AsyncFunctionStart (promiseCapability,ExpressionBody ).
- Perform !
- Else,
- Perform !
Call (promiseCapability.[[Reject]],undefined , « declResult.[[Value]] »).
- Perform !
- Return
Completion { [[Type]]:return , [[Value]]: promiseCapability.[[Promise]], [[Target]]:empty }.
15.9.5 Runtime Semantics: InstantiateAsyncArrowFunctionExpression
With optional parameter name.
- If name is not present, set name to
"" . - Let scope be the LexicalEnvironment of the
running execution context . - Let sourceText be the
source text matched by AsyncArrowFunction . - Let parameters be
AsyncArrowBindingIdentifier . - Let closure be !
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText, parameters,AsyncConciseBody ,lexical-this , scope). - Perform
SetFunctionName (closure, name). - Return closure.
- If name is not present, set name to
"" . - Let scope be the LexicalEnvironment of the
running execution context . - Let sourceText be the
source text matched by AsyncArrowFunction . - Let head be
CoveredAsyncArrowHead ofCoverCallExpressionAndAsyncArrowHead . - Let parameters be the
ArrowFormalParameters of head. - Let closure be !
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText, parameters,AsyncConciseBody ,lexical-this , scope). - Perform
SetFunctionName (closure, name). - Return closure.
15.9.6 Runtime Semantics: Evaluation
15.10 Tail Position Calls
15.10.1 Static Semantics: IsInTailPosition ( call )
The abstract operation IsInTailPosition takes argument call. It performs the following steps when called:
Assert : call is aParse Node .- If the source code matching call is
non-strict code , returnfalse . - If call is not contained within a
FunctionBody ,ConciseBody , orAsyncConciseBody , returnfalse . - Let body be the
FunctionBody ,ConciseBody , orAsyncConciseBody that most closely contains call. - If body is the
FunctionBody of aGeneratorBody , returnfalse . - If body is the
FunctionBody of anAsyncFunctionBody , returnfalse . - If body is the
FunctionBody of anAsyncGeneratorBody , returnfalse . - If body is an
AsyncConciseBody , returnfalse . - Return the result of
HasCallInTailPosition of body with argument call.
Tail Position calls are only defined in
15.10.2 Static Semantics: HasCallInTailPosition
With parameter call.
call is a
15.10.2.1 Statement Rules
- Let has be
HasCallInTailPosition ofStatementList with argument call. - If has is
true , returntrue . - Return
HasCallInTailPosition ofStatementListItem with argument call.
- Return
false .
- Let has be
HasCallInTailPosition of the firstStatement with argument call. - If has is
true , returntrue . - Return
HasCallInTailPosition of the secondStatement with argument call.
- Return
HasCallInTailPosition ofStatement with argument call.
- Return
HasCallInTailPosition ofLabelledItem with argument call.
- Return
HasCallInTailPosition ofExpression with argument call.
- Return
HasCallInTailPosition ofCaseBlock with argument call.
- Let has be
false . - If the first
CaseClauses is present, let has beHasCallInTailPosition of the firstCaseClauses with argument call. - If has is
true , returntrue . - Let has be
HasCallInTailPosition ofDefaultClause with argument call. - If has is
true , returntrue . - If the second
CaseClauses is present, let has beHasCallInTailPosition of the secondCaseClauses with argument call. - Return has.
- Let has be
HasCallInTailPosition ofCaseClauses with argument call. - If has is
true , returntrue . - Return
HasCallInTailPosition ofCaseClause with argument call.
- If
StatementList is present, returnHasCallInTailPosition ofStatementList with argument call. - Return
false .
- Return
HasCallInTailPosition ofCatch with argument call.
- Return
HasCallInTailPosition ofFinally with argument call.
- Return
HasCallInTailPosition ofBlock with argument call.
15.10.2.2 Expression Rules
A potential tail position call that is immediately followed by return
- Return
false .
- Return
HasCallInTailPosition ofAssignmentExpression with argument call.
- Let has be
HasCallInTailPosition of the firstAssignmentExpression with argument call. - If has is
true , returntrue . - Return
HasCallInTailPosition of the secondAssignmentExpression with argument call.
- Return
HasCallInTailPosition ofBitwiseORExpression with argument call.
- Return
HasCallInTailPosition ofLogicalANDExpression with argument call.
- Return
HasCallInTailPosition ofBitwiseORExpression with argument call.
- If this
CallExpression is call, returntrue . - Return
false .
- Return
HasCallInTailPosition ofOptionalChain with argument call.
- Return
false .
- If this
OptionalChain is call, returntrue . - Return
false .
- If this
MemberExpression is call, returntrue . - Return
false .
- Let expr be
CoveredParenthesizedExpression ofCoverParenthesizedExpressionAndArrowParameterList . - Return
HasCallInTailPosition of expr with argument call.
- Return
HasCallInTailPosition ofExpression with argument call.
15.10.3 PrepareForTailCall ( )
The abstract operation PrepareForTailCall takes no arguments. It performs the following steps when called:
- Let leafContext be the
running execution context . - Suspend leafContext.
- Pop leafContext from the
execution context stack . Theexecution context now on the top of the stack becomes therunning execution context . Assert : leafContext has no further use. It will never be activated as therunning execution context .
A tail position call must either release any transient internal resources associated with the currently executing function
For example, a tail position call should only grow an implementation's activation record stack by the amount that the size of the target function's activation record exceeds the size of the calling function's activation record. If the target function's activation record is smaller, then the total size of the stack should decrease.