ページ表示設定

15 ECMAScript 言語: 関数とクラス

注

さまざまな 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 注

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

15.1.2 Static Semantics: ContainsExpression

構文指向操作 ContainsExpression。引数なし。戻り値:Boolean。 次の生成規則ごとに定義される。

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. has を BindingElementList の ContainsExpression とする。
  2. has が true である場合、true を返す。
  3. BindingRestElement の ContainsExpression を返す。
BindingPropertyList : BindingPropertyList , BindingProperty
  1. has を BindingPropertyList の ContainsExpression とする。
  2. has が true である場合、true を返す。
  3. BindingProperty の ContainsExpression を返す。
BindingElementList : BindingElementList , BindingElisionElement
  1. has を BindingElementList の ContainsExpression とする。
  2. has が true である場合、true を返す。
  3. BindingElisionElement の ContainsExpression を返す。
BindingElisionElement : Elisionopt BindingElement
  1. BindingElement の ContainsExpression を返す。
BindingProperty : PropertyName : BindingElement
  1. has を PropertyName の IsComputedPropertyKey とする。
  2. has が true である場合、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. formals を CoverParenthesizedExpressionAndArrowParameterList によって被覆される ArrowFormalParameters とする。
  2. formals の ContainsExpression を返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. false を返す。

15.1.3 Static Semantics: IsSimpleParameterList

構文指向操作 IsSimpleParameterList。引数なし。戻り値:Boolean。 次の生成規則ごとに定義される。

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. formals を CoverParenthesizedExpressionAndArrowParameterList によって被覆される ArrowFormalParameters とする。
  2. formals の IsSimpleParameterList を返す。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. true を返す。
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. head を CoverCallExpressionAndAsyncArrowHead によって被覆される AsyncArrowHead とする。
  2. head の IsSimpleParameterList を返す。

15.1.4 Static Semantics: HasInitializer

構文指向操作 HasInitializer。引数なし。戻り値:Boolean。 次の生成規則ごとに定義される。

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 Static Semantics: ExpectedArgumentCount

構文指向操作 ExpectedArgumentCount。引数なし。戻り値:非負整数。 次の生成規則ごとに定義される。

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

FormalParameterList の ExpectedArgumentCount は、rest パラメーターまたは Initializer を持つ最初の FormalParameter のいずれかより左側にある FormalParameters の数です。Initializer を持つ最初のパラメーターの後に、initializer を持たない FormalParameter を置くことは許可されますが、そのようなパラメーターは、既定値が undefined の省略可能なものとみなされます。

FormalParameterList : FormalParameter
  1. FormalParameter の HasInitializer が true である場合、0 を返す。
  2. 1 を返す。
FormalParameterList : FormalParameterList , FormalParameter
  1. count を FormalParameterList の ExpectedArgumentCount とする。
  2. FormalParameterList の HasInitializer が true であるか、FormalParameter の HasInitializer が true である場合、count を返す。
  3. count + 1 を返す。
ArrowParameters : BindingIdentifier
  1. 1 を返す。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. formals を CoverParenthesizedExpressionAndArrowParameterList によって被覆される ArrowFormalParameters とする。
  2. formals の ExpectedArgumentCount を返す。
PropertySetParameterList : FormalParameter
  1. FormalParameter の HasInitializer が true である場合、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 } 注

FunctionBody の LexicallyDeclaredNames には、var または関数宣言を使用して束縛された識別子は含まれません。

FunctionBody : FunctionStatementList

15.2.2 Static Semantics: FunctionBodyContainsUseStrict

構文指向操作 FunctionBodyContainsUseStrict。引数なし。戻り値:Boolean。 次の生成規則ごとに定義される。

FunctionBody : FunctionStatementList
  1. FunctionBody のディレクティブプロローグが Use Strict ディレクティブを含む場合、true を返す。
  2. false を返す。

15.2.3 Runtime Semantics: EvaluateFunctionBody

構文指向操作 EvaluateFunctionBody。引数 funcObj (ECMAScript 関数オブジェクト) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(return 完了 または throw 完了)。 次の生成規則ごとに定義される。

FunctionBody : FunctionStatementList
  1. ? FunctionDeclarationInstantiation(funcObj, argList) を実行する。
  2. FunctionStatementList の ? Evaluation を実行する。
  3. 注記: 前の手順が正常完了になった場合、評価は FunctionStatementList の末尾を通過して終了した。
  4. ReturnCompletion(undefined) を返す。

15.2.4 Runtime Semantics: InstantiateOrdinaryFunctionObject

構文指向操作 InstantiateOrdinaryFunctionObject。引数 envRecord (Environmentレコード) および privateEnv ((PrivateEnvironmentレコード または null))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

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

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

15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression

構文指向操作 InstantiateOrdinaryFunctionExpression。省略可能な引数 name ((プロパティキー または プライベート名))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. name が存在しない場合、name を空の String に設定する。
  2. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceText を FunctionExpression に一致するソーステキストとする。
  5. closure を OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv) とする。
  6. SetFunctionName(closure, name) を実行する。
  7. MakeConstructor(closure) を実行する。
  8. closure を返す。
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. 表明: name は存在しない。
  2. name を BindingIdentifier の StringValue に設定する。
  3. outerEnv を実行中の実行コンテキストの LexicalEnvironment とする。
  4. funcEnv を NewDeclarativeEnvironment(outerEnv) とする。
  5. ! funcEnv.CreateImmutableBinding(name, false) を実行する。
  6. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  7. sourceText を FunctionExpression に一致するソーステキストとする。
  8. closure を OrdinaryFunctionCreate(%Function.prototype%, sourceText, FormalParameters, FunctionBody, non-lexical-this, funcEnv, privateEnv) とする。
  9. SetFunctionName(closure, name) を実行する。
  10. MakeConstructor(closure) を実行する。
  11. ! funcEnv.InitializeBinding(name, closure) を実行する。
  12. closure を返す。
注

FunctionExpression 内の BindingIdentifier は、関数自身を再帰的に呼び出せるように、FunctionExpression の FunctionBody の内部から参照できます。ただし、FunctionDeclaration とは異なり、FunctionExpression 内の BindingIdentifier は FunctionExpression を囲むスコープから参照することはできず、そのスコープにも影響を与えません。

15.2.6 Runtime Semantics: Evaluation

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

関数がコンストラクターとして使用される可能性を許容するため、FunctionDeclaration または FunctionExpression を使用して定義されたすべての関数には、"prototype" プロパティが自動的に作成されます。

FunctionStatementList : [empty]
  1. undefined を返す。
FunctionStatementList : StatementList
  1. result を Completion(StatementList の Evaluation) とする。
  2. env を実行中の実行コンテキストの LexicalEnvironment とする。
  3. 表明: env は Declarative Environment Record である。
  4. ? DisposeResources(env.[[DisposableResourceStack]], result) を返す。

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

構文指向操作 ConciseBodyContainsUseStrict。引数なし。戻り値:Boolean。 次の生成規則ごとに定義される。

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

15.3.3 Runtime Semantics: EvaluateConciseBody

構文指向操作 EvaluateConciseBody。引数 funcObj (ECMAScript 関数オブジェクト) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(return 完了 または throw 完了)。 次の生成規則ごとに定義される。

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

15.3.4 Runtime Semantics: InstantiateArrowFunctionExpression

構文指向操作 InstantiateArrowFunctionExpression。省略可能な引数 name ((プロパティキー または プライベート名))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

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

ArrowFunction は arguments、super、this、または new.target に対するローカル束縛を定義しません。ArrowFunction 内の arguments、super、this、または new.target への参照は、レキシカルに外側の環境内の束縛へ解決されなければなりません。通常、これは直近の外側の関数の Function Environment です。ArrowFunction が super への参照を含む場合でも、手順 5 で作成された関数オブジェクトは MakeMethod の実行によってメソッドにはされません。super を参照する ArrowFunction は常に非 ArrowFunction 内に含まれており、super を実装するために必要な状態には、ArrowFunction の関数オブジェクトが捕捉した envRecord を介してアクセスできます。

15.3.5 Runtime Semantics: Evaluation

ArrowFunction : ArrowParameters => ConciseBody
  1. ArrowFunction の InstantiateArrowFunctionExpression を返す。
ExpressionBody : AssignmentExpression
  1. exprRef を AssignmentExpression の ? 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

構文指向操作 HasDirectSuper。引数なし。戻り値:Boolean。 次の生成規則ごとに定義される。

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. UniqueFormalParameters Contains SuperCall が true である場合、true を返す。
  2. FunctionBody Contains SuperCall を返す。
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. FunctionBody Contains SuperCall を返す。
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. PropertySetParameterList Contains SuperCall が true である場合、true を返す。
  2. FunctionBody Contains SuperCall を返す。
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. UniqueFormalParameters Contains SuperCall が true である場合、true を返す。
  2. GeneratorBody Contains SuperCall を返す。
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. UniqueFormalParameters Contains SuperCall が true である場合、true を返す。
  2. AsyncGeneratorBody Contains SuperCall を返す。
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. UniqueFormalParameters Contains SuperCall が true である場合、true を返す。
  2. AsyncFunctionBody Contains SuperCall を返す。

15.4.3 Static Semantics: SpecialMethod

構文指向操作 SpecialMethod。引数なし。戻り値:Boolean。 次の生成規則ごとに定義される。

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

構文指向操作 DefineMethod。引数 obj (Object)および省略可能な引数 proto (Object)。戻り値:(正常完了 (値:レコード (フィールド:[[Key]] (プロパティキー), [[Closure]] (ECMAScript 関数オブジェクト))) または 中途完了)。 次の生成規則ごとに定義される。

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. propertyKey を ClassElementName の ? Evaluation とする。
  2. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. proto が存在しない場合、proto を %Function.prototype% に設定する。
  5. sourceText を MethodDefinition に一致するソーステキストとする。
  6. closure を OrdinaryFunctionCreate(proto, sourceText, UniqueFormalParameters, FunctionBody, non-lexical-this, envRecord, privateEnv) とする。
  7. MakeMethod(closure, obj) を実行する。
  8. Record { [[Key]]: propertyKey, [[Closure]]: closure } を返す。

15.4.5 Runtime Semantics: MethodDefinitionEvaluation

構文指向操作 MethodDefinitionEvaluation。引数 obj (Object) および enumerable (Boolean)。戻り値:(正常完了 (値:(PrivateElement または empty)) または 中途完了)。 次の生成規則ごとに定義される。

MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody }
  1. methodDef を、引数 obj を指定した MethodDefinition の ? DefineMethod とする。
  2. SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]]) を実行する。
  3. ? DefineMethodProperty(obj, methodDef.[[Key]], methodDef.[[Closure]], enumerable) を返す。
MethodDefinition : get ClassElementName ( ) { FunctionBody }
  1. propertyKey を ClassElementName の ? Evaluation とする。
  2. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceText を MethodDefinition に一致するソーステキストとする。
  5. formalParamList を生成規則 FormalParameters : [empty] のインスタンスとする。
  6. closure を OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParamList, FunctionBody, non-lexical-this, envRecord, privateEnv) とする。
  7. MakeMethod(closure, obj) を実行する。
  8. SetFunctionName(closure, propertyKey, "get") を実行する。
  9. propertyKey が Private Name である場合、
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Getter]]: closure, [[Setter]]: undefined } を返す。
  10. propertyDesc を PropertyDescriptor { [[Getter]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true } とする。
  11. ? DefinePropertyOrThrow(obj, propertyKey, propertyDesc) を実行する。
  12. empty を返す。
MethodDefinition : set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. propertyKey を ClassElementName の ? Evaluation とする。
  2. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceText を MethodDefinition に一致するソーステキストとする。
  5. closure を OrdinaryFunctionCreate(%Function.prototype%, sourceText, PropertySetParameterList, FunctionBody, non-lexical-this, envRecord, privateEnv) とする。
  6. MakeMethod(closure, obj) を実行する。
  7. SetFunctionName(closure, propertyKey, "set") を実行する。
  8. propertyKey が Private Name である場合、
    1. PrivateElement { [[Key]]: propertyKey, [[Kind]]: accessor, [[Getter]]: undefined, [[Setter]]: closure } を返す。
  9. propertyDesc を PropertyDescriptor { [[Setter]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true } とする。
  10. ? DefinePropertyOrThrow(obj, propertyKey, propertyDesc) を実行する。
  11. empty を返す。
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. propertyKey を ClassElementName の ? Evaluation とする。
  2. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceText を GeneratorMethod に一致するソーステキストとする。
  5. closure を OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, UniqueFormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv) とする。
  6. MakeMethod(closure, obj) を実行する。
  7. SetFunctionName(closure, propertyKey) を実行する。
  8. proto を OrdinaryObjectCreate(%GeneratorPrototype%) とする。
  9. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  10. ? DefineMethodProperty(obj, propertyKey, closure, enumerable) を返す。
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. propertyKey を ClassElementName の ? Evaluation とする。
  2. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceText を AsyncGeneratorMethod に一致するソーステキストとする。
  5. closure を OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, UniqueFormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv) とする。
  6. MakeMethod(closure, obj) を実行する。
  7. SetFunctionName(closure, propertyKey) を実行する。
  8. proto を OrdinaryObjectCreate(%AsyncGeneratorPrototype%) とする。
  9. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  10. ? DefineMethodProperty(obj, propertyKey, closure, enumerable) を返す。
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. propertyKey を ClassElementName の ? Evaluation とする。
  2. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceText を AsyncMethod に一致するソーステキストとする。
  5. closure を OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, UniqueFormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv) とする。
  6. MakeMethod(closure, obj) を実行する。
  7. SetFunctionName(closure, propertyKey) を実行する。
  8. ? DefineMethodProperty(obj, propertyKey, closure, enumerable) を返す。

15.5 ジェネレーター関数定義

構文

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] 注 1

yield の直後の構文文脈では、InputElementRegExpOrTemplateTail 字句目標を使用する必要があります。

注 2

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

注 3

Generator に関連する抽象操作は 27.8.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

構文指向操作 EvaluateGeneratorBody。引数 funcObj (ECMAScript 関数オブジェクト) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(throw 完了 または return 完了)。 次の生成規則ごとに定義される。

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

15.5.3 Runtime Semantics: InstantiateGeneratorFunctionObject

構文指向操作 InstantiateGeneratorFunctionObject。引数 envRecord (Environmentレコード) および privateEnv ((PrivateEnvironmentレコード または null))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. name を BindingIdentifier の StringValue とする。
  2. sourceText を GeneratorDeclaration に一致するソーステキストとする。
  3. closure を OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv) とする。
  4. SetFunctionName(closure, name) を実行する。
  5. proto を OrdinaryObjectCreate(%GeneratorPrototype%) とする。
  6. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  7. closure を返す。
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. sourceText を GeneratorDeclaration に一致するソーステキストとする。
  2. closure を OrdinaryFunctionCreate(%GeneratorFunction.prototype%, sourceText, FormalParameters, GeneratorBody, non-lexical-this, envRecord, privateEnv) とする。
  3. SetFunctionName(closure, "default") を実行する。
  4. proto を OrdinaryObjectCreate(%GeneratorPrototype%) とする。
  5. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  6. closure を返す。
注

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

15.5.4 Runtime Semantics: InstantiateGeneratorFunctionExpression

構文指向操作 InstantiateGeneratorFunctionExpression。省略可能な引数 name ((プロパティキー または プライベート名))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

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

GeneratorExpression 内の BindingIdentifier は、ジェネレーターコードが自身を再帰的に呼び出せるように、GeneratorExpression の FunctionBody の内部から参照できます。ただし、GeneratorDeclaration とは異なり、GeneratorExpression 内の BindingIdentifier は GeneratorExpression を囲むスコープから参照することはできず、そのスコープにも影響を与えません。

15.5.5 Runtime Semantics: Evaluation

GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody }
  1. GeneratorExpression の InstantiateGeneratorFunctionExpression を返す。
YieldExpression : yield
  1. ? Yield(undefined) を返す。
YieldExpression : yield AssignmentExpression
  1. exprRef を AssignmentExpression の ? Evaluation とする。
  2. value を ? GetValue(exprRef) とする。
  3. ? Yield(value) を返す。
YieldExpression : yield * AssignmentExpression
  1. genKind を GetGeneratorKind() とする。
  2. 表明: genKind は sync または async のいずれかである。
  3. exprRef を AssignmentExpression の ? Evaluation とする。
  4. value を ? GetValue(exprRef) とする。
  5. iteratorRecord を ? GetIterator(value, genKind) とする。
  6. iterator を iteratorRecord.[[Iterator]] とする。
  7. received を NormalCompletion(undefined) とする。
  8. 次を繰り返す。
    1. received が正常完了である場合、
      1. innerResult を ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] ») とする。
      2. genKind が async である場合、innerResult を ? Await(innerResult) に設定する。
      3. innerResult が Object でない場合、TypeError 例外をスローする。
      4. done を ? IteratorComplete(innerResult) とする。
      5. done が true である場合、
        1. ? IteratorValue(innerResult) を返す。
      6. genKind が async である場合、received を Completion(AsyncGeneratorYield(? IteratorValue(innerResult))) に設定する。
      7. そうでない場合、received を Completion(GeneratorYield(innerResult)) に設定する。
    2. そうでなく、received がスロー完了である場合、
      1. throw を ? GetMethod(iterator, "throw") とする。
      2. throw が undefined でない場合、
        1. innerResult を ? Call(throw, iterator, « received.[[Value]] ») とする。
        2. genKind が async である場合、innerResult を ? Await(innerResult) に設定する。
        3. 注記: 内側のイテレーターの throw メソッドからの例外は伝播される。内側の throw メソッドからの正常完了は、内側の next と同様に処理される。
        4. innerResult が Object でない場合、TypeError 例外をスローする。
        5. done を ? IteratorComplete(innerResult) とする。
        6. done が true である場合、
          1. ? IteratorValue(innerResult) を返す。
        7. genKind が async である場合、received を Completion(AsyncGeneratorYield(? IteratorValue(innerResult))) に設定する。
        8. そうでない場合、received を Completion(GeneratorYield(innerResult)) に設定する。
      3. そうでない場合、
        1. 注記: iterator が throw メソッドを持たない場合、このスローによって yield* ループは終了する。ただし、まず iterator にクリーンアップの機会を与える必要がある。
        2. closeCompletion を NormalCompletion(empty) とする。
        3. genKind が async である場合、? AsyncIteratorClose(iteratorRecord, closeCompletion) を実行する。
        4. そうでない場合、? IteratorClose(iteratorRecord, closeCompletion) を実行する。
        5. 注記: 次の手順では、yield* プロトコル違反、すなわち iterator が throw メソッドを持たないことを示すために TypeError をスローする。
        6. TypeError 例外をスローする。
    3. そうでない場合、
      1. 表明: received は return 完了である。
      2. return を ? GetMethod(iterator, "return") とする。
      3. return が undefined である場合、
        1. receivedValue を received.[[Value]] とする。
        2. genKind が async である場合、
          1. receivedValue を ? Await(receivedValue) に設定する。
        3. ReturnCompletion(receivedValue) を返す。
      4. innerReturnResult を ? Call(return, iterator, « received.[[Value]] ») とする。
      5. genKind が async である場合、innerReturnResult を ? Await(innerReturnResult) に設定する。
      6. innerReturnResult が Object でない場合、TypeError 例外をスローする。
      7. done を ? IteratorComplete(innerReturnResult) とする。
      8. done が true である場合、
        1. returnedValue を ? IteratorValue(innerReturnResult) とする。
        2. ReturnCompletion(returnedValue) を返す。
      9. genKind が async である場合、received を Completion(AsyncGeneratorYield(? IteratorValue(innerReturnResult))) に設定する。
      10. そうでない場合、received を Completion(GeneratorYield(innerReturnResult)) に設定する。

15.6 Async ジェネレーター関数定義

構文

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] 注 1

YieldExpression および AwaitExpression は async ジェネレーター関数の FormalParameters 内では使用できません。FormalParameters の一部である式は、生成される AsyncGenerator が再開可能な状態になる前に評価されるためです。

注 2

AsyncGenerator に関連する抽象操作は 27.9.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

構文指向操作 EvaluateAsyncGeneratorBody。引数 funcObj (ECMAScript 関数オブジェクト) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(throw 完了 または return 完了)。 次の生成規則ごとに定義される。

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

15.6.3 Runtime Semantics: InstantiateAsyncGeneratorFunctionObject

構文指向操作 InstantiateAsyncGeneratorFunctionObject。引数 envRecord (Environmentレコード) および privateEnv ((PrivateEnvironmentレコード または null))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. name を BindingIdentifier の StringValue とする。
  2. sourceText を AsyncGeneratorDeclaration に一致するソーステキストとする。
  3. closure を OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv) とする。
  4. SetFunctionName(closure, name) を実行する。
  5. proto を OrdinaryObjectCreate(%AsyncGeneratorPrototype%) とする。
  6. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  7. closure を返す。
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. sourceText を AsyncGeneratorDeclaration に一致するソーステキストとする。
  2. closure を OrdinaryFunctionCreate(%AsyncGeneratorFunction.prototype%, sourceText, FormalParameters, AsyncGeneratorBody, non-lexical-this, envRecord, privateEnv) とする。
  3. SetFunctionName(closure, "default") を実行する。
  4. proto を OrdinaryObjectCreate(%AsyncGeneratorPrototype%) とする。
  5. ! DefinePropertyOrThrow(closure, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  6. closure を返す。
注

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

15.6.4 Runtime Semantics: InstantiateAsyncGeneratorFunctionExpression

構文指向操作 InstantiateAsyncGeneratorFunctionExpression。省略可能な引数 name ((プロパティキー または プライベート名))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

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

AsyncGeneratorExpression 内の BindingIdentifier は、ジェネレーターコードが自身を再帰的に呼び出せるように、AsyncGeneratorExpression の AsyncGeneratorBody の内部から参照できます。ただし、AsyncGeneratorDeclaration とは異なり、AsyncGeneratorExpression 内の BindingIdentifier は AsyncGeneratorExpression を囲むスコープから参照することはできず、そのスコープにも影響を与えません。

15.6.5 Runtime Semantics: Evaluation

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

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 注

クラス定義は常に strict モードコードです。

15.7.1 Static Semantics: 早期エラー

ClassTail : ClassHeritageopt { ClassBody } ClassBody : ClassElementList
  • ClassElementList の PrototypePropertyNameList に "constructor" が複数回含まれる場合、Syntax Error です。
  • ClassElementList の PrivateBoundIdentifiers に重複する項目が含まれる場合、Syntax Error です。ただし、その名前が getter に1回、setter に1回だけ使用され、それ以外の項目には存在せず、かつ getter と setter が両方とも static または両方とも非 static である場合を除きます。
ClassElement : MethodDefinition ClassElement : static MethodDefinition ClassElement : FieldDefinition ; ClassElement : static FieldDefinition ;
  • FieldDefinition の PropName が "prototype" または "constructor" のいずれかである場合、Syntax Error です。
FieldDefinition : ClassElementName Initializeropt ClassElementName : PrivateIdentifier ClassStaticBlockBody : ClassStaticBlockStatementList

15.7.2 Static Semantics: ClassElementKind

構文指向操作 ClassElementKind。引数なし。戻り値:(constructor-method、non-constructor-method または empty)。 次の生成規則ごとに定義される。

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 Static Semantics: ConstructorMethod

構文指向操作 ConstructorMethod。引数なし。戻り値:(a ClassElement Parse Node または empty)。 次の生成規則ごとに定義される。

ClassElementList : ClassElement
  1. ClassElement の ClassElementKind が constructor-method である場合、ClassElement を返す。
  2. empty を返す。
ClassElementList : ClassElementList ClassElement
  1. head を ClassElementList の ConstructorMethod とする。
  2. head が empty でない場合、head を返す。
  3. ClassElement の ClassElementKind が constructor-method である場合、ClassElement を返す。
  4. empty を返す。
注

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

15.7.4 Static Semantics: IsStatic

構文指向操作 IsStatic。引数なし。戻り値:Boolean。 次の生成規則ごとに定義される。

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

構文指向操作 NonConstructorElements。引数なし。戻り値:リスト (要素:ClassElement Parse Nodes)。 次の生成規則ごとに定義される。

ClassElementList : ClassElement
  1. ClassElement の ClassElementKind が non-constructor-method である場合、
    1. « ClassElement » を返す。
  2. 新しい空の List を返す。
ClassElementList : ClassElementList ClassElement
  1. list を ClassElementList の NonConstructorElements とする。
  2. ClassElement の ClassElementKind が non-constructor-method である場合、
    1. ClassElement を list に追加する。
  3. list を返す。

15.7.6 Static Semantics: PrototypePropertyNameList

構文指向操作 PrototypePropertyNameList。引数なし。戻り値:リスト (要素:プロパティキー)。 次の生成規則ごとに定義される。

ClassElementList : ClassElement
  1. propertyName を ClassElement の PropName とする。
  2. propertyName が empty である場合、新しい空の List を返す。
  3. ClassElement の IsStatic が true である場合、新しい空の List を返す。
  4. « propertyName » を返す。
ClassElementList : ClassElementList ClassElement
  1. list を ClassElementList の PrototypePropertyNameList とする。
  2. propertyName を ClassElement の PropName とする。
  3. propertyName が empty である場合、list を返す。
  4. ClassElement の IsStatic が true である場合、list を返す。
  5. list と « propertyName » のリスト連結を返す。

15.7.7 Static Semantics: AllPrivateIdentifiersValid

構文指向操作 AllPrivateIdentifiersValid。引数 names (リスト (要素:String))。戻り値:Boolean。

以下に列挙されていない、この仕様内のすべての文法生成規則の選択肢は、暗黙的に次の AllPrivateIdentifiersValid の既定定義を持ちます。

  1. この Parse Node の各子ノード child について、次を行う。
    1. child が非終端記号のインスタンスである場合、
      1. 引数 names を指定した child の AllPrivateIdentifiersValid が false である場合、false を返す。
  2. true を返す。
MemberExpression : MemberExpression . PrivateIdentifier
  1. names が PrivateIdentifier の StringValue を含む場合、
    1. 引数 names を指定した MemberExpression の AllPrivateIdentifiersValid を返す。
  2. false を返す。
CallExpression : CallExpression . PrivateIdentifier
  1. names が PrivateIdentifier の StringValue を含む場合、
    1. 引数 names を指定した CallExpression の AllPrivateIdentifiersValid を返す。
  2. false を返す。
OptionalChain : ?. PrivateIdentifier
  1. names が PrivateIdentifier の StringValue を含む場合、true を返す。
  2. false を返す。
OptionalChain : OptionalChain . PrivateIdentifier
  1. names が PrivateIdentifier の StringValue を含む場合、
    1. 引数 names を指定した OptionalChain の AllPrivateIdentifiersValid を返す。
  2. false を返す。
ClassBody : ClassElementList
  1. newNames を names と ClassBody の PrivateBoundIdentifiers のリスト連結とする。
  2. 引数 newNames を指定した ClassElementList の AllPrivateIdentifiersValid を返す。
RelationalExpression : PrivateIdentifier in ShiftExpression
  1. names が PrivateIdentifier の StringValue を含む場合、
    1. 引数 names を指定した ShiftExpression の AllPrivateIdentifiersValid を返す。
  2. false を返す。

15.7.8 Static Semantics: PrivateBoundIdentifiers

構文指向操作 PrivateBoundIdentifiers。引数なし。戻り値:リスト (要素:String)。 次の生成規則ごとに定義される。

FieldDefinition : ClassElementName Initializeropt
  1. ClassElementName の PrivateBoundIdentifiers を返す。
ClassElementName : PrivateIdentifier
  1. 唯一の要素が PrivateIdentifier の StringValue である List を返す。
ClassElementName : PropertyName ClassElement : ClassStaticBlock ;
  1. 新しい空の List を返す。
ClassElementList : ClassElementList ClassElement
  1. names1 を ClassElementList の PrivateBoundIdentifiers とする。
  2. names2 を ClassElement の PrivateBoundIdentifiers とする。
  3. names1 と names2 のリスト連結を返す。
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 Static Semantics: ContainsArguments

構文指向操作 ContainsArguments。引数なし。戻り値:Boolean。

以下に列挙されていない、この仕様内のすべての文法生成規則の選択肢は、暗黙的に次の ContainsArguments の既定定義を持ちます。

  1. この Parse Node の各子ノード child について、次を行う。
    1. child が非終端記号のインスタンスである場合、
      1. child の ContainsArguments が 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. ClassElementName の ContainsArguments を返す。

15.7.10 Runtime Semantics: ClassFieldDefinitionEvaluation

構文指向操作 ClassFieldDefinitionEvaluation。引数 homeObj (Object)。戻り値:(正常完了 (値:ClassFieldDefinitionレコード) または 中途完了)。 次の生成規則ごとに定義される。

FieldDefinition : ClassElementName Initializeropt
  1. name を ClassElementName の ? Evaluation とする。
  2. Initializer が存在する場合、
    1. formalParamList を生成規則 FormalParameters : [empty] のインスタンスとする。
    2. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
    3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
    4. sourceText を Unicode コードポイントの空の列とする。
    5. initializer を OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParamList, Initializer, non-lexical-this, envRecord, privateEnv) とする。
    6. MakeMethod(initializer, homeObj) を実行する。
    7. initializer.[[ClassFieldInitializerName]] を name に設定する。
  3. そうでない場合、
    1. initializer を empty とする。
  4. ClassFieldDefinition Record { [[Name]]: name, [[Initializer]]: initializer } を返す。
注
initializer のために作成された関数は、ECMAScript コードから直接アクセスされることはありません。

15.7.11 Runtime Semantics: ClassStaticBlockDefinitionEvaluation

構文指向操作 ClassStaticBlockDefinitionEvaluation。引数 homeObj (Object)。戻り値:ClassStaticBlockDefinitionレコード。 次の生成規則ごとに定義される。

ClassStaticBlock : static { ClassStaticBlockBody }
  1. lexicalEnv を実行中の実行コンテキストの LexicalEnvironment とする。
  2. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  3. sourceText を Unicode コードポイントの空の列とする。
  4. formalParams を生成規則 FormalParameters : [empty] のインスタンスとする。
  5. bodyFunc を OrdinaryFunctionCreate(%Function.prototype%, sourceText, formalParams, ClassStaticBlockBody, non-lexical-this, lexicalEnv, privateEnv) とする。
  6. MakeMethod(bodyFunc, homeObj) を実行する。
  7. ClassStaticBlockDefinition Record { [[BodyFunction]]: bodyFunc } を返す。
注
関数 bodyFunc は ECMAScript コードから直接アクセスされることはありません。

15.7.12 Runtime Semantics: EvaluateClassStaticBlockBody

構文指向操作 EvaluateClassStaticBlockBody。引数 funcObj (ECMAScript 関数オブジェクト)。戻り値:(return 完了 または throw 完了)。 次の生成規則ごとに定義される。

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. 表明: funcObj は ClassStaticBlockDefinitionEvaluation の手順 5 によって作成された合成関数である。
  2. ! FunctionDeclarationInstantiation(funcObj, « ») を実行する。
  3. result を Completion(ClassStaticBlockStatementList の Evaluation) とする。
  4. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  5. 表明: envRecord は Declarative Environment Record である。
  6. ? DisposeResources(envRecord.[[DisposableResourceStack]], result) を実行する。
  7. ReturnCompletion(undefined) を返す。

15.7.13 Runtime Semantics: ClassElementEvaluation

構文指向操作 ClassElementEvaluation。引数 obj (Object)。戻り値:(正常完了 (値:(ClassFieldDefinitionレコード、ClassStaticBlockDefinitionレコード、PrivateElement または empty)) または 中途完了)。 次の生成規則ごとに定義される。

ClassElement : FieldDefinition ; static FieldDefinition ;
  1. 引数 obj を指定した FieldDefinition の ? ClassFieldDefinitionEvaluation を返す。
ClassElement : MethodDefinition static MethodDefinition
  1. 引数 obj および false を指定した MethodDefinition の ? MethodDefinitionEvaluation を返す。
ClassElement : ClassStaticBlock
  1. 引数 obj を指定した ClassStaticBlock の ClassStaticBlockDefinitionEvaluation を返す。
ClassElement : ;
  1. empty を返す。

15.7.14 Runtime Semantics: ClassDefinitionEvaluation

構文指向操作 ClassDefinitionEvaluation。引数 classBinding ((String または undefined))、className ((プロパティキー または プライベート名)) および sourceText (ECMAScript ソーステキスト)。戻り値:(正常完了 (値:関数オブジェクト) または 中途完了)。

注

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

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

これはプライベートフィールドとは異なります。フィールド初期化子はクラスのインスタンス化中にスローする可能性があるため、個々のオブジェクトが特定のクラスのプライベートフィールドの真部分集合のみを持つ場合があり、そのため一般にプライベートフィールドは個別に追跡しなければなりません。

次の生成規則ごとに定義される。

ClassTail : ClassHeritageopt { ClassBodyopt }
  1. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  2. classEnv を NewDeclarativeEnvironment(envRecord) とする。
  3. classBinding が undefined でない場合、
    1. ! classEnv.CreateImmutableBinding(classBinding, true) を実行する。
  4. outerPrivateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  5. classPrivateEnv を NewPrivateEnvironment(outerPrivateEnv) とする。
  6. ClassBody が存在する場合、
    1. ClassBody の PrivateBoundIdentifiers の各 String description について、次を行う。
      1. classPrivateEnv.[[Names]] が、privateName.[[Description]] が description である Private Name privateName を含む場合、
        1. 表明: これは getter/setter の組に対してのみ可能である。
      2. そうでない場合、
        1. name を [[Description]] が description である新しい Private Name とする。
        2. name を classPrivateEnv.[[Names]] に追加する。
  7. ClassHeritage が存在しない場合、
    1. protoParent を %Object.prototype% とする。
    2. ctorParent を %Function.prototype% とする。
  8. そうでない場合、
    1. 実行中の実行コンテキストの LexicalEnvironment を classEnv に設定する。
    2. 注記: ClassHeritage を評価するとき、実行中の実行コンテキストの PrivateEnvironment は outerPrivateEnv である。
    3. superclassRef を Completion(ClassHeritage の Evaluation) とする。
    4. 実行中の実行コンテキストの LexicalEnvironment を envRecord に設定する。
    5. superclass を ? GetValue(? superclassRef) とする。
    6. superclass が null である場合、
      1. protoParent を null とする。
      2. ctorParent を %Function.prototype% とする。
    7. そうでなく、IsConstructor(superclass) が false である場合、
      1. TypeError 例外をスローする。
    8. そうでない場合、
      1. protoParent を ? Get(superclass, "prototype") とする。
      2. protoParent が Object でなく、かつ protoParent が null でない場合、TypeError 例外をスローする。
      3. ctorParent を superclass とする。
  9. proto を OrdinaryObjectCreate(protoParent) とする。
  10. ClassBody が存在しない場合、ctor を empty とする。
  11. そうでない場合、ctor を ClassBody の ConstructorMethod とする。
  12. 実行中の実行コンテキストの LexicalEnvironment を classEnv に設定する。
  13. 実行中の実行コンテキストの PrivateEnvironment を classPrivateEnv に設定する。
  14. ctor が empty である場合、
    1. defaultCtor を、パラメーターを持たず何も捕捉せず、呼び出されたときに次の手順を実行する新しい Abstract Closure とする。
      1. args を [[Call]] または [[Construct]] によってこの関数へ渡された引数の List とする。
      2. NewTarget が undefined である場合、TypeError 例外をスローする。
      3. ctorFunc をアクティブな関数オブジェクトとする。
      4. ctorFunc.[[ConstructorKind]] が derived である場合、
        1. 注記: この分岐は constructor(...args) { super(...args); } と同様に動作する。最も重要な違いは、前述の ECMAScript ソーステキストでは %Array.prototype% 上の %Symbol.iterator% メソッドが観測可能な形で呼び出されるのに対し、この関数では呼び出されないことである。
        2. func を ! ctorFunc.[[GetPrototypeOf]]() とする。
        3. IsConstructor(func) が false である場合、TypeError 例外をスローする。
        4. result を ? Construct(func, args, NewTarget) とする。
      5. そうでない場合、
        1. 注記: この分岐は constructor() {} と同様に動作する。
        2. result を ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%") とする。
      6. ? InitializeInstanceElements(result, ctorFunc) を実行する。
      7. NormalCompletion(result) を返す。
    2. ctorFunc を CreateBuiltinFunction(defaultCtor, 0, className, « [[ConstructorKind]], [[SourceText]], [[PrivateMethods]], [[Fields]] », 現在の Realm Record, ctorParent) とする。
  15. そうでない場合、
    1. ctorInfo を、引数 proto および ctorParent を指定した ctor の ! DefineMethod とする。
    2. ctorFunc を ctorInfo.[[Closure]] とする。
    3. MakeClassConstructor(ctorFunc) を実行する。
    4. SetFunctionName(ctorFunc, className) を実行する。
  16. ctorFunc.[[SourceText]] を sourceText に設定する。
  17. MakeConstructor(ctorFunc, false, proto) を実行する。
  18. ClassHeritage が存在する場合、ctorFunc.[[ConstructorKind]] を derived に設定する。
  19. ! DefineMethodProperty(proto, "constructor", ctorFunc, false) を実行する。
  20. ClassBody が存在しない場合、classElements を新しい空の List とする。
  21. そうでない場合、classElements を ClassBody の NonConstructorElements とする。
  22. instancePrivateMethods を新しい空の List とする。
  23. staticPrivateMethods を新しい空の List とする。
  24. instanceFields を新しい空の List とする。
  25. staticElements を新しい空の List とする。
  26. classElements の各 ClassElement classElement について、次を行う。
    1. classElement の IsStatic が false である場合、
      1. element を Completion(引数 proto を指定した classElement の ClassElementEvaluation) とする。
    2. そうでない場合、
      1. element を Completion(引数 ctorFunc を指定した classElement の ClassElementEvaluation) とする。
    3. element が中断完了である場合、
      1. 実行中の実行コンテキストの LexicalEnvironment を envRecord に設定する。
      2. 実行中の実行コンテキストの PrivateEnvironment を outerPrivateEnv に設定する。
      3. ? element を返す。
    4. element を ! element に設定する。
    5. element が PrivateElement である場合、
      1. 表明: element.[[Kind]] は method または accessor のいずれかである。
      2. classElement の IsStatic が false である場合、container を instancePrivateMethods とする。
      3. そうでない場合、container を staticPrivateMethods とする。
      4. container が、existingElement.[[Key]] が element.[[Key]] である PrivateElement existingElement を含む場合、
        1. 表明: element.[[Kind]] と existingElement.[[Kind]] はどちらも accessor である。
        2. element.[[Getter]] が undefined である場合、
          1. combined を PrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Getter]]: existingElement.[[Getter]], [[Setter]]: element.[[Setter]] } とする。
        3. そうでない場合、
          1. combined を PrivateElement { [[Key]]: element.[[Key]], [[Kind]]: accessor, [[Getter]]: element.[[Getter]], [[Setter]]: existingElement.[[Setter]] } とする。
        4. container 内の existingElement を combined に置換する。
      5. そうでない場合、
        1. element を container に追加する。
    6. そうでなく、element が ClassFieldDefinition Record である場合、
      1. classElement の IsStatic が false である場合、element を instanceFields に追加する。
      2. そうでない場合、element を staticElements に追加する。
    7. そうでなく、element が ClassStaticBlockDefinition Record である場合、
      1. element を staticElements に追加する。
    8. そうでない場合、
      1. 表明: element は empty である。
  27. 実行中の実行コンテキストの LexicalEnvironment を envRecord に設定する。
  28. classBinding が undefined でない場合、
    1. ! classEnv.InitializeBinding(classBinding, ctorFunc) を実行する。
  29. ctorFunc.[[PrivateMethods]] を instancePrivateMethods に設定する。
  30. ctorFunc.[[Fields]] を instanceFields に設定する。
  31. staticPrivateMethods の各 PrivateElement method について、次を行う。
    1. ! PrivateMethodOrAccessorAdd(ctorFunc, method) を実行する。
  32. staticElements の各要素 elementRecord について、次を行う。
    1. elementRecord が ClassFieldDefinition Record である場合、
      1. result を Completion(DefineField(ctorFunc, elementRecord)) とする。
    2. そうでない場合、
      1. 表明: elementRecord は ClassStaticBlockDefinition Record である。
      2. result を Completion(Call(elementRecord.[[BodyFunction]], ctorFunc)) とする。
    3. result が中断完了である場合、
      1. 実行中の実行コンテキストの PrivateEnvironment を outerPrivateEnv に設定する。
      2. ? result を返す。
  33. 実行中の実行コンテキストの PrivateEnvironment を outerPrivateEnv に設定する。
  34. ctorFunc を返す。

15.7.15 Runtime Semantics: BindingClassDeclarationEvaluation

構文指向操作 BindingClassDeclarationEvaluation。引数なし。戻り値:(正常完了 (値:関数オブジェクト) または 中途完了)。 次の生成規則ごとに定義される。

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

ClassDeclaration : class ClassTail は ExportDeclaration の一部としてのみ現れ、その束縛の確立はその生成規則の評価動作の一部として処理されます。16.2.3.7 を参照してください。

15.7.16 Runtime Semantics: Evaluation

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

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

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

15.8 Async 関数定義

構文

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] 注 1

[Await] パラメーターが存在する場合、await は AwaitExpression のキーワードとして構文解析されます。[Await] パラメーターは次の文脈のトップレベルに存在しますが、FunctionBody などの非終端記号によっては一部の文脈でパラメーターが存在しない場合があります。

Script が構文上の目標記号である場合、[Await] パラメーターが存在しないとき、await は識別子として構文解析される場合があります。これには次の文脈が含まれます。

注 2

YieldExpression とは異なり、AwaitExpression のオペランドを省略すると Syntax Error です。何かを 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

構文指向操作 InstantiateAsyncFunctionObject。引数 envRecord (Environmentレコード) および privateEnv ((PrivateEnvironmentレコード または null))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

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

15.8.3 Runtime Semantics: InstantiateAsyncFunctionExpression

構文指向操作 InstantiateAsyncFunctionExpression。省略可能な引数 name ((プロパティキー または プライベート名))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. name が存在しない場合、name を空の String に設定する。
  2. envRecord を実行中の実行コンテキストの LexicalEnvironment とする。
  3. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  4. sourceText を AsyncFunctionExpression に一致するソーステキストとする。
  5. closure を OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, envRecord, privateEnv) とする。
  6. SetFunctionName(closure, name) を実行する。
  7. closure を返す。
AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. 表明: name は存在しない。
  2. name を BindingIdentifier の StringValue に設定する。
  3. outerEnv を実行中の実行コンテキストの LexicalEnvironment とする。
  4. funcEnv を NewDeclarativeEnvironment(outerEnv) とする。
  5. ! funcEnv.CreateImmutableBinding(name, false) を実行する。
  6. privateEnv を実行中の実行コンテキストの PrivateEnvironment とする。
  7. sourceText を AsyncFunctionExpression に一致するソーステキストとする。
  8. closure を OrdinaryFunctionCreate(%AsyncFunction.prototype%, sourceText, FormalParameters, AsyncFunctionBody, non-lexical-this, funcEnv, privateEnv) とする。
  9. SetFunctionName(closure, name) を実行する。
  10. ! funcEnv.InitializeBinding(name, closure) を実行する。
  11. closure を返す。
注

AsyncFunctionExpression 内の BindingIdentifier は、関数自身を再帰的に呼び出せるように、AsyncFunctionExpression の AsyncFunctionBody の内部から参照できます。ただし、FunctionDeclaration とは異なり、AsyncFunctionExpression 内の BindingIdentifier は AsyncFunctionExpression を囲むスコープから参照することはできず、そのスコープにも影響を与えません。

15.8.4 Runtime Semantics: EvaluateAsyncFunctionBody

構文指向操作 EvaluateAsyncFunctionBody。引数 funcObj (ECMAScript 関数オブジェクト) および argList (リスト (要素:ECMAScript 言語値))。戻り値:return 完了。 次の生成規則ごとに定義される。

AsyncFunctionBody : FunctionBody
  1. promiseCapability を ! NewPromiseCapability(%Promise%) とする。
  2. completion を Completion(FunctionDeclarationInstantiation(funcObj, argList)) とする。
  3. 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. AsyncFunctionExpression の InstantiateAsyncFunctionExpression を返す。
UnaryExpression : CoverAwaitExpressionAndAwaitUsingDeclarationHead
  1. expr を CoverAwaitExpressionAndAwaitUsingDeclarationHead によって被覆される AwaitExpression とする。
  2. expr の ? Evaluation を返す。
AwaitExpression : await UnaryExpression
  1. exprRef を UnaryExpression の ? Evaluation とする。
  2. value を ? GetValue(exprRef) とする。
  3. ? Await(value) を返す。

15.9 Async アロー関数定義

構文

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

構文指向操作 AsyncConciseBodyContainsUseStrict。引数なし。戻り値:Boolean。 次の生成規則ごとに定義される。

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

15.9.3 Runtime Semantics: EvaluateAsyncConciseBody

構文指向操作 EvaluateAsyncConciseBody。引数 funcObj (ECMAScript 関数オブジェクト) および argList (リスト (要素:ECMAScript 言語値))。戻り値:return 完了。 次の生成規則ごとに定義される。

AsyncConciseBody : ExpressionBody
  1. promiseCapability を ! NewPromiseCapability(%Promise%) とする。
  2. completion を Completion(FunctionDeclarationInstantiation(funcObj, argList)) とする。
  3. completion が中断完了である場合、
    1. ! Call(promiseCapability.[[Reject]], undefined, « completion.[[Value]] ») を実行する。
  4. そうでない場合、
    1. AsyncFunctionStart(promiseCapability, ExpressionBody) を実行する。
  5. ReturnCompletion(promiseCapability.[[Promise]]) を返す。

15.9.4 Runtime Semantics: InstantiateAsyncArrowFunctionExpression

構文指向操作 InstantiateAsyncArrowFunctionExpression。省略可能な引数 name ((プロパティキー または プライベート名))。戻り値:ECMAScript 関数オブジェクト。 次の生成規則ごとに定義される。

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

15.9.5 Runtime Semantics: Evaluation

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

15.10 末尾位置の呼出し

15.10.1 Static Semantics: IsInTailPosition ( call )

抽象操作 IsInTailPosition。引数 call ((a CallExpression Parse Node、a MemberExpression Parse Node または an OptionalChain Parse Node))。戻り値:Boolean。 呼び出されると、次の手順を実行する。

  1. IsStrict(call) が false である場合、false を返す。
  2. call が FunctionBody、ConciseBody、または AsyncConciseBody 内に含まれていない場合、false を返す。
  3. body を、call を最も近くで包含する FunctionBody、ConciseBody、または AsyncConciseBody とする。
  4. body が GeneratorBody の FunctionBody である場合、false を返す。
  5. body が AsyncFunctionBody の FunctionBody である場合、false を返す。
  6. body が AsyncGeneratorBody の FunctionBody である場合、false を返す。
  7. body が AsyncConciseBody である場合、false を返す。
  8. 引数 call を指定した body の HasCallInTailPosition の結果を返す。
注

末尾位置の呼出しが定義されるのは strict モードコード内だけです。これは、呼出し元コンテキストの連鎖を観測できるようにする一般的な非標準言語拡張(10.2.4 を参照)が存在するためです。

15.10.2 Static Semantics: HasCallInTailPosition

構文指向操作 HasCallInTailPosition。引数 call ((a CallExpression Parse Node、a MemberExpression Parse Node または an OptionalChain Parse Node))。戻り値:Boolean。

注 1

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

注 2

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

注 3

同じ Block、ForStatement、ForInOfStatement、FunctionBody、GeneratorBody、AsyncGeneratorBody、AsyncFunctionBody、または ClassStaticBlockBody 内で、呼出しより前に using 宣言または await using 宣言がある場合、その呼出しは末尾位置呼出しになることができません。

次の生成規則ごとに定義される。

StatementList : StatementList StatementListItem
  1. has を、引数 call を指定した派生 StatementList の HasCallInTailPosition とする。
  2. has が true である場合、true を返す。
  3. 派生 StatementList の ContainsUsing が true である場合、false を返す。
  4. 引数 call を指定した StatementListItem の HasCallInTailPosition を返す。
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 を指定した最初の Statement の HasCallInTailPosition とする。
  2. has が true である場合、true を返す。
  3. 引数 call を指定した2番目の Statement の HasCallInTailPosition を返す。
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 を指定した Statement の HasCallInTailPosition を返す。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 引数 call を指定した LabelledItem の HasCallInTailPosition を返す。
ReturnStatement : return Expression ;
  1. 引数 call を指定した Expression の HasCallInTailPosition を返す。
SwitchStatement : switch ( Expression ) CaseBlock
  1. 引数 call を指定した CaseBlock の HasCallInTailPosition を返す。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. has を false とする。
  2. 最初の CaseClauses が存在する場合、has を、引数 call を指定した最初の CaseClauses の HasCallInTailPosition に設定する。
  3. has が true である場合、true を返す。
  4. has を、引数 call を指定した DefaultClause の HasCallInTailPosition に設定する。
  5. has が true である場合、true を返す。
  6. 2番目の CaseClauses が存在する場合、has を、引数 call を指定した2番目の CaseClauses の HasCallInTailPosition に設定する。
  7. has を返す。
CaseClauses : CaseClauses CaseClause
  1. has を、引数 call を指定した CaseClauses の HasCallInTailPosition とする。
  2. has が true である場合、true を返す。
  3. 引数 call を指定した CaseClause の HasCallInTailPosition を返す。
CaseClause : case Expression : StatementListopt DefaultClause : default : StatementListopt
  1. StatementList が存在する場合、引数 call を指定した StatementList の HasCallInTailPosition を返す。
  2. false を返す。
TryStatement : try Block Catch
  1. 引数 call を指定した Catch の HasCallInTailPosition を返す。
TryStatement : try Block Finally try Block Catch Finally
  1. 引数 call を指定した Finally の HasCallInTailPosition を返す。
Catch : catch ( CatchParameter ) Block
  1. 引数 call を指定した Block の HasCallInTailPosition を返す。
AssignmentExpression : YieldExpression ArrowFunction AsyncArrowFunction LeftHandSideExpression = AssignmentExpression LeftHandSideExpression AssignmentOperator AssignmentExpression LeftHandSideExpression &&= AssignmentExpression LeftHandSideExpression ||= AssignmentExpression LeftHandSideExpression ??= AssignmentExpression BitwiseANDExpression : BitwiseANDExpression & EqualityExpression BitwiseXORExpression : BitwiseXORExpression ^ BitwiseANDExpression BitwiseORExpression : BitwiseORExpression | BitwiseXORExpression EqualityExpression : EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression EqualityExpression === RelationalExpression EqualityExpression !== RelationalExpression RelationalExpression : RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ShiftExpression RelationalExpression in ShiftExpression PrivateIdentifier in ShiftExpression ShiftExpression : ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression AdditiveExpression : AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator ExponentiationExpression ExponentiationExpression : UpdateExpression ** ExponentiationExpression UpdateExpression : LeftHandSideExpression ++ LeftHandSideExpression -- ++ UnaryExpression -- UnaryExpression UnaryExpression : delete UnaryExpression void UnaryExpression typeof UnaryExpression + UnaryExpression - UnaryExpression ~ UnaryExpression ! UnaryExpression CoverAwaitExpressionAndAwaitUsingDeclarationHead CallExpression : SuperCall ImportCall CallExpression [ Expression ] CallExpression . IdentifierName CallExpression . PrivateIdentifier NewExpression : new NewExpression MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier PrimaryExpression : this IdentifierReference Literal ArrayLiteral ObjectLiteral FunctionExpression ClassExpression GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral
  1. false を返す。
Expression : AssignmentExpression Expression , AssignmentExpression
  1. 引数 call を指定した AssignmentExpression の HasCallInTailPosition を返す。
ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
  1. has を、引数 call を指定した最初の AssignmentExpression の HasCallInTailPosition とする。
  2. has が true である場合、true を返す。
  3. 引数 call を指定した2番目の AssignmentExpression の HasCallInTailPosition を返す。
LogicalANDExpression : LogicalANDExpression && BitwiseORExpression
  1. 引数 call を指定した BitwiseORExpression の HasCallInTailPosition を返す。
LogicalORExpression : LogicalORExpression || LogicalANDExpression
  1. 引数 call を指定した LogicalANDExpression の HasCallInTailPosition を返す。
CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression
  1. 引数 call を指定した BitwiseORExpression の HasCallInTailPosition を返す。
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments CallExpression TemplateLiteral
  1. この CallExpression が call である場合、true を返す。
  2. false を返す。
OptionalExpression : MemberExpression OptionalChain CallExpression OptionalChain OptionalExpression OptionalChain
  1. 引数 call を指定した OptionalChain の HasCallInTailPosition を返す。
OptionalChain : ?. [ Expression ] ?. IdentifierName ?. PrivateIdentifier OptionalChain [ Expression ] OptionalChain . IdentifierName OptionalChain . PrivateIdentifier
  1. false を返す。
OptionalChain : ?. Arguments OptionalChain Arguments
  1. この OptionalChain が call である場合、true を返す。
  2. false を返す。
MemberExpression : MemberExpression TemplateLiteral
  1. この MemberExpression が call である場合、true を返す。
  2. false を返す。
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. expr を CoverParenthesizedExpressionAndArrowParameterList によって被覆される ParenthesizedExpression とする。
  2. 引数 call を指定した expr の HasCallInTailPosition を返す。
ParenthesizedExpression : ( Expression )
  1. 引数 call を指定した Expression の HasCallInTailPosition を返す。

15.10.3 PrepareForTailCall ( )

抽象操作 PrepareForTailCall。引数なし。戻り値:unused。 呼び出されると、次の手順を実行する。

  1. 表明: 現在の実行コンテキストは、その後いかなる ECMAScript コードまたは組込み関数の評価にも使用されない。この抽象操作の呼出しに続く Call の呼出しは、そのような評価を実行する前に新しい実行コンテキストを作成してプッシュする。
  2. 現在の実行コンテキストに関連付けられたすべてのリソースを破棄する。
  3. unused を返す。

末尾位置の呼出しは、対象関数を呼び出す前に、現在実行中の関数の実行コンテキストに関連付けられた一時的な内部リソースを解放するか、対象関数をサポートするためにそれらのリソースを再利用しなければなりません。

注

たとえば、末尾位置の呼出しによって実装のアクティベーションレコードスタックが増加する量は、対象関数のアクティベーションレコードのサイズが呼出し元関数のアクティベーションレコードのサイズを超える分だけであるべきです。対象関数のアクティベーションレコードの方が小さい場合、スタック全体のサイズは減少するべきです。