14 ECMAScript Language: Functions and Classes
14.1 Function Definitions
Syntax
14.1.1 Directive Prologues and the Use Strict Directive
A Directive Prologue is the longest sequence of
A Use Strict Directive is an "use strict" or 'use strict'. A
A
The
14.1.2 Static Semantics: Early Errors
-
If the source code matching this production is
strict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters -
If the source code matching this production is
strict mode code , it is a Syntax Error ifBindingIdentifier is present and the StringValue ofBindingIdentifier is"eval"or"arguments". -
It is a Syntax Error if ContainsUseStrict of
FunctionBody istrue and IsSimpleParameterList ofFormalParameters isfalse . -
It is a Syntax Error if any element of the BoundNames of
FormalParameters also occurs in the LexicallyDeclaredNames ofFunctionBody . -
It is a Syntax Error if
FormalParameters ContainsSuperProperty istrue . -
It is a Syntax Error if
FunctionBody ContainsSuperProperty istrue . -
It is a Syntax Error if
FormalParameters ContainsSuperCall istrue . -
It is a Syntax Error if
FunctionBody ContainsSuperCall istrue .
The LexicallyDeclaredNames of a
-
It is a Syntax Error if BoundNames of
FormalParameters contains any duplicate elements.
-
It is a Syntax Error if IsSimpleParameterList of
FormalParameterList isfalse and BoundNames ofFormalParameterList contains any duplicate elements.
Multiple occurrences of the same
-
It is a Syntax Error if the LexicallyDeclaredNames of
FunctionStatementList contains any duplicate entries. -
It is a Syntax Error if any element of the LexicallyDeclaredNames of
FunctionStatementList also occurs in the VarDeclaredNames ofFunctionStatementList . -
It is a Syntax Error if ContainsDuplicateLabels of
FunctionStatementList with argument « » istrue . -
It is a Syntax Error if ContainsUndefinedBreakTarget of
FunctionStatementList with argument « » istrue . -
It is a Syntax Error if ContainsUndefinedContinueTarget of
FunctionStatementList with arguments « » and « » istrue .
14.1.3 Static Semantics: BoundNames
- Return the BoundNames of
BindingIdentifier .
- Return «
"*default*"».
"*default*" is used within this specification as a synthetic name for hoistable anonymous functions that are defined using export declarations.
- Return a new empty
List .
- Let names be BoundNames of
FormalParameterList . - Append to names the BoundNames of
FunctionRestParameter . - Return names.
- Let names be BoundNames of
FormalParameterList . - Append to names the BoundNames of
FormalParameter . - Return names.
14.1.4 Static Semantics: Contains
With parameter symbol.
- Return
false .
Static semantic rules that depend upon substructure generally do not look into function definitions.
14.1.5 Static Semantics: ContainsExpression
- Return
false .
- If ContainsExpression of
FormalParameterList istrue , returntrue . - Return ContainsExpression of
FunctionRestParameter .
- If ContainsExpression of
FormalParameterList istrue , returntrue . - Return ContainsExpression of
FormalParameter .
14.1.6 Static Semantics: ContainsUseStrict
- If the
Directive Prologue ofFunctionStatementList contains aUse Strict Directive , returntrue ; otherwise, returnfalse .
14.1.7 Static Semantics: ExpectedArgumentCount
- Return 0.
- Return ExpectedArgumentCount of
FormalParameterList .
The ExpectedArgumentCount of a
- Let count be ExpectedArgumentCount of
FormalParameterList . - If HasInitializer of
FormalParameterList istrue or HasInitializer ofFormalParameter istrue , return count. - Return count + 1.
14.1.8 Static Semantics: HasInitializer
- If HasInitializer of
FormalParameterList istrue , returntrue . - Return HasInitializer of
FormalParameter .
14.1.9 Static Semantics: HasName
- Return
false .
- Return
true .
14.1.10 Static Semantics: IsAnonymousFunctionDefinition ( expr )
The abstract operation IsAnonymousFunctionDefinition determines if its argument is a function definition that does not bind a name. The argument expr is the result of parsing an
- If IsFunctionDefinition of expr is
false , returnfalse . - Let hasName be the result of HasName of expr.
- If hasName is
true , returnfalse . - Return
true .
14.1.11 Static Semantics: IsConstantDeclaration
- Return
false .
14.1.12 Static Semantics: IsFunctionDefinition
- Return
true .
14.1.13 Static Semantics: IsSimpleParameterList
- Return
true .
- Return
false .
- If IsSimpleParameterList of
FormalParameterList isfalse , returnfalse . - Return IsSimpleParameterList of
FormalParameter .
- Return IsSimpleParameterList of
BindingElement .
14.1.14 Static Semantics: LexicallyDeclaredNames
- Return a new empty
List .
- Return TopLevelLexicallyDeclaredNames of
StatementList .
14.1.15 Static Semantics: LexicallyScopedDeclarations
- Return a new empty
List .
- Return the TopLevelLexicallyScopedDeclarations of
StatementList .
14.1.16 Static Semantics: VarDeclaredNames
- Return a new empty
List .
- Return TopLevelVarDeclaredNames of
StatementList .
14.1.17 Static Semantics: VarScopedDeclarations
- Return a new empty
List .
- Return the TopLevelVarScopedDeclarations of
StatementList .
14.1.18 Runtime Semantics: EvaluateBody
With parameters functionObject and
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Return the result of evaluating
FunctionStatementList .
14.1.19 Runtime Semantics: IteratorBindingInitialization
With parameters iteratorRecord and environment.
When
- Return
NormalCompletion (empty ).
- Perform ? IteratorBindingInitialization for
FormalParameterList using iteratorRecord and environment as the arguments. - Return the result of performing IteratorBindingInitialization for
FunctionRestParameter using iteratorRecord and environment as the arguments.
- Perform ? IteratorBindingInitialization for
FormalParameterList using iteratorRecord and environment as the arguments. - Return the result of performing IteratorBindingInitialization for
FormalParameter using iteratorRecord and environment as the arguments.
- If ContainsExpression of
BindingElement isfalse , return the result of performing IteratorBindingInitialization forBindingElement using iteratorRecord and environment as the arguments. - Let currentContext be the
running execution context . - Let originalEnv be the VariableEnvironment of currentContext.
Assert : The VariableEnvironment and LexicalEnvironment of currentContext are the same.Assert : environment and originalEnv are the same.- Let paramVarEnv be
NewDeclarativeEnvironment (originalEnv). Set the VariableEnvironment of currentContext to paramVarEnv.Set the LexicalEnvironment of currentContext to paramVarEnv.- Let result be the result of performing IteratorBindingInitialization for
BindingElement using iteratorRecord and environment as the arguments. Set the VariableEnvironment of currentContext to originalEnv.Set the LexicalEnvironment of currentContext to originalEnv.- Return result.
The new
- If ContainsExpression of
BindingRestElement isfalse , return the result of performing IteratorBindingInitialization forBindingRestElement using iteratorRecord and environment as the arguments. - Let currentContext be the
running execution context . - Let originalEnv be the VariableEnvironment of currentContext.
Assert : The VariableEnvironment and LexicalEnvironment of currentContext are the same.Assert : environment and originalEnv are the same.- Let paramVarEnv be
NewDeclarativeEnvironment (originalEnv). Set the VariableEnvironment of currentContext to paramVarEnv.Set the LexicalEnvironment of currentContext to paramVarEnv.- Let result be the result of performing IteratorBindingInitialization for
BindingRestElement using iteratorRecord and environment as the arguments. Set the VariableEnvironment of currentContext to originalEnv.Set the LexicalEnvironment of currentContext to originalEnv.- Return result.
The new
14.1.20 Runtime Semantics: InstantiateFunctionObject
With parameter scope.
- If the function code for
FunctionDeclaration isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let name be StringValue of
BindingIdentifier . - Let F be
FunctionCreate (Normal ,FormalParameters ,FunctionBody , scope, strict). - Perform
MakeConstructor (F). - Perform
SetFunctionName (F, name). Set F.[[SourceText]] to thesource text matched by FunctionDeclaration .- Return F.
- Let F be
FunctionCreate (Normal ,FormalParameters ,FunctionBody , scope,true ). - Perform
MakeConstructor (F). - Perform
SetFunctionName (F,"default"). Set F.[[SourceText]] to thesource text matched by FunctionDeclaration .- Return F.
An anonymous export default declaration, and its function code is therefore always
14.1.21 Runtime Semantics: NamedEvaluation
With parameter name.
- Let closure be the result of evaluating this
FunctionExpression . - Perform
SetFunctionName (closure, name). - Return closure.
14.1.22 Runtime Semantics: Evaluation
- Return
NormalCompletion (empty ).
An alternative semantics is provided in
- Return
NormalCompletion (empty ).
- If the function code for
FunctionExpression isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the LexicalEnvironment of the
running execution context . - Let closure be
FunctionCreate (Normal ,FormalParameters ,FunctionBody , scope, strict). - Perform
MakeConstructor (closure). Set closure.[[SourceText]] to thesource text matched by FunctionExpression .- Return closure.
- If the function code for
FunctionExpression isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the
running execution context 's LexicalEnvironment. - Let funcEnv be
NewDeclarativeEnvironment (scope). - Let envRec be funcEnv's
EnvironmentRecord . - Let name be StringValue of
BindingIdentifier . - Perform envRec.CreateImmutableBinding(name,
false ). - Let closure be
FunctionCreate (Normal ,FormalParameters ,FunctionBody , funcEnv, strict). - Perform
MakeConstructor (closure). - Perform
SetFunctionName (closure, name). Set closure.[[SourceText]] to thesource text matched by FunctionExpression .- Perform envRec.InitializeBinding(name, closure).
- Return closure.
The
A prototype property is automatically created for every function defined using a
- Return
NormalCompletion (undefined ).
14.2 Arrow Function Definitions
Syntax
Supplemental Syntax
When the production
is recognized the following grammar is used to refine the interpretation of
14.2.1 Static Semantics: Early Errors
-
It is a Syntax Error if
ArrowParameters ContainsYieldExpression istrue . -
It is a Syntax Error if
ArrowParameters ContainsAwaitExpression istrue . -
It is a Syntax Error if ContainsUseStrict of
ConciseBody istrue and IsSimpleParameterList ofArrowParameters isfalse . -
It is a Syntax Error if any element of the BoundNames of
ArrowParameters also occurs in the LexicallyDeclaredNames ofConciseBody .
-
It is a Syntax Error if
CoverParenthesizedExpressionAndArrowParameterList is notcovering anArrowFormalParameters . -
All
early error rules forArrowFormalParameters and its derived productions also apply to CoveredFormalsList ofCoverParenthesizedExpressionAndArrowParameterList .
14.2.2 Static Semantics: BoundNames
- Let formals be CoveredFormalsList of
CoverParenthesizedExpressionAndArrowParameterList . - Return the BoundNames of formals.
14.2.3 Static Semantics: Contains
With parameter symbol.
- If symbol is not one of
NewTarget ,SuperProperty ,SuperCall ,superorthis, returnfalse . - If
ArrowParameters Contains symbol istrue , returntrue . - Return
ConciseBody Contains symbol.
Normally, Contains does not look inside most function forms. However, Contains is used to detect new.target, this, and super usage within an
- Let formals be CoveredFormalsList of
CoverParenthesizedExpressionAndArrowParameterList . - Return formals Contains symbol.
14.2.4 Static Semantics: ContainsExpression
14.2.5 Static Semantics: ContainsUseStrict
14.2.6 Static Semantics: ExpectedArgumentCount
14.2.7 Static Semantics: HasName
14.2.8 Static Semantics: IsSimpleParameterList
- Return
true .
- Let formals be CoveredFormalsList of
CoverParenthesizedExpressionAndArrowParameterList . - Return IsSimpleParameterList of formals.
14.2.9 Static Semantics: CoveredFormalsList
- Return this
ArrowParameters .
- Return the
ArrowFormalParameters that iscovered byCoverParenthesizedExpressionAndArrowParameterList .
14.2.10 Static Semantics: LexicallyDeclaredNames
14.2.11 Static Semantics: LexicallyScopedDeclarations
14.2.12 Static Semantics: VarDeclaredNames
14.2.13 Static Semantics: VarScopedDeclarations
14.2.14 Runtime Semantics: IteratorBindingInitialization
With parameters iteratorRecord and environment.
When
Assert : iteratorRecord.[[Done]] isfalse .- Let next be
IteratorStep (iteratorRecord). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue . - Else,
- Let v be
IteratorValue (next). - If v is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (v).
- Let v be
- If iteratorRecord.[[Done]] is
true , let v beundefined . - Return the result of performing BindingInitialization for
BindingIdentifier using v and environment as the arguments.
14.2.15 Runtime Semantics: EvaluateBody
With parameters functionObject and
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Let exprRef be the result of evaluating
AssignmentExpression . - Let exprValue be ?
GetValue (exprRef). - Return
Completion { [[Type]]:return , [[Value]]: exprValue, [[Target]]:empty }.
14.2.16 Runtime Semantics: NamedEvaluation
With parameter name.
- Let closure be the result of evaluating this
ArrowFunction . - Perform
SetFunctionName (closure, name). - Return closure.
14.2.17 Runtime Semantics: Evaluation
- If the function code for this
ArrowFunction isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the LexicalEnvironment of the
running execution context . - Let parameters be CoveredFormalsList of
ArrowParameters . - Let closure be
FunctionCreate (Arrow , parameters,ConciseBody , scope, strict). Set closure.[[SourceText]] to thesource text matched by ArrowFunction .- 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
14.3 Method Definitions
Syntax
14.3.1 Static Semantics: Early Errors
-
It is a Syntax Error if ContainsUseStrict of
FunctionBody istrue and IsSimpleParameterList ofUniqueFormalParameters isfalse . -
It is a Syntax Error if any element of the BoundNames of
UniqueFormalParameters also occurs in the LexicallyDeclaredNames ofFunctionBody .
-
It is a Syntax Error if BoundNames of
PropertySetParameterList contains any duplicate elements. -
It is a Syntax Error if ContainsUseStrict of
FunctionBody istrue and IsSimpleParameterList ofPropertySetParameterList isfalse . -
It is a Syntax Error if any element of the BoundNames of
PropertySetParameterList also occurs in the LexicallyDeclaredNames ofFunctionBody .
14.3.2 Static Semantics: ComputedPropertyContains
With parameter symbol.
- Return the result of ComputedPropertyContains for
PropertyName with argument symbol.
14.3.3 Static Semantics: ExpectedArgumentCount
- If HasInitializer of
FormalParameter istrue , return 0. - Return 1.
14.3.4 Static Semantics: HasDirectSuper
- If
UniqueFormalParameters ContainsSuperCall istrue , returntrue . - Return
FunctionBody ContainsSuperCall .
- Return
FunctionBody ContainsSuperCall .
- If
PropertySetParameterList ContainsSuperCall istrue , returntrue . - Return
FunctionBody ContainsSuperCall .
14.3.5 Static Semantics: PropName
- Return PropName of
PropertyName .
14.3.6 Static Semantics: SpecialMethod
- Return
false .
- Return
true .
14.3.7 Runtime Semantics: DefineMethod
With parameters object and optional parameter functionPrototype.
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- If the function code for this
MethodDefinition isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the
running execution context 's LexicalEnvironment. - If functionPrototype is present as a parameter, then
- Let kind be
Normal . - Let prototype be functionPrototype.
- Let kind be
- Else,
- Let kind be
Method . - Let prototype be the intrinsic object
%FunctionPrototype% .
- Let kind be
- Let closure be
FunctionCreate (kind,UniqueFormalParameters ,FunctionBody , scope, strict, prototype). - Perform
MakeMethod (closure, object). Set closure.[[SourceText]] to thesource text matched by MethodDefinition .- Return the
Record { [[Key]]: propKey, [[Closure]]: closure }.
14.3.8 Runtime Semantics: PropertyDefinitionEvaluation
With parameters object and enumerable.
- Let methodDef be DefineMethod of
MethodDefinition with argument object. ReturnIfAbrupt (methodDef).- 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).- If the function code for this
MethodDefinition isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the
running execution context 's LexicalEnvironment. - Let formalParameterList be an instance of the production
.FormalParameters : [empty] - Let closure be
FunctionCreate (Method , formalParameterList,FunctionBody , scope, strict). - Perform
MakeMethod (closure, object). - Perform
SetFunctionName (closure, propKey,"get"). Set closure.[[SourceText]] to thesource text matched by MethodDefinition .- 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).- If the function code for this
MethodDefinition isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the
running execution context 's LexicalEnvironment. - Let closure be
FunctionCreate (Method ,PropertySetParameterList ,FunctionBody , scope, strict). - Perform
MakeMethod (closure, object). - Perform
SetFunctionName (closure, propKey,"set"). Set closure.[[SourceText]] to thesource text matched by MethodDefinition .- Let desc be the PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]:
true }. - Return ?
DefinePropertyOrThrow (object, propKey, desc).
14.4 Generator Function Definitions
Syntax
The syntactic context immediately following yield requires use of the
14.4.1 Static Semantics: Early Errors
-
It is a Syntax Error if HasDirectSuper of
GeneratorMethod istrue . -
It is a Syntax Error if
UniqueFormalParameters ContainsYieldExpression istrue . -
It is a Syntax Error if ContainsUseStrict of
GeneratorBody istrue and IsSimpleParameterList ofUniqueFormalParameters isfalse . -
It is a Syntax Error if any element of the BoundNames of
UniqueFormalParameters also occurs in the LexicallyDeclaredNames ofGeneratorBody .
-
If the source code matching this production is
strict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters -
If the source code matching this production is
strict mode code , it is a Syntax Error ifBindingIdentifier is present and the StringValue ofBindingIdentifier is"eval"or"arguments". -
It is a Syntax Error if ContainsUseStrict of
GeneratorBody istrue and IsSimpleParameterList ofFormalParameters isfalse . -
It is a Syntax Error if any element of the BoundNames of
FormalParameters also occurs in the LexicallyDeclaredNames ofGeneratorBody . -
It is a Syntax Error if
FormalParameters ContainsYieldExpression istrue . -
It is a Syntax Error if
FormalParameters ContainsSuperProperty istrue . -
It is a Syntax Error if
GeneratorBody ContainsSuperProperty istrue . -
It is a Syntax Error if
FormalParameters ContainsSuperCall istrue . -
It is a Syntax Error if
GeneratorBody ContainsSuperCall istrue .
14.4.2 Static Semantics: BoundNames
- Return the BoundNames of
BindingIdentifier .
- Return «
"*default*"».
"*default*" is used within this specification as a synthetic name for hoistable anonymous functions that are defined using export declarations.
14.4.3 Static Semantics: ComputedPropertyContains
With parameter symbol.
- Return the result of ComputedPropertyContains for
PropertyName with argument symbol.
14.4.4 Static Semantics: Contains
With parameter symbol.
- Return
false .
Static semantic rules that depend upon substructure generally do not look into function definitions.
14.4.5 Static Semantics: HasDirectSuper
- If
UniqueFormalParameters ContainsSuperCall istrue , returntrue . - Return
GeneratorBody ContainsSuperCall .
14.4.6 Static Semantics: HasName
- Return
false .
- Return
true .
14.4.7 Static Semantics: IsConstantDeclaration
- Return
false .
14.4.8 Static Semantics: IsFunctionDefinition
- Return
true .
14.4.9 Static Semantics: PropName
- Return PropName of
PropertyName .
14.4.10 Runtime Semantics: EvaluateBody
With parameters functionObject and
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Let G be ?
OrdinaryCreateFromConstructor (functionObject,"%GeneratorPrototype%", « [[GeneratorState]], [[GeneratorContext]] »). - Perform
GeneratorStart (G,FunctionBody ). - Return
Completion { [[Type]]:return , [[Value]]: G, [[Target]]:empty }.
14.4.11 Runtime Semantics: InstantiateFunctionObject
With parameter scope.
- If the function code for
GeneratorDeclaration isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let name be StringValue of
BindingIdentifier . - Let F be
GeneratorFunctionCreate (Normal ,FormalParameters ,GeneratorBody , scope, strict). - Let prototype be
ObjectCreate (%GeneratorPrototype% ). - Perform
DefinePropertyOrThrow (F,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform
SetFunctionName (F, name). Set F.[[SourceText]] to thesource text matched by GeneratorDeclaration .- Return F.
- Let F be
GeneratorFunctionCreate (Normal ,FormalParameters ,GeneratorBody , scope,true ). - Let prototype be
ObjectCreate (%GeneratorPrototype% ). - Perform
DefinePropertyOrThrow (F,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform
SetFunctionName (F,"default"). Set F.[[SourceText]] to thesource text matched by GeneratorDeclaration .- Return F.
An anonymous export default declaration, and its function code is therefore always
14.4.12 Runtime Semantics: PropertyDefinitionEvaluation
With parameters object and enumerable.
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- If the function code for this
GeneratorMethod isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the
running execution context 's LexicalEnvironment. - Let closure be
GeneratorFunctionCreate (Method ,UniqueFormalParameters ,GeneratorBody , scope, strict). - Perform
MakeMethod (closure, object). - Let prototype be
ObjectCreate (%GeneratorPrototype% ). - Perform
DefinePropertyOrThrow (closure,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform
SetFunctionName (closure, propKey). Set closure.[[SourceText]] to thesource text matched by GeneratorMethod .- Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]:
true , [[Enumerable]]: enumerable, [[Configurable]]:true }. - Return ?
DefinePropertyOrThrow (object, propKey, desc).
14.4.13 Runtime Semantics: NamedEvaluation
With parameter name.
- Let closure be the result of evaluating this
GeneratorExpression . - Perform
SetFunctionName (closure, name). - Return closure.
14.4.14 Runtime Semantics: Evaluation
- If the function code for this
GeneratorExpression isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the LexicalEnvironment of the
running execution context . - Let closure be
GeneratorFunctionCreate (Normal ,FormalParameters ,GeneratorBody , scope, strict). - Let prototype be
ObjectCreate (%GeneratorPrototype% ). - Perform
DefinePropertyOrThrow (closure,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). Set closure.[[SourceText]] to thesource text matched by GeneratorExpression .- Return closure.
- If the function code for this
GeneratorExpression isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the
running execution context 's LexicalEnvironment. - Let funcEnv be
NewDeclarativeEnvironment (scope). - Let envRec be funcEnv's
EnvironmentRecord . - Let name be StringValue of
BindingIdentifier . - Perform envRec.CreateImmutableBinding(name,
false ). - Let closure be
GeneratorFunctionCreate (Normal ,FormalParameters ,GeneratorBody , funcEnv, strict). - Let prototype be
ObjectCreate (%GeneratorPrototype% ). - Perform
DefinePropertyOrThrow (closure,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform
SetFunctionName (closure, name). - Perform envRec.InitializeBinding(name, closure).
Set closure.[[SourceText]] to thesource text matched by GeneratorExpression .- Return closure.
The
- Let generatorKind be !
GetGeneratorKind (). - If generatorKind is
async , then return ?AsyncGeneratorYield (undefined ). - Otherwise, return ?
GeneratorYield (CreateIterResultObject (undefined ,false )).
- Let generatorKind be !
GetGeneratorKind (). - Let exprRef be the result of evaluating
AssignmentExpression . - Let value be ?
GetValue (exprRef). - If generatorKind is
async , then return ?AsyncGeneratorYield (value). - Otherwise, return ?
GeneratorYield (CreateIterResultObject (value,false )).
- 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 , then 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 , then 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 , then 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 , then 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 , then 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 , then 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 , then set received toAsyncGeneratorYield (?IteratorValue (innerReturnResult)). - Else, set received to
GeneratorYield (innerReturnResult).
- If received.[[Type]] is
14.5 Async Generator Function Definitions
Syntax
14.5.1 Static Semantics: Early Errors
- It is a Syntax Error if HasDirectSuper of
AsyncGeneratorMethod istrue . - It is a Syntax Error if
UniqueFormalParameters ContainsYieldExpression istrue . - It is a Syntax Error if
UniqueFormalParameters ContainsAwaitExpression istrue . - It is a Syntax Error if ContainsUseStrict of
AsyncGeneratorBody istrue and IsSimpleParameterList ofUniqueFormalParameters isfalse . - It is a Syntax Error if any element of the BoundNames of
UniqueFormalParameters also occurs in the LexicallyDeclaredNames ofAsyncGeneratorBody .
- If the source code matching this production is
strict mode code , the Early Error rules for are applied.UniqueFormalParameters : FormalParameters - If the source code matching this production is
strict mode code , it is a Syntax Error ifBindingIdentifier is theIdentifierName evalor theIdentifierName arguments. - It is a Syntax Error if ContainsUseStrict of
AsyncGeneratorBody istrue and IsSimpleParameterList ofFormalParameters isfalse . - It is a Syntax Error if any element of the BoundNames of
FormalParameters also occurs in the LexicallyDeclaredNames ofAsyncGeneratorBody . - It is a Syntax Error if
FormalParameters ContainsYieldExpression istrue . - It is a Syntax Error if
FormalParameters ContainsAwaitExpression istrue . - It is a Syntax Error if
FormalParameters ContainsSuperProperty istrue . - It is a Syntax Error if
AsyncGeneratorBody ContainsSuperProperty istrue . - It is a Syntax Error if
FormalParameters ContainsSuperCall istrue . - It is a Syntax Error if
AsyncGeneratorBody ContainsSuperCall istrue .
14.5.2 Static Semantics: BoundNames
- Return the BoundNames of
BindingIdentifier .
- Return «
"*default*"».
"*default*" is used within this specification as a synthetic name for hoistable anonymous functions that are defined using export declarations.
14.5.3 Static Semantics: ComputedPropertyContains
With parameter symbol.
- Return the result of ComputedPropertyContains for
PropertyName with argument symbol.
14.5.4 Static Semantics: Contains
With parameter symbol.
- Return
false .
Static semantic rules that depend upon substructure generally do not look into function definitions.
14.5.5 Static Semantics: HasDirectSuper
- If
UniqueFormalParameters ContainsSuperCall istrue , returntrue . - Return
AsyncGeneratorBody ContainsSuperCall .
14.5.6 Static Semantics: HasName
- Return
false .
- Return
true .
14.5.7 Static Semantics: IsConstantDeclaration
- Return
false .
14.5.8 Static Semantics: IsFunctionDefinition
- Return
true .
14.5.9 Static Semantics: PropName
- Return PropName of
PropertyName .
14.5.10 Runtime Semantics: EvaluateBody
With parameters functionObject and
- Perform ?
FunctionDeclarationInstantiation (functionObject, argumentsList). - Let generator be ?
OrdinaryCreateFromConstructor (functionObject,"%AsyncGeneratorPrototype%", « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]] »). - Perform !
AsyncGeneratorStart (generator,FunctionBody ). - Return
Completion { [[Type]]:return , [[Value]]: generator, [[Target]]:empty }.
14.5.11 Runtime Semantics: InstantiateFunctionObject
With parameter scope.
- If the function code for
AsyncGeneratorDeclaration isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let name be StringValue of
BindingIdentifier . - Let F be !
AsyncGeneratorFunctionCreate (Normal ,FormalParameters ,AsyncGeneratorBody , scope, strict). - Let prototype be !
ObjectCreate (%AsyncGeneratorPrototype% ). - Perform !
DefinePropertyOrThrow (F,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform !
SetFunctionName (F, name). Set F.[[SourceText]] to thesource text matched by AsyncGeneratorDeclaration .- Return F.
- If the function code for
AsyncGeneratorDeclaration isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let F be
AsyncGeneratorFunctionCreate (Normal ,FormalParameters ,AsyncGeneratorBody , scope, strict). - Let prototype be
ObjectCreate (%AsyncGeneratorPrototype% ). - Perform
DefinePropertyOrThrow (F,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform
SetFunctionName (F,"default"). Set F.[[SourceText]] to thesource text matched by AsyncGeneratorDeclaration .- Return F.
An anonymous export default declaration.
14.5.12 Runtime Semantics: PropertyDefinitionEvaluation
With parameter object and enumerable.
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- If the function code for this
AsyncGeneratorMethod isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the
running execution context 's LexicalEnvironment. - Let closure be !
AsyncGeneratorFunctionCreate (Method ,UniqueFormalParameters ,AsyncGeneratorBody , scope, strict). - Perform !
MakeMethod (closure, object). - Let prototype be !
ObjectCreate (%AsyncGeneratorPrototype% ). - Perform !
DefinePropertyOrThrow (closure,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform !
SetFunctionName (closure, propKey). Set closure.[[SourceText]] to thesource text matched by AsyncGeneratorMethod .- Let desc be PropertyDescriptor { [[Value]]: closure, [[Writable]]:
true , [[Enumerable]]: enumerable, [[Configurable]]:true }. - Return ?
DefinePropertyOrThrow (object, propKey, desc).
14.5.13 Runtime Semantics: NamedEvaluation
With parameter name.
- Let closure be the result of evaluating this
AsyncGeneratorExpression . - Perform
SetFunctionName (closure, name). - Return closure.
14.5.14 Runtime Semantics: Evaluation
- If the function code for this
AsyncGeneratorExpression isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the LexicalEnvironment of the
running execution context . - Let closure be !
AsyncGeneratorFunctionCreate (Normal ,FormalParameters ,AsyncGeneratorBody , scope, strict). - Let prototype be !
ObjectCreate (%AsyncGeneratorPrototype% ). - Perform !
DefinePropertyOrThrow (closure,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). Set closure.[[SourceText]] to thesource text matched by AsyncGeneratorExpression .- Return closure.
- If the function code for this
AsyncGeneratorExpression isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the
running execution context 's LexicalEnvironment. - Let funcEnv be !
NewDeclarativeEnvironment (scope). - Let envRec be funcEnv's
EnvironmentRecord . - Let name be StringValue of
BindingIdentifier . - Perform ! envRec.CreateImmutableBinding(name).
- Let closure be !
AsyncGeneratorFunctionCreate (Normal ,FormalParameters ,AsyncGeneratorBody , funcEnv, strict). - Let prototype be !
ObjectCreate (%AsyncGeneratorPrototype% ). - Perform !
DefinePropertyOrThrow (closure,"prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }). - Perform !
SetFunctionName (closure, name). - Perform ! envRec.InitializeBinding(name, closure).
Set closure.[[SourceText]] to thesource text matched by AsyncGeneratorExpression .- Return closure.
The
14.6 Class Definitions
Syntax
A class definition is always
14.6.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 of
ClassBody . - If constructor is
empty , returnfalse . - Return HasDirectSuper of constructor.
- Let constructor be ConstructorMethod of
-
It is a Syntax Error if PrototypePropertyNameList of
ClassElementList contains more than one occurrence of"constructor".
-
It is a Syntax Error if PropName of
MethodDefinition is not"constructor"and HasDirectSuper ofMethodDefinition istrue . -
It is a Syntax Error if PropName of
MethodDefinition is"constructor"and SpecialMethod ofMethodDefinition istrue .
-
It is a Syntax Error if HasDirectSuper of
MethodDefinition istrue . -
It is a Syntax Error if PropName of
MethodDefinition is"prototype".
14.6.2 Static Semantics: BoundNames
- Return the BoundNames of
BindingIdentifier .
- Return «
"*default*"».
14.6.3 Static Semantics: ConstructorMethod
- If
ClassElement is , returnClassElement : ; empty . - If IsStatic of
ClassElement istrue , returnempty . - If PropName of
ClassElement is not"constructor", returnempty . - Return
ClassElement .
- Let head be ConstructorMethod of
ClassElementList . - If head is not
empty , return head. - If
ClassElement is , returnClassElement : ; empty . - If IsStatic of
ClassElement istrue , returnempty . - If PropName of
ClassElement is not"constructor", returnempty . - Return
ClassElement .
Early Error rules ensure that there is only one method definition named "constructor" and that it is not an
14.6.4 Static Semantics: Contains
With parameter symbol.
- If symbol is
ClassBody , returntrue . - If symbol is
ClassHeritage , then- If
ClassHeritage is present, returntrue ; otherwise returnfalse .
- If
- Let inHeritage be
ClassHeritage Contains symbol. - If inHeritage is
true , returntrue . - Return the result of ComputedPropertyContains for
ClassBody with argument symbol.
Static semantic rules that depend upon substructure generally do not look into class bodies except for
14.6.5 Static Semantics: ComputedPropertyContains
With parameter symbol.
- Let inList be the result of ComputedPropertyContains for
ClassElementList with argument symbol. - If inList is
true , returntrue . - Return the result of ComputedPropertyContains for
ClassElement with argument symbol.
- Return the result of ComputedPropertyContains for
MethodDefinition with argument symbol.
- Return the result of ComputedPropertyContains for
MethodDefinition with argument symbol.
- Return
false .
14.6.6 Static Semantics: HasName
- Return
false .
- Return
true .
14.6.7 Static Semantics: IsConstantDeclaration
- Return
false .
14.6.8 Static Semantics: IsFunctionDefinition
14.6.9 Static Semantics: IsStatic
- Return
false .
- Return
true .
- Return
false .
14.6.10 Static Semantics: NonConstructorMethodDefinitions
- If
ClassElement is , return a new emptyClassElement : ; List . - If IsStatic of
ClassElement isfalse and PropName ofClassElement is"constructor", return a new emptyList . - Return a
List containingClassElement .
- Let list be NonConstructorMethodDefinitions of
ClassElementList . - If
ClassElement is , return list.ClassElement : ; - If IsStatic of
ClassElement isfalse and PropName ofClassElement is"constructor", return list. - Append
ClassElement to the end of list. - Return list.
14.6.11 Static Semantics: PrototypePropertyNameList
- If PropName of
ClassElement isempty , return a new emptyList . - If IsStatic of
ClassElement istrue , return a new emptyList . - Return a
List containing PropName ofClassElement .
- Let list be PrototypePropertyNameList of
ClassElementList . - If PropName of
ClassElement isempty , return list. - If IsStatic of
ClassElement istrue , return list. - Append PropName of
ClassElement to the end of list. - Return list.
14.6.12 Static Semantics: PropName
14.6.13 Runtime Semantics: ClassDefinitionEvaluation
With parameters classBinding and className.
- Let lex be the LexicalEnvironment of the
running execution context . - Let classScope be
NewDeclarativeEnvironment (lex). - Let classScopeEnvRec be classScope's
EnvironmentRecord . - If classBinding is not
undefined , then- Perform classScopeEnvRec.CreateImmutableBinding(classBinding,
true ).
- Perform classScopeEnvRec.CreateImmutableBinding(classBinding,
- If
ClassHeritage_opt is not present, then- Let protoParent be the intrinsic object
%ObjectPrototype% . - Let constructorParent be the intrinsic object
%FunctionPrototype% .
- Let protoParent be the intrinsic object
- Else,
Set therunning execution context 's LexicalEnvironment to classScope.- Let superclassRef be the result of evaluating
ClassHeritage . Set therunning execution context 's LexicalEnvironment to lex.- Let superclass be ?
GetValue (superclassRef). - If superclass is
null , then- Let protoParent be
null . - Let constructorParent be the intrinsic object
%FunctionPrototype% .
- Let protoParent be
- Else if
IsConstructor (superclass) isfalse , throw aTypeError exception. - Else,
- Let proto be
ObjectCreate (protoParent). - If
ClassBody_opt is not present, let constructor beempty . - Else, let constructor be ConstructorMethod of
ClassBody . - If constructor is
empty , then- If
ClassHeritage_opt is present, thenSet constructor to the result of parsing the source textusing the syntactic grammar with theconstructor(... args){ super (...args);}goal symbol MethodDefinition .[~Yield, ~ Await ]
- Else,
Set constructor to the result of parsing the source textusing the syntactic grammar with theconstructor(){ }goal symbol MethodDefinition .[~Yield, ~ Await ]
- If
Set therunning execution context 's LexicalEnvironment to classScope.- Let constructorInfo be the result of performing DefineMethod for constructor with arguments proto and constructorParent as the optional functionPrototype argument.
Assert : constructorInfo is not anabrupt completion .- Let F be constructorInfo.[[Closure]].
- If
ClassHeritage_opt is present, set F.[[ConstructorKind]] to"derived". - Perform
MakeConstructor (F,false , proto). - Perform
MakeClassConstructor (F). - If className is not
undefined , then- Perform
SetFunctionName (F, className).
- Perform
- Perform
CreateMethodProperty (proto,"constructor", F). - If
ClassBody_opt is not present, let methods be a new emptyList . - Else, let methods be NonConstructorMethodDefinitions of
ClassBody . - For each
ClassElement m in order from methods, do- If IsStatic of m is
false , then- Let status be the result of performing PropertyDefinitionEvaluation for m with arguments proto and
false .
- Let status be the result of performing PropertyDefinitionEvaluation for m with arguments proto and
- Else,
- Let status be the result of performing PropertyDefinitionEvaluation for m with arguments F and
false .
- Let status be the result of performing PropertyDefinitionEvaluation for m with arguments F and
- If status is an
abrupt completion , thenSet therunning execution context 's LexicalEnvironment to lex.- Return
Completion (status).
- If IsStatic of m is
Set therunning execution context 's LexicalEnvironment to lex.- If classBinding is not
undefined , then- Perform classScopeEnvRec.InitializeBinding(classBinding, F).
- Return F.
14.6.14 Runtime Semantics: BindingClassDeclarationEvaluation
- Let className be StringValue of
BindingIdentifier . - Let value be the result of ClassDefinitionEvaluation of
ClassTail with arguments className and className. ReturnIfAbrupt (value).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 the result of ClassDefinitionEvaluation of
ClassTail with argumentsundefined and"default". ReturnIfAbrupt (value).Set value.[[SourceText]] to thesource text matched by ClassDeclaration .- Return value.
14.6.15 Runtime Semantics: NamedEvaluation
With parameter name.
- Return the result of ClassDefinitionEvaluation of
ClassTail with argumentsundefined and name.
14.6.16 Runtime Semantics: Evaluation
- Perform ? BindingClassDeclarationEvaluation of this
ClassDeclaration . - Return
NormalCompletion (empty ).
- If
BindingIdentifier_opt is not present, let className beundefined . - Else, let className be StringValue of
BindingIdentifier . - Let value be the result of ClassDefinitionEvaluation of
ClassTail with arguments className and className. ReturnIfAbrupt (value).Set value.[[SourceText]] to thesource text matched by ClassExpression .- Return value.
14.7 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 keyword and will be a Syntax error. 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
14.7.1 Static Semantics: Early Errors
- It is a Syntax Error if ContainsUseStrict of
AsyncFunctionBody istrue and IsSimpleParameterList ofUniqueFormalParameters isfalse . - It is a Syntax Error if HasDirectSuper of
AsyncMethod istrue . - It is a Syntax Error if
UniqueFormalParameters ContainsAwaitExpression istrue . - It is a Syntax Error if any element of the BoundNames of
UniqueFormalParameters also occurs in the LexicallyDeclaredNames ofAsyncFunctionBody .
- It is a Syntax Error if ContainsUseStrict of
AsyncFunctionBody istrue and IsSimpleParameterList ofFormalParameters isfalse . - It is a Syntax Error if
FormalParameters ContainsAwaitExpression istrue . - If the source code matching this production is strict code, the Early Error rules for
are applied.UniqueFormalParameters : FormalParameters - If the source code matching this production is strict code, it is a Syntax Error if
BindingIdentifier is present and the StringValue ofBindingIdentifier is"eval"or"arguments". - It is a Syntax Error if any element of the BoundNames of
FormalParameters also occurs in the LexicallyDeclaredNames ofAsyncFunctionBody . - It is a Syntax Error if
FormalParameters ContainsSuperProperty istrue . - It is a Syntax Error if
AsyncFunctionBody ContainsSuperProperty istrue . - It is a Syntax Error if
FormalParameters ContainsSuperCall istrue . - It is a Syntax Error if
AsyncFunctionBody ContainsSuperCall istrue .
14.7.2 Static Semantics: BoundNames
- Return the BoundNames of
BindingIdentifier .
- Return «
"*default*"».
*default*" is used within this specification as a synthetic name for hoistable anonymous functions that are defined using export declarations.14.7.3 Static Semantics: ComputedPropertyContains
With parameter symbol.
- Return the result of ComputedPropertyContains for
PropertyName with argument symbol.
14.7.4 Static Semantics: Contains
With parameter symbol.
- Return
false .
14.7.5 Static Semantics: HasDirectSuper
- If
UniqueFormalParameters ContainsSuperCall istrue , returntrue .
14.7.6 Static Semantics: HasName
- Return
false .
- Return
true .
14.7.7 Static Semantics: IsConstantDeclaration
- Return
false .
14.7.8 Static Semantics: IsFunctionDefinition
- Return
true .
14.7.9 Static Semantics: PropName
- Return PropName of
PropertyName .
14.7.10 Runtime Semantics: InstantiateFunctionObject
With parameter scope.
- If the function code for
AsyncFunctionDeclaration isstrict mode code , let strict betrue . Otherwise, let strict befalse . - Let name be StringValue of
BindingIdentifier . - Let F be !
AsyncFunctionCreate (Normal ,FormalParameters ,AsyncFunctionBody , scope, strict). - Perform !
SetFunctionName (F, name). Set F.[[SourceText]] to thesource text matched by AsyncFunctionDeclaration .- Return F.
- If the function code for
AsyncFunctionDeclaration isstrict mode code , let strict betrue . Otherwise, let strict befalse . - Let F be !
AsyncFunctionCreate (Normal ,FormalParameters ,AsyncFunctionBody , scope, strict). - Perform !
SetFunctionName (F,"default"). Set F.[[SourceText]] to thesource text matched by AsyncFunctionDeclaration .- Return F.
14.7.11 Runtime Semantics: EvaluateBody
With parameters functionObject and
- 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 declResult is an
abrupt completion ,- Perform !
Call (promiseCapability.[[Reject]],undefined , « declResult.[[Value]] »).
- Perform !
- Return
Completion { [[Type]]:return , [[Value]]: promiseCapability.[[Promise]], [[Target]]:empty }.
14.7.12 Runtime Semantics: PropertyDefinitionEvaluation
With parameters object and enumerable.
- Let propKey be the result of evaluating
PropertyName . ReturnIfAbrupt (propKey).- If the function code for this
AsyncMethod isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the LexicalEnvironment of the
running execution context . - Let closure be !
AsyncFunctionCreate (Method ,UniqueFormalParameters ,AsyncFunctionBody , scope, strict). - Perform !
MakeMethod (closure, object). - Perform !
SetFunctionName (closure, propKey). Set closure.[[SourceText]] to thesource text matched by AsyncMethod .- Let desc be the PropertyDescriptor { [[Value]]: closure, [[Writable]]:
true , [[Enumerable]]: enumerable, [[Configurable]]:true }. - Return ?
DefinePropertyOrThrow (object, propKey, desc).
14.7.13 Runtime Semantics: NamedEvaluation
With parameter name.
- Let closure be the result of evaluating this
AsyncFunctionExpression . - Perform
SetFunctionName (closure, name). - Return closure.
14.7.14 Runtime Semantics: Evaluation
- Return
NormalCompletion (empty ).
- Return
NormalCompletion (empty ).
- If the function code for
AsyncFunctionExpression isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the LexicalEnvironment of the
running execution context . - Let closure be !
AsyncFunctionCreate (Normal ,FormalParameters ,AsyncFunctionBody , scope, strict). Set closure.[[SourceText]] to thesource text matched by AsyncFunctionExpression .- Return closure.
- If the function code for
AsyncFunctionExpression isstrict mode code , let strict betrue . Otherwise let strict befalse . - Let scope be the LexicalEnvironment of the
running execution context . - Let funcEnv be !
NewDeclarativeEnvironment (scope). - Let envRec be funcEnv's
EnvironmentRecord . - Let name be StringValue of
BindingIdentifier . - Perform ! envRec.CreateImmutableBinding(name).
- Let closure be !
AsyncFunctionCreate (Normal ,FormalParameters ,AsyncFunctionBody , funcEnv, strict). - Perform !
SetFunctionName (closure, name). - Perform ! envRec.InitializeBinding(name, closure).
Set closure.[[SourceText]] to thesource text matched by AsyncFunctionExpression .- Return closure.
- Let exprRef be the result of evaluating
UnaryExpression . - Let value be ?
GetValue (exprRef). - Return ?
Await (value).
14.8 Async Arrow Function Definitions
Syntax
Supplemental Syntax
When processing an instance of the production
14.8.1 Static Semantics: Early Errors
- It is a Syntax Error if any element of the BoundNames of
AsyncArrowBindingIdentifier also occurs in the LexicallyDeclaredNames ofAsyncConciseBody .
- It is a Syntax Error if
CoverCallExpressionAndAsyncArrowHead ContainsYieldExpression istrue . - It is a Syntax Error if
CoverCallExpressionAndAsyncArrowHead ContainsAwaitExpression istrue . - It is a Syntax Error if
CoverCallExpressionAndAsyncArrowHead is notcovering anAsyncArrowHead . - It is a Syntax Error if any element of the BoundNames of
CoverCallExpressionAndAsyncArrowHead also occurs in the LexicallyDeclaredNames ofAsyncConciseBody . - It is a Syntax Error if ContainsUseStrict of
AsyncConciseBody istrue and IsSimpleParameterList ofCoverCallExpressionAndAsyncArrowHead isfalse . - All Early Error rules for
AsyncArrowHead and its derived productions apply to CoveredAsyncArrowHead ofCoverCallExpressionAndAsyncArrowHead .
14.8.2 Static Semantics: CoveredAsyncArrowHead
- Return the
AsyncArrowHead that iscovered byCoverCallExpressionAndAsyncArrowHead .
14.8.3 Static Semantics: BoundNames
- Let head be CoveredAsyncArrowHead of
CoverCallExpressionAndAsyncArrowHead . - Return the BoundNames of head.
14.8.4 Static Semantics: Contains
With parameter symbol.
- If symbol is not one of
NewTarget ,SuperProperty ,SuperCall ,super, orthis, returnfalse . - Return
AsyncConciseBody Contains symbol.
- If symbol is not one of
NewTarget ,SuperProperty ,SuperCall ,super, orthis, returnfalse .
new.target, this, and super usage within an AsyncArrowFunction.14.8.5 Static Semantics: ContainsExpression
- Return
false .
14.8.6 Static Semantics: ExpectedArgumentCount
- Return 1.
14.8.7 Static Semantics: HasName
- Return
false .
14.8.8 Static Semantics: IsSimpleParameterList
- Return
true .
- Let head be CoveredAsyncArrowHead of
CoverCallExpressionAndAsyncArrowHead . - Return IsSimpleParameterList of head.
14.8.9 Static Semantics: LexicallyDeclaredNames
- Return a new empty
List .
14.8.10 Static Semantics: LexicallyScopedDeclarations
- Return a new empty
List .
14.8.11 Static Semantics: VarDeclaredNames
- Return a new empty
List .
14.8.12 Static Semantics: VarScopedDeclarations
- Return a new empty
List .
14.8.13 Runtime Semantics: IteratorBindingInitialization
With parameters iteratorRecord and environment.
Assert : iteratorRecord.[[Done]] isfalse .- Let next be
IteratorStep (iteratorRecord). - If next is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (next).- If next is
false , set iteratorRecord.[[Done]] totrue . - Else,
- Let v be
IteratorValue (next). - If v is an
abrupt completion , set iteratorRecord.[[Done]] totrue . ReturnIfAbrupt (v).
- Let v be
- If iteratorRecord.[[Done]] is
true , let v beundefined . - Return the result of performing BindingInitialization for
BindingIdentifier using v and environment as the arguments.
14.8.14 Runtime Semantics: EvaluateBody
With parameters functionObject and
- Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let declResult be
FunctionDeclarationInstantiation (functionObject, argumentsList). - If declResult is not an
abrupt completion , then- Perform !
AsyncFunctionStart (promiseCapability,AssignmentExpression ).
- Perform !
- Else declResult is an
abrupt completion ,- Perform !
Call (promiseCapability.[[Reject]],undefined , « declResult.[[Value]] »).
- Perform !
- Return
Completion { [[Type]]:return , [[Value]]: promiseCapability.[[Promise]], [[Target]]:empty }.
- Return the result of EvaluateBody of
AsyncFunctionBody passing functionObject and argumentsList as the arguments.
14.8.15 Runtime Semantics: NamedEvaluation
With parameter name.
- Let closure be the result of evaluating this
AsyncArrowFunction . - Perform
SetFunctionName (closure, name). - Return closure.
14.8.16 Runtime Semantics: Evaluation
- If the function code for this
AsyncArrowFunction isstrict mode code , let strict betrue . Otherwise, let strict befalse . - Let scope be the LexicalEnvironment of the
running execution context . - Let parameters be
AsyncArrowBindingIdentifier . - Let closure be !
AsyncFunctionCreate (Arrow , parameters,AsyncConciseBody , scope, strict). - Return closure.
- If the function code for this
AsyncArrowFunction isstrict mode code , let strict betrue . Otherwise, let strict befalse . - Let scope be the LexicalEnvironment of the
running execution context . - Let head be CoveredAsyncArrowHead of
CoverCallExpressionAndAsyncArrowHead . - Let parameters be the
ArrowFormalParameters of head. - Let closure be !
AsyncFunctionCreate (Arrow , parameters,AsyncConciseBody , scope, strict). - Return closure.
14.9 Tail Position Calls
14.9.1 Static Semantics: IsInTailPosition ( call )
The abstract operation IsInTailPosition with argument call performs the following steps:
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
14.9.2 Static Semantics: HasCallInTailPosition
With parameter call.
call is a
14.9.2.1 Statement Rules
- Return HasCallInTailPosition of
AssignmentExpression with argument call.
- 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, let has be HasCallInTailPosition of the firstCaseClauses with argument call. - If has is
true , returntrue . - Let has be HasCallInTailPosition of the
DefaultClause with argument call. - If has is
true , returntrue . - If the second
CaseClauses is present, let has be 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.
14.9.2.2 Expression Rules
- 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.
- If this
CallExpression is call, returntrue . - Return
false .
- If this
MemberExpression is call, returntrue . - Return
false .
- Let expr be CoveredParenthesizedExpression of
CoverParenthesizedExpressionAndArrowParameterList . - Return HasCallInTailPosition of expr with argument call.
- Return HasCallInTailPosition of
Expression with argument call.
14.9.3 Runtime Semantics: PrepareForTailCall ( )
The abstract operation PrepareForTailCall performs the following steps:
- 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.