15 ECMAScript Language: Functions and Classes

Note

さまざまなECMAScript language elementsは、ECMAScript function objects10.2)の作成を引き起こします。そのようなfunctionsのevaluationは、それらの[[Call]] internal method(10.2.1)の実行から開始します。

15.1 Parameter Lists

Syntax

UniqueFormalParameters[Yield, Await] : FormalParameters[?Yield, ?Await] FormalParameters[Yield, Await] : [empty] FunctionRestParameter[?Yield, ?Await] FormalParameterList[?Yield, ?Await] FormalParameterList[?Yield, ?Await] , FormalParameterList[?Yield, ?Await] , FunctionRestParameter[?Yield, ?Await] FormalParameterList[Yield, Await] : FormalParameter[?Yield, ?Await] FormalParameterList[?Yield, ?Await] , FormalParameter[?Yield, ?Await] FunctionRestParameter[Yield, Await] : BindingRestElement[?Yield, ?Await] FormalParameter[Yield, Await] : BindingElement[?Yield, ?Await]

15.1.1 Static Semantics: Early Errors

UniqueFormalParameters : FormalParameters FormalParameters : FormalParameterList Note

FormalParameterList内で同じBindingIdentifierが複数回出現することは、simple parameter listsを持ち、かつstrict mode code内で定義されていないfunctionsに対してのみ許可されます。

15.1.2 Static Semantics: ContainsExpression

The syntax-directed operation ContainsExpression takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

ObjectBindingPattern : { } { BindingRestProperty }
  1. falseを返す。
ObjectBindingPattern : { BindingPropertyList , BindingRestProperty }
  1. BindingPropertyListContainsExpressionを返す。
ArrayBindingPattern : [ Elisionopt ]
  1. falseを返す。
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. BindingRestElementContainsExpressionを返す。
ArrayBindingPattern : [ BindingElementList , Elisionopt ]
  1. BindingElementListContainsExpressionを返す。
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. hasBindingElementListContainsExpressionとする。
  2. hastrueなら、trueを返す。
  3. BindingRestElementContainsExpressionを返す。
BindingPropertyList : BindingPropertyList , BindingProperty
  1. hasBindingPropertyListContainsExpressionとする。
  2. hastrueなら、trueを返す。
  3. BindingPropertyContainsExpressionを返す。
BindingElementList : BindingElementList , BindingElisionElement
  1. hasBindingElementListContainsExpressionとする。
  2. hastrueなら、trueを返す。
  3. BindingElisionElementContainsExpressionを返す。
BindingElisionElement : Elisionopt BindingElement
  1. BindingElementContainsExpressionを返す。
BindingProperty : PropertyName : BindingElement
  1. hasPropertyNameIsComputedPropertyKeyとする。
  2. hastrueなら、trueを返す。
  3. BindingElementContainsExpressionを返す。
BindingElement : BindingPattern Initializer
  1. trueを返す。
SingleNameBinding : BindingIdentifier
  1. falseを返す。
SingleNameBinding : BindingIdentifier Initializer
  1. trueを返す。
BindingRestElement : ... BindingIdentifier
  1. falseを返す。
BindingRestElement : ... BindingPattern
  1. BindingPatternContainsExpressionを返す。
FormalParameters : [empty]
  1. falseを返す。
FormalParameters : FormalParameterList , FunctionRestParameter
  1. FormalParameterListContainsExpressiontrueなら、trueを返す。
  2. FunctionRestParameterContainsExpressionを返す。
FormalParameterList : FormalParameterList , FormalParameter
  1. FormalParameterListContainsExpressiontrueなら、trueを返す。
  2. FormalParameterContainsExpressionを返す。
ArrowParameters : BindingIdentifier
  1. falseを返す。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterListによってcoverされるArrowFormalParametersとする。
  2. formalsContainsExpressionを返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. falseを返す。

15.1.3 Static Semantics: IsSimpleParameterList

The syntax-directed operation IsSimpleParameterList takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

BindingElement : BindingPattern
  1. falseを返す。
BindingElement : BindingPattern Initializer
  1. falseを返す。
SingleNameBinding : BindingIdentifier
  1. trueを返す。
SingleNameBinding : BindingIdentifier Initializer
  1. falseを返す。
FormalParameters : [empty]
  1. trueを返す。
FormalParameters : FunctionRestParameter
  1. falseを返す。
FormalParameters : FormalParameterList , FunctionRestParameter
  1. falseを返す。
FormalParameterList : FormalParameterList , FormalParameter
  1. FormalParameterListIsSimpleParameterListfalseなら、falseを返す。
  2. FormalParameterIsSimpleParameterListを返す。
FormalParameter : BindingElement
  1. BindingElementIsSimpleParameterListを返す。
ArrowParameters : BindingIdentifier
  1. trueを返す。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterListによってcoverされるArrowFormalParametersとする。
  2. formalsIsSimpleParameterListを返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. trueを返す。
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. headCoverCallExpressionAndAsyncArrowHeadによってcoverされるAsyncArrowHeadとする。
  2. headIsSimpleParameterListを返す。

15.1.4 Static Semantics: HasInitializer

The syntax-directed operation HasInitializer takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

BindingElement : BindingPattern
  1. falseを返す。
BindingElement : BindingPattern Initializer
  1. trueを返す。
SingleNameBinding : BindingIdentifier
  1. falseを返す。
SingleNameBinding : BindingIdentifier Initializer
  1. trueを返す。
FormalParameterList : FormalParameterList , FormalParameter
  1. FormalParameterListHasInitializertrueなら、trueを返す。
  2. FormalParameterHasInitializerを返す。

15.1.5 Static Semantics: ExpectedArgumentCount

The syntax-directed operation ExpectedArgumentCount takes no arguments and returns a non-negative integer. It is defined piecewise over the following productions:

FormalParameters : [empty] FunctionRestParameter
  1. 0を返す。
FormalParameters : FormalParameterList , FunctionRestParameter
  1. FormalParameterListExpectedArgumentCountを返す。
Note

FormalParameterListのExpectedArgumentCountは、rest parameterまたはInitializerを持つ最初のFormalParameterのいずれかの左側にあるFormalParametersの数です。initializerを持たないFormalParameterは、initializerを持つ最初のparameterの後に許可されますが、そのようなparametersはundefinedをdefault valueとするoptionalと見なされます。

FormalParameterList : FormalParameter
  1. FormalParameterHasInitializertrueなら、0を返す。
  2. 1を返す。
FormalParameterList : FormalParameterList , FormalParameter
  1. countFormalParameterListExpectedArgumentCountとする。
  2. FormalParameterListHasInitializertrue、またはFormalParameterHasInitializertrueなら、countを返す。
  3. count + 1を返す。
ArrowParameters : BindingIdentifier
  1. 1を返す。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterListによってcoverされるArrowFormalParametersとする。
  2. formalsExpectedArgumentCountを返す。
PropertySetParameterList : FormalParameter
  1. FormalParameterHasInitializertrueなら、0を返す。
  2. 1を返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. 1を返す。

15.2 Function Definitions

Syntax

FunctionDeclaration[Yield, Await, Default] : function BindingIdentifier[?Yield, ?Await] ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } [+Default] function ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } FunctionExpression : function BindingIdentifier[~Yield, ~Await]opt ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } FunctionBody[Yield, Await] : FunctionStatementList[?Yield, ?Await] FunctionStatementList[Yield, Await] : StatementList[?Yield, ?Await, +Return]opt

15.2.1 Static Semantics: Early Errors

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } function ( FormalParameters ) { FunctionBody } FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody } Note

FunctionBodyLexicallyDeclaredNamesには、varまたはfunction declarationsを使用してboundされるidentifiersは含まれません。

FunctionBody : FunctionStatementList

15.2.2 Static Semantics: FunctionBodyContainsUseStrict

The syntax-directed operation FunctionBodyContainsUseStrict takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionBodyDirective PrologueUse Strict Directiveを含むなら、trueを返す。
  2. falseを返す。

15.2.3 Runtime Semantics: EvaluateFunctionBody

The syntax-directed operation EvaluateFunctionBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a return completion or a throw completion. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionDeclarationInstantiation(funcObj, argList)を実行する。
  2. FunctionStatementListの ? Evaluationを実行する。
  3. NOTE: previous stepがnormal completionをもたらした場合、evaluationはFunctionStatementListの終端を越えて進むことで終了した。
  4. ReturnCompletion(undefined)を返す。

15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject

The syntax-directed operation InstantiateOrdinaryFunctionObject takes arguments envRecord (an Environment Record) and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. It is defined piecewise over the following productions:

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. nameBindingIdentifierStringValueとする。
  2. sourceTextFunctionDeclarationによってmatchされたsource textとする。
  3. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  4. SetFunctionName(closure, name)を実行する。
  5. MakeConstructor(closure)を実行する。
  6. closureを返す。
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. sourceTextFunctionDeclarationによってmatchされたsource textとする。
  2. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  3. SetFunctionName(closure, "default")を実行する。
  4. MakeConstructor(closure)を実行する。
  5. closureを返す。
Note

anonymous FunctionDeclarationexport default declarationの一部としてのみ出現できるため、そのfunction codeは常にstrict mode codeです。

15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression

The syntax-directed operation InstantiateOrdinaryFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. nameが存在しない場合、nameをempty Stringに設定する。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextFunctionExpressionによってmatchされたsource textとする。
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  6. SetFunctionName(closure, name)を実行する。
  7. MakeConstructor(closure)を実行する。
  8. closureを返す。
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. Assert: nameは存在しない。
  2. nameBindingIdentifierStringValueに設定する。
  3. outerEnvrunning execution contextのLexicalEnvironmentとする。
  4. funcEnvNewDeclarativeEnvironment(outerEnv)とする。
  5. funcEnv.CreateImmutableBinding(name, false)を実行する。
  6. privateEnvrunning execution contextのPrivateEnvironmentとする。
  7. sourceTextFunctionExpressionによってmatchされたsource textとする。
  8. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, funcEnv, privateEnv)とする。
  9. SetFunctionName(closure, name)を実行する。
  10. MakeConstructor(closure)を実行する。
  11. funcEnv.InitializeBinding(name, closure)を実行する。
  12. closureを返す。
Note

FunctionExpression内のBindingIdentifierは、functionがそれ自身を再帰的に呼び出せるように、FunctionExpressionFunctionBody内部からreferenceできます。ただし、FunctionDeclarationの場合とは異なり、FunctionExpression内のBindingIdentifierは、FunctionExpressionを囲むscopeからreferenceできず、そのscopeに影響しません。

15.2.6 Runtime Semantics: Evaluation

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. emptyを返す。
Note 1 FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. emptyを返す。
FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody }
  1. FunctionExpressionInstantiateOrdinaryFunctionExpressionを返す。
Note 2

FunctionDeclarationまたはFunctionExpressionを使用して定義されたすべてのfunctionには、そのfunctionがconstructorとして使用される可能性を許容するために、"prototype" propertyが自動的に作成されます。

FunctionStatementList : [empty]
  1. undefinedを返す。
FunctionStatementList : StatementList
  1. resultStatementListEvaluationCompletion とする。
  2. env を、実行中の実行コンテキストの LexicalEnvironment とする。
  3. Assert: envDeclarative Environment Record である。
  4. Return ? DisposeResources(env.[[DisposableResourceStack]], result).

15.3 Arrow Function Definitions

Syntax

ArrowFunction[In, Yield, Await] : ArrowParameters[?Yield, ?Await] [no LineTerminator here] => ConciseBody[?In] ArrowParameters[Yield, Await] : BindingIdentifier[?Yield, ?Await] CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] ConciseBody[In] : [lookahead ≠ {] ExpressionBody[?In, ~Await] { FunctionBody[~Yield, ~Await] } ExpressionBody[In, Await] : AssignmentExpression[?In, ~Yield, ?Await]

Supplemental Syntax

production
ArrowParameters[Yield, Await] : CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await]
のinstanceを処理するとき、CoverParenthesizedExpressionAndArrowParameterListのinterpretationは次のgrammarを使用してrefineされます:

ArrowFormalParameters[Yield, Await] : ( UniqueFormalParameters[?Yield, ?Await] )

15.3.1 Static Semantics: Early Errors

ArrowFunction : ArrowParameters => ConciseBody ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList

15.3.2 Static Semantics: ConciseBodyContainsUseStrict

The syntax-directed operation ConciseBodyContainsUseStrict takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

ConciseBody : ExpressionBody
  1. falseを返す。
ConciseBody : { FunctionBody }
  1. FunctionBodyFunctionBodyContainsUseStrictを返す。

15.3.3 Runtime Semantics: EvaluateConciseBody

The syntax-directed operation EvaluateConciseBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a return completion or a throw completion. It is defined piecewise over the following productions:

ConciseBody : ExpressionBody
  1. FunctionDeclarationInstantiation(funcObj, argList)を実行する。
  2. ExpressionBodyの ? Evaluationを返す。

15.3.4 Runtime Semantics: InstantiateArrowFunctionExpression

The syntax-directed operation InstantiateArrowFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

ArrowFunction : ArrowParameters => ConciseBody
  1. nameが存在しない場合、nameをempty Stringに設定する。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextArrowFunctionによってmatchされたsource textとする。
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, ArrowParameters, ConciseBody, lexical-this, envRecord, privateEnv)とする。
  6. SetFunctionName(closure, name)を実行する。
  7. closureを返す。
Note

ArrowFunctionargumentssuperthis、またはnew.targetに対するlocal bindingsを定義しません。ArrowFunction内のargumentssuperthis、またはnew.targetへのreferenceはいずれも、lexically enclosing environment内のbindingへresolveされなければなりません。通常、これは直ちに囲むfunctionのFunction Environmentになります。ArrowFunctionsuperへのreferencesを含む場合でも、step 5で作成されるfunction objectMakeMethodを実行することによってmethodにはされません。superをreferenceするArrowFunctionは常にnon-ArrowFunction内に含まれ、superを実装するために必要なstateは、ArrowFunctionfunction objectによってcaptureされるenvRecordを介してaccessできます。

15.3.5 Runtime Semantics: Evaluation

ArrowFunction : ArrowParameters => ConciseBody
  1. ArrowFunctionInstantiateArrowFunctionExpressionを返す。
ExpressionBody : AssignmentExpression
  1. exprRefAssignmentExpressionの ? Evaluationとする。
  2. exprValueを ? GetValue(exprRef) とする。
  3. ReturnCompletion(exprValue)を返す。

15.4 Method Definitions

Syntax

MethodDefinition[Yield, Await] : ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] } GeneratorMethod[?Yield, ?Await] AsyncMethod[?Yield, ?Await] AsyncGeneratorMethod[?Yield, ?Await] get ClassElementName[?Yield, ?Await] ( ) { FunctionBody[~Yield, ~Await] } set ClassElementName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] } PropertySetParameterList : FormalParameter[~Yield, ~Await]

15.4.1 Static Semantics: Early Errors

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }

15.4.2 Static Semantics: HasDirectSuper

The syntax-directed operation HasDirectSuper takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. UniqueFormalParameters Contains SuperCalltrueなら、trueを返す。
  2. FunctionBody Contains SuperCallを返す。
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. FunctionBody Contains SuperCallを返す。
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. PropertySetParameterList Contains SuperCalltrueなら、trueを返す。
  2. FunctionBody Contains SuperCallを返す。
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. UniqueFormalParameters Contains SuperCalltrueなら、trueを返す。
  2. GeneratorBody Contains SuperCallを返す。
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. UniqueFormalParameters Contains SuperCalltrueなら、trueを返す。
  2. AsyncGeneratorBody Contains SuperCallを返す。
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. UniqueFormalParameters Contains SuperCalltrueなら、trueを返す。
  2. AsyncFunctionBody Contains SuperCallを返す。

15.4.3 Static Semantics: SpecialMethod

The syntax-directed operation SpecialMethod takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. falseを返す。
MethodDefinition : GeneratorMethod AsyncMethod AsyncGeneratorMethod get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. trueを返す。

15.4.4 Runtime Semantics: DefineMethod

The syntax-directed operation DefineMethod takes argument obj (an Object) and optional argument proto (an Object) and returns either a normal completion containing a Record with fields [[Key]] (a property key) and [[Closure]] (an ECMAScript function object) or an abrupt completion. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. propertyKeyClassElementNameの ? Evaluationとする。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. protoが存在しないなら、proto%Function.prototype%に設定する。
  5. sourceTextMethodDefinitionによってmatchされたsource textとする。
  6. closureOrdinaryFunctionCreate(proto, sourceText, UniqueFormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  7. MakeMethod(closure, obj)を実行する。
  8. Record { [[Key]]: propertyKey, [[Closure]]: closure }を返す。

15.4.5 Runtime Semantics: MethodDefinitionEvaluation

The syntax-directed operation MethodDefinitionEvaluation takes arguments obj (an Object) and enumerable (a Boolean) and returns either a normal completion containing either a PrivateElement or unused, or an abrupt completion. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. methodDefを、argument objを伴うMethodDefinitionの ? DefineMethodとする。
  2. SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]])を実行する。
  3. DefineMethodProperty(obj, methodDef.[[Key]], methodDef.[[Closure]], enumerable)を返す。
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. propertyKeyClassElementNameの ? Evaluationとする。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextMethodDefinitionによってmatchされたsource textとする。
  5. formalParamListをproduction FormalParameters : [empty] のinstanceとする。
  6. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParamList, FunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  7. MakeMethod(closure, obj)を実行する。
  8. SetFunctionName(closure, propertyKey, "get")を実行する。
  9. propertyKeyPrivate Nameなら、
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Get]]: closure, [[Set]]: undefined }を返す。
  10. propertyDescをPropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }とする。
  11. DefinePropertyOrThrow(obj, propertyKey, propertyDesc)を実行する。
  12. unusedを返す。
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. propertyKeyClassElementNameの ? Evaluationとする。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextMethodDefinitionによってmatchされたsource textとする。
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, PropertySetParameterList, FunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  6. MakeMethod(closure, obj)を実行する。
  7. SetFunctionName(closure, propertyKey, "set")を実行する。
  8. propertyKeyPrivate Nameなら、
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Get]]: undefined, [[Set]]: closure }を返す。
  9. propertyDescをPropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true }とする。
  10. DefinePropertyOrThrow(obj, propertyKey, propertyDesc)を実行する。
  11. unusedを返す。
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. propertyKeyClassElementNameの ? Evaluationとする。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextGeneratorMethodによってmatchされたsource textとする。
  5. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, UniqueFormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)とする。
  6. MakeMethod(closure, obj)を実行する。
  7. SetFunctionName(closure, propertyKey)を実行する。
  8. protoOrdinaryObjectCreate(%GeneratorPrototype%)とする。
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  10. DefineMethodProperty(obj, propertyKey, closure, enumerable)を返す。
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. propertyKeyClassElementNameの ? Evaluationとする。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextAsyncGeneratorMethodによってmatchされたsource textとする。
  5. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, UniqueFormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)とする。
  6. MakeMethod(closure, obj)を実行する。
  7. SetFunctionName(closure, propertyKey)を実行する。
  8. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)とする。
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  10. DefineMethodProperty(obj, propertyKey, closure, enumerable)を返す。
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. propertyKeyClassElementNameの ? Evaluationとする。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextAsyncMethodによってmatchされたsource textとする。
  5. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, UniqueFormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  6. MakeMethod(closure, obj)を実行する。
  7. SetFunctionName(closure, propertyKey)を実行する。
  8. DefineMethodProperty(obj, propertyKey, closure, enumerable)を返す。

