15 ECMAScript 言語: 関数とクラス

Note

さまざまな ECMAScript 言語要素は、ECMAScript 関数オブジェクトの生成を引き起こす(10.2)。これらの関数の評価は、それらの [[Call]] 内部メソッドの実行から開始される(10.2.1)。

15.1 パラメータリスト

構文

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: 早期エラー

UniqueFormalParameters : FormalParameters FormalParameters : FormalParameterList Note

FormalParameterList 内で同一の BindingIdentifier が複数回出現することは、単純なパラメータリストを持ち、かつ strict モードコードで定義されていない関数にのみ許可される。

15.1.2 Static Semantics: ContainsExpression

The syntax-directed operation ContainsExpression takes no arguments and returns ブール値. 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 によってカバーされる ArrowFormalParameters とする。
  2. formalsContainsExpression を返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. false を返す。

15.1.3 Static Semantics: IsSimpleParameterList

The syntax-directed operation IsSimpleParameterList takes no arguments and returns ブール値. 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 によってカバーされる ArrowFormalParameters とする。
  2. formalsIsSimpleParameterList を返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. true を返す。
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. headCoverCallExpressionAndAsyncArrowHead によってカバーされる AsyncArrowHead とする。
  2. headIsSimpleParameterList を返す。

15.1.4 Static Semantics: HasInitializer

The syntax-directed operation HasInitializer takes no arguments and returns ブール値. 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 非負整数. It is defined piecewise over the following productions:

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

FormalParameterList の ExpectedArgumentCount は、レストパラメータまたは Initializer を持つ最初の FormalParameter のいずれかの左側にある FormalParameters の数である。Initializer を持たない FormalParameter は、最初の Initializer を持つパラメータの後に現れることが許されるが、そのようなパラメータは既定値として undefined を持つオプションとして扱われる。

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 によってカバーされる ArrowFormalParameters とする。
  2. formalsExpectedArgumentCount を返す。
PropertySetParameterList : FormalParameter
  1. FormalParameterHasInitializertrue の場合、0 を返す。
  2. 1 を返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. 1 を返す。

15.2 関数定義

構文

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: 早期エラー

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

FunctionBodyLexicallyDeclaredNames には、var または関数宣言を用いて束縛された識別子は含まれない。

FunctionBody : FunctionStatementList

15.2.2 Static Semantics: FunctionBodyContainsUseStrict

The syntax-directed operation FunctionBodyContainsUseStrict takes no arguments and returns 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 functionObject (ECMAScript function object) and argumentsList (ECMAScript language valuesList) and returns return completion または throw completion. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionDeclarationInstantiation(functionObject, argumentsList) を実行する。
  2. FunctionStatementListEvaluation を ? 実行する。
  3. NOTE: 前のステップが normal completion となった場合、評価は FunctionStatementList の末尾を越えて進むことで終了した。
  4. ReturnCompletion(undefined) を返す。

15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject

The syntax-directed operation InstantiateOrdinaryFunctionObject takes arguments env (Environment Record) and privateEnv (PrivateEnvironment Record または null) and returns ECMAScript function object. It is defined piecewise over the following productions:

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. nameBindingIdentifierStringValue とする。
  2. sourceTextFunctionDeclaration に一致したソーステキストとする。
  3. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, env, privateEnv) とする。
  4. SetFunctionName(closure, name) を実行する。
  5. MakeConstructor(closure) を実行する。
  6. closure を返す。
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. sourceTextFunctionDeclaration に一致したソーステキストとする。
  2. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, env, privateEnv) とする。
  3. SetFunctionName(closure, "default") を実行する。
  4. MakeConstructor(closure) を実行する。
  5. closure を返す。
Note

無名の FunctionDeclarationexport default 宣言の一部としてのみ現れることができ、その関数コードはしたがって常に strict mode code である。

15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression

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

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. name が存在しない場合、name を空の String に設定する。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextFunctionExpression に一致したソーステキストとする。
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, env, privateEnv) とする。
  6. SetFunctionName(closure, name) を実行する。
  7. MakeConstructor(closure) を実行する。
  8. closure を返す。
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. Assert: name は存在しない。
  2. nameBindingIdentifierStringValue に設定する。
  3. outerEnv を実行中の実行コンテキストの LexicalEnvironment とする。
  4. funcEnvNewDeclarativeEnvironment(outerEnv) とする。
  5. funcEnv.CreateImmutableBinding(name, false) を実行する。
  6. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  7. sourceTextFunctionExpression に一致したソーステキストとする。
  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 は、関数が再帰的に自分自身を呼び出せるようにするため、FunctionExpressionFunctionBody 内から参照できる。しかし、FunctionDeclaration の場合とは異なり、FunctionExpression 内の BindingIdentifierFunctionExpression を囲むスコープから参照できず、そのスコープに影響しない。

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 を用いて定義されたすべての関数には、その関数がコンストラクタとして使用される可能性を許すため、"prototype" プロパティが自動的に作成される。

FunctionStatementList : [empty]
  1. undefined を返す。

15.3 アロー関数定義

構文

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]

補足構文

生成規則
ArrowParameters[Yield, Await] : CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await]
のインスタンスを処理するとき、CoverParenthesizedExpressionAndArrowParameterList の解釈は次の文法を用いて精緻化される:

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

15.3.1 Static Semantics: 早期エラー

ArrowFunction : ArrowParameters => ConciseBody ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList

15.3.2 Static Semantics: ConciseBodyContainsUseStrict

The syntax-directed operation ConciseBodyContainsUseStrict takes no arguments and returns ブール値. 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 functionObject (ECMAScript 関数オブジェクト) and argumentsList (ECMAScript 言語値List) and returns return 完了または throw 完了. It is defined piecewise over the following productions:

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

15.3.4 Runtime Semantics: InstantiateArrowFunctionExpression

The syntax-directed operation InstantiateArrowFunctionExpression takes optional argument name (property key または Private Name) and returns ECMAScript 関数オブジェクト. It is defined piecewise over the following productions:

ArrowFunction : ArrowParameters => ConciseBody
  1. name が存在しない場合、name を空の String に設定する。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextArrowFunction に一致したソーステキストとする。
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, ArrowParameters, ConciseBody, lexical-this, env, privateEnv) とする。
  6. SetFunctionName(closure, name) を実行する。
  7. closure を返す。
Note

ArrowFunction は、argumentssuperthis、または new.target の局所束縛を定義しない。ArrowFunction 内の argumentssuperthis、または new.target への任意の参照は、レキシカルに包含する環境内の束縛に解決されなければならない。通常、これは直近で包含する関数の Function Environment である。ArrowFunctionsuper への参照を含む場合があっても、ステップ 5 で作成される関数オブジェクトは MakeMethod を実行することによってメソッドにはされない。super を参照する ArrowFunction は常に非-ArrowFunction の内部に含まれ、super を実装するために必要な状態は、ArrowFunction の関数オブジェクトによって捕捉された env を介してアクセス可能である。

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 メソッド定義

構文

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: 早期エラー

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 ブール値. 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 ブール値. 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 object (Object) and optional argument functionPrototype (Object) and returns [[Key]] (property key) および [[Closure]] (ECMAScript 関数オブジェクト) フィールドを持つ Record を含む normal completion、または abrupt completion のいずれか. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. propertyKeyClassElementName の ? Evaluation とする。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. functionPrototype が存在する場合、
    1. prototypefunctionPrototype とする。
  5. そうでなければ、
    1. prototype%Function.prototype% とする。
  6. sourceTextMethodDefinition に一致したソーステキストとする。
  7. closureOrdinaryFunctionCreate(prototype, sourceText, UniqueFormalParameters, FunctionBody, non-lexical-this, env, privateEnv) とする。
  8. MakeMethod(closure, object) を実行する。
  9. Record { [[Key]]: propertyKey, [[Closure]]: closure } を返す。

15.4.5 Runtime Semantics: MethodDefinitionEvaluation

The syntax-directed operation MethodDefinitionEvaluation takes arguments object (Object) and enumerable (Boolean) and returns PrivateElement または unused のいずれかを含む normal completion、または abrupt completion のいずれか. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. methodDef を、引数 objectMethodDefinition の ? DefineMethod とする。
  2. SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]]) を実行する。
  3. DefineMethodProperty(object, methodDef.[[Key]], methodDef.[[Closure]], enumerable) を返す。
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. propertyKeyClassElementName の ? Evaluation とする。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextMethodDefinition に一致したソーステキストとする。
  5. formalParameterList を生成規則 FormalParameters : [empty] のインスタンスとする。
  6. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameterList, FunctionBody, non-lexical-this, env, privateEnv) とする。
  7. MakeMethod(closure, object) を実行する。
  8. SetFunctionName(closure, propertyKey, "get") を実行する。
  9. propertyKeyPrivate Name である場合、
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Get]]: closure, [[Set]]: undefined } を返す。
  10. desc を PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true } とする。
  11. DefinePropertyOrThrow(object, propertyKey, desc) を実行する。
  12. unused を返す。
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. propertyKeyClassElementName の ? Evaluation とする。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextMethodDefinition に一致したソーステキストとする。
  5. closureOrdinaryFunctionCreate(%Function.prototype%, sourceText, PropertySetParameterList, FunctionBody, non-lexical-this, env, privateEnv) とする。
  6. MakeMethod(closure, object) を実行する。
  7. SetFunctionName(closure, propertyKey, "set") を実行する。
  8. propertyKeyPrivate Name である場合、
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Get]]: undefined, [[Set]]: closure } を返す。
  9. desc を PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true } とする。
  10. DefinePropertyOrThrow(object, propertyKey, desc) を実行する。
  11. unused を返す。
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. propertyKeyClassElementName の ? Evaluation とする。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextGeneratorMethod に一致したソーステキストとする。
  5. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, UniqueFormalParameters, GeneratorBody, non-lexical-this, env, privateEnv) とする。
  6. MakeMethod(closure, object) を実行する。
  7. SetFunctionName(closure, propertyKey) を実行する。
  8. prototypeOrdinaryObjectCreate(%GeneratorPrototype%) とする。
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  10. DefineMethodProperty(object, propertyKey, closure, enumerable) を返す。
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. propertyKeyClassElementName の ? Evaluation とする。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextAsyncGeneratorMethod に一致したソーステキストとする。
  5. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, UniqueFormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv) とする。
  6. MakeMethod(closure, object) を実行する。
  7. SetFunctionName(closure, propertyKey) を実行する。
  8. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%) とする。
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  10. DefineMethodProperty(object, propertyKey, closure, enumerable) を返す。
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. propertyKeyClassElementName の ? Evaluation とする。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextAsyncMethod に一致したソーステキストとする。
  5. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, UniqueFormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv) とする。
  6. MakeMethod(closure, object) を実行する。
  7. SetFunctionName(closure, propertyKey) を実行する。
  8. DefineMethodProperty(object, propertyKey, closure, enumerable) を返す。

15.5 ジェネレータ関数定義

構文

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 の直後の構文コンテキストでは、InputElementRegExpOrTemplateTail 字句目標の使用が要求される。

Note 2

YieldExpression は、ジェネレータ関数の FormalParameters 内では使用できない。なぜなら、FormalParameters の一部である任意の式は、結果の Generator が再開可能状態になる前に評価されるからである。

Note 3

Generators に関係する抽象操作は 27.5.3 で定義される。

15.5.1 Static Semantics: 早期エラー

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 functionObject (ECMAScript 関数オブジェクト) and argumentsList (ECMAScript 言語値List) and returns throw 完了または return 完了. It is defined piecewise over the following productions:

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

15.5.3 Runtime Semantics: InstantiateGeneratorFunctionObject

The syntax-directed operation InstantiateGeneratorFunctionObject takes arguments env (Environment Record) and privateEnv (PrivateEnvironment Record または null) and returns ECMAScript 関数オブジェクト. It is defined piecewise over the following productions:

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. nameBindingIdentifierStringValue とする。
  2. sourceTextGeneratorDeclaration に一致したソーステキストとする。
  3. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, env, privateEnv) とする。
  4. SetFunctionName(closure, name) を実行する。
  5. prototypeOrdinaryObjectCreate(%GeneratorPrototype%) とする。
  6. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  7. closure を返す。
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. sourceTextGeneratorDeclaration に一致したソーステキストとする。
  2. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, env, privateEnv) とする。
  3. SetFunctionName(closure, "default") を実行する。
  4. prototypeOrdinaryObjectCreate(%GeneratorPrototype%) とする。
  5. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  6. closure を返す。
Note

匿名 GeneratorDeclarationexport default 宣言の一部としてのみ現れることができ、その関数コードはしたがって常に strict mode コードである。

15.5.4 Runtime Semantics: InstantiateGeneratorFunctionExpression

The syntax-directed operation InstantiateGeneratorFunctionExpression takes optional argument name (property key または Private Name) and returns ECMAScript 関数オブジェクト. It is defined piecewise over the following productions:

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. name が存在しない場合、name を空の String に設定する。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextGeneratorExpression に一致したソーステキストとする。
  5. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, env, privateEnv) とする。
  6. SetFunctionName(closure, name) を実行する。
  7. prototypeOrdinaryObjectCreate(%GeneratorPrototype%) とする。
  8. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  9. closure を返す。
GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. Assert: name は存在しない。
  2. nameBindingIdentifierStringValue に設定する。
  3. outerEnv を実行中の実行コンテキストの LexicalEnvironment とする。
  4. funcEnvNewDeclarativeEnvironment(outerEnv) とする。
  5. funcEnv.CreateImmutableBinding(name, false) を実行する。
  6. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  7. sourceTextGeneratorExpression に一致したソーステキストとする。
  8. closureOrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, funcEnv, privateEnv) とする。
  9. SetFunctionName(closure, name) を実行する。
  10. prototypeOrdinaryObjectCreate(%GeneratorPrototype%) とする。
  11. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  12. funcEnv.InitializeBinding(name, closure) を実行する。
  13. closure を返す。
Note

GeneratorExpression 内の BindingIdentifier は、ジェネレータコードが自身を再帰的に呼び出せるように、GeneratorExpressionFunctionBody 内から参照できる。しかし、GeneratorDeclaration の場合とは異なり、GeneratorExpression 内の BindingIdentifier は、GeneratorExpression を包含するスコープから参照できず、そのスコープに影響もしない。

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. generatorKindGetGeneratorKind() とする。
  2. Assert: generatorKindsync または async のいずれかである。
  3. exprRefAssignmentExpression の ? Evaluation とする。
  4. value を ? GetValue(exprRef) とする。
  5. iteratorRecord を ? GetIterator(value, generatorKind) とする。
  6. iteratoriteratorRecord.[[Iterator]] とする。
  7. receivedNormalCompletion(undefined) とする。
  8. 繰り返し、
    1. receivednormal completion である場合、
      1. innerResult を ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] ») とする。
      2. generatorKindasync である場合、innerResult を ? Await(innerResult) に設定する。
      3. innerResult が Object でない場合、TypeError 例外を投げる。
      4. done を ? IteratorComplete(innerResult) とする。
      5. donetrue である場合、
        1. IteratorValue(innerResult) を返す。
      6. generatorKindasync である場合、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. generatorKindasync である場合、innerResult を ? Await(innerResult) に設定する。
        3. NOTE: 内側イテレータの throw メソッドからの例外は伝播される。内側の throw メソッドからの normal completion は、内側の next と同様に処理される。
        4. innerResult が Object でない場合、TypeError 例外を投げる。
        5. done を ? IteratorComplete(innerResult) とする。
        6. donetrue である場合、
          1. IteratorValue(innerResult) を返す。
        7. generatorKindasync である場合、receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerResult))) に設定する。
        8. そうでなければ、receivedCompletion(GeneratorYield(innerResult)) に設定する。
      3. そうでなければ、
        1. NOTE: iteratorthrow メソッドを持たない場合、この throw は yield* ループを終了させる。しかし、その前に iterator にクリーンアップの機会を与える必要がある。
        2. closeCompletionNormalCompletion(empty) とする。
        3. generatorKindasync である場合、? AsyncIteratorClose(iteratorRecord, closeCompletion) を実行する。
        4. そうでなければ、? IteratorClose(iteratorRecord, closeCompletion) を実行する。
        5. NOTE: 次のステップは、iteratorthrow メソッドを持たないという yield* プロトコル違反を示すために TypeError を投げる。
        6. TypeError 例外を投げる。
    3. そうでなければ、
      1. Assert: receivedreturn completion である。
      2. return を ? GetMethod(iterator, "return") とする。
      3. returnundefined である場合、
        1. receivedValuereceived.[[Value]] とする。
        2. generatorKindasync である場合、
          1. receivedValue を ? Await(receivedValue) に設定する。
        3. ReturnCompletion(receivedValue) を返す。
      4. innerReturnResult を ? Call(return, iterator, « received.[[Value]] ») とする。
      5. generatorKindasync である場合、innerReturnResult を ? Await(innerReturnResult) に設定する。
      6. innerReturnResult が Object でない場合、TypeError 例外を投げる。
      7. done を ? IteratorComplete(innerReturnResult) とする。
      8. donetrue である場合、
        1. returnedValue を ? IteratorValue(innerReturnResult) とする。
        2. ReturnCompletion(returnedValue) を返す。
      9. generatorKindasync である場合、receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerReturnResult))) に設定する。
      10. そうでなければ、receivedCompletion(GeneratorYield(innerReturnResult)) に設定する。

15.6 非同期ジェネレータ関数定義

構文

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 は、非同期ジェネレータ関数の FormalParameters 内では使用できない。なぜなら、FormalParameters の一部である任意の式は、結果の AsyncGenerator が再開可能状態になる前に評価されるからである。

Note 2

AsyncGenerators に関係する抽象操作は 27.6.3 で定義される。

15.6.1 Static Semantics: 早期エラー

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 functionObject (ECMAScript 関数オブジェクト) and argumentsList (ECMAScript 言語値List) and returns throw 完了または return 完了. It is defined piecewise over the following productions:

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

15.6.3 Runtime Semantics: InstantiateAsyncGeneratorFunctionObject

The syntax-directed operation InstantiateAsyncGeneratorFunctionObject takes arguments env (Environment Record) and privateEnv (PrivateEnvironment Record または null) and returns ECMAScript 関数オブジェクト. It is defined piecewise over the following productions:

AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. nameBindingIdentifierStringValue とする。
  2. sourceTextAsyncGeneratorDeclaration に一致したソーステキストとする。
  3. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv) とする。
  4. SetFunctionName(closure, name) を実行する。
  5. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%) とする。
  6. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  7. closure を返す。
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. sourceTextAsyncGeneratorDeclaration に一致したソーステキストとする。
  2. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv) とする。
  3. SetFunctionName(closure, "default") を実行する。
  4. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%) とする。
  5. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  6. closure を返す。
Note

匿名 AsyncGeneratorDeclaration は、export default 宣言の一部としてのみ現れることができる。

15.6.4 Runtime Semantics: InstantiateAsyncGeneratorFunctionExpression

The syntax-directed operation InstantiateAsyncGeneratorFunctionExpression takes optional argument name (property key または Private Name) and returns ECMAScript 関数オブジェクト. It is defined piecewise over the following productions:

AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. name が存在しない場合、name を空の String に設定する。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextAsyncGeneratorExpression に一致したソーステキストとする。
  5. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, env, privateEnv) とする。
  6. SetFunctionName(closure, name) を実行する。
  7. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%) とする。
  8. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  9. closure を返す。
AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. Assert: name は存在しない。
  2. nameBindingIdentifierStringValue に設定する。
  3. outerEnv を実行中の実行コンテキストの LexicalEnvironment とする。
  4. funcEnvNewDeclarativeEnvironment(outerEnv) とする。
  5. funcEnv.CreateImmutableBinding(name, false) を実行する。
  6. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  7. sourceTextAsyncGeneratorExpression に一致したソーステキストとする。
  8. closureOrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, funcEnv, privateEnv) とする。
  9. SetFunctionName(closure, name) を実行する。
  10. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%) とする。
  11. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  12. funcEnv.InitializeBinding(name, closure) を実行する。
  13. closure を返す。
Note

AsyncGeneratorExpression 内の BindingIdentifier は、ジェネレータコードが自身を再帰的に呼び出せるように、AsyncGeneratorExpressionAsyncGeneratorBody 内から参照できる。しかし、AsyncGeneratorDeclaration の場合とは異なり、AsyncGeneratorExpression 内の BindingIdentifier は、AsyncGeneratorExpression を包含するスコープから参照できず、そのスコープに影響もしない。

15.6.5 Runtime Semantics: Evaluation

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

15.7 クラス定義

構文

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

クラス定義は常に strict mode コードである。

15.7.1 Static Semantics: 早期エラー

ClassTail : ClassHeritageopt { ClassBody }
  • ClassHeritage が存在せず、次のアルゴリズムが true を返す場合、これは構文エラーである:

    1. constructorClassBodyConstructorMethod とする。
    2. constructorempty である場合、false を返す。
    3. constructorHasDirectSuper を返す。
ClassBody : ClassElementList
  • ClassElementListPrototypePropertyNameList"constructor" の出現を複数含む場合、これは構文エラーである。
  • ClassElementListPrivateBoundIdentifiers が重複エントリを含む場合、これは構文エラーである。ただし、その名前が getter と setter にそれぞれ一度ずつ使用され、それ以外のエントリでは使用されず、かつ getter と setter がどちらも static であるか、どちらも非 static である場合を除く。
ClassElement : MethodDefinition ClassElement : static MethodDefinition ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ;
  • FieldDefinitionPropName"prototype" または "constructor" のいずれかである場合、これは構文エラーである。
FieldDefinition : ClassElementName Initializeropt ClassElementName : PrivateIdentifier ClassStaticBlockBody : ClassStaticBlockStatementList

15.7.2 Static Semantics: ClassElementKind

The syntax-directed operation ClassElementKind takes no arguments and returns constructor-methodnon-constructor-method、または 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 ClassElement Parse Node または 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

早期エラールールにより、"constructor" という名前のメソッド定義は一つだけであり、それがアクセサプロパティまたはジェネレータ定義ではないことが保証される。

15.7.4 Static Semantics: IsStatic

The syntax-directed operation IsStatic takes no arguments and returns ブール値. 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 ClassElement Parse NodeList. 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 に追加する。
  3. list を返す。

15.7.6 Static Semantics: PrototypePropertyNameList

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

ClassElementList : ClassElement
  1. propNameClassElementPropName とする。
  2. propNameempty である場合、新しい空の List を返す。
  3. ClassElementIsStatictrue である場合、新しい空の List を返す。
  4. « propName » を返す。
ClassElementList : ClassElementList ClassElement
  1. listClassElementListPrototypePropertyNameList とする。
  2. propNameClassElementPropName とする。
  3. propNameempty である場合、list を返す。
  4. ClassElementIsStatictrue である場合、list を返す。
  5. list と « propName » の list-concatenation を返す。

15.7.7 Static Semantics: AllPrivateIdentifiersValid

The syntax-directed operation AllPrivateIdentifiersValid takes argument names (String の List) and returns ブール値.

この仕様において以下に列挙されていないすべての文法生成規則選択肢は、暗黙に AllPrivateIdentifiersValid の次のデフォルト定義を持つ:

  1. この Parse Node の各子ノード child について、次を行う。
    1. child が非終端記号のインスタンスである場合、
      1. 引数 names を伴う childAllPrivateIdentifiersValidfalse である場合、false を返す。
  2. true を返す。
MemberExpression : MemberExpression . PrivateIdentifier
  1. namesPrivateIdentifierStringValue を含む場合、
    1. 引数 names を伴う MemberExpressionAllPrivateIdentifiersValid を返す。
  2. false を返す。
CallExpression : CallExpression . PrivateIdentifier
  1. namesPrivateIdentifierStringValue を含む場合、
    1. 引数 names を伴う CallExpressionAllPrivateIdentifiersValid を返す。
  2. false を返す。
OptionalChain : ?. PrivateIdentifier
  1. namesPrivateIdentifierStringValue を含む場合、true を返す。
  2. false を返す。
OptionalChain : OptionalChain . PrivateIdentifier
  1. namesPrivateIdentifierStringValue を含む場合、
    1. 引数 names を伴う OptionalChainAllPrivateIdentifiersValid を返す。
  2. false を返す。
ClassBody : ClassElementList
  1. newNamesnamesClassBodyPrivateBoundIdentifierslist-concatenation とする。
  2. 引数 newNames を伴う ClassElementListAllPrivateIdentifiersValid を返す。
RelationalExpression : PrivateIdentifier in ShiftExpression
  1. namesPrivateIdentifierStringValue を含む場合、
    1. 引数 names を伴う ShiftExpressionAllPrivateIdentifiersValid を返す。
  2. false を返す。

15.7.8 Static Semantics: PrivateBoundIdentifiers

The syntax-directed operation PrivateBoundIdentifiers takes no arguments and returns String の List. 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 ブール値.

この仕様において以下に列挙されていないすべての文法生成規則選択肢は、暗黙に ContainsArguments の次のデフォルト定義を持つ:

  1. この Parse Node の各子ノード child について、次を行う。
    1. child が非終端記号のインスタンスである場合、
      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 homeObject (Object) and returns ClassFieldDefinition Record を含む normal completion、または abrupt completion のいずれか. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. nameClassElementName の ? Evaluation とする。
  2. Initializer が存在する場合、
    1. formalParameterList を生成規則 FormalParameters : [empty] のインスタンスとする。
    2. env を実行中の実行コンテキストの LexicalEnvironment とする。
    3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
    4. sourceText を Unicode 符号位置の空の列とする。
    5. initializerOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameterList, Initializer, non-lexical-this, env, privateEnv) とする。
    6. MakeMethod(initializer, homeObject) を実行する。
    7. initializer.[[ClassFieldInitializerName]]name に設定する。
  3. そうでなければ、
    1. initializerempty とする。
  4. ClassFieldDefinition Record { [[Name]]: name, [[Initializer]]: initializer } を返す。
Note
initializer のために作成される関数は、ECMAScript コードから直接アクセス可能になることはない。

15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation

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

ClassStaticBlock : static { ClassStaticBlockBody }
  1. lex を実行中の実行コンテキストの LexicalEnvironment とする。
  2. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  3. sourceText を Unicode 符号位置の空の列とする。
  4. formalParameters を生成規則 FormalParameters : [empty] のインスタンスとする。
  5. bodyFunctionOrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParameters, ClassStaticBlockBody, non-lexical-this, lex, privateEnv) とする。
  6. MakeMethod(bodyFunction, homeObject) を実行する。
  7. ClassStaticBlockDefinition Record { [[BodyFunction]]: bodyFunction } を返す。
Note
関数 bodyFunction は、ECMAScript コードから直接アクセス可能になることはない。

15.7.12 Runtime Semantics: EvaluateClassStaticBlockBody

The syntax-directed operation EvaluateClassStaticBlockBody takes argument functionObject (ECMAScript 関数オブジェクト) and returns return 完了または throw 完了. It is defined piecewise over the following productions:

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. Assert: functionObjectClassStaticBlockDefinitionEvaluation のステップ 5 によって作成された合成関数である。
  2. FunctionDeclarationInstantiation(functionObject, « ») を実行する。
  3. ClassStaticBlockStatementList の ? Evaluation を実行する。
  4. ReturnCompletion(undefined) を返す。

15.7.13 Runtime Semantics: ClassElementEvaluation

The syntax-directed operation ClassElementEvaluation takes argument object (Object) and returns ClassFieldDefinition RecordClassStaticBlockDefinition RecordPrivateElement、または unused のいずれかを含む normal completion、または abrupt completion のいずれか. It is defined piecewise over the following productions:

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

15.7.14 Runtime Semantics: ClassDefinitionEvaluation

The syntax-directed operation ClassDefinitionEvaluation takes arguments classBinding (String または undefined), className (property key または Private Name), and sourceText (ECMAScript ソーステキスト) and returns 関数オブジェクトを含む normal completion、または abrupt completion のいずれか.

Note

仕様を簡潔にするため、private メソッドおよびアクセサは、private フィールドとともに、クラスインスタンスの [[PrivateElements]] スロットに含まれる。しかし、任意のオブジェクトは、所与のクラスによって定義された private メソッドおよびアクセサのすべてを持つか、まったく持たないかのいずれかである。この機能は、実装が各メソッドまたはアクセサを個別に追跡する必要のない戦略を用いて private メソッドおよびアクセサを実装することを選択できるように設計されている。

例えば、実装はインスタンス private メソッドを対応する Private Name に直接関連付け、各オブジェクトについて、どのクラスコンストラクタがそのオブジェクトを this 値として実行されたかを追跡できる。その場合、オブジェクト上でインスタンス private メソッドを検索することは、そのメソッドを定義するクラスコンストラクタがそのオブジェクトを初期化するために使用されたことを確認し、その後 Private Name に関連付けられたメソッドを返すことから成る。

これは private フィールドとは異なる。フィールド初期化子はクラスのインスタンス化中に投げる可能性があるため、個々のオブジェクトは所与のクラスの private フィールドの適切な部分集合だけを持つ場合があり、したがって private フィールドは一般に個別に追跡されなければならない。

It is defined piecewise over the following productions:

ClassTail : ClassHeritageopt { ClassBodyopt }
  1. env を実行中の実行コンテキストの LexicalEnvironment とする。
  2. classEnvNewDeclarativeEnvironment(env) とする。
  3. classBindingundefined でない場合、
    1. classEnv.CreateImmutableBinding(classBinding, true) を実行する。
  4. outerPrivateEnvironment を実行中の実行コンテキストの PrivateEnvironment とする。
  5. classPrivateEnvironmentNewPrivateEnvironment(outerPrivateEnvironment) とする。
  6. ClassBody が存在する場合、
    1. ClassBodyPrivateBoundIdentifiers の各 String dn について、次を行う。
      1. classPrivateEnvironment.[[Names]] が、pn.[[Description]]dn である Private Name pn を含む場合、
        1. Assert: これは getter/setter ペアについてのみ可能である。
      2. そうでない場合、
        1. name を、[[Description]]dn である新しい Private Name とする。
        2. nameclassPrivateEnvironment.[[Names]] に追加する。
  7. ClassHeritage が存在しない場合、
    1. protoParent%Object.prototype% とする。
    2. constructorParent%Function.prototype% とする。
  8. そうでない場合、
    1. 実行中の実行コンテキストの LexicalEnvironment を classEnv に設定する。
    2. NOTE: ClassHeritage を評価するとき、実行中の実行コンテキストの PrivateEnvironment は outerPrivateEnvironment である。
    3. superclassRefClassHeritage の評価の Completion とする。
    4. 実行中の実行コンテキストの LexicalEnvironment を env に設定する。
    5. superclass を ? GetValue(? superclassRef) とする。
    6. superclassnull である場合、
      1. protoParentnull とする。
      2. constructorParent%Function.prototype% とする。
    7. そうでなく、IsConstructor(superclass) が false である場合、
      1. TypeError 例外を投げる。
    8. そうでない場合、
      1. protoParent を ? Get(superclass, "prototype") とする。
      2. protoParent が Object でなく、かつ protoParentnull でない場合、TypeError 例外を投げる。
      3. constructorParentsuperclass とする。
  9. protoOrdinaryObjectCreate(protoParent) とする。
  10. ClassBody が存在しない場合、constructorempty とする。
  11. そうでない場合、constructorClassBodyConstructorMethod とする。
  12. 実行中の実行コンテキストの LexicalEnvironment を classEnv に設定する。
  13. 実行中の実行コンテキストの PrivateEnvironment を classPrivateEnvironment に設定する。
  14. constructorempty である場合、
    1. defaultConstructor を、パラメータを持たず、何もキャプチャせず、呼び出されたときに次の手順を実行する新しい Abstract Closure とする。
      1. args を、[[Call]] または [[Construct]] によりこの関数に渡された引数の List とする。
      2. NewTarget が undefined である場合、TypeError 例外を投げる。
      3. constructorFunction を現在アクティブな関数オブジェクトとする。
      4. constructorFunction.[[ConstructorKind]]derived である場合、
        1. NOTE: この分岐は constructor(...args) { super(...args); } と同様に振る舞う。最も注目すべき相違点は、前述の ECMAScript ソーステキスト%Array.prototype% 上の %Symbol.iterator% メソッドを観測可能に呼び出す一方で、この関数はそれを行わないことである。
        2. func を ! constructorFunction.[[GetPrototypeOf]]() とする。
        3. IsConstructor(func) が false である場合、TypeError 例外を投げる。
        4. result を ? Construct(func, args, NewTarget) とする。
      5. そうでない場合、
        1. NOTE: この分岐は constructor() {} と同様に振る舞う。
        2. result を ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%") とする。
      6. InitializeInstanceElements(result, constructorFunction) を実行する。
      7. NormalCompletion(result) を返す。
    2. constructorFunctionCreateBuiltinFunction(defaultConstructor, 0, className, « [[ConstructorKind]], [[SourceText]], [[PrivateMethods]], [[Fields]] », the current Realm Record, constructorParent) とする。
  15. そうでない場合、
    1. constructorInfo を、引数 proto および constructorParent での constructor の ! DefineMethod とする。
    2. constructorFunctionconstructorInfo.[[Closure]] とする。
    3. MakeClassConstructor(constructorFunction) を実行する。
    4. SetFunctionName(constructorFunction, className) を実行する。
  16. constructorFunction.[[SourceText]]sourceText に設定する。
  17. MakeConstructor(constructorFunction, false, proto) を実行する。
  18. ClassHeritage が存在する場合、constructorFunction.[[ConstructorKind]]derived に設定する。
  19. DefineMethodProperty(proto, "constructor", constructorFunction, false) を実行する。
  20. ClassBody が存在しない場合、elements を新しい空の List とする。
  21. そうでない場合、elementsClassBodyNonConstructorElements とする。
  22. instancePrivateMethods を新しい空の List とする。
  23. staticPrivateMethods を新しい空の List とする。
  24. instanceFields を新しい空の List とする。
  25. staticElements を新しい空の List とする。
  26. elements の各 ClassElement e について、次を行う。
    1. eIsStaticfalse である場合、
      1. element を、引数 proto での eClassElementEvaluationCompletion とする。
    2. そうでない場合、
      1. element を、引数 constructorFunction での eClassElementEvaluationCompletion とする。
    3. elementabrupt completion である場合、
      1. 実行中の実行コンテキストの LexicalEnvironment を env に設定する。
      2. 実行中の実行コンテキストの PrivateEnvironment を outerPrivateEnvironment に設定する。
      3. element を返す。
    4. element を ! element に設定する。
    5. elementPrivateElement である場合、
      1. Assert: element.[[Kind]]method または accessor のどちらかである。
      2. eIsStaticfalse である場合、containerinstancePrivateMethods とする。
      3. そうでない場合、containerstaticPrivateMethods とする。
      4. container が、pe.[[Key]]element.[[Key]] である PrivateElement pe を含む場合、
        1. Assert: element.[[Kind]]pe.[[Kind]] はともに accessor である。
        2. element.[[Get]]undefined である場合、
          1. combinedPrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Get]]: pe.[[Get]], [[Set]]: element.[[Set]] } とする。
        3. そうでない場合、
          1. combinedPrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Get]]: element.[[Get]], [[Set]]: pe.[[Set]] } とする。
        4. container 内の pecombined で置き換える。
      5. そうでない場合、
        1. elementcontainer に追加する。
    6. そうでなく、elementClassFieldDefinition Record である場合、
      1. eIsStaticfalse である場合、elementinstanceFields に追加する。
      2. そうでない場合、elementstaticElements に追加する。
    7. そうでなく、elementClassStaticBlockDefinition Record である場合、
      1. elementstaticElements に追加する。
  27. 実行中の実行コンテキストの LexicalEnvironment を env に設定する。
  28. classBindingundefined でない場合、
    1. classEnv.InitializeBinding(classBinding, constructorFunction) を実行する。
  29. constructorFunction.[[PrivateMethods]]instancePrivateMethods に設定する。
  30. constructorFunction.[[Fields]]instanceFields に設定する。
  31. staticPrivateMethods の各 PrivateElement method について、次を行う。
    1. PrivateMethodOrAccessorAdd(constructorFunction, method) を実行する。
  32. staticElements の各要素 elementRecord について、次を行う。
    1. elementRecordClassFieldDefinition Record である場合、
      1. resultCompletion(DefineField(constructorFunction, elementRecord)) とする。
    2. そうでない場合、
      1. Assert: elementRecordClassStaticBlockDefinition Record である。
      2. resultCompletion(Call(elementRecord.[[BodyFunction]], constructorFunction)) とする。
    3. resultabrupt completion である場合、
      1. 実行中の実行コンテキストの PrivateEnvironment を outerPrivateEnvironment に設定する。
      2. result を返す。
  33. 実行中の実行コンテキストの PrivateEnvironment を outerPrivateEnvironment に設定する。
  34. constructorFunction を返す。

15.7.15 Runtime Semantics: BindingClassDeclarationEvaluation

The syntax-directed operation BindingClassDeclarationEvaluation takes no arguments and returns 関数オブジェクトを含む normal completion、または abrupt completion のいずれか. It is defined piecewise over the following productions:

ClassDeclaration : class BindingIdentifier ClassTail
  1. classNameBindingIdentifierStringValue とする。
  2. sourceTextClassDeclaration に一致したソーステキストとする。
  3. value を、引数 classNameclassName、および sourceText を伴う ClassTail の ? ClassDefinitionEvaluation とする。
  4. env を実行中の実行コンテキストの LexicalEnvironment とする。
  5. InitializeBoundName(className, value, env) を実行する。
  6. value を返す。
ClassDeclaration : class ClassTail
  1. sourceTextClassDeclaration に一致したソーステキストとする。
  2. 引数 undefined"default"、および sourceText を伴う ClassTail の ? ClassDefinitionEvaluation を返す。
Note

ClassDeclaration : class ClassTail ExportDeclaration の一部としてのみ現れ、その束縛の確立は当該生成規則の評価アクションの一部として扱われる。16.2.3.7 を参照。

15.7.16 Runtime Semantics: Evaluation

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

ClassDeclaration : class ClassTail ExportDeclaration の一部としてのみ現れ、直接評価されることはない。

ClassExpression : class ClassTail
  1. sourceTextClassExpression に一致したソーステキストとする。
  2. 引数 undefined、空の String、および sourceText を伴う ClassTail の ? ClassDefinitionEvaluation を返す。
ClassExpression : class BindingIdentifier ClassTail
  1. classNameBindingIdentifierStringValue とする。
  2. sourceTextClassExpression に一致したソーステキストとする。
  3. 引数 classNameclassName、および sourceText を伴う ClassTail の ? ClassDefinitionEvaluation を返す。
ClassElementName : PrivateIdentifier
  1. privateIdentifierPrivateIdentifierStringValue とする。
  2. privateEnvRec を実行中の実行コンテキストの PrivateEnvironment とする。
  3. namesprivateEnvRec.[[Names]] とする。
  4. Assert: names のうち正確に一つの要素が、[[Description]]privateIdentifier である Private Name である。
  5. privateName を、[[Description]]privateIdentifier である names 内の Private Name とする。
  6. privateName を返す。
ClassStaticBlockStatementList : [empty]
  1. undefined を返す。

15.8 非同期関数定義

構文

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] パラメータが存在するとき、awaitAwaitExpression のキーワードとして解析される。[Await] パラメータは、次のコンテキストのトップレベルに存在する。ただし、FunctionBody などの非終端記号によっては、一部のコンテキストでこのパラメータが存在しない場合がある:

Script が構文目標記号であるとき、[Await] パラメータが存在しない場合、await は識別子として解析されてもよい。これには次のコンテキストが含まれる:

Note 2

YieldExpression とは異なり、AwaitExpression のオペランドを省略することは構文エラーである。何らかのものを await しなければならない。

15.8.1 Static Semantics: 早期エラー

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 env (Environment Record) and privateEnv (PrivateEnvironment Record または null) and returns ECMAScript 関数オブジェクト. It is defined piecewise over the following productions:

AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. nameBindingIdentifierStringValue とする。
  2. sourceTextAsyncFunctionDeclaration に一致したソーステキストとする。
  3. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv) とする。
  4. SetFunctionName(closure, name) を実行する。
  5. closure を返す。
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. sourceTextAsyncFunctionDeclaration に一致したソーステキストとする。
  2. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv) とする。
  3. SetFunctionName(closure, "default") を実行する。
  4. closure を返す。

15.8.3 Runtime Semantics: InstantiateAsyncFunctionExpression

The syntax-directed operation InstantiateAsyncFunctionExpression takes optional argument name (property key または Private Name) and returns ECMAScript 関数オブジェクト. It is defined piecewise over the following productions:

AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. name が存在しない場合、name を空の String に設定する。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextAsyncFunctionExpression に一致したソーステキストとする。
  5. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv) とする。
  6. SetFunctionName(closure, name) を実行する。
  7. closure を返す。
AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. Assert: name は存在しない。
  2. nameBindingIdentifierStringValue に設定する。
  3. outerEnv を実行中の実行コンテキストの LexicalEnvironment とする。
  4. funcEnvNewDeclarativeEnvironment(outerEnv) とする。
  5. funcEnv.CreateImmutableBinding(name, false) を実行する。
  6. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  7. sourceTextAsyncFunctionExpression に一致したソーステキストとする。
  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 は、関数が自身を再帰的に呼び出せるように、AsyncFunctionExpressionAsyncFunctionBody 内から参照できる。しかし、FunctionDeclaration の場合とは異なり、AsyncFunctionExpression 内の BindingIdentifier は、AsyncFunctionExpression を包含するスコープから参照できず、そのスコープに影響もしない。

15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody

The syntax-directed operation EvaluateAsyncFunctionBody takes arguments functionObject (ECMAScript 関数オブジェクト) and argumentsList (ECMAScript 言語値List) and returns return 完了. It is defined piecewise over the following productions:

AsyncFunctionBody : FunctionBody
  1. promiseCapability を ! NewPromiseCapability(%Promise%) とする。
  2. completionCompletion(FunctionDeclarationInstantiation(functionObject, argumentsList)) とする。
  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 を返す。
AwaitExpression : await UnaryExpression
  1. exprRefUnaryExpression の ? Evaluation とする。
  2. value を ? GetValue(exprRef) とする。
  3. Await(value) を返す。

15.9 非同期アロー関数定義

構文

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]

補足構文

生成規則
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
のインスタンスを処理するとき、CoverCallExpressionAndAsyncArrowHead の解釈は次の文法を用いて精緻化される:

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

15.9.1 Static Semantics: 早期エラー

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

15.9.2 Static Semantics: AsyncConciseBodyContainsUseStrict

The syntax-directed operation AsyncConciseBodyContainsUseStrict takes no arguments and returns ブール値. 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 functionObject (ECMAScript 関数オブジェクト) and argumentsList (ECMAScript 言語値List) and returns return 完了. It is defined piecewise over the following productions:

AsyncConciseBody : ExpressionBody
  1. promiseCapability を ! NewPromiseCapability(%Promise%) とする。
  2. completionCompletion(FunctionDeclarationInstantiation(functionObject, argumentsList)) とする。
  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 (property key または Private Name) and returns ECMAScript 関数オブジェクト. It is defined piecewise over the following productions:

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. name が存在しない場合、name を空の String に設定する。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextAsyncArrowFunction に一致したソーステキストとする。
  5. parametersAsyncArrowBindingIdentifier とする。
  6. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, parameters, AsyncConciseBody, lexical-this, env, privateEnv) とする。
  7. SetFunctionName(closure, name) を実行する。
  8. closure を返す。
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. name が存在しない場合、name を空の String に設定する。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceTextAsyncArrowFunction に一致したソーステキストとする。
  5. head を、CoverCallExpressionAndAsyncArrowHead によってカバーされる AsyncArrowHead とする。
  6. parametersheadArrowFormalParameters とする。
  7. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, parameters, AsyncConciseBody, lexical-this, env, privateEnv) とする。
  8. SetFunctionName(closure, name) を実行する。
  9. closure を返す。

15.9.5 Runtime Semantics: Evaluation

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

15.10 末尾位置呼び出し

15.10.1 Static Semantics: IsInTailPosition ( call )

The abstract operation IsInTailPosition takes argument call (CallExpression Parse NodeMemberExpression Parse Node、または OptionalChain Parse Node) and returns ブール値. It performs the following steps when called:

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

末尾位置呼び出しは、呼び出し元コンテキストの連鎖の観測を可能にする一般的な非標準言語拡張(10.2.4 参照)のため、strict mode コードでのみ定義される。

15.10.2 Static Semantics: HasCallInTailPosition

The syntax-directed operation HasCallInTailPosition takes argument call (CallExpression Parse NodeMemberExpression Parse Node、または OptionalChain Parse Node) and returns ブール値.

Note 1

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

Note 2

呼び出し結果の GetValue を返す処理が直後に続く潜在的な末尾位置呼び出しも、末尾位置呼び出しであり得る。関数呼び出しは Reference Record を返せないため、そのような GetValue 操作は常に実際の関数呼び出し結果と同じ値を返す。

It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. has を、引数 call を伴う StatementListHasCallInTailPosition とする。
  2. hastrue である場合、true を返す。
  3. 引数 call を伴う StatementListItemHasCallInTailPosition を返す。
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 を、引数 call を伴う最初の StatementHasCallInTailPosition とする。
  2. hastrue である場合、true を返す。
  3. 引数 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. 引数 call を伴う StatementHasCallInTailPosition を返す。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 引数 call を伴う LabelledItemHasCallInTailPosition を返す。
ReturnStatement : return Expression ;
  1. 引数 call を伴う ExpressionHasCallInTailPosition を返す。
SwitchStatement : switch ( Expression ) CaseBlock
  1. 引数 call を伴う CaseBlockHasCallInTailPosition を返す。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. hasfalse とする。
  2. 最初の CaseClauses が存在する場合、has を引数 call を伴う最初の CaseClausesHasCallInTailPosition に設定する。
  3. hastrue である場合、true を返す。
  4. has を、引数 call を伴う DefaultClauseHasCallInTailPosition に設定する。
  5. hastrue である場合、true を返す。
  6. 2 番目の CaseClauses が存在する場合、has を引数 call を伴う 2 番目の CaseClausesHasCallInTailPosition に設定する。
  7. has を返す。
CaseClauses : CaseClauses CaseClause
  1. has を、引数 call を伴う CaseClausesHasCallInTailPosition とする。
  2. hastrue である場合、true を返す。
  3. 引数 call を伴う CaseClauseHasCallInTailPosition を返す。
CaseClause : case Expression : StatementListopt DefaultClause : default : StatementListopt
  1. StatementList が存在する場合、引数 call を伴う StatementListHasCallInTailPosition を返す。
  2. false を返す。
TryStatement : try Block Catch
  1. 引数 call を伴う CatchHasCallInTailPosition を返す。
TryStatement : try Block Finally try Block Catch Finally
  1. 引数 call を伴う FinallyHasCallInTailPosition を返す。
Catch : catch ( CatchParameter ) Block
  1. 引数 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 AwaitExpression 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. 引数 call を伴う AssignmentExpressionHasCallInTailPosition を返す。
ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  1. has を、引数 call を伴う最初の AssignmentExpressionHasCallInTailPosition とする。
  2. hastrue である場合、true を返す。
  3. 引数 call を伴う 2 番目の AssignmentExpressionHasCallInTailPosition を返す。
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. 引数 call を伴う BitwiseORExpressionHasCallInTailPosition を返す。
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. 引数 call を伴う LogicalANDExpressionHasCallInTailPosition を返す。
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. 引数 call を伴う BitwiseORExpressionHasCallInTailPosition を返す。
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments CallExpression TemplateLiteral
  1. この CallExpressioncall である場合、true を返す。
  2. false を返す。
OptionalExpression : MemberExpression OptionalChain CallExpression OptionalChain OptionalExpression OptionalChain
  1. 引数 call を伴う OptionalChainHasCallInTailPosition を返す。
OptionalChain : ?. [ Expression ] ?. IdentifierName ?. PrivateIdentifier OptionalChain [ Expression ] OptionalChain . IdentifierName OptionalChain . PrivateIdentifier
  1. false を返す。
OptionalChain : ?. Arguments OptionalChain Arguments
  1. この OptionalChaincall である場合、true を返す。
  2. false を返す。
MemberExpression : MemberExpression TemplateLiteral
  1. この MemberExpressioncall である場合、true を返す。
  2. false を返す。
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. exprCoverParenthesizedExpressionAndArrowParameterList によってカバーされる ParenthesizedExpression とする。
  2. 引数 call を伴う exprHasCallInTailPosition を返す。
ParenthesizedExpression : ( Expression )
  1. 引数 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: 現在の実行コンテキストは、その後 ECMAScript コードまたは組込み関数の評価に使用されない。この抽象操作の呼び出しに続く Call の呼び出しは、そのような評価を実行する前に新しい実行コンテキストを作成して push する。
  2. 現在の実行コンテキストに関連付けられたすべてのリソースを破棄する。
  3. unused を返す。

末尾位置呼び出しは、ターゲット関数を呼び出す前に、現在実行中の関数実行コンテキストに関連付けられた一時的な内部リソースを解放するか、ターゲット関数を支援するためにそれらのリソースを再利用しなければならない。

Note

例えば、末尾位置呼び出しは、ターゲット関数のアクティベーションレコードのサイズが呼び出し元関数のアクティベーションレコードのサイズを超える分だけ、実装のアクティベーションレコードスタックを増加させるべきである。ターゲット関数のアクティベーションレコードがより小さい場合、スタックの合計サイズは減少するべきである。