15 ECMAScript 言語: 関数とクラス

Note

様々な ECMAScript 言語要素は ECMAScript 関数オブジェクト (10.2) を生成する。これらの関数の評価は、その [[Call]] 内部メソッド (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 静的意味論: 早期エラー (Early Errors)

UniqueFormalParameters : FormalParameters
  • FormalParameters の BoundNames に重複要素が含まれる場合は構文エラーである。
FormalParameters : FormalParameterList Note

同一の BindingIdentifierFormalParameterList 内に複数回出現することが許されるのは、パラメータリストが「単純 (simple)」であり、かつ strict mode コード内で定義されていない関数の場合に限られる。

15.1.2 静的意味論: ContainsExpression : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ObjectBindingPattern : { } { BindingRestProperty }
  1. false を返す。
ObjectBindingPattern : { BindingPropertyList , BindingRestProperty }
  1. BindingPropertyList の ContainsExpression を返す。
ArrayBindingPattern : [ Elisionopt ]
  1. false を返す。
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. BindingRestElement の ContainsExpression を返す。
ArrayBindingPattern : [ BindingElementList , Elisionopt ]
  1. BindingElementList の ContainsExpression を返す。
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. hasBindingElementList の ContainsExpression とする。
  2. hastrue なら true を返す。
  3. BindingRestElement の ContainsExpression を返す。
BindingPropertyList : BindingPropertyList , BindingProperty
  1. hasBindingPropertyList の ContainsExpression とする。
  2. hastrue なら true を返す。
  3. BindingProperty の ContainsExpression を返す。
BindingElementList : BindingElementList , BindingElisionElement
  1. hasBindingElementList の ContainsExpression とする。
  2. hastrue なら true を返す。
  3. BindingElisionElement の ContainsExpression を返す。
BindingElisionElement : Elisionopt BindingElement
  1. BindingElement の ContainsExpression を返す。
BindingProperty : PropertyName : BindingElement
  1. hasPropertyName の IsComputedPropertyKey とする。
  2. hastrue なら true を返す。
  3. BindingElement の ContainsExpression を返す。
BindingElement : BindingPattern Initializer
  1. true を返す。
SingleNameBinding : BindingIdentifier
  1. false を返す。
SingleNameBinding : BindingIdentifier Initializer
  1. true を返す。
BindingRestElement : ... BindingIdentifier
  1. false を返す。
BindingRestElement : ... BindingPattern
  1. BindingPattern の ContainsExpression を返す。
FormalParameters : [empty]
  1. false を返す。
FormalParameters : FormalParameterList , FunctionRestParameter
  1. FormalParameterList の ContainsExpression が true なら true を返す。
  2. FunctionRestParameter の ContainsExpression を返す。
FormalParameterList : FormalParameterList , FormalParameter
  1. FormalParameterList の ContainsExpression が true なら true を返す。
  2. FormalParameter の ContainsExpression を返す。
ArrowParameters : BindingIdentifier
  1. false を返す。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterList が覆う ArrowFormalParameters とする。
  2. formals の ContainsExpression を返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. false を返す。

15.1.3 静的意味論: IsSimpleParameterList : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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. FormalParameterList の IsSimpleParameterList が false なら false を返す。
  2. FormalParameter の IsSimpleParameterList を返す。
FormalParameter : BindingElement
  1. BindingElement の IsSimpleParameterList を返す。
ArrowParameters : BindingIdentifier
  1. true を返す。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterList が覆う ArrowFormalParameters とする。
  2. formals の IsSimpleParameterList を返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. true を返す。
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. headCoverCallExpressionAndAsyncArrowHead が覆う AsyncArrowHead とする。
  2. head の IsSimpleParameterList を返す。

15.1.4 静的意味論: HasInitializer : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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. FormalParameterList の HasInitializer が true なら true を返す。
  2. FormalParameter の HasInitializer を返す。

15.1.5 静的意味論: ExpectedArgumentCount

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

FormalParameterList の ExpectedArgumentCount は、rest parameter または初期化子を持つ最初の FormalParameter の左側にある FormalParameters の個数である。初期化子を持つ最初のパラメータの後に初期化子を持たないパラメータを置くことは許されるが、そのようなパラメータはデフォルト値 undefined の任意 (optional) パラメータと見なされる。

FormalParameterList : FormalParameter
  1. FormalParameter の HasInitializer が true なら 0 を返す。
  2. 1 を返す。
FormalParameterList : FormalParameterList , FormalParameter
  1. countFormalParameterList の ExpectedArgumentCount とする。
  2. FormalParameterList の HasInitializer が true または FormalParameter の HasInitializer が true なら count を返す。
  3. count + 1 を返す。
ArrowParameters : BindingIdentifier
  1. 1 を返す。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formalsCoverParenthesizedExpressionAndArrowParameterList が覆う ArrowFormalParameters とする。
  2. formals の ExpectedArgumentCount を返す。
PropertySetParameterList : FormalParameter
  1. FormalParameter の HasInitializer が true なら 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 静的意味論: 早期エラー (Early Errors)

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

FunctionBody の LexicallyDeclaredNames には var 宣言や function 宣言で束縛された識別子は含まれない。

FunctionBody : FunctionStatementList
  • FunctionStatementList の LexicallyDeclaredNames に重複があれば構文エラー。
  • FunctionStatementList の LexicallyDeclaredNames の任意の要素が VarDeclaredNames にも現れるなら構文エラー。
  • ContainsDuplicateLabels of FunctionStatementList (引数 « ») が true なら構文エラー。
  • ContainsUndefinedBreakTarget of FunctionStatementList (引数 « ») が true なら構文エラー。
  • ContainsUndefinedContinueTarget of FunctionStatementList (引数 « » および « ») が true なら構文エラー。

15.2.2 静的意味論: FunctionBodyContainsUseStrict : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionBody の Directive Prologue が Use Strict Directive を含むなら true、そうでなければ false を返す。

15.2.3 実行時意味論: EvaluateFunctionBody : return completion または throw completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FunctionBody : FunctionStatementList
  1. FunctionDeclarationInstantiation(functionObject, argumentsList) を実行する。
  2. FunctionStatementList の Evaluation を実行する。
  3. 注: 前の手順が normal completion なら評価は FunctionStatementList 終端まで進み終了している。
  4. ReturnCompletion(undefined) を返す。

15.2.4 実行時意味論: InstantiateOrdinaryFunctionObject : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

匿名の FunctionDeclarationexport default 宣言の一部としてのみ出現でき、その関数コードは常に strict mode である。

15.2.5 実行時意味論: InstantiateOrdinaryFunctionExpression : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. name が存在しなければ "" を代入。
  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. nameBindingIdentifier の StringValue に設定。
  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 はその FunctionBody 内から参照でき、再帰呼び出しを可能にする。しかし FunctionDeclaration と異なり、FunctionExpressionBindingIdentifier は外側のスコープから参照できず、外側スコープに影響を与えない。

15.2.6 実行時意味論: 評価 (Evaluation)

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

FunctionDeclaration または FunctionExpression により定義された全ての関数には自動的に "prototype" プロパティが作成され、その関数がコンストラクタとして利用される可能性を持たせる。

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

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)

生成規則
ArrowParameters[Yield, Await] : CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await]
のインスタンスを処理するとき、CoverParenthesizedExpressionAndArrowParameterList の解釈は以下の文法で精密化される:

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

15.3.1 静的意味論: 早期エラー (Early Errors)

ArrowFunction : ArrowParameters => ConciseBody ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList

15.3.2 静的意味論: ConciseBodyContainsUseStrict : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

15.3.3 実行時意味論: EvaluateConciseBody : return completion または throw completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

15.3.4 実行時意味論: InstantiateArrowFunctionExpression : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ArrowFunction : ArrowParameters => ConciseBody
  1. name が存在しなければ "" を代入。
  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

ArrowFunctionarguments, super, this, new.target の局所束縛を定義しない。これらへの参照はレキシカルに囲む環境の束縛へ解決される。典型的には直近の(非アロー)関数の Function Environment となる。ArrowFunctionsuper を参照し得ても、ステップ 5 で生成される関数オブジェクトMakeMethod によりメソッド化されない。super を参照する ArrowFunction は常に非 ArrowFunction 内に含まれ、super 実装に必要な状態はその ArrowFunction関数オブジェクトが捕捉する env から得られる。

15.3.5 実行時意味論: 評価 (Evaluation)

ArrowFunction : ArrowParameters => ConciseBody
  1. InstantiateArrowFunctionExpression of ArrowFunction を返す。
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 静的意味論: 早期エラー (Early Errors)

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

15.4.2 静的意味論: HasDirectSuper : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 静的意味論: SpecialMethod : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 実行時意味論: DefineMethod を含むか、または abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. propKeyClassElementName の 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]]: propKey, [[Closure]]: closure } を返す。

15.4.5 実行時意味論: MethodDefinitionEvaluation : 正常完了なら PrivateElement か unused のいずれか、または abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. methodDef を ? DefineMethod of MethodDefinition (引数 object) とする。
  2. SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]]) を実行。
  3. DefineMethodProperty(object, methodDef.[[Key]], methodDef.[[Closure]], enumerable) を返す。
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. propKey を ? Evaluation of ClassElementName とする。
  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, propKey, "get") を実行。
  9. propKeyPrivate Name なら:
    1. PrivateElement { [[Key]]: propKey, [[Kind]]: accessor, [[Get]]: closure, [[Set]]: undefined } を返す。
  10. そうでなければ:
    1. desc を PropertyDescriptor { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true } とする。
    2. DefinePropertyOrThrow(object, propKey, desc) を実行。
    3. unused を返す。
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. propKey を ? Evaluation of ClassElementName とする。
  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, propKey, "set") を実行。
  8. propKeyPrivate Name なら:
    1. PrivateElement { [[Key]]: propKey, [[Kind]]: accessor, [[Get]]: undefined, [[Set]]: closure } を返す。
  9. そうでなければ:
    1. desc を PropertyDescriptor { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true } とする。
    2. DefinePropertyOrThrow(object, propKey, desc) を実行。
    3. unused を返す。
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. propKey を ? Evaluation of ClassElementName とする。
  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, propKey) を実行。
  8. prototypeOrdinaryObjectCreate(%GeneratorPrototype%) とする。
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行。
  10. DefineMethodProperty(object, propKey, closure, enumerable) を返す。
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. propKey を ? Evaluation of ClassElementName とする。
  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, propKey) を実行。
  8. prototypeOrdinaryObjectCreate(%AsyncGeneratorPrototype%) とする。
  9. DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行。
  10. DefineMethodProperty(object, propKey, closure, enumerable) を返す。
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. propKey を ? Evaluation of ClassElementName とする。
  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, propKey) を実行。
  8. DefineMethodProperty(object, propKey, 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 直後の構文文脈では字句目標 InputElementRegExpOrTemplateTail を用いる必要がある。

Note 2

YieldExpression はジェネレーター関数の FormalParameters 内では使用できない。これは FormalParameters に含まれる式が、生成される Generator が再開可能状態になる前に評価されるためである。

Note 3

Generator に関する抽象操作27.5.3 で定義される。

15.5.1 静的意味論: 早期エラー (Early Errors)

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

15.5.2 実行時意味論: EvaluateGeneratorBody : throw completion または return completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

15.5.3 実行時意味論: InstantiateGeneratorFunctionObject : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

匿名の GeneratorDeclarationexport default 宣言の一部でのみ出現し、その関数コードは常に strict mode である。

15.5.4 実行時意味論: InstantiateGeneratorFunctionExpression : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. name が存在しなければ name"" を設定。
  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. nameBindingIdentifier の StringValue に設定。
  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

GeneratorExpressionBindingIdentifier はその FunctionBody 内から参照でき再帰呼び出しを可能にするが、GeneratorDeclaration と異なり外側のスコープには現れず影響しない。

15.5.5 実行時意味論: 評価 (Evaluation)

GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  1. InstantiateGeneratorFunctionExpression of GeneratorExpression を返す。
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: generatorKindsyncasync のいずれか。
  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 を throw。
      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. 注: 内部イテレータ throw メソッドの例外は伝播し、正常完了は内部 next と同様に処理される。
        4. innerResult が Object でなければ TypeError を throw。
        5. done を ? IteratorComplete(innerResult) とする。
        6. donetrue なら
          1. IteratorValue(innerResult) を返す。
        7. generatorKindasync なら receivedCompletion(AsyncGeneratorYield(? IteratorValue(innerResult))) に設定。
        8. それ以外は receivedCompletion(GeneratorYield(innerResult)) に設定。
      3. それ以外:
        1. 注: iteratorthrow メソッドがない場合、この throw は yield* ループを終了させる。まずクリーンアップを与える。
        2. closeCompletionNormalCompletion(empty) とする。
        3. generatorKindasync なら ? AsyncIteratorClose(iteratorRecord, closeCompletion) を実行。
        4. それ以外は ? IteratorClose(iteratorRecord, closeCompletion) を実行。
        5. 注: 次のステップで throw メソッド欠如による yield* プロトコル違反として TypeError を投げる。
        6. TypeError を throw。
    3. それ以外:
      1. Assert: receivedreturn completion
      2. return を ? GetMethod(iterator, "return") とする。
      3. returnundefined なら
        1. valuereceived.[[Value]] に設定。
        2. generatorKindasync なら
          1. value を ? Await(value) に設定。
        3. ReturnCompletion(value) を返す。
      4. innerReturnResult を ? Call(return, iterator, « received.[[Value]] ») とする。
      5. generatorKindasync なら innerReturnResult を ? Await(innerReturnResult) に設定。
      6. innerReturnResult が Object でなければ TypeError を throw。
      7. done を ? IteratorComplete(innerReturnResult) とする。
      8. donetrue なら
        1. value を ? IteratorValue(innerReturnResult) に設定。
        2. ReturnCompletion(value) を返す。
      9. generatorKindasync なら 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

非同期ジェネレーター関数の FormalParameters 内では YieldExpressionAwaitExpression は使用できない。FormalParameters 内の式は結果の AsyncGenerator が再開可能となる前に評価されるためである。

Note 2

AsyncGenerator に関する抽象操作27.6.3 で定義される。

15.6.1 静的意味論: 早期エラー (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 実行時意味論: EvaluateAsyncGeneratorBody : throw completion または return completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 実行時意味論: InstantiateAsyncGeneratorFunctionObject : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

匿名の AsyncGeneratorDeclarationexport default 宣言の一部でのみ出現する。

15.6.4 実行時意味論: InstantiateAsyncGeneratorFunctionExpression : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. name が存在しなければ name"" を設定。
  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. nameBindingIdentifier の StringValue に設定。
  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

AsyncGeneratorExpressionBindingIdentifier はその AsyncGeneratorBody 内から参照でき再帰呼び出しを可能にするが、AsyncGeneratorDeclaration と異なり外側スコープには現れず影響しない。

15.6.5 実行時意味論: 評価 (Evaluation)

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

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

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

15.7.1 静的意味論: 早期エラー (Early Errors)

ClassTail : ClassHeritageopt { ClassBody }
  • ClassHeritage が存在しない場合、次のアルゴリズムが true を返すなら構文エラー:

    1. constructorClassBody の ConstructorMethod とする。
    2. constructorempty なら false を返す。
    3. HasDirectSuper of constructor を返す。
ClassBody : ClassElementList
  • ClassElementList の PrototypePropertyNameList に "constructor" が 2 回以上含まれる場合は構文エラー。
  • ClassElementList の PrivateBoundIdentifiers に重複があり、その名前がゲッターとセッターの 1 回ずつ(他で未使用)かつ両方 static か両方非 static である場合を除いて構文エラー。
ClassElement : MethodDefinition ClassElement : static MethodDefinition ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ;
  • FieldDefinition の PropName が "prototype" または "constructor" なら構文エラー。
FieldDefinition : ClassElementName Initializeropt ClassElementName : PrivateIdentifier ClassStaticBlockBody : ClassStaticBlockStatementList

15.7.2 静的意味論: ClassElementKind : constructor-method, non-constructor-method, または empty

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElement : MethodDefinition
  1. MethodDefinition の PropName が "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 静的意味論: ConstructorMethod : ClassElement Parse Node または empty

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. ClassElement の ClassElementKind が constructor-method なら ClassElement を返す。
  2. empty を返す。
ClassElementList : ClassElementList ClassElement
  1. headClassElementList の ConstructorMethod とする。
  2. headempty でなければ head を返す。
  3. ClassElement の ClassElementKind が constructor-method なら ClassElement を返す。
  4. empty を返す。
Note

早期エラー規則により "constructor" という名前のメソッドは 1 つであり、 accessor や generator ではないことが保証される。

15.7.4 静的意味論: IsStatic : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 静的意味論: NonConstructorElements : ClassElement Parse Nodes の List

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. ClassElement の ClassElementKind が non-constructor-method なら
    1. « ClassElement » を返す。
  2. 新しい空 List を返す。
ClassElementList : ClassElementList ClassElement
  1. listClassElementList の NonConstructorElements とする。
  2. ClassElement の ClassElementKind が non-constructor-method なら
    1. list の末尾に ClassElement を追加。
  3. list を返す。

15.7.6 静的意味論: PrototypePropertyNameList : プロパティキーの List

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElementList : ClassElement
  1. propNameClassElement の PropName とする。
  2. propNameempty なら空の新しい List を返す。
  3. IsStatic(ClassElement) が true なら空の新しい List を返す。
  4. « propName » を返す。
ClassElementList : ClassElementList ClassElement
  1. listClassElementList の PrototypePropertyNameList とする。
  2. propNameClassElement の PropName とする。
  3. propNameempty なら list を返す。
  4. IsStatic(ClassElement) が true なら list を返す。
  5. list と « propName » のリスト連結を返す。

15.7.7 静的意味論: AllPrivateIdentifiersValid : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS.

以下に列挙されない仕様中のすべての生成規則選択肢は、暗黙に次の既定定義を持つ:

  1. この Parse Node の各子ノード child について:
    1. child が非終端記号インスタンスなら
      1. AllPrivateIdentifiersValid(child, names) が false なら false を返す。
  2. true を返す。
MemberExpression : MemberExpression . PrivateIdentifier
  1. namesPrivateIdentifier の StringValue を含むなら
    1. AllPrivateIdentifiersValid(MemberExpression, names) を返す。
  2. false を返す。
CallExpression : CallExpression . PrivateIdentifier
  1. namesPrivateIdentifier の StringValue を含むなら
    1. AllPrivateIdentifiersValid(CallExpression, names) を返す。
  2. false を返す。
OptionalChain : ?. PrivateIdentifier
  1. namesPrivateIdentifier の StringValue を含むなら true を返す。
  2. false を返す。
OptionalChain : OptionalChain . PrivateIdentifier
  1. namesPrivateIdentifier の StringValue を含むなら
    1. AllPrivateIdentifiersValid(OptionalChain, names) を返す。
  2. false を返す。
ClassBody : ClassElementList
  1. newNamesnamesClassBody の PrivateBoundIdentifiers のリスト連結とする。
  2. AllPrivateIdentifiersValid(ClassElementList, newNames) を返す。
RelationalExpression : PrivateIdentifier in ShiftExpression
  1. namesPrivateIdentifier の StringValue を含むなら
    1. AllPrivateIdentifiersValid(ShiftExpression, names) を返す。
  2. false を返す。

15.7.8 静的意味論: PrivateBoundIdentifiers : 文字列 List

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. ClassElementName の PrivateBoundIdentifiers を返す。
ClassElementName : PrivateIdentifier
  1. PrivateIdentifier の StringValue 1 要素のみを含む List を返す。
ClassElementName : PropertyName ClassElement : ClassStaticBlock ;
  1. 新しい空 List を返す。
ClassElementList : ClassElementList ClassElement
  1. names1ClassElementList の PrivateBoundIdentifiers とする。
  2. names2ClassElement の PrivateBoundIdentifiers とする。
  3. names1names2 のリスト連結を返す。
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. ClassElementName の PrivateBoundIdentifiers を返す。

15.7.9 静的意味論: ContainsArguments : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS.

以下に列挙されないすべての生成規則選択肢は暗黙に次の既定定義を持つ:

  1. この Parse Node の各子 child について:
    1. child が非終端であれば
      1. ContainsArguments(child) が true なら true を返す。
  2. false を返す。
IdentifierReference : Identifier
  1. Identifier の StringValue が "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. ContainsArguments(ClassElementName) を返す。

15.7.10 実行時意味論: ClassFieldDefinitionEvaluation : ClassFieldDefinition Record を含む normal completion または abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

FieldDefinition : ClassElementName Initializeropt
  1. name を ? Evaluation of ClassElementName とする。
  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 実行時意味論: ClassStaticBlockDefinitionEvaluation : ClassStaticBlockDefinition Record

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 実行時意味論: EvaluateClassStaticBlockBody : return completion または throw completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

15.7.13 実行時意味論: ClassElementEvaluation : ClassFieldDefinition Record / ClassStaticBlockDefinition Record / PrivateElement / unused のいずれかを含む normal completion または abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassElement : FieldDefinition ; static FieldDefinition ;
  1. ? ClassFieldDefinitionEvaluation of FieldDefinition (引数 object) を返す。
ClassElement : MethodDefinition static MethodDefinition
  1. ? MethodDefinitionEvaluation of MethodDefinition (引数 object, false) を返す。
ClassElement : ClassStaticBlock
  1. ClassStaticBlockDefinitionEvaluation of ClassStaticBlock (引数 object) を返す。
ClassElement : ;
  1. unused を返す。

15.7.14 実行時意味論: ClassDefinitionEvaluation : 関数オブジェクトを含む normal completion または abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS.

Note

仕様を簡潔にするため、private method と accessor はクラスインスタンスの [[PrivateElements]] スロットで private field と並列に扱われる。ただし任意のオブジェクトは、そのクラスで定義された private method / accessor を全部持つか全く持たないかのどちらかである。この設計により実装は各メソッドやアクセサを個別に追跡しない戦略を選択できる。

例として、実装はインスタンスの private method を対応する Private Name と直接関連付け、各オブジェクトに対しどのクラスコンストラクタthis として走ったかを追跡できる。オブジェクト上の private method 参照は、そのメソッドを定義するクラスコンストラクタで初期化されたかを確認し、Private Name に結び付くメソッドを返す手順になる。

これは private field と異なる。field 初期化子はクラスインスタンス化中に例外を投げ得るため、個々のオブジェクトがクラスの private field の真部分集合だけを持つ状況があり、private field は一般に個別追跡する必要がある。

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. ClassBody の PrivateBoundIdentifiers の各文字列 dn について、次を行う:
      1. classPrivateEnvironment.[[Names]] に、[[Description]]dn である Private Name pn が含まれているなら、
        1. Assert: これは getter/setter ペアの場合にのみ起こり得る。
      2. そうでなければ、
        1. dn[[Description]] とする新しい Private Name name を生成する。
        2. nameclassPrivateEnvironment.[[Names]] に追加する。
  7. ClassHeritage が存在しない場合、
    1. protoParent%Object.prototype% とする。
    2. constructorParent%Function.prototype% とする。
  8. そうでなければ、
    1. 実行中の実行コンテキストの LexicalEnvironment を classEnv に設定する。
    2. 注: ClassHeritage の評価中、実行中の実行コンテキストの PrivateEnvironment は outerPrivateEnvironment である。
    3. superclassRefCompletion(Evaluation of ClassHeritage) とする。
    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 がオブジェクトでも null でもないなら、TypeError 例外を投げる。
      3. constructorParentsuperclass とする。
  9. protoOrdinaryObjectCreate(protoParent) とする。
  10. ClassBody が存在しない場合、constructorempty とする。
  11. そうでなければ、constructorClassBody の ConstructorMethod とする。
  12. 実行中の実行コンテキストの LexicalEnvironment を classEnv に設定する。
  13. 実行中の実行コンテキストの PrivateEnvironment を classPrivateEnvironment に設定する。
  14. もし constructorempty であるなら、
    1. 引数を持たず、何もキャプチャしない新しい Abstract Closure defaultConstructor を生成し、呼び出された時に次を実行する:
      1. args を、この関数に [[Call]] または [[Construct]] で渡された引数のリストとする。
      2. もし NewTarget が undefined であるなら、TypeError 例外を投げる。
      3. F をアクティブな関数オブジェクトとする。
      4. もし F.[[ConstructorKind]]derived であるなら、
        1. 注: この分岐は constructor(...args) { super(...args); } に類似しているが、前述の ECMAScript ソーステキストが観測可能に %Array.prototype%%Symbol.iterator% メソッドを呼び出す一方で、この関数はそれを呼び出さない。
        2. func を ! F.[[GetPrototypeOf]]() とする。
        3. もし IsConstructor(func) が false であるなら、TypeError 例外を投げる。
        4. result を ? Construct(func, args, NewTarget) とする。
      5. そうでなければ、
        1. 注: この分岐は constructor() {} に類似している。
        2. result を ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%") とする。
      6. InitializeInstanceElements(result, F) を実行する。
      7. NormalCompletion(result) を返す。
    2. FCreateBuiltinFunction(defaultConstructor, 0, className, « [[ConstructorKind]], [[SourceText]] », the current Realm Record, constructorParent) とする。
  15. そうでなければ、
    1. constructorInfo を ! DefineMethod of constructor (引数 protoconstructorParent) とする。
    2. FconstructorInfo.[[Closure]] とする。
    3. MakeClassConstructor(F) を実行する。
    4. SetFunctionName(F, className) を実行する。
  16. F.[[SourceText]]sourceText に設定する。
  17. MakeConstructor(F, false, proto) を実行する。
  18. もし ClassHeritage が存在するなら、F.[[ConstructorKind]]derived に設定する。
  19. DefineMethodProperty(proto, "constructor", F, false) を実行する。
  20. もし ClassBody が存在しないなら、elements を新しい空の List とする。
  21. そうでなければ、elementsClassBody の NonConstructorElements とする。
  22. instancePrivateMethods を新しい空の List とする。
  23. staticPrivateMethods を新しい空の List とする。
  24. instanceFields を新しい空の List とする。
  25. staticElements を新しい空の List とする。
  26. elements の各 ClassElement e について、次を行う:
    1. もし IsStatic(e) が false なら、
      1. elementCompletion(ClassElementEvaluation of e with argument proto) とする。
    2. そうでなければ、
      1. elementCompletion(ClassElementEvaluation of e with argument F) とする。
    3. もし elementabrupt completion なら、
      1. 実行中の実行コンテキストの LexicalEnvironment を env に戻す。
      2. 実行中の実行コンテキストの PrivateEnvironment を outerPrivateEnvironment に戻す。
      3. element を返す。
    4. element を ! element に設定する。
    5. もし elementPrivateElement であるなら、
      1. Assert: element.[[Kind]]method または accessor のいずれかである。
      2. もし IsStatic(e) が false なら、containerinstancePrivateMethods とし、そうでなければ staticPrivateMethods とする。
      3. もし container に、element.[[Key]] と同じ [[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 で置き換える。
      4. そうでなければ、
        1. elementcontainer に追加する。
    6. そうでなく、もし elementClassFieldDefinition Record であるなら、
      1. もし IsStatic(e) が false なら、elementinstanceFields に追加し、そうでなければ staticElements に追加する。
    7. そうでなく、もし elementClassStaticBlockDefinition Record であるなら、
      1. elementstaticElements に追加する。
  27. 実行中の実行コンテキストの LexicalEnvironment を env に戻す。
  28. もし classBindingundefined でないなら、
    1. classEnv.InitializeBinding(classBinding, F) を実行する。
  29. F.[[PrivateMethods]]instancePrivateMethods に設定する。
  30. F.[[Fields]]instanceFields に設定する。
  31. staticPrivateMethods の各 PrivateElement method について、次を行う:
    1. PrivateMethodOrAccessorAdd(F, method) を実行する。
  32. staticElements の各要素 elementRecord について、次を行う:
    1. もし elementRecordClassFieldDefinition Record であるなら、
      1. resultCompletion(DefineField(F, elementRecord)) とする。
    2. そうでなければ、
      1. Assert: elementRecordClassStaticBlockDefinition Record である。
      2. resultCompletion(Call(elementRecord.[[BodyFunction]], F)) とする。
    3. もし resultabrupt completion であるなら、
      1. 実行中の実行コンテキストの PrivateEnvironment を outerPrivateEnvironment に戻す。
      2. result を返す。
  33. 実行中の実行コンテキストの PrivateEnvironment を outerPrivateEnvironment に戻す。
  34. F を返す。

15.7.15 実行時意味論: BindingClassDeclarationEvaluation : 関数オブジェクトを含む normal completion または abrupt completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

ClassDeclaration : class BindingIdentifier ClassTail
  1. classNameBindingIdentifier の StringValue とする。
  2. sourceTextClassDeclaration にマッチしたソースとする。
  3. value を ? ClassDefinitionEvaluation(ClassTail, className, className, sourceText) とする。
  4. env を実行中コンテキストの LexicalEnvironment とする。
  5. InitializeBoundName(className, value, env) を実行。
  6. value を返す。
ClassDeclaration : class ClassTail
  1. sourceTextClassDeclaration にマッチしたソースとする。
  2. ? ClassDefinitionEvaluation(ClassTail, undefined, "default", sourceText) を返す。
Note

ClassDeclaration : class ClassTail ExportDeclaration の一部としてのみ出現し、その束縛確立は該当生成規則の評価で処理される。16.2.3.7 参照。

15.7.16 実行時意味論: 評価 (Evaluation)

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

ClassDeclaration : class ClassTail ExportDeclaration の一部でのみ出現し直接評価されない。

ClassExpression : class ClassTail
  1. sourceTextClassExpression にマッチしたソースとする。
  2. ? ClassDefinitionEvaluation(ClassTail, undefined, "", sourceText) を返す。
ClassExpression : class BindingIdentifier ClassTail
  1. classNameBindingIdentifier の StringValue とする。
  2. sourceTextClassExpression にマッチしたソースとする。
  3. ? ClassDefinitionEvaluation(ClassTail, className, className, sourceText) を返す。
ClassElementName : PrivateIdentifier
  1. privateIdentifierPrivateIdentifier の StringValue とする。
  2. privateEnvRec を実行中コンテキストの PrivateEnvironment とする。
  3. namesprivateEnvRec.[[Names]] とする。
  4. Assert: names[[Description]] = privateIdentifierPrivate Name が正確に 1 つ存在。
  5. privateName をその 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[Await] パラメータが存在する場合に AwaitExpression のキーワードとして構文解析される。[Await] パラメータは次の文脈のトップレベルで存在し得る(FunctionBody など非終端により欠如し得る):

構文目標記号が Script の場合、[Await] パラメータが無い文脈では await は識別子として解析され得る。例:

Note 2

YieldExpression と異なり、AwaitExpression のオペランド省略は Syntax Error である。必ず何かを await しなければならない。

15.8.1 静的意味論: 早期エラー (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 実行時意味論: InstantiateAsyncFunctionObject : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. nameBindingIdentifier の StringValue とする。
  2. sourceTextAsyncFunctionDeclaration にマッチしたソースとする。
  3. FOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv) とする。
  4. SetFunctionName(F, name) を実行。
  5. F を返す。
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. sourceTextAsyncFunctionDeclaration にマッチしたソースとする。
  2. FOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, env, privateEnv) とする。
  3. SetFunctionName(F, "default") を実行。
  4. F を返す。

15.8.3 実行時意味論: InstantiateAsyncFunctionExpression : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. name が存在しなければ "" を設定。
  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. nameBindingIdentifier の StringValue に設定。
  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

AsyncFunctionExpressionBindingIdentifier はその AsyncFunctionBody 内から参照でき再帰呼び出しを可能にするが、FunctionDeclaration と異なり外側スコープには影響しない。

15.8.4 実行時意味論: EvaluateAsyncFunctionBody : return completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncFunctionBody : FunctionBody
  1. promiseCapability を ! NewPromiseCapability(%Promise%) とする。
  2. completionCompletion(FunctionDeclarationInstantiation(functionObject, argumentsList)) とする。
  3. completion が abrupt なら
    1. ! Call(promiseCapability.[[Reject]], undefined, « completion.[[Value]] ») を実行。
  4. それ以外
    1. AsyncFunctionStart(promiseCapability, FunctionBody) を実行。
  5. ReturnCompletion(promiseCapability.[[Promise]]) を返す。

15.8.5 実行時意味論: 評価 (Evaluation)

AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. InstantiateAsyncFunctionExpression of AsyncFunctionExpression を返す。
AwaitExpression : await UnaryExpression
  1. exprRef を ? Evaluation of UnaryExpression とする。
  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)

生成規則
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
のインスタンス処理時、CoverCallExpressionAndAsyncArrowHead の解釈は以下の文法で精密化される:

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

15.9.1 静的意味論: 早期エラー (Early Errors)

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

15.9.2 静的意味論: AsyncConciseBodyContainsUseStrict : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

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

15.9.3 実行時意味論: EvaluateAsyncConciseBody : return completion

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncConciseBody : ExpressionBody
  1. promiseCapability を ! NewPromiseCapability(%Promise%) とする。
  2. completionCompletion(FunctionDeclarationInstantiation(functionObject, argumentsList)) とする。
  3. completion が abrupt なら
    1. ! Call(promiseCapability.[[Reject]], undefined, « completion.[[Value]] ») を実行。
  4. それ以外
    1. AsyncFunctionStart(promiseCapability, ExpressionBody) を実行。
  5. ReturnCompletion(promiseCapability.[[Promise]]) を返す。

15.9.4 実行時意味論: InstantiateAsyncArrowFunctionExpression : ECMAScript 関数オブジェクト

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It is defined piecewise over the following productions:

AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. name が存在しなければ "" を設定。
  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 が存在しなければ "" を設定。
  2. env を実行中コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中コンテキストの PrivateEnvironment とする。
  4. sourceTextAsyncArrowFunction にマッチしたソースとする。
  5. headCoverCallExpressionAndAsyncArrowHead が覆う AsyncArrowHead とする。
  6. parametersheadArrowFormalParameters とする。
  7. closureOrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, parameters, AsyncConciseBody, lexical-this, env, privateEnv) とする。
  8. SetFunctionName(closure, name) を実行。
  9. closure を返す。

15.9.5 実行時意味論: 評価 (Evaluation)

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

15.10 末尾位置呼び出し (Tail Position Calls)

15.10.1 静的意味論: IsInTailPosition ( call: CallExpression / MemberExpression / OptionalChain Parse Node, ): Boolean

The abstract operation UNKNOWN takes UNPARSEABLE ARGUMENTS. It performs the following steps when called:

  1. IsStrict(call) が false なら false を返す。
  2. callFunctionBody, ConciseBody, AsyncConciseBody の内部に含まれていなければ false を返す。
  3. bodycall を最も近く包含する FunctionBody / ConciseBody / AsyncConciseBody とする。
  4. bodyGeneratorBodyFunctionBody なら false を返す。
  5. bodyAsyncFunctionBodyFunctionBody なら false を返す。
  6. bodyAsyncGeneratorBodyFunctionBody なら false を返す。
  7. bodyAsyncConciseBody なら false を返す。
  8. HasCallInTailPosition(body, call) の結果を返す。
Note

末尾位置呼び出しは strict mode コードでのみ定義される。これは caller chain を観測可能にする一般的な非標準拡張(10.2.4 参照)との整合のためである。

15.10.2 静的意味論: HasCallInTailPosition : Boolean

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS.

Note 1

call は特定のソース範囲を表す Parse Node である。以下のアルゴリズムで他の Parse Node と比較する場合、それらが同一ソース範囲を表すかを判定する。

Note 2

潜在的な末尾位置呼び出しの直後が return でその呼び出し結果の GetValue を返している場合も末尾位置呼び出しと見なされる。関数呼び出しは Reference Record を返さないため、その GetValue は呼び出し結果と同じ値を返す。

It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. has を HasCallInTailPosition(StatementList, call) とする。
  2. hastrue なら true を返す。
  3. HasCallInTailPosition(StatementListItem, call) を返す。
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 を最初の Statement の HasCallInTailPosition(…, call) とする。
  2. hastrue なら true を返す。
  3. 2 番目の Statement の HasCallInTailPosition(…, call) を返す。
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. HasCallInTailPosition(Statement, call) を返す。
LabelledStatement : LabelIdentifier : LabelledItem
  1. HasCallInTailPosition(LabelledItem, call) を返す。
ReturnStatement : return Expression ;
  1. HasCallInTailPosition(Expression, call) を返す。
SwitchStatement : switch ( Expression ) CaseBlock
  1. HasCallInTailPosition(CaseBlock, call) を返す。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. hasfalse とする。
  2. 最初の CaseClauses があれば has = HasCallInTailPosition(その CaseClauses, call)。
  3. hastrue なら true を返す。
  4. has = HasCallInTailPosition(DefaultClause, call)。
  5. hastrue なら true を返す。
  6. 2 番目の CaseClauses があれば has = HasCallInTailPosition(その CaseClauses, call)。
  7. has を返す。
CaseClauses : CaseClauses CaseClause
  1. has を HasCallInTailPosition(CaseClauses, call) とする。
  2. hastrue なら true を返す。
  3. HasCallInTailPosition(CaseClause, call) を返す。
CaseClause : case Expression : StatementListopt DefaultClause : default : StatementListopt
  1. StatementList があれば HasCallInTailPosition(StatementList, call) を返す。
  2. false を返す。
TryStatement : try Block Catch
  1. HasCallInTailPosition(Catch, call) を返す。
TryStatement : try Block Finally try Block Catch Finally
  1. HasCallInTailPosition(Finally, call) を返す。
Catch : catch ( CatchParameter ) Block
  1. HasCallInTailPosition(Block, call) を返す。
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. HasCallInTailPosition(AssignmentExpression, call) を返す。
ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  1. has を最初の AssignmentExpression の HasCallInTailPosition(…, call) とする。
  2. hastrue なら true を返す。
  3. 2 番目の AssignmentExpression の HasCallInTailPosition(…, call) を返す。
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. HasCallInTailPosition(BitwiseORExpression, call) を返す。
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. HasCallInTailPosition(LogicalANDExpression, call) を返す。
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. HasCallInTailPosition(BitwiseORExpression, call) を返す。
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments CallExpression TemplateLiteral
  1. この CallExpressioncall なら true を返す。
  2. false を返す。
OptionalExpression : MemberExpression OptionalChain CallExpression OptionalChain OptionalExpression OptionalChain
  1. HasCallInTailPosition(OptionalChain, call) を返す。
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. HasCallInTailPosition(expr, call) を返す。
ParenthesizedExpression : ( Expression )
  1. HasCallInTailPosition(Expression, call) を返す。

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

例えば末尾位置呼び出しは、ターゲット関数のアクティベーションレコードが呼出元より大きい差分のみスタックを増加させるべきである。ターゲットの方が小さいなら総スタックサイズは減少すべきである。