15.5 Generator Function Definitions

Syntax

GeneratorDeclaration[Yield, Await, Default] : function * BindingIdentifier[?Yield, ?Await] ( FormalParameters[+Yield, ~Await] ) { GeneratorBody } [+Default] function * ( FormalParameters[+Yield, ~Await] ) { GeneratorBody } GeneratorExpression : function * BindingIdentifier[+Yield, ~Await]opt ( FormalParameters[+Yield, ~Await] ) { GeneratorBody } GeneratorMethod[Yield, Await] : * ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, ~Await] ) { GeneratorBody } GeneratorBody : FunctionBody[+Yield, ~Await] YieldExpression[In, Await] : yield yield [no LineTerminator here] AssignmentExpression[?In, +Yield, ?Await] yield [no LineTerminator here] * AssignmentExpression[?In, +Yield, ?Await] Note 1

yieldの直後のsyntactic contextでは、InputElementRegExpOrTemplateTail lexical goalの使用が必要です。

Note 2

YieldExpressionはgenerator functionのFormalParameters内では使用できません。なぜなら、FormalParametersの一部であるexpressionsは、結果として得られるGeneratorがresumable stateになる前に評価されるからです。

Note 3

Generatorsに関係するabstract operations27.8.3で定義されます。

15.5.1 Static Semantics: Early Errors

GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody } GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }

15.5.2 Runtime Semantics: EvaluateGeneratorBody

The syntax-directed operation EvaluateGeneratorBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a throw completion or a return completion. It is defined piecewise over the following productions:

GeneratorBody : FunctionBody
  1. FunctionDeclarationInstantiation(funcObj, argList)を実行する。
  2. genを ? OrdinaryCreateFromConstructor(funcObj, "%GeneratorPrototype%", « [[GeneratorState]], [[GeneratorContext]], [[GeneratorBrand]] ») とする。
  3. gen.[[GeneratorBrand]]emptyに設定する。
  4. gen.[[GeneratorState]]suspended-startに設定する。
  5. GeneratorStart(gen, FunctionBody)を実行する。
  6. ReturnCompletion(gen)を返す。

15.5.3 Runtime Semantics: InstantiateGeneratorFunctionObject

The syntax-directed operation InstantiateGeneratorFunctionObject takes arguments envRecord (an Environment Record) and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. It is defined piecewise over the following productions:

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. nameBindingIdentifierStringValueとする。
  2. sourceTextGeneratorDeclarationによってmatchされたsource textとする。
  3. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)とする。
  4. SetFunctionName(closure, name)を実行する。
  5. protoOrdinaryObjectCreate(%GeneratorPrototype%)とする。
  6. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  7. closureを返す。
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. sourceTextGeneratorDeclarationによってmatchされたsource textとする。
  2. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)とする。
  3. SetFunctionName(closure, "default")を実行する。
  4. protoOrdinaryObjectCreate(%GeneratorPrototype%)とする。
  5. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  6. closureを返す。
Note

anonymous GeneratorDeclarationexport default declarationの一部としてのみ出現できるため、そのfunction codeは常にstrict mode codeです。

15.5.4 Runtime Semantics: InstantiateGeneratorFunctionExpression

The syntax-directed operation InstantiateGeneratorFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. nameが存在しない場合、nameをempty Stringに設定する。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextGeneratorExpressionによってmatchされたsource textとする。
  5. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv)とする。
  6. SetFunctionName(closure, name)を実行する。
  7. protoOrdinaryObjectCreate(%GeneratorPrototype%)とする。
  8. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  9. closureを返す。
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. Assert: nameは存在しない。
  2. nameBindingIdentifierStringValueに設定する。
  3. outerEnvrunning execution contextのLexicalEnvironmentとする。
  4. funcEnvNewDeclarativeEnvironment(outerEnv)とする。
  5. funcEnv.CreateImmutableBinding(name, false)を実行する。
  6. privateEnvrunning execution contextのPrivateEnvironmentとする。
  7. sourceTextGeneratorExpressionによってmatchされたsource textとする。
  8. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, funcEnv, privateEnv)とする。
  9. SetFunctionName(closure, name)を実行する。
  10. protoOrdinaryObjectCreate(%GeneratorPrototype%)とする。
  11. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  12. funcEnv.InitializeBinding(name, closure)を実行する。
  13. closureを返す。
Note

GeneratorExpression内のBindingIdentifierは、generator codeがそれ自身を再帰的に呼び出せるように、GeneratorExpressionFunctionBody内部からreferenceできます。ただし、GeneratorDeclarationの場合とは異なり、GeneratorExpression内のBindingIdentifierは、GeneratorExpressionを囲むscopeからreferenceできず、そのscopeに影響しません。

15.5.5 Runtime Semantics: Evaluation

GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  1. GeneratorExpressionInstantiateGeneratorFunctionExpressionを返す。
YieldExpression : yield
  1. Yield(undefined)を返す。
YieldExpression : yield AssignmentExpression
  1. exprRefAssignmentExpressionの ? Evaluationとする。
  2. valueを ? GetValue(exprRef) とする。
  3. Yield(value)を返す。
YieldExpression : yield * AssignmentExpression
  1. genKindGetGeneratorKind()とする。
  2. Assert: genKindsyncまたはasyncのいずれかである。
  3. exprRefAssignmentExpressionの ? Evaluationとする。
  4. valueを ? GetValue(exprRef) とする。
  5. iteratorRecordを ? GetIterator(value, genKind) とする。
  6. iteratoriteratorRecord.[[Iterator]]とする。
  7. receivedNormalCompletion(undefined)とする。
  8. 繰り返す
    1. receivednormal completionなら、
      1. innerResultを ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] ») とする。
      2. genKindasyncなら、innerResultを ? Await(innerResult) に設定する。
      3. innerResultがObjectでないなら、TypeError例外をthrowする。
      4. doneを ? IteratorComplete(innerResult) とする。
      5. donetrueなら、
        1. IteratorValue(innerResult)を返す。
      6. genKindasyncなら、receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerResult)))に設定する。
      7. そうでなければ、receivedCompletion(GeneratorYield(innerResult))に設定する。
    2. そうでなく、receivedthrow completionなら、
      1. throwを ? GetMethod(iterator, "throw") とする。
      2. throwundefinedでないなら、
        1. innerResultを ? Call(throw, iterator, « received.[[Value]] ») とする。
        2. genKindasyncなら、innerResultを ? Await(innerResult) に設定する。
        3. NOTE: inner iteratorthrow methodからのexceptionsは伝播される。inner throw methodからのnormal completionsは、inner nextと同様に処理される。
        4. innerResultがObjectでないなら、TypeError例外をthrowする。
        5. doneを ? IteratorComplete(innerResult) とする。
        6. donetrueなら、
          1. IteratorValue(innerResult)を返す。
        7. genKindasyncなら、receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerResult)))に設定する。
        8. そうでなければ、receivedCompletion(GeneratorYield(innerResult))に設定する。
      3. そうでなければ、
        1. NOTE: iteratorthrow methodを持たない場合、このthrowはyield* loopを終了させることになる。しかし、まずiteratorにclean upの機会を与える必要がある。
        2. closeCompletionNormalCompletion(empty)とする。
        3. genKindasyncなら、? AsyncIteratorClose(iteratorRecord, closeCompletion)を実行する。
        4. そうでなければ、? IteratorClose(iteratorRecord, closeCompletion)を実行する。
        5. NOTE: next stepは、yield* protocol violationがあったこと、すなわちiteratorthrow methodを持たないことを示すためにTypeErrorをthrowする。
        6. TypeError例外をthrowする。
    3. そうでなければ、
      1. Assert: receivedreturn completionである。
      2. returnを ? GetMethod(iterator, "return") とする。
      3. returnundefinedなら、
        1. receivedValuereceived.[[Value]]とする。
        2. genKindasyncなら、
          1. receivedValueを ? Await(receivedValue) に設定する。
        3. ReturnCompletion(receivedValue)を返す。
      4. innerReturnResultを ? Call(return, iterator, « received.[[Value]] ») とする。
      5. genKindasyncなら、innerReturnResultを ? Await(innerReturnResult) に設定する。
      6. innerReturnResultがObjectでないなら、TypeError例外をthrowする。
      7. doneを ? IteratorComplete(innerReturnResult) とする。
      8. donetrueなら、
        1. returnedValueを ? IteratorValue(innerReturnResult) とする。
        2. ReturnCompletion(returnedValue)を返す。
      9. genKindasyncなら、receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerReturnResult)))に設定する。
      10. そうでなければ、receivedCompletion(GeneratorYield(innerReturnResult))に設定する。

15.6 Async Generator Function Definitions

Syntax

AsyncGeneratorDeclaration[Yield, Await, Default] : async [no LineTerminator here] function * BindingIdentifier[?Yield, ?Await] ( FormalParameters[+Yield, +Await] ) { AsyncGeneratorBody } [+Default] async [no LineTerminator here] function * ( FormalParameters[+Yield, +Await] ) { AsyncGeneratorBody } AsyncGeneratorExpression : async [no LineTerminator here] function * BindingIdentifier[+Yield, +Await]opt ( FormalParameters[+Yield, +Await] ) { AsyncGeneratorBody } AsyncGeneratorMethod[Yield, Await] : async [no LineTerminator here] * ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[+Yield, +Await] ) { AsyncGeneratorBody } AsyncGeneratorBody : FunctionBody[+Yield, +Await] Note 1

YieldExpressionおよびAwaitExpressionはasync generator functionのFormalParameters内では使用できません。なぜなら、FormalParametersの一部であるexpressionsは、結果として得られるAsyncGeneratorがresumable stateになる前に評価されるからです。

Note 2

AsyncGeneratorsに関係するabstract operations27.9.3で定義されます。

15.6.1 Static Semantics: Early Errors

AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody } AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody }

15.6.2 Runtime Semantics: EvaluateAsyncGeneratorBody

The syntax-directed operation EvaluateAsyncGeneratorBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a throw completion or a return completion. It is defined piecewise over the following productions:

AsyncGeneratorBody : FunctionBody
  1. FunctionDeclarationInstantiation(funcObj, argList)を実行する。
  2. genを ? OrdinaryCreateFromConstructor(funcObj, "%AsyncGeneratorPrototype%", « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]], [[GeneratorBrand]] ») とする。
  3. gen.[[GeneratorBrand]]emptyに設定する。
  4. gen.[[AsyncGeneratorState]]suspended-startに設定する。
  5. AsyncGeneratorStart(gen, FunctionBody)を実行する。
  6. ReturnCompletion(gen)を返す。

15.6.3 Runtime Semantics: InstantiateAsyncGeneratorFunctionObject

The syntax-directed operation InstantiateAsyncGeneratorFunctionObject takes arguments envRecord (an Environment Record) and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. nameBindingIdentifierStringValueとする。
  2. sourceTextAsyncGeneratorDeclarationによってmatchされたsource textとする。
  3. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)とする。
  4. SetFunctionName(closure, name)を実行する。
  5. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)とする。
  6. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  7. closureを返す。
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. sourceTextAsyncGeneratorDeclarationによってmatchされたsource textとする。
  2. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)とする。
  3. SetFunctionName(closure, "default")を実行する。
  4. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)とする。
  5. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  6. closureを返す。
Note

anonymous AsyncGeneratorDeclarationexport default declarationの一部としてのみ出現できます。

15.6.4 Runtime Semantics: InstantiateAsyncGeneratorFunctionExpression

The syntax-directed operation InstantiateAsyncGeneratorFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. nameが存在しない場合、nameをempty Stringに設定する。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextAsyncGeneratorExpressionによってmatchされたsource textとする。
  5. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv)とする。
  6. SetFunctionName(closure, name)を実行する。
  7. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)とする。
  8. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  9. closureを返す。
AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. Assert: nameは存在しない。
  2. nameBindingIdentifierStringValueに設定する。
  3. outerEnvrunning execution contextのLexicalEnvironmentとする。
  4. funcEnvNewDeclarativeEnvironment(outerEnv)とする。
  5. funcEnv.CreateImmutableBinding(name, false)を実行する。
  6. privateEnvrunning execution contextのPrivateEnvironmentとする。
  7. sourceTextAsyncGeneratorExpressionによってmatchされたsource textとする。
  8. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, funcEnv, privateEnv)とする。
  9. SetFunctionName(closure, name)を実行する。
  10. protoOrdinaryObjectCreate(%AsyncGeneratorPrototype%)とする。
  11. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false })を実行する。
  12. funcEnv.InitializeBinding(name, closure)を実行する。
  13. closureを返す。
Note

AsyncGeneratorExpression内のBindingIdentifierは、generator codeがそれ自身を再帰的に呼び出せるように、AsyncGeneratorExpressionAsyncGeneratorBody内部からreferenceできます。ただし、AsyncGeneratorDeclarationの場合とは異なり、AsyncGeneratorExpression内のBindingIdentifierは、AsyncGeneratorExpressionを囲むscopeからreferenceできず、そのscopeに影響しません。

15.6.5 Runtime Semantics: Evaluation

AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody }
  1. AsyncGeneratorExpressionInstantiateAsyncGeneratorFunctionExpressionを返す。

15.7 Class Definitions

Syntax

ClassDeclaration[Yield, Await, Default] : class BindingIdentifier[?Yield, ?Await] ClassTail[?Yield, ?Await] [+Default] class ClassTail[?Yield, ?Await] ClassExpression[Yield, Await] : class BindingIdentifier[?Yield, ?Await]opt ClassTail[?Yield, ?Await] ClassTail[Yield, Await] : ClassHeritage[?Yield, ?Await]opt { ClassBody[?Yield, ?Await]opt } ClassHeritage[Yield, Await] : extends LeftHandSideExpression[?Yield, ?Await] ClassBody[Yield, Await] : ClassElementList[?Yield, ?Await] ClassElementList[Yield, Await] : ClassElement[?Yield, ?Await] ClassElementList[?Yield, ?Await] ClassElement[?Yield, ?Await] ClassElement[Yield, Await] : MethodDefinition[?Yield, ?Await] static MethodDefinition[?Yield, ?Await] FieldDefinition[?Yield, ?Await] ; static FieldDefinition[?Yield, ?Await] ; ClassStaticBlock ; FieldDefinition[Yield, Await] : ClassElementName[?Yield, ?Await] Initializer[+In, ?Yield, ?Await]opt ClassElementName[Yield, Await] : PropertyName[?Yield, ?Await] PrivateIdentifier ClassStaticBlock : static { ClassStaticBlockBody } ClassStaticBlockBody : ClassStaticBlockStatementList ClassStaticBlockStatementList : StatementList[~Yield, +Await, ~Return]opt Note

class definitionは常にstrict mode codeです。

15.7.1 Static Semantics: Early Errors

ClassTail : ClassHeritageopt { ClassBody } ClassBody : ClassElementList
  • ClassElementListPrototypePropertyNameList"constructor"の出現を複数含む場合、それはSyntax Errorです。
  • ClassElementListPrivateBoundIdentifiersが重複entriesを含む場合、それはSyntax Errorです。ただし、そのnameがgetterに1回、setterに1回だけ使用され、他のentriesでは使用されず、getterとsetterが両方ともstaticまたは両方ともnon-staticである場合を除きます。
ClassElement : MethodDefinition ClassElement : static MethodDefinition ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ;
  • FieldDefinitionPropName"prototype"または"constructor"のいずれかである場合、それはSyntax Errorです。
FieldDefinition : ClassElementName Initializeropt ClassElementName : PrivateIdentifier ClassStaticBlockBody : ClassStaticBlockStatementList

15.7.2 Static Semantics: ClassElementKind

The syntax-directed operation ClassElementKind takes no arguments and returns constructor-method, non-constructor-method, or empty. It is defined piecewise over the following productions:

ClassElement : MethodDefinition
  1. MethodDefinitionPropName"constructor"なら、constructor-methodを返す。
  2. non-constructor-methodを返す。
ClassElement : static MethodDefinition FieldDefinition ; static FieldDefinition ;
  1. non-constructor-methodを返す。
ClassElement : ClassStaticBlock
  1. non-constructor-methodを返す。
ClassElement : ;
  1. emptyを返す。

15.7.3 Static Semantics: ConstructorMethod

The syntax-directed operation ConstructorMethod takes no arguments and returns a ClassElement Parse Node or empty. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. ClassElementClassElementKindconstructor-methodなら、ClassElementを返す。
  2. emptyを返す。
ClassElementList : ClassElementList ClassElement
  1. headClassElementListConstructorMethodとする。
  2. heademptyでないなら、headを返す。
  3. ClassElementClassElementKindconstructor-methodなら、ClassElementを返す。
  4. emptyを返す。
Note

Early Error rulesは、"constructor"と名付けられたmethod definitionが1つだけ存在し、それがaccessor propertyまたはgenerator definitionでないことを保証します。

15.7.4 Static Semantics: IsStatic

The syntax-directed operation IsStatic takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

ClassElement : MethodDefinition
  1. falseを返す。
ClassElement : static MethodDefinition
  1. trueを返す。
ClassElement : FieldDefinition ;
  1. falseを返す。
ClassElement : static FieldDefinition ;
  1. trueを返す。
ClassElement : ClassStaticBlock
  1. trueを返す。
ClassElement : ;
  1. falseを返す。

15.7.5 Static Semantics: NonConstructorElements

The syntax-directed operation NonConstructorElements takes no arguments and returns a List of ClassElement Parse Nodes. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. ClassElementClassElementKindnon-constructor-methodなら、
    1. « ClassElement »を返す。
  2. 新しい空のListを返す。
ClassElementList : ClassElementList ClassElement
  1. listClassElementListNonConstructorElementsとする。
  2. ClassElementClassElementKindnon-constructor-methodなら、
    1. ClassElementlistへappendする。
  3. listを返す。

15.7.6 Static Semantics: PrototypePropertyNameList

The syntax-directed operation PrototypePropertyNameList takes no arguments and returns a List of property keys. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. propertyNameClassElementPropNameとする。
  2. propertyNameemptyなら、新しい空のListを返す。
  3. ClassElementIsStatictrueなら、新しい空のListを返す。
  4. « propertyName »を返す。
ClassElementList : ClassElementList ClassElement
  1. listClassElementListPrototypePropertyNameListとする。
  2. propertyNameClassElementPropNameとする。
  3. propertyNameemptyなら、listを返す。
  4. ClassElementIsStatictrueなら、listを返す。
  5. listと« propertyName »のlist-concatenationを返す。

15.7.7 Static Semantics: AllPrivateIdentifiersValid

The syntax-directed operation AllPrivateIdentifiersValid takes argument names (a List of Strings) and returns a Boolean.

この仕様内で下に列挙されていないすべてのgrammar production alternativeは、暗黙的にAllPrivateIdentifiersValidの次のdefault definitionを持ちます:

  1. このParse Nodeの各child node childについて、以下を行う
    1. childがnonterminalのinstanceなら、
      1. argument namesを伴うchildAllPrivateIdentifiersValidfalseなら、falseを返す。
  2. trueを返す。
MemberExpression : MemberExpression . PrivateIdentifier
  1. namesPrivateIdentifierStringValueを含むなら、
    1. argument namesを伴うMemberExpressionAllPrivateIdentifiersValidを返す。
  2. falseを返す。
CallExpression : CallExpression . PrivateIdentifier
  1. namesPrivateIdentifierStringValueを含むなら、
    1. argument namesを伴うCallExpressionAllPrivateIdentifiersValidを返す。
  2. falseを返す。
OptionalChain : ?. PrivateIdentifier
  1. namesPrivateIdentifierStringValueを含むなら、trueを返す。
  2. falseを返す。
OptionalChain : OptionalChain . PrivateIdentifier
  1. namesPrivateIdentifierStringValueを含むなら、
    1. argument namesを伴うOptionalChainAllPrivateIdentifiersValidを返す。
  2. falseを返す。
ClassBody : ClassElementList
  1. newNamesnamesClassBodyPrivateBoundIdentifierslist-concatenationとする。
  2. argument newNamesを伴うClassElementListAllPrivateIdentifiersValidを返す。
RelationalExpression : PrivateIdentifier in ShiftExpression
  1. namesPrivateIdentifierStringValueを含むなら、
    1. argument namesを伴うShiftExpressionAllPrivateIdentifiersValidを返す。
  2. falseを返す。

15.7.8 Static Semantics: PrivateBoundIdentifiers

The syntax-directed operation PrivateBoundIdentifiers takes no arguments and returns a List of Strings. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. ClassElementNamePrivateBoundIdentifiersを返す。
ClassElementName : PrivateIdentifier
  1. 唯一の要素がPrivateIdentifierStringValueであるListを返す。
ClassElementName : PropertyName ClassElement : ClassStaticBlock ;
  1. 新しい空のListを返す。
ClassElementList : ClassElementList ClassElement
  1. names1ClassElementListPrivateBoundIdentifiersとする。
  2. names2ClassElementPrivateBoundIdentifiersとする。
  3. names1names2list-concatenationを返す。
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody } GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. ClassElementNamePrivateBoundIdentifiersを返す。

15.7.9 Static Semantics: ContainsArguments

The syntax-directed operation ContainsArguments takes no arguments and returns a Boolean.

この仕様内で下に列挙されていないすべてのgrammar production alternativeは、暗黙的にContainsArgumentsの次のdefault definitionを持ちます:

  1. このParse Nodeの各child node childについて、以下を行う
    1. childがnonterminalのinstanceなら、
      1. childContainsArgumentstrueなら、trueを返す。
  2. falseを返す。
IdentifierReference : Identifier
  1. IdentifierStringValue"arguments"なら、trueを返す。
  2. falseを返す。
FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } function ( FormalParameters ) { FunctionBody } FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody } GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody } AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. falseを返す。
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody } GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody } AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody } AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. ClassElementNameContainsArgumentsを返す。

15.7.10 Runtime Semantics: ClassFieldDefinitionEvaluation

The syntax-directed operation ClassFieldDefinitionEvaluation takes argument homeObj (an Object) and returns either a normal completion containing a ClassFieldDefinition Record or an abrupt completion. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. nameClassElementNameの ? Evaluationとする。
  2. Initializerが存在するなら、
    1. formalParamListをproduction FormalParameters : [empty] のinstanceとする。
    2. envRecordrunning execution contextのLexicalEnvironmentとする。
    3. privateEnvrunning execution contextのPrivateEnvironmentとする。
    4. sourceTextをUnicode code pointsのempty sequenceとする。
    5. initializerOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParamList, Initializer, non-lexical-this, envRecord, privateEnv)とする。
    6. MakeMethod(initializer, homeObj)を実行する。
    7. initializer.[[ClassFieldInitializerName]]nameに設定する。
  3. そうでなければ、
    1. initializeremptyとする。
  4. ClassFieldDefinition Record { [[Name]]: name, [[Initializer]]: initializer }を返す。
Note
initializerのために作成されるfunctionは、ECMAScript codeから直接accessできることは決してありません。

15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation

The syntax-directed operation ClassStaticBlockDefinitionEvaluation takes argument homeObj (an Object) and returns a ClassStaticBlockDefinition Record. It is defined piecewise over the following productions:

ClassStaticBlock : static { ClassStaticBlockBody }
  1. 実行中の実行コンテキストのLexicalEnvironmentをlexicalEnvとする。
  2. 実行中の実行コンテキストのPrivateEnvironmentをprivateEnvとする。
  3. 空のUnicode符号点列をsourceTextとする。
  4. 生成規則 FormalParameters : [empty] のインスタンスをformalParamsとする。
  5. OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParams, ClassStaticBlockBody, non-lexical-this, lexicalEnv, privateEnv)をbodyFuncとする。
  6. MakeMethod(bodyFunc, homeObj)を実行する。
  7. ClassStaticBlockDefinition Record { [[BodyFunction]]: bodyFunc }を返す。
Note
function bodyFuncはECMAScript codeから直接accessできることは決してありません。

15.7.12 Runtime Semantics: EvaluateClassStaticBlockBody

The syntax-directed operation EvaluateClassStaticBlockBody takes argument funcObj (an ECMAScript function object) and returns a return completion or a throw completion. It is defined piecewise over the following productions:

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. Assert: funcObjClassStaticBlockDefinitionEvaluation ステップ 5 によって作成された合成関数である。
  2. FunctionDeclarationInstantiation(funcObj, « ») を実行する。
  3. resultClassStaticBlockStatementListEvaluationCompletion とする。
  4. envRecord を、実行中の実行コンテキストの LexicalEnvironment とする。
  5. Assert: envRecordDeclarative Environment Record である。
  6. DisposeResources(envRecord.[[DisposableResourceStack]], result) を実行する。
  7. ReturnCompletion(undefined) を返す。

15.7.13 Runtime Semantics: ClassElementEvaluation

The syntax-directed operation ClassElementEvaluation takes argument obj (an Object) and returns either a normal completion containing either a ClassFieldDefinition Record, a ClassStaticBlockDefinition Record, a PrivateElement, or unused, or an abrupt completion. It is defined piecewise over the following productions:

ClassElement : FieldDefinition ; static FieldDefinition ;
  1. argument objを伴うFieldDefinitionの ? ClassFieldDefinitionEvaluationを返す。
ClassElement : MethodDefinition static MethodDefinition
  1. arguments objおよびfalseを伴うMethodDefinitionの ? MethodDefinitionEvaluationを返す。
ClassElement : ClassStaticBlock
  1. argument objを伴うClassStaticBlockClassStaticBlockDefinitionEvaluationを返す。
ClassElement : ;
  1. unusedを返す。

15.7.14 Runtime Semantics: ClassDefinitionEvaluation

The syntax-directed operation ClassDefinitionEvaluation takes arguments classBinding (a String or undefined), className (a property key or a Private Name), and sourceText (ECMAScript source text) and returns either a normal completion containing a function object or an abrupt completion.

Note

specificationの容易さのため、private methodsおよびaccessorsは、private fieldsと並んでclass instancesの[[PrivateElements]] slotに含められます。ただし、任意のobjectは、与えられたclassによって定義されるprivate methodsおよびaccessorsのすべてを持つか、まったく持たないかのいずれかです。この機能は、implementationsが各methodまたはaccessorを個別にtrackする必要のないstrategyを使用してprivate methodsおよびaccessorsを実装することを選択できるように設計されています。

例えば、implementationはinstance private methodsをそれらに対応するPrivate Nameへ直接関連付け、各objectについて、どのclass constructorsがそのobjectをthis valueとして実行されたかをtrackできます。object上でinstance private methodをlookupすることは、そのmethodを定義するclass constructorがそのobjectをinitializeするために使用されたことをcheckし、その後Private Nameに関連付けられたmethodを返すことからなります。

これはprivate fieldsとは異なります。field initializersはclass instantiation中にthrowする可能性があるため、個々のobjectは与えられたclassのprivate fieldsのproper subsetだけを持つ場合があり、そのためprivate fieldsは一般に個別にtrackされなければなりません。

It is defined piecewise over the following productions:

ClassTail : ClassHeritageopt { ClassBodyopt }
  1. envRecordrunning execution contextのLexicalEnvironmentとする。
  2. classEnvNewDeclarativeEnvironment(envRecord)とする。
  3. classBindingundefinedでないなら、
    1. classEnv.CreateImmutableBinding(classBinding, true)を実行する。
  4. outerPrivateEnvrunning execution contextのPrivateEnvironmentとする。
  5. classPrivateEnvNewPrivateEnvironment(outerPrivateEnv)とする。
  6. ClassBodyが存在するなら、
    1. ClassBodyPrivateBoundIdentifiersの各String descriptionについて、以下を行う
      1. classPrivateEnv.[[Names]]が、[[Description]]descriptionであるPrivate Name privateNameを含むなら、
        1. Assert: これはgetter/setter pairsの場合にのみ可能である。
      2. そうでなければ、
        1. nameを、その[[Description]]descriptionである新しいPrivate Nameとする。
        2. nameclassPrivateEnv.[[Names]]へappendする。
  7. ClassHeritageが存在しないなら、
    1. protoParent%Object.prototype%とする。
    2. ctorParent%Function.prototype%とする。
  8. そうでなければ、
    1. running execution contextのLexicalEnvironmentをclassEnvに設定する。
    2. NOTE: ClassHeritageを評価するとき、running execution contextのPrivateEnvironmentはouterPrivateEnvである。
    3. superclassRefClassHeritageEvaluationCompletionとする。
    4. running execution contextのLexicalEnvironmentをenvRecordに設定する。
    5. superclassを ? GetValue(? superclassRef) とする。
    6. superclassnullなら、
      1. protoParentnullとする。
      2. ctorParent%Function.prototype%とする。
    7. そうでなく、IsConstructor(superclass)がfalseなら、
      1. TypeError例外をthrowする。
    8. そうでなければ、
      1. protoParentを ? Get(superclass, "prototype") とする。
      2. protoParentがObjectでなく、かつprotoParentnullでないなら、TypeError例外をthrowする。
      3. ctorParentsuperclassとする。
  9. protoOrdinaryObjectCreate(protoParent)とする。
  10. ClassBodyが存在しないなら、ctoremptyとする。
  11. そうでなければ、ctorClassBodyConstructorMethodとする。
  12. running execution contextのLexicalEnvironmentをclassEnvに設定する。
  13. running execution contextのPrivateEnvironmentをclassPrivateEnvに設定する。
  14. ctoremptyなら、
    1. defaultCtorを、parametersを持たず、何もcaptureせず、呼び出されたときに次のstepsを実行する新しいAbstract Closureとする:
      1. argsを、このfunctionに[[Call]]または[[Construct]]によって渡されたargumentsのListとする。
      2. NewTargetがundefinedなら、TypeError例外をthrowする。
      3. ctorFuncactive function objectとする。
      4. ctorFunc.[[ConstructorKind]]derivedなら、
        1. NOTE: このbranchはconstructor(...args) { super(...args); }と同様に振る舞う。最も注目すべき違いは、前述のECMAScript source text%Array.prototype%上の%Symbol.iterator% methodをobservablyに呼び出すのに対し、このfunctionはそれを行わないことである。
        2. funcを ! ctorFunc.[[GetPrototypeOf]]() とする。
        3. IsConstructor(func)がfalseなら、TypeError例外をthrowする。
        4. resultを ? Construct(func, args, NewTarget) とする。
      5. そうでなければ、
        1. NOTE: このbranchはconstructor() {}と同様に振る舞う。
        2. resultを ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%") とする。
      6. InitializeInstanceElements(result, ctorFunc)を実行する。
      7. NormalCompletion(result)を返す。
    2. ctorFuncCreateBuiltinFunction(defaultCtor, 0, className, « [[ConstructorKind]], [[SourceText]], [[PrivateMethods]], [[Fields]] », the current Realm Record, ctorParent)とする。
  15. そうでなければ、
    1. ctorInfoを、arguments protoおよびctorParentを伴うctorの ! DefineMethodとする。
    2. ctorFuncctorInfo.[[Closure]]とする。
    3. MakeClassConstructor(ctorFunc)を実行する。
    4. SetFunctionName(ctorFunc, className)を実行する。
  16. ctorFunc.[[SourceText]]sourceTextに設定する。
  17. MakeConstructor(ctorFunc, false, proto)を実行する。
  18. ClassHeritageが存在するなら、ctorFunc.[[ConstructorKind]]derivedに設定する。
  19. DefineMethodProperty(proto, "constructor", ctorFunc, false)を実行する。
  20. ClassBodyが存在しないなら、classElementsを新しい空のListとする。
  21. そうでなければ、classElementsClassBodyNonConstructorElementsとする。
  22. instancePrivateMethodsを新しい空のListとする。
  23. staticPrivateMethodsを新しい空のListとする。
  24. instanceFieldsを新しい空のListとする。
  25. staticElementsを新しい空のListとする。
  26. classElementsの各ClassElement classElementについて、以下を行う
    1. classElementIsStaticfalseなら、
      1. elementを、argument protoを伴うclassElementClassElementEvaluationCompletionとする。
    2. そうでなければ、
      1. elementを、argument ctorFuncを伴うclassElementClassElementEvaluationCompletionとする。
    3. elementabrupt completionなら、
      1. running execution contextのLexicalEnvironmentをenvRecordに設定する。
      2. running execution contextのPrivateEnvironmentをouterPrivateEnvに設定する。
      3. elementを返す。
    4. elementを ! element に設定する。
    5. elementPrivateElementなら、
      1. Assert: element.[[Kind]]methodまたはaccessorのいずれかである。
      2. classElementIsStaticfalseなら、containerinstancePrivateMethodsとする。
      3. そうでなければ、containerstaticPrivateMethodsとする。
      4. containerが、その[[Key]]element.[[Key]]であるPrivateElement existingElementを含むなら、
        1. Assert: element.[[Kind]]existingElement.[[Kind]]は両方ともaccessorである。
        2. element.[[Get]]undefinedなら、
          1. combinedPrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Get]]: existingElement.[[Get]], [[Set]]: element.[[Set]] }とする。
        3. そうでなければ、
          1. combinedPrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Get]]: element.[[Get]], [[Set]]: existingElement.[[Set]] }とする。
        4. container内のexistingElementcombinedで置き換える。
      5. そうでなければ、
        1. elementcontainerへappendする。
    6. そうでなく、elementClassFieldDefinition Recordなら、
      1. classElementIsStaticfalseなら、elementinstanceFieldsへappendする。
      2. そうでなければ、elementstaticElementsへappendする。
    7. そうでなく、elementClassStaticBlockDefinition Recordなら、
      1. elementstaticElementsへappendする。
  27. running execution contextのLexicalEnvironmentをenvRecordに設定する。
  28. classBindingundefinedでないなら、
    1. classEnv.InitializeBinding(classBinding, ctorFunc)を実行する。
  29. ctorFunc.[[PrivateMethods]]instancePrivateMethodsに設定する。
  30. ctorFunc.[[Fields]]instanceFieldsに設定する。
  31. staticPrivateMethodsの各PrivateElement methodについて、以下を行う
    1. PrivateMethodOrAccessorAdd(ctorFunc, method)を実行する。
  32. staticElementsの各要素elementRecordについて、以下を行う
    1. elementRecordClassFieldDefinition Recordなら、
      1. resultDefineField(ctorFunc, elementRecord)のCompletionとする。
    2. そうでなければ、
      1. Assert: elementRecordClassStaticBlockDefinition Recordである。
      2. resultCall(elementRecord.[[BodyFunction]], ctorFunc)のCompletionとする。
    3. resultabrupt completionなら、
      1. running execution contextのPrivateEnvironmentをouterPrivateEnvに設定する。
      2. resultを返す。
  33. running execution contextのPrivateEnvironmentをouterPrivateEnvに設定する。
  34. ctorFuncを返す。

15.7.15 Runtime Semantics: BindingClassDeclarationEvaluation

The syntax-directed operation BindingClassDeclarationEvaluation takes no arguments and returns either a normal completion containing a function object or an abrupt completion. It is defined piecewise over the following productions:

ClassDeclaration : class BindingIdentifier ClassTail
  1. classNameBindingIdentifierStringValueとする。
  2. sourceTextClassDeclarationによってmatchされたsource textとする。
  3. valueを、arguments classNameclassName、およびsourceTextを伴うClassTailの ? ClassDefinitionEvaluationとする。
  4. envRecordrunning execution contextのLexicalEnvironmentとする。
  5. InitializeBoundName(className, value, envRecord)を実行する。
  6. valueを返す。
ClassDeclaration : class ClassTail
  1. sourceTextClassDeclarationによってmatchされたsource textとする。
  2. arguments undefined"default"、およびsourceTextを伴うClassTailの ? ClassDefinitionEvaluationを返す。
Note

ClassDeclaration : class ClassTail ExportDeclarationの一部としてのみ出現し、そのbindingの確立はそのproductionに対するevaluation actionの一部として処理されます。16.2.3.7を参照してください。

15.7.16 Runtime Semantics: Evaluation

ClassDeclaration : class BindingIdentifier ClassTail
  1. this ClassDeclarationの ? BindingClassDeclarationEvaluationを実行する。
  2. emptyを返す。
Note

ClassDeclaration : class ClassTail ExportDeclarationの一部としてのみ出現し、直接評価されることは決してありません。

ClassExpression : class ClassTail
  1. sourceTextClassExpressionによってmatchされたsource textとする。
  2. arguments undefined、empty String、およびsourceTextを伴うClassTailの ? ClassDefinitionEvaluationを返す。
ClassExpression : class BindingIdentifier ClassTail
  1. classNameBindingIdentifierStringValueとする。
  2. sourceTextClassExpressionによってmatchされたsource textとする。
  3. arguments classNameclassName、およびsourceTextを伴うClassTailの ? ClassDefinitionEvaluationを返す。
ClassElementName : PrivateIdentifier
  1. privateIdentifierPrivateIdentifierStringValueとする。
  2. privateEnvRecordrunning execution contextのPrivateEnvironmentとする。
  3. namesprivateEnvRecord.[[Names]]とする。
  4. Assert: namesのちょうど1つの要素が、その[[Description]]privateIdentifierであるPrivate Nameである。
  5. privateNameを、names内の、その[[Description]]privateIdentifierであるPrivate Nameとする。
  6. privateNameを返す。
ClassStaticBlockStatementList : [empty]
  1. undefinedを返す。

15.8 Async Function Definitions

Syntax

AsyncFunctionDeclaration[Yield, Await, Default] : async [no LineTerminator here] function BindingIdentifier[?Yield, ?Await] ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } [+Default] async [no LineTerminator here] function ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncFunctionExpression : async [no LineTerminator here] function BindingIdentifier[~Yield, +Await]opt ( FormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncMethod[Yield, Await] : async [no LineTerminator here] ClassElementName[?Yield, ?Await] ( UniqueFormalParameters[~Yield, +Await] ) { AsyncFunctionBody } AsyncFunctionBody : FunctionBody[~Yield, +Await] AwaitExpression[Yield] : await UnaryExpression[?Yield, +Await] Note 1

[Await] parameterが存在するとき、awaitAwaitExpressionkeywordとしてparseされます。[Await] parameterは次のcontextsのtop levelに存在しますが、FunctionBodyなどのnonterminalsによっては一部のcontextsでそのparameterが存在しない場合があります:

Scriptがsyntactic goal symbolである場合、[Await] parameterが存在しないとき、awaitはidentifierとしてparseされる場合があります。これには次のcontextsが含まれます:

Note 2

YieldExpressionとは異なり、AwaitExpressionのoperandを省略することはSyntax Errorです。何かをawaitしなければなりません。

15.8.1 Static Semantics: Early Errors

AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody } AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }

15.8.2 Runtime Semantics: InstantiateAsyncFunctionObject

The syntax-directed operation InstantiateAsyncFunctionObject takes arguments envRecord (an Environment Record) and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. nameBindingIdentifierStringValueとする。
  2. sourceTextAsyncFunctionDeclarationによってmatchされたsource textとする。
  3. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  4. SetFunctionName(closure, name)を実行する。
  5. closureを返す。
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. sourceTextAsyncFunctionDeclarationによってmatchされたsource textとする。
  2. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  3. SetFunctionName(closure, "default")を実行する。
  4. closureを返す。

15.8.3 Runtime Semantics: InstantiateAsyncFunctionExpression

The syntax-directed operation InstantiateAsyncFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. nameが存在しない場合、nameをempty Stringに設定する。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextAsyncFunctionExpressionによってmatchされたsource textとする。
  5. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv)とする。
  6. SetFunctionName(closure, name)を実行する。
  7. closureを返す。
AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. Assert: nameは存在しない。
  2. nameBindingIdentifierStringValueに設定する。
  3. outerEnvrunning execution contextのLexicalEnvironmentとする。
  4. funcEnvNewDeclarativeEnvironment(outerEnv)とする。
  5. funcEnv.CreateImmutableBinding(name, false)を実行する。
  6. privateEnvrunning execution contextのPrivateEnvironmentとする。
  7. sourceTextAsyncFunctionExpressionによってmatchされたsource textとする。
  8. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, funcEnv, privateEnv)とする。
  9. SetFunctionName(closure, name)を実行する。
  10. funcEnv.InitializeBinding(name, closure)を実行する。
  11. closureを返す。
Note

AsyncFunctionExpression内のBindingIdentifierは、functionがそれ自身を再帰的に呼び出せるように、AsyncFunctionExpressionAsyncFunctionBody内部からreferenceできます。ただし、FunctionDeclarationの場合とは異なり、AsyncFunctionExpression内のBindingIdentifierは、AsyncFunctionExpressionを囲むscopeからreferenceできず、そのscopeに影響しません。

15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody

The syntax-directed operation EvaluateAsyncFunctionBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a return completion. It is defined piecewise over the following productions:

AsyncFunctionBody : FunctionBody
  1. promiseCapabilityを ! NewPromiseCapability(%Promise%) とする。
  2. completionCompletion(FunctionDeclarationInstantiation(funcObj, argList))とする。
  3. completionabrupt completionなら、
    1. Call(promiseCapability.[[Reject]], undefined, « completion.[[Value]] »)を実行する。
  4. そうでなければ、
    1. AsyncFunctionStart(promiseCapability, FunctionBody)を実行する。
  5. ReturnCompletion(promiseCapability.[[Promise]])を返す。

15.8.5 Runtime Semantics: Evaluation

AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. AsyncFunctionExpressionInstantiateAsyncFunctionExpressionを返す。
UnaryExpression : CoverAwaitExpressionAndAwaitUsingDeclarationHead
  1. expr を、CoverAwaitExpressionAndAwaitUsingDeclarationHead によってカバーされる AwaitExpression とする。
  2. Return ? Evaluation of expr.
AwaitExpression : await UnaryExpression
  1. exprRefUnaryExpressionの ? Evaluationとする。
  2. valueを ? GetValue(exprRef) とする。
  3. Await(value)を返す。

15.9 Async Arrow Function Definitions

Syntax

AsyncArrowFunction[In, Yield, Await] : async [no LineTerminator here] AsyncArrowBindingIdentifier[?Yield] [no LineTerminator here] => AsyncConciseBody[?In] CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] [no LineTerminator here] => AsyncConciseBody[?In] AsyncConciseBody[In] : [lookahead ≠ {] ExpressionBody[?In, +Await] { AsyncFunctionBody } AsyncArrowBindingIdentifier[Yield] : BindingIdentifier[?Yield, +Await] CoverCallExpressionAndAsyncArrowHead[Yield, Await] : MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

Supplemental Syntax

production
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
のinstanceを処理するとき、CoverCallExpressionAndAsyncArrowHeadのinterpretationは次のgrammarを使用してrefineされます:

AsyncArrowHead : async [no LineTerminator here] ArrowFormalParameters[~Yield, +Await]

15.9.1 Static Semantics: Early Errors

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody

15.9.2 Static Semantics: AsyncConciseBodyContainsUseStrict

The syntax-directed operation AsyncConciseBodyContainsUseStrict takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

AsyncConciseBody : ExpressionBody
  1. falseを返す。
AsyncConciseBody : { AsyncFunctionBody }
  1. AsyncFunctionBodyFunctionBodyContainsUseStrictを返す。

15.9.3 Runtime Semantics: EvaluateAsyncConciseBody

The syntax-directed operation EvaluateAsyncConciseBody takes arguments funcObj (an ECMAScript function object) and argList (a List of ECMAScript language values) and returns a return completion. It is defined piecewise over the following productions:

AsyncConciseBody : ExpressionBody
  1. promiseCapabilityを ! NewPromiseCapability(%Promise%) とする。
  2. completionCompletion(FunctionDeclarationInstantiation(funcObj, argList))とする。
  3. completionabrupt completionなら、
    1. Call(promiseCapability.[[Reject]], undefined, « completion.[[Value]] »)を実行する。
  4. そうでなければ、
    1. AsyncFunctionStart(promiseCapability, ExpressionBody)を実行する。
  5. ReturnCompletion(promiseCapability.[[Promise]])を返す。

15.9.4 Runtime Semantics: InstantiateAsyncArrowFunctionExpression

The syntax-directed operation InstantiateAsyncArrowFunctionExpression takes optional argument name (a property key or a Private Name) and returns an ECMAScript function object. It is defined piecewise over the following productions:

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. nameが存在しない場合、nameをempty Stringに設定する。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextAsyncArrowFunctionによってmatchされたsource textとする。
  5. paramsAsyncArrowBindingIdentifierとする。
  6. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, params, AsyncConciseBody, lexical-this, envRecord, privateEnv)とする。
  7. SetFunctionName(closure, name)を実行する。
  8. closureを返す。
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. nameが存在しない場合、nameをempty Stringに設定する。
  2. envRecordrunning execution contextのLexicalEnvironmentとする。
  3. privateEnvrunning execution contextのPrivateEnvironmentとする。
  4. sourceTextAsyncArrowFunctionによってmatchされたsource textとする。
  5. headCoverCallExpressionAndAsyncArrowHeadによってcoverされるAsyncArrowHeadとする。
  6. paramsheadArrowFormalParametersとする。
  7. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, params, AsyncConciseBody, lexical-this, envRecord, privateEnv)とする。
  8. SetFunctionName(closure, name)を実行する。
  9. closureを返す。

15.9.5 Runtime Semantics: Evaluation

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. AsyncArrowFunctionInstantiateAsyncArrowFunctionExpressionを返す。

15.10 Tail Position Calls

15.10.1 Static Semantics: IsInTailPosition ( call )

The abstract operation IsInTailPosition takes argument call (a CallExpression Parse Node, a MemberExpression Parse Node, or an OptionalChain Parse Node) and returns a Boolean. It performs the following steps when called:

  1. IsStrict(call)がfalseなら、falseを返す。
  2. callFunctionBodyConciseBody、またはAsyncConciseBody内に含まれていないなら、falseを返す。
  3. bodycallを最も近く含むFunctionBodyConciseBody、またはAsyncConciseBodyとする。
  4. bodyGeneratorBodyFunctionBodyなら、falseを返す。
  5. bodyAsyncFunctionBodyFunctionBodyなら、falseを返す。
  6. bodyAsyncGeneratorBodyFunctionBodyなら、falseを返す。
  7. bodyAsyncConciseBodyなら、falseを返す。
  8. argument callを伴うbodyHasCallInTailPositionの結果を返す。
Note

Tail Position callsはstrict mode code内でのみ定義されます。これは、caller contextsのchainの観測を可能にする一般的なnon-standard language extension(10.2.4を参照)のためです。

15.10.2 Static Semantics: HasCallInTailPosition

The syntax-directed operation HasCallInTailPosition takes argument call (a CallExpression Parse Node, a MemberExpression Parse Node, or an OptionalChain Parse Node) and returns a Boolean.

Note 1

call は、ソーステキストの特定の範囲を表す Parse Node である。次のアルゴリズムが call を別の Parse Node と比較する場合、それらが同じソーステキストを表しているかどうかのテストである。

Note 2

呼び出し結果の return GetValue が直後に続く可能な末尾位置呼び出しも、可能な末尾位置呼び出しである。関数呼び出しは Reference Record を返すことができないため、そのような GetValue 操作は常に、実際の関数呼び出し結果と同じ値を返す。

Note 3

同じ BlockForStatementForInOfStatementFunctionBodyGeneratorBodyAsyncGeneratorBodyAsyncFunctionBody、または ClassStaticBlockBody 内で呼び出しに先行する using 宣言または await using 宣言は、その呼び出しが可能な末尾位置呼び出しになることを防ぐ。

It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. has を、引数 call で派生した StatementListHasCallInTailPosition とする。
  2. hastrue である場合、true を返す。
  3. 派生した StatementListContainsUsingtrue である場合、false を返す。
  4. 引数 callStatementListItemHasCallInTailPosition を返す。
FunctionStatementList : [empty] StatementListItem : Declaration Statement : VariableStatement EmptyStatement ExpressionStatement ContinueStatement BreakStatement ThrowStatement DebuggerStatement Block : { } ReturnStatement : return ; LabelledItem : FunctionDeclaration ForInOfStatement : for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement CaseBlock : { }
  1. falseを返す。
IfStatement : if ( Expression ) Statement else Statement
  1. hasを、argument callを伴う最初のStatementHasCallInTailPositionとする。
  2. hastrueなら、trueを返す。
  3. argument callを伴う2番目のStatementHasCallInTailPositionを返す。
IfStatement : if ( Expression ) Statement DoWhileStatement : do Statement while ( Expression ) ; WhileStatement : while ( Expression ) Statement ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( var ForBinding in Expression ) Statement for ( ForDeclaration in Expression ) Statement WithStatement : with ( Expression ) Statement
  1. argument callを伴うStatementHasCallInTailPositionを返す。
LabelledStatement : LabelIdentifier : LabelledItem
  1. argument callを伴うLabelledItemHasCallInTailPositionを返す。
ReturnStatement : return Expression ;
  1. argument callを伴うExpressionHasCallInTailPositionを返す。
SwitchStatement : switch ( Expression ) CaseBlock
  1. argument callを伴うCaseBlockHasCallInTailPositionを返す。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. hasfalseとする。
  2. 最初のCaseClausesが存在するなら、hasを、argument callを伴う最初のCaseClausesHasCallInTailPositionに設定する。
  3. hastrueなら、trueを返す。
  4. hasを、argument callを伴うDefaultClauseHasCallInTailPositionに設定する。
  5. hastrueなら、trueを返す。
  6. 2番目のCaseClausesが存在するなら、hasを、argument callを伴う2番目のCaseClausesHasCallInTailPositionに設定する。
  7. hasを返す。
CaseClauses : CaseClauses CaseClause
  1. hasを、argument callを伴うCaseClausesHasCallInTailPositionとする。
  2. hastrueなら、trueを返す。
  3. argument callを伴うCaseClauseHasCallInTailPositionを返す。
CaseClause : case Expression : StatementListopt DefaultClause : default : StatementListopt
  1. StatementListが存在するなら、argument callを伴うStatementListHasCallInTailPositionを返す。
  2. falseを返す。
TryStatement : try Block Catch
  1. argument callを伴うCatchHasCallInTailPositionを返す。
TryStatement : try Block Finally try Block Catch Finally
  1. argument callを伴うFinallyHasCallInTailPositionを返す。
Catch : catch ( CatchParameter ) Block
  1. argument callを伴うBlockHasCallInTailPositionを返す。
AssignmentExpression : YieldExpression ArrowFunction AsyncArrowFunction LeftHandSideExpression = AssignmentExpression LeftHandSideExpression AssignmentOperator AssignmentExpression LeftHandSideExpression &&= AssignmentExpression LeftHandSideExpression ||= AssignmentExpression LeftHandSideExpression ??= AssignmentExpression BitwiseANDExpression : BitwiseANDExpression & EqualityExpression BitwiseXORExpression : BitwiseXORExpression ^ BitwiseANDExpression BitwiseORExpression : BitwiseORExpression | BitwiseXORExpression EqualityExpression : EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression EqualityExpression === RelationalExpression EqualityExpression !== RelationalExpression RelationalExpression : RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ShiftExpression RelationalExpression in ShiftExpression PrivateIdentifier in ShiftExpression ShiftExpression : ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression AdditiveExpression : AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator ExponentiationExpression ExponentiationExpression : UpdateExpression ** ExponentiationExpression UpdateExpression : LeftHandSideExpression ++ LeftHandSideExpression -- ++ UnaryExpression -- UnaryExpression UnaryExpression : delete UnaryExpression void UnaryExpression typeof UnaryExpression + UnaryExpression - UnaryExpression ~ UnaryExpression ! UnaryExpression CoverAwaitExpressionAndAwaitUsingDeclarationHead CallExpression : SuperCall ImportCall CallExpression [ Expression ] CallExpression . IdentifierName CallExpression . PrivateIdentifier NewExpression : new NewExpression MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier PrimaryExpression : this IdentifierReference Literal ArrayLiteral ObjectLiteral FunctionExpression ClassExpression GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral
  1. falseを返す。
Expression : AssignmentExpression Expression , AssignmentExpression
  1. argument callを伴うAssignmentExpressionHasCallInTailPositionを返す。
ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  1. hasを、argument callを伴う最初のAssignmentExpressionHasCallInTailPositionとする。
  2. hastrueなら、trueを返す。
  3. argument callを伴う2番目のAssignmentExpressionHasCallInTailPositionを返す。
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. argument callを伴うBitwiseORExpressionHasCallInTailPositionを返す。
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. argument callを伴うLogicalANDExpressionHasCallInTailPositionを返す。
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. argument callを伴うBitwiseORExpressionHasCallInTailPositionを返す。
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments CallExpression TemplateLiteral
  1. this CallExpressioncallなら、trueを返す。
  2. falseを返す。
OptionalExpression : MemberExpression OptionalChain CallExpression OptionalChain OptionalExpression OptionalChain
  1. argument callを伴うOptionalChainHasCallInTailPositionを返す。
OptionalChain : ?. [ Expression ] ?. IdentifierName ?. PrivateIdentifier OptionalChain [ Expression ] OptionalChain . IdentifierName OptionalChain . PrivateIdentifier
  1. falseを返す。
OptionalChain : ?. Arguments OptionalChain Arguments
  1. this OptionalChaincallなら、trueを返す。
  2. falseを返す。
MemberExpression : MemberExpression TemplateLiteral
  1. this MemberExpressioncallなら、trueを返す。
  2. falseを返す。
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. exprCoverParenthesizedExpressionAndArrowParameterListによってcoverされるParenthesizedExpressionとする。
  2. argument callを伴うexprHasCallInTailPositionを返す。
ParenthesizedExpression : ( Expression )
  1. argument callを伴うExpressionHasCallInTailPositionを返す。

15.10.3 PrepareForTailCall ( )

The abstract operation PrepareForTailCall takes no arguments and returns unused. It performs the following steps when called:

  1. Assert: current execution contextは、以後いかなるECMAScript codeまたはbuilt-in functionsのevaluationにも使用されない。このabstract operationの呼び出しに続くCallの呼び出しは、そのようなevaluationを実行する前に新しいexecution contextを作成してpushする。
  2. current execution contextに関連付けられたすべてのresourcesを破棄する。
  3. unusedを返す。

tail position callは、target functionを呼び出す前に、現在実行中のfunction execution contextに関連付けられたtransient internal resourcesを解放するか、target functionをsupportするためにそれらのresourcesを再利用しなければなりません。

Note

例えば、tail position callは、target functionのactivation recordのsizeがcalling functionのactivation recordのsizeを超える分だけ、implementationのactivation record stackを増加させるべきです。target functionのactivation recordの方が小さい場合、stackのtotal sizeは減少するべきです。