15 ECMAScript Language: Functions and Classes
Various ECMAScript language elements cause the creation of ECMAScript
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
The
- 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 the
ArrowFormalParameters that iscovered byCoverParenthesizedExpressionAndArrowParameterList . - Return ContainsExpression of formals.
- Return
false .
15.1.3 Static Semantics: IsSimpleParameterList
The
- 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 the
ArrowFormalParameters that iscovered byCoverParenthesizedExpressionAndArrowParameterList . - Return IsSimpleParameterList of formals.
- Return
true .
- Let head be the
AsyncArrowHead that iscovered byCoverCallExpressionAndAsyncArrowHead . - Return IsSimpleParameterList of head.
15.1.4 Static Semantics: HasInitializer
The
- Return
false .
- Return
true .
- Return
false .
- Return
true .
- If HasInitializer of
FormalParameterList istrue , returntrue . - Return HasInitializer of
FormalParameter .
15.1.5 Static Semantics: ExpectedArgumentCount
The
- 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 the
ArrowFormalParameters that iscovered byCoverParenthesizedExpressionAndArrowParameterList . - 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 text matched by FormalParameters isstrict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters -
If
BindingIdentifier is present and thesource text matched by BindingIdentifier isstrict mode code , it is a Syntax Error if theStringValue ofBindingIdentifier is either"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
The
- If the
Directive Prologue ofFunctionBody contains aUse Strict Directive , returntrue ; otherwise, returnfalse .
15.2.3 Runtime Semantics: EvaluateFunctionBody
The
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Return ?
Evaluation ofFunctionStatementList .
15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject
The
- 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 , env, privateEnv). - 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 , env, privateEnv). - 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
The
- If name is not present, set name to
"" . - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by FunctionExpression . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , env, privateEnv). - Perform
SetFunctionName (closure, name). - Perform
MakeConstructor (closure). - Return closure.
Assert : name is not present.- Set name to
StringValue ofBindingIdentifier . - Let outerEnv be the
running execution context 's LexicalEnvironment. - Let funcEnv be
NewDeclarativeEnvironment (outerEnv). - Perform ! funcEnv.CreateImmutableBinding(name,
false ). - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by FunctionExpression . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,FormalParameters ,FunctionBody ,non-lexical-this , funcEnv, privateEnv). - Perform
SetFunctionName (closure, name). - Perform
MakeConstructor (closure). - Perform ! funcEnv.InitializeBinding(name, closure).
- Return closure.
The
15.2.6 Runtime Semantics: Evaluation
- Return
empty .
An alternative semantics is provided in
- Return
empty .
A
- Return
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 .
15.3.2 Static Semantics: ConciseBodyContainsUseStrict
The
- Return
false .
- Return
FunctionBodyContainsUseStrict ofFunctionBody .
15.3.3 Runtime Semantics: EvaluateConciseBody
The
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Return ?
Evaluation ofExpressionBody .
15.3.4 Runtime Semantics: InstantiateArrowFunctionExpression
The
- If name is not present, set name to
"" . - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by ArrowFunction . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,ArrowParameters ,ConciseBody ,lexical-this , env, privateEnv). - 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 env that is captured by the
15.3.5 Runtime Semantics: Evaluation
- Return
InstantiateArrowFunctionExpression ofArrowFunction .
- Let exprRef be ?
Evaluation ofAssignmentExpression . - Let exprValue be ?
GetValue (exprRef). - Return
Completion Record { [[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
The
- 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
The
- Return
false .
- Return
true .
15.4.4 Runtime Semantics: DefineMethod
The
- Let propKey be ?
Evaluation ofClassElementName . - Let env be the
running execution context 's LexicalEnvironment. - Let privateEnv be the
running execution context 's PrivateEnvironment. - 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 , env, privateEnv). - Perform
MakeMethod (closure, object). - Return the
Record { [[Key]]: propKey, [[Closure]]: closure }.
15.4.5 Runtime Semantics: MethodDefinitionEvaluation
The
- Let methodDef be ?
DefineMethod ofMethodDefinition with argument object. - Perform
SetFunctionName (methodDef.[[Closure]], methodDef.[[Key]]). - Return ?
DefineMethodProperty (object, methodDef.[[Key]], methodDef.[[Closure]], enumerable).
- Let propKey be ?
Evaluation ofClassElementName . - Let env be the
running execution context 's LexicalEnvironment. - Let privateEnv be the
running execution context 's PrivateEnvironment. - 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 , env, privateEnv). - Perform
MakeMethod (closure, object). - Perform
SetFunctionName (closure, propKey,"get" ). - If propKey is a
Private Name , then- Return
PrivateElement { [[Key]]: propKey, [[Kind]]:accessor , [[Get]]: closure, [[Set]]:undefined }.
- Return
- Else,
- Let desc be the PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]:
true }. - Perform ?
DefinePropertyOrThrow (object, propKey, desc). - Return
unused .
- Let desc be the PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]:
- Let propKey be ?
Evaluation ofClassElementName . - Let env be the
running execution context 's LexicalEnvironment. - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by MethodDefinition . - Let closure be
OrdinaryFunctionCreate (%Function.prototype% , sourceText,PropertySetParameterList ,FunctionBody ,non-lexical-this , env, privateEnv). - Perform
MakeMethod (closure, object). - Perform
SetFunctionName (closure, propKey,"set" ). - If propKey is a
Private Name , then- Return
PrivateElement { [[Key]]: propKey, [[Kind]]:accessor , [[Get]]:undefined , [[Set]]: closure }.
- Return
- Else,
- Let desc be the PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]:
true }. - Perform ?
DefinePropertyOrThrow (object, propKey, desc). - Return
unused .
- Let desc be the PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]:
- Let propKey be ?
Evaluation ofClassElementName . - Let env be the
running execution context 's LexicalEnvironment. - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by GeneratorMethod . - Let closure be
OrdinaryFunctionCreate (%GeneratorFunction.prototype% , sourceText,UniqueFormalParameters ,GeneratorBody ,non-lexical-this , env, privateEnv). - 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 }). - Return ?
DefineMethodProperty (object, propKey, closure, enumerable).
- Let propKey be ?
Evaluation ofClassElementName . - Let env be the
running execution context 's LexicalEnvironment. - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by AsyncGeneratorMethod . - Let closure be
OrdinaryFunctionCreate (%AsyncGeneratorFunction.prototype% , sourceText,UniqueFormalParameters ,AsyncGeneratorBody ,non-lexical-this , env, privateEnv). - 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 }). - Return ?
DefineMethodProperty (object, propKey, closure, enumerable).
- Let propKey be ?
Evaluation ofClassElementName . - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by AsyncMethod . - Let closure be
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText,UniqueFormalParameters ,AsyncFunctionBody ,non-lexical-this , env, privateEnv). - Perform
MakeMethod (closure, object). - Perform
SetFunctionName (closure, propKey). - Return ?
DefineMethodProperty (object, propKey, closure, enumerable).
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 text matched by FormalParameters isstrict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters -
If
BindingIdentifier is present and thesource text matched by BindingIdentifier isstrict mode code , it is a Syntax Error if theStringValue ofBindingIdentifier is either"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
The
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Let G be ?
OrdinaryCreateFromConstructor (functionObject," , « [[GeneratorState]], [[GeneratorContext]], [[GeneratorBrand]] »).%GeneratorFunction.prototype.prototype% " - Set G.[[GeneratorBrand]] to
empty . - Perform
GeneratorStart (G,FunctionBody ). - Return
Completion Record { [[Type]]:return , [[Value]]: G, [[Target]]:empty }.
15.5.3 Runtime Semantics: InstantiateGeneratorFunctionObject
The
- 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 , env, privateEnv). - 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 , env, privateEnv). - 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
The
- If name is not present, set name to
"" . - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by GeneratorExpression . - Let closure be
OrdinaryFunctionCreate (%GeneratorFunction.prototype% , sourceText,FormalParameters ,GeneratorBody ,non-lexical-this , env, privateEnv). - 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 to
StringValue ofBindingIdentifier . - Let outerEnv be the
running execution context 's LexicalEnvironment. - Let funcEnv be
NewDeclarativeEnvironment (outerEnv). - Perform ! funcEnv.CreateImmutableBinding(name,
false ). - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by GeneratorExpression . - Let closure be
OrdinaryFunctionCreate (%GeneratorFunction.prototype% , sourceText,FormalParameters ,GeneratorBody ,non-lexical-this , funcEnv, privateEnv). - 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 ?
Evaluation ofAssignmentExpression . - Let value be ?
GetValue (exprRef). - Return ?
Yield (value).
- Let generatorKind be
GetGeneratorKind (). - Let exprRef be ?
Evaluation ofAssignmentExpression . - Let value be ?
GetValue (exprRef). - Let iteratorRecord be ?
GetIterator (value, generatorKind). - Let iterator be iteratorRecord.[[Iterator]].
- Let received be
NormalCompletion (undefined ). - Repeat,
- If received is a
normal completion , then- Let innerResult be ?
Call (iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] »). - If generatorKind is
async , set innerResult to ?Await (innerResult). - If innerResult
is not an Object , throw aTypeError exception. - Let done be ?
IteratorComplete (innerResult). - If done is
true , then- Return ?
IteratorValue (innerResult).
- Return ?
- If generatorKind is
async , set received toCompletion (AsyncGeneratorYield (?IteratorValue (innerResult))). - Else, set received to
Completion (GeneratorYield (innerResult)).
- Let innerResult be ?
- Else if received is a
throw completion , 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 innerResult
is not an Object , throw aTypeError exception. - Let done be ?
IteratorComplete (innerResult). - If done is
true , then- Return ?
IteratorValue (innerResult).
- Return ?
- If generatorKind is
async , set received toCompletion (AsyncGeneratorYield (?IteratorValue (innerResult))). - Else, set received to
Completion (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 Record { [[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 is areturn completion .- Let return be ?
GetMethod (iterator,"return" ). - If return is
undefined , then- Set value to received.[[Value]].
- If generatorKind is
async , then- Set value to ?
Await (value).
- Set value to ?
- Return
Completion Record { [[Type]]:return , [[Value]]: value, [[Target]]:empty }.
- Let innerReturnResult be ?
Call (return, iterator, « received.[[Value]] »). - If generatorKind is
async , set innerReturnResult to ?Await (innerReturnResult). - If innerReturnResult
is not an Object , throw aTypeError exception. - Let done be ?
IteratorComplete (innerReturnResult). - If done is
true , then- Set value to ?
IteratorValue (innerReturnResult). - Return
Completion Record { [[Type]]:return , [[Value]]: value, [[Target]]:empty }.
- Set value to ?
- If generatorKind is
async , set received toCompletion (AsyncGeneratorYield (?IteratorValue (innerReturnResult))). - Else, set received to
Completion (GeneratorYield (innerReturnResult)).
- If received is a
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 text matched by FormalParameters isstrict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters - If
BindingIdentifier is present and thesource text matched by BindingIdentifier isstrict mode code , it is a Syntax Error if theStringValue ofBindingIdentifier is either"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
The
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Let generator be ?
OrdinaryCreateFromConstructor (functionObject," , « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]], [[GeneratorBrand]] »).%AsyncGeneratorFunction.prototype.prototype% " - Set generator.[[GeneratorBrand]] to
empty . - Perform
AsyncGeneratorStart (generator,FunctionBody ). - Return
Completion Record { [[Type]]:return , [[Value]]: generator, [[Target]]:empty }.
15.6.3 Runtime Semantics: InstantiateAsyncGeneratorFunctionObject
The
- 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 , env, privateEnv). - 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 , env, privateEnv). - 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
The
- If name is not present, set name to
"" . - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by AsyncGeneratorExpression . - Let closure be
OrdinaryFunctionCreate (%AsyncGeneratorFunction.prototype% , sourceText,FormalParameters ,AsyncGeneratorBody ,non-lexical-this , env, privateEnv). - 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 to
StringValue ofBindingIdentifier . - Let outerEnv be the
running execution context 's LexicalEnvironment. - Let funcEnv be
NewDeclarativeEnvironment (outerEnv). - Perform ! funcEnv.CreateImmutableBinding(name,
false ). - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by AsyncGeneratorExpression . - Let closure be
OrdinaryFunctionCreate (%AsyncGeneratorFunction.prototype% , sourceText,FormalParameters ,AsyncGeneratorBody ,non-lexical-this , funcEnv, privateEnv). - 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 returnstrue :- 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
PrivateBoundIdentifiers ofClassElementList contains any duplicate entries, unless the name is used once for a getter and once for a setter and in no other entries, and the getter and setter are either both static or both non-static.
-
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" .
- It is a Syntax Error if
PropName ofFieldDefinition is"constructor" .
-
It is a Syntax Error if
PropName ofFieldDefinition is either"prototype" or"constructor" .
- It is a Syntax Error if
Initializer is present andContainsArguments ofInitializer istrue . - It is a Syntax Error if
Initializer is present andInitializer Contains SuperCall istrue .
- It is a Syntax Error if
StringValue ofPrivateIdentifier is"#constructor" .
-
It is a Syntax Error if the
LexicallyDeclaredNames ofClassStaticBlockStatementList contains any duplicate entries. -
It is a Syntax Error if any element of the
LexicallyDeclaredNames ofClassStaticBlockStatementList also occurs in theVarDeclaredNames ofClassStaticBlockStatementList . -
It is a Syntax Error if
ContainsDuplicateLabels ofClassStaticBlockStatementList with argument « » istrue . -
It is a Syntax Error if
ContainsUndefinedBreakTarget ofClassStaticBlockStatementList with argument « » istrue . -
It is a Syntax Error if
ContainsUndefinedContinueTarget ofClassStaticBlockStatementList with arguments « » and « » istrue . -
It is a Syntax Error if
ContainsArguments ofClassStaticBlockStatementList istrue . -
It is a Syntax Error if
ClassStaticBlockStatementList Contains SuperCall istrue . -
It is a Syntax Error if
ClassStaticBlockStatementList Contains awaitistrue .
15.7.2 Static Semantics: ClassElementKind
The
- If
PropName ofMethodDefinition is"constructor" , returnconstructor-method . - Return
non-constructor-method .
- Return
non-constructor-method .
- Return
non-constructor-method .
- Return
empty .
15.7.3 Static Semantics: ConstructorMethod
The
- If
ClassElementKind ofClassElement isconstructor-method , returnClassElement . - Return
empty .
- Let head be ConstructorMethod of
ClassElementList . - If head is not
empty , return head. - If
ClassElementKind ofClassElement isconstructor-method , returnClassElement . - Return
empty .
Early Error rules ensure that there is only one method definition named
15.7.4 Static Semantics: IsStatic
The
- Return
false .
- Return
true .
- Return
false .
- Return
true .
- Return
true .
- Return
false .
15.7.5 Static Semantics: NonConstructorElements
The
- If
ClassElementKind ofClassElement isnon-constructor-method , then- Return «
ClassElement ».
- Return «
- Return a new empty
List .
- Let list be NonConstructorElements of
ClassElementList . - If
ClassElementKind ofClassElement isnon-constructor-method , then- Append
ClassElement to the end of list.
- Append
- Return list.
15.7.6 Static Semantics: PrototypePropertyNameList
The
- Let propName be
PropName ofClassElement . - If propName is
empty , return a new emptyList . - If
IsStatic ofClassElement istrue , return a new emptyList . - Return « propName ».
- Let list be PrototypePropertyNameList of
ClassElementList . - Let propName be
PropName ofClassElement . - If propName is
empty , return list. - If
IsStatic ofClassElement istrue , return list. - Return the
list-concatenation of list and « propName ».
15.7.7 Static Semantics: AllPrivateIdentifiersValid
The
Every grammar production alternative in this specification which is not listed below implicitly has the following default definition of AllPrivateIdentifiersValid:
- For each child node child of this
Parse Node , do- If child is an instance of a nonterminal, then
- If AllPrivateIdentifiersValid of child with argument names is
false , returnfalse .
- If AllPrivateIdentifiersValid of child with argument names is
- If child is an instance of a nonterminal, then
- Return
true .
- If names contains the
StringValue ofPrivateIdentifier , then- Return AllPrivateIdentifiersValid of
MemberExpression with argument names.
- Return AllPrivateIdentifiersValid of
- Return
false .
- If names contains the
StringValue ofPrivateIdentifier , then- Return AllPrivateIdentifiersValid of
CallExpression with argument names.
- Return AllPrivateIdentifiersValid of
- Return
false .
- If names contains the
StringValue ofPrivateIdentifier , returntrue . - Return
false .
- If names contains the
StringValue ofPrivateIdentifier , then- Return AllPrivateIdentifiersValid of
OptionalChain with argument names.
- Return AllPrivateIdentifiersValid of
- Return
false .
- Let newNames be the
list-concatenation of names andPrivateBoundIdentifiers ofClassBody . - Return AllPrivateIdentifiersValid of
ClassElementList with argument newNames.
- If names contains the
StringValue ofPrivateIdentifier , then- Return AllPrivateIdentifiersValid of
ShiftExpression with argument names.
- Return AllPrivateIdentifiersValid of
- Return
false .
15.7.8 Static Semantics: PrivateBoundIdentifiers
The
- Return PrivateBoundIdentifiers of
ClassElementName .
- Return a
List whose sole element is theStringValue ofPrivateIdentifier .
- Return a new empty
List .
- Let names1 be PrivateBoundIdentifiers of
ClassElementList . - Let names2 be PrivateBoundIdentifiers of
ClassElement . - Return the
list-concatenation of names1 and names2.
- Return PrivateBoundIdentifiers of
ClassElementName .
15.7.9 Static Semantics: ContainsArguments
The
Every grammar production alternative in this specification which is not listed below implicitly has the following default definition of ContainsArguments:
- For each child node child of this
Parse Node , do- If child is an instance of a nonterminal, then
- If ContainsArguments of child is
true , returntrue .
- If ContainsArguments of child is
- If child is an instance of a nonterminal, then
- Return
false .
- If the
StringValue ofIdentifier is"arguments" , returntrue . - Return
false .
- Return
false .
- Return ContainsArguments of
ClassElementName .
15.7.10 Runtime Semantics: ClassFieldDefinitionEvaluation
The
- Let name be ?
Evaluation ofClassElementName . - If
Initializer is present, then- Let formalParameterList be an instance of the production
.FormalParameters : [empty] - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the empty sequence of Unicode code points.
- Let initializer be
OrdinaryFunctionCreate (%Function.prototype% , sourceText, formalParameterList,Initializer ,non-lexical-this , env, privateEnv). - Perform
MakeMethod (initializer, homeObject). - Set initializer.[[ClassFieldInitializerName]] to name.
- Let formalParameterList be an instance of the production
- Else,
- Let initializer be
empty .
- Let initializer be
- Return the
ClassFieldDefinition Record { [[Name]]: name, [[Initializer]]: initializer }.
15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation
The
- Let lex be the
running execution context 's LexicalEnvironment. - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the empty sequence of Unicode code points.
- Let formalParameters be an instance of the production
.FormalParameters : [empty] - Let bodyFunction be
OrdinaryFunctionCreate (%Function.prototype% , sourceText, formalParameters,ClassStaticBlockBody ,non-lexical-this , lex, privateEnv). - Perform
MakeMethod (bodyFunction, homeObject). - Return the
ClassStaticBlockDefinition Record { [[BodyFunction]]: bodyFunction }.
15.7.12 Runtime Semantics: EvaluateClassStaticBlockBody
The
Assert : functionObject is a synthetic function created byClassStaticBlockDefinitionEvaluation step5 .- Perform !
FunctionDeclarationInstantiation (functionObject, « »). - Return ?
Evaluation ofClassStaticBlockStatementList .
15.7.13 Runtime Semantics: ClassElementEvaluation
The
- Return ?
ClassFieldDefinitionEvaluation ofFieldDefinition with argument object.
- Return ?
MethodDefinitionEvaluation ofMethodDefinition with arguments object andfalse .
- Return
ClassStaticBlockDefinitionEvaluation ofClassStaticBlock with argument object.
- Return
unused .
15.7.14 Runtime Semantics: ClassDefinitionEvaluation
The
For ease of specification, private methods and accessors are included alongside private fields in the [[PrivateElements]] slot of class instances. However, any given object has either all or none of the private methods and accessors defined by a given class. This feature has been designed so that implementations may choose to implement private methods and accessors using a strategy which does not require tracking each method or accessor individually.
For example, an implementation could directly associate instance private methods with their corresponding this value. Looking up an instance private method on an object then consists of checking that the class
This differs from private fields: because field initializers can throw during class instantiation, an individual object may have some proper subset of the private fields of a given class, and so private fields must in general be tracked individually.
It is defined piecewise over the following productions:
- Let env be the LexicalEnvironment of the
running execution context . - Let classEnv be
NewDeclarativeEnvironment (env). - If classBinding is not
undefined , then- Perform ! classEnv.CreateImmutableBinding(classBinding,
true ).
- Perform ! classEnv.CreateImmutableBinding(classBinding,
- Let outerPrivateEnvironment be the
running execution context 's PrivateEnvironment. - Let classPrivateEnvironment be
NewPrivateEnvironment (outerPrivateEnvironment). - If
ClassBody is present, then- For each String dn of the
PrivateBoundIdentifiers ofClassBody , do- If classPrivateEnvironment.[[Names]] contains a
Private Name pn such that pn.[[Description]] is dn, thenAssert : This is only possible for getter/setter pairs.
- Else,
- Let name be a new
Private Name whose [[Description]] is dn. - Append name to classPrivateEnvironment.[[Names]].
- Let name be a new
- If classPrivateEnvironment.[[Names]] contains a
- For each String dn of the
- If
ClassHeritage is not present, then- Let protoParent be
%Object.prototype% . - Let constructorParent be
%Function.prototype% .
- Let protoParent be
- Else,
- Set the
running execution context 's LexicalEnvironment to classEnv. - NOTE: The
running execution context 's PrivateEnvironment is outerPrivateEnvironment when evaluatingClassHeritage . - Let superclassRef be
Completion (Evaluation ofClassHeritage ). - Set the
running 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 , then- Throw a
TypeError exception.
- Throw a
- Else,
- Let protoParent be ?
Get (superclass,"prototype" ). - If protoParent
is not an Object and protoParent is notnull , throw aTypeError exception. - Let constructorParent be superclass.
- Let protoParent be ?
- Set the
- Let proto be
OrdinaryObjectCreate (protoParent). - If
ClassBody is not present, let constructor beempty . - Else, let constructor be
ConstructorMethod ofClassBody . - Set the
running execution context 's LexicalEnvironment to classEnv. - Set the
running execution context 's PrivateEnvironment to classPrivateEnvironment. - If constructor is
empty , then- Let defaultConstructor be a new
Abstract Closure with no parameters that captures nothing and performs the following steps when called:- Let args be the
List of arguments that was passed to this function by [[Call]] or [[Construct]]. - 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 aforementionedECMAScript source text observably calls the @@iterator method on%Array.prototype%, this function does not. - Let func be ! F.[[GetPrototypeOf]]().
- If
IsConstructor (func) isfalse , throw aTypeError exception. - Let result be ?
Construct (func, args, NewTarget).
- NOTE: This branch behaves similarly to
- Else,
- NOTE: This branch behaves similarly to
constructor() {}. - Let result be ?
OrdinaryCreateFromConstructor (NewTarget," ).%Object.prototype% "
- NOTE: This branch behaves similarly to
- Perform ?
InitializeInstanceElements (result, F). - Return result.
- Let args be the
- Let F be
CreateBuiltinFunction (defaultConstructor, 0, className, « [[ConstructorKind]], [[SourceText]] »,the current Realm Record , constructorParent).
- Let defaultConstructor be a new
- 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 is present, set F.[[ConstructorKind]] toderived . - Perform !
DefineMethodProperty (proto,"constructor" , F,false ). - If
ClassBody is not present, let elements be a new emptyList . - Else, let elements be
NonConstructorElements ofClassBody . - Let instancePrivateMethods be a new empty
List . - Let staticPrivateMethods be a new empty
List . - Let instanceFields be a new empty
List . - Let staticElements be a new empty
List . - For each
ClassElement e of elements, do- If
IsStatic of e isfalse , then- Let element be
Completion (ClassElementEvaluation of e with argument proto).
- Let element be
- Else,
- Let element be
Completion (ClassElementEvaluation of e with argument F).
- Let element be
- If element is an
abrupt completion , then- Set the
running execution context 's LexicalEnvironment to env. - Set the
running execution context 's PrivateEnvironment to outerPrivateEnvironment. - Return ? element.
- Set the
- Set element to ! element.
- If element is a
PrivateElement , thenAssert : element.[[Kind]] is eithermethod oraccessor .- If
IsStatic of e isfalse , let container be instancePrivateMethods. - Else, let container be staticPrivateMethods.
- If container contains a
PrivateElement pe such that pe.[[Key]] is element.[[Key]], thenAssert : element.[[Kind]] and pe.[[Kind]] are bothaccessor .- If element.[[Get]] is
undefined , then- Let combined be
PrivateElement { [[Key]]: element.[[Key]], [[Kind]]:accessor , [[Get]]: pe.[[Get]], [[Set]]: element.[[Set]] }.
- Let combined be
- Else,
- Let combined be
PrivateElement { [[Key]]: element.[[Key]], [[Kind]]:accessor , [[Get]]: element.[[Get]], [[Set]]: pe.[[Set]] }.
- Let combined be
- Replace pe in container with combined.
- Else,
- Append element to container.
- Else if element is a
ClassFieldDefinition Record , then- If
IsStatic of e isfalse , append element to instanceFields. - Else, append element to staticElements.
- If
- Else if element is a
ClassStaticBlockDefinition Record , then- Append element to staticElements.
- If
- Set the
running execution context 's LexicalEnvironment to env. - If classBinding is not
undefined , then- Perform ! classEnv.InitializeBinding(classBinding, F).
- Set F.[[PrivateMethods]] to instancePrivateMethods.
- Set F.[[Fields]] to instanceFields.
- For each
PrivateElement method of staticPrivateMethods, do- Perform !
PrivateMethodOrAccessorAdd (F, method).
- Perform !
- For each element elementRecord of staticElements, do
- If elementRecord is a
ClassFieldDefinition Record , then- Let result be
Completion (DefineField (F, elementRecord)).
- Let result be
- Else,
Assert : elementRecord is aClassStaticBlockDefinition Record .- Let result be
Completion (Call (elementRecord.[[BodyFunction]], F)).
- If result is an
abrupt completion , then- Set the
running execution context 's PrivateEnvironment to outerPrivateEnvironment. - Return ? result.
- Set the
- If elementRecord is a
- Set the
running execution context 's PrivateEnvironment to outerPrivateEnvironment. - Return F.
15.7.15 Runtime Semantics: BindingClassDeclarationEvaluation
The
- Let className be
StringValue ofBindingIdentifier . - Let value be ?
ClassDefinitionEvaluation ofClassTail with arguments className and className. - Set value.[[SourceText]] to the
source 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 the
source text matched by ClassDeclaration . - Return value.
15.7.16 Runtime Semantics: Evaluation
- Perform ?
BindingClassDeclarationEvaluation of thisClassDeclaration . - Return
empty .
- Let value be ?
ClassDefinitionEvaluation ofClassTail with argumentsundefined and"" . - Set value.[[SourceText]] to the
source 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 the
source text matched by ClassExpression . - Return value.
- Let privateIdentifier be
StringValue ofPrivateIdentifier . - Let privateEnvRec be the
running execution context 's PrivateEnvironment. - Let names be privateEnvRec.[[Names]].
Assert : Exactly one element of names is aPrivate Name whose [[Description]] is privateIdentifier.- Let privateName be the
Private Name in names whose [[Description]] is privateIdentifier. - Return privateName.
- Return
undefined .
15.8 Async Function Definitions
Syntax
await is parsed as a
- In an
AsyncFunctionBody . - In the
FormalParameters of anAsyncFunctionDeclaration ,AsyncFunctionExpression ,AsyncGeneratorDeclaration , orAsyncGeneratorExpression .AwaitExpression in this position is a Syntax error viastatic semantics . - In a
Module .
When 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 text matched by FormalParameters isstrict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters - If
BindingIdentifier is present and thesource text matched by BindingIdentifier isstrict mode code , it is a Syntax Error if theStringValue ofBindingIdentifier is either"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
The
- 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 , env, privateEnv). - 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 , env, privateEnv). - Perform
SetFunctionName (F,"default" ). - Return F.
15.8.3 Runtime Semantics: InstantiateAsyncFunctionExpression
The
- If name is not present, set name to
"" . - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by AsyncFunctionExpression . - Let closure be
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText,FormalParameters ,AsyncFunctionBody ,non-lexical-this , env, privateEnv). - Perform
SetFunctionName (closure, name). - Return closure.
Assert : name is not present.- Set name to
StringValue ofBindingIdentifier . - Let outerEnv be the LexicalEnvironment of the
running execution context . - Let funcEnv be
NewDeclarativeEnvironment (outerEnv). - Perform ! funcEnv.CreateImmutableBinding(name,
false ). - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by AsyncFunctionExpression . - Let closure be
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText,FormalParameters ,AsyncFunctionBody ,non-lexical-this , funcEnv, privateEnv). - Perform
SetFunctionName (closure, name). - Perform ! funcEnv.InitializeBinding(name, closure).
- Return closure.
The
15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody
The
- Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let declResult be
Completion (FunctionDeclarationInstantiation (functionObject, argumentsList)). - If declResult is an
abrupt completion , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « declResult.[[Value]] »).
- Perform !
- Else,
- Perform
AsyncFunctionStart (promiseCapability,FunctionBody ).
- Perform
- Return
Completion Record { [[Type]]:return , [[Value]]: promiseCapability.[[Promise]], [[Target]]:empty }.
15.8.5 Runtime Semantics: Evaluation
- Let exprRef be ?
Evaluation ofUnaryExpression . - 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 .
CoverCallExpressionAndAsyncArrowHead must cover anAsyncArrowHead .- 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 any element of the
BoundNames ofCoverCallExpressionAndAsyncArrowHead also occurs in theLexicallyDeclaredNames ofAsyncConciseBody . - It is a Syntax Error if
AsyncConciseBodyContainsUseStrict ofAsyncConciseBody istrue andIsSimpleParameterList ofCoverCallExpressionAndAsyncArrowHead isfalse .
15.9.2 Static Semantics: AsyncConciseBodyContainsUseStrict
The
- Return
false .
- Return
FunctionBodyContainsUseStrict ofAsyncFunctionBody .
15.9.3 Runtime Semantics: EvaluateAsyncConciseBody
The
- Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let declResult be
Completion (FunctionDeclarationInstantiation (functionObject, argumentsList)). - If declResult is an
abrupt completion , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « declResult.[[Value]] »).
- Perform !
- Else,
- Perform
AsyncFunctionStart (promiseCapability,ExpressionBody ).
- Perform
- Return
Completion Record { [[Type]]:return , [[Value]]: promiseCapability.[[Promise]], [[Target]]:empty }.
15.9.4 Runtime Semantics: InstantiateAsyncArrowFunctionExpression
The
- If name is not present, set name to
"" . - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by AsyncArrowFunction . - Let parameters be
AsyncArrowBindingIdentifier . - Let closure be
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText, parameters,AsyncConciseBody ,lexical-this , env, privateEnv). - Perform
SetFunctionName (closure, name). - Return closure.
- If name is not present, set name to
"" . - Let env be the LexicalEnvironment of the
running execution context . - Let privateEnv be the
running execution context 's PrivateEnvironment. - Let sourceText be the
source text matched by AsyncArrowFunction . - Let head be the
AsyncArrowHead that iscovered byCoverCallExpressionAndAsyncArrowHead . - Let parameters be the
ArrowFormalParameters of head. - Let closure be
OrdinaryFunctionCreate (%AsyncFunction.prototype% , sourceText, parameters,AsyncConciseBody ,lexical-this , env, privateEnv). - Perform
SetFunctionName (closure, name). - Return closure.
15.9.5 Runtime Semantics: Evaluation
15.10 Tail Position Calls
15.10.1 Static Semantics: IsInTailPosition ( call )
The abstract operation IsInTailPosition takes argument call (a
- If the
source text matched by call isnon-strict code , returnfalse . - If call is not contained within a
FunctionBody , aConciseBody , or anAsyncConciseBody , 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
The
call is a
A potential tail position call that is immediately followed by return
It is defined piecewise over the following productions:
- Let has be HasCallInTailPosition of
StatementList with argument call. - If has is
true , returntrue . - Return HasCallInTailPosition of
StatementListItem with argument call.
- Return
false .
- Return HasCallInTailPosition of
Statement with argument call.
- Return HasCallInTailPosition of
LabelledItem with argument call.
- Return HasCallInTailPosition of
Expression with argument call.
- Return HasCallInTailPosition of
CaseBlock with argument call.
- Let has be
false . - If the first
CaseClauses is present, set has to HasCallInTailPosition of the firstCaseClauses with argument call. - If has is
true , returntrue . - Set has to HasCallInTailPosition of
DefaultClause with argument call. - If has is
true , returntrue . - If the second
CaseClauses is present, set has to HasCallInTailPosition of the secondCaseClauses with argument call. - Return has.
- Let has be HasCallInTailPosition of
CaseClauses with argument call. - If has is
true , returntrue . - Return HasCallInTailPosition of
CaseClause with argument call.
- If
StatementList is present, return HasCallInTailPosition ofStatementList with argument call. - Return
false .
- Return HasCallInTailPosition of
Catch with argument call.
- Return HasCallInTailPosition of
Finally with argument call.
- Return HasCallInTailPosition of
Block with argument call.
- Return
false .
- Return HasCallInTailPosition of
AssignmentExpression with argument call.
- Let has be HasCallInTailPosition of the first
AssignmentExpression with argument call. - If has is
true , returntrue . - Return HasCallInTailPosition of the second
AssignmentExpression with argument call.
- Return HasCallInTailPosition of
BitwiseORExpression with argument call.
- Return HasCallInTailPosition of
LogicalANDExpression with argument call.
- Return HasCallInTailPosition of
BitwiseORExpression with argument call.
- If this
CallExpression is call, returntrue . - Return
false .
- Return HasCallInTailPosition of
OptionalChain with argument call.
- Return
false .
- If this
OptionalChain is call, returntrue . - Return
false .
- If this
MemberExpression is call, returntrue . - Return
false .
- Let expr be the
ParenthesizedExpression that iscovered byCoverParenthesizedExpressionAndArrowParameterList . - Return HasCallInTailPosition of expr with argument call.
- Return HasCallInTailPosition of
Expression with argument call.
15.10.3 PrepareForTailCall ( )
The abstract operation PrepareForTailCall takes no arguments and returns
Assert : The currentexecution context will not subsequently be used for the evaluation of any ECMAScript code or built-in functions. The invocation of Call subsequent to the invocation of this abstract operation will create and push a newexecution context before performing any such evaluation.- Discard all resources associated with the current
execution context . - Return
unused .
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.