このページはECMAScript® 2020 Language Specificationの 14 ECMAScript Language: Functions and Classes章をJavaScriptの学習目的で私的に日本語訳したものであり、直訳と意訳および推測が混在しています。そのため内容については正確ではない可能性があります。正確な情報を知りたい場合は、原文をご覧ください。また一部訳者によるコメントが含まれていることがあります。※このサイトの内容で損害や不利益を受けたとしても当方は一切の責任を負いません。
ECMAScript関数オブジェクトは、さまざまなECMAScript言語要素から作成されます(9.2)。 関数の評価は、[[Call]]内部メソッド(9.2.1)の実行から始まります。

14.1 関数定義(Function Definitions)

構文:

FunctionDeclaration[Yield, Await, Default] :

functionBindingIdentifier[?Yield, ?Await] (FormalParameters[~Yield, ~Await] ){FunctionBody[~Yield, ~Await] }
[+Default]function(FormalParameters[~Yield, ~Await] ){FunctionBody[~Yield, ~Await] }
FunctionExpression :

functionBindingIdentifier[~Yield, ~Await]opt (FormalParameters[~Yield, ~Await] ){FunctionBody[~Yield, ~Await] }
UniqueFormalParameters[Yield, Await] :

FormalParameters[?Yield, ?Await]
FormalParameters[Yield, Await] :

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]
FunctionBody[Yield, Await] :

FunctionStatementList[?Yield, ?Await]
FunctionStatementList[Yield, Await] :

StatementList[?Yield, ?Await, +Return]opt

14.1.1 ディレクティブプロローグと Use Strictディレクティブ

ディレクティブプロローグ

ディレクティブ(命令)プロローグは、FunctionBody、ScriptBody、ModuleBodyの最初のStatementListItemまたはModuleItemとして発生するExpressionStatementの最長シーケンスです。シーケンス内の各ExpressionStatementは完全なStringLiteralトークンとそれに続くセミコロンで構成されます。 セミコロンは明示的に記述される場合と、自動セミコロン挿入で挿入されることがあります。 ディレクティブプロローグは空のシーケンスである可能性があります。

Use Strictディレクティブ

Use Strictディレクティブは、StringLiteralが "use strict" または 'use strict' に正確に一致するコードポイントシーケンスであるディレクティブプロローグのExpressionStatementです。 Use Strictディレクティブには、EscapeSequenceまたはLineContinuation
を含めることはできません。

ディレクティブプロローグには、複数のUse Strictディレクティブが含まれることがあります。 ただし、実装は警告を発行する場合があります。

通常、含まれているプロダクションの評価中に、ディレクティブプロローグのExpressionStatementは、評価されます。 実装は、ディレクティブプロローグで発生するExpressionStatementのUse Strictディレクティブではない、実装固有の意味を定義できます。 その際、実装は、意味を持たないExpressionStatementを検出したら、適切な通知メカニズムが存在するなら、警告を発行する必要があります。

14.1.2 静的セマンティクス:早期エラー(Static Semantics: Early Errors)

FunctionBodyのLexicallyDeclaredNamesには、var宣言または関数宣言を使用してバインドされた識別子は含まれていません。
  • FormalParameters の BoundNames に重複する要素が含まれているなら、構文エラー
単純なパラメーターリストを持ち、strictモードコードで定義されていない関数のときだけ、FormalParameterList で同じ BindingIdentifier が複数回出現することを許可されます。

14.1.3 静的セマンティクス(Static Semantics): BoundNames

  1. BindingIdentifier の BoundNames を返す
  1. « "*default*" » を返す
"*default*" は、export宣言を使用して定義されたホイスタブル無名関数の合成名として、この仕様内で使用されます。
  1. 空の新規List を返す
  1. FormalParameterList の BoundNames を names とする
  2. FunctionRestParameter の BoundNames を names に追加する
  3. names を返す
  1. FormalParameterList の BoundNames を names とする
  2. FormalParameter の BoundNames を names に追加する
  3. names を返す

14.1.4 静的セマンティクス(Static Semantics): Contains

引数 symbol を使用。

  1. false を返す
通常、下部構造に依存する静的セマンティックルールは、関数定義を調べません。

14.1.5 静的セマンティクス(Static Semantics): ContainsDuplicateLabels

引数 labelSet を使用。

  1. false を返す

14.1.6 静的セマンティクス(Static Semantics): ContainsExpression

  1. false を返す
  1. FormalParameterList の ContainsExpression が true なら、 true を返す
  2. FunctionRestParameter の ContainsExpression を返す
  1. FormalParameterList の ContainsExpression が true なら、 true を返す
  2. FormalParameter の ContainsExpression を返す

14.1.7 静的セマンティクス(Static Semantics): ContainsUndefinedBreakTarget

引数 labelSet を使用。

  1. false を返す

14.1.8 静的セマンティクス(Static Semantics): ContainsUndefinedContinueTarget

引数 iterationSet と labelSet を使用。

  1. false を返す

14.1.9 静的セマンティクス(Static Semantics): ContainsUseStrict

  1. FunctionBody の ディレクティブプロローグ に Use Strictディレクティブ が含まれているなら true を、含まれていないなら false を返す

14.1.10 静的セマンティクス(Static Semantics): ExpectedArgumentCount

  1. 0 を返す
  1. FormalParameterList の ExpectedArgumentCount を返す
FormalParameterListのExpectedArgumentCountは、レストパラメーターまたは初期化子を持つ最初のFormalParameterの左側にあるFormalParametersの数です。 初期化子のないFormalParameterは、初期化子のある最初のパラメーターの後に許可されますが、そのようなパラメーターはオプションと見なされ、デフォルト値はundefinedです。
  1. FormalParameter の HasInitializer が true なら、 0 を返す
  2. 1 を返す
  1. FormalParameterList の ExpectedArgumentCount を count とする
  2. FormalParameterList の HasInitializer が true または、 FormalParameter の HasInitializer が true なら count を返す
  3. count + 1 を返す

14.1.11 静的セマンティクス(Static Semantics): HasInitializer

  1. FormalParameterList の HasInitializer が true なら、 true を返す
  2. FormalParameter の HasInitializer を返す

14.1.12 静的セマンティクス(Static Semantics): HasName

  1. false を返す
  1. true を返す

14.1.13 静的セマンティクス(Static Semantics): IsAnonymousFunctionDefinition ( expr )

抽象操作IsAnonymousFunctionDefinitionは、exprが名前をバインドしない関数定義であるかどうかを判別します。 引数exprは、AssignmentExpressionまたはInitializerを解析した結果です。 次の手順が実行されます。

  1. expr の IsFunctionDefinition が false なら、 false を返す
  2. expr の HasName を hasName とする
  3. hasName が true なら、 false を返す
  4. true を返す

14.1.14 静的セマンティクス(Static Semantics): IsConstantDeclaration

  1. false を返す

14.1.15 静的セマンティクス(Static Semantics): IsFunctionDefinition

  1. true を返す

14.1.16 静的セマンティクス(Static Semantics): IsSimpleParameterList

  1. true を返す
  1. false を返す
  1. false を返す
  1. FormalParameterList の IsSimpleParameterList が false なら、 false を返す
  2. FormalParameter の IsSimpleParameterList を返す
  1. BindingElement の IsSimpleParameterList を返す

14.1.17 静的セマンティクス(Static Semantics): LexicallyDeclaredNames

  1. 空の新規List を返す
  1. StatementList の TopLevelLexicallyDeclaredNames を返す

14.1.18 静的セマンティクス(Static Semantics): LexicallyScopedDeclarations

  1. 空の新規List を返す
  1. StatementList の TopLevelLexicallyScopedDeclarations を返す

14.1.19 静的セマンティクス(Static Semantics): VarDeclaredNames

  1. 空の新規List を返す
  1. StatementList の TopLevelVarDeclaredNames を返す

14.1.20 静的セマンティクス(Static Semantics): VarScopedDeclarations

  1. 空の新規List を返す
  1. StatementList の TopLevelVarScopedDeclarations を返す

14.1.21 ランタイムセマンティクス(Runtime Semantics): EvaluateBody

引数 functionObject と argumentsList を使用。

  1. ? FunctionDeclarationInstantiation(functionObject, argumentsList) を実行する
  2. FunctionStatementList の 評価結果を返す

14.1.22 ランタイムセマンティクス(Runtime Semantics): IteratorBindingInitialization

引数 iteratorRecord と environment を使用。

environment に undefined が指定されたとき、PutValue操作で初期化値を割り当てます。 これは、非strict関数の仮パラメータリストの場合です。 その場合、複数の同名パラメーターに対応するために、正式なパラメーターバインディングが事前に初期化されます。
  1. NormalCompletion(empty) を返す
  1. 引数 iteratorRecord と environment を使用して ? FormalParameterList の IteratorBindingInitialization を実行する
  2. 引数 iteratorRecord と environment を使用して FunctionRestParameter の IteratorBindingInitialization の実行結果を返す
  1. 引数 iteratorRecord と environment を使用して ? FormalParameterList の IteratorBindingInitialization を実行する
  2. 引数 iteratorRecord と environment を使用して FormalParameter の IteratorBindingInitialization の実行結果を返す
  1. 引数 iteratorRecord と environment を使用して BindingElement の IteratorBindingInitialization の実行結果を返す
  1. 引数 iteratorRecord と environment を使用して BindingRestElement の IteratorBindingInitialization の実行結果を返す

14.1.23 ランタイムセマンティクス(Runtime Semantics): InstantiateFunctionObject

引数 scope を使用。

  1. BindingIdentifier の StringValue を name とする
  2. OrdinaryFunctionCreate(%Function.prototype%, FormalParameters , FunctionBody , non-lexical-this, scope) を F とする
  3. MakeConstructor(F) を実行する
  4. SetFunctionName(F, name) を実行する
  5. FunctionDeclaration に一致するソーステキスト を F.[[SourceText]] にセットする
  6. F を返す
  1. OrdinaryFunctionCreate(%Function.prototype%, FormalParameters , FunctionBody , non-lexical-this, scope) を F とする
  2. MakeConstructor(F) を実行する
  3. SetFunctionName(F, "default") を実行する
  4. FunctionDeclaration に一致するソーステキスト を F.[[SourceText]] にセットする
  5. F を返す
匿名のFunctionDeclarationは、export default宣言の一部としてのみ発生する可能性があるため、その関数コードは常にstrictモードコードです。

14.1.24 ランタイムセマンティクス(Runtime Semantics): NamedEvaluation

引数 name を使用。

  1. FunctionExpression の評価結果を closure とする
  2. SetFunctionName(closure, name) を実行する
  3. closure を返す

14.1.25 ランタイムセマンティクス:評価(Runtime Semantics: Evaluation)

  1. NormalCompletion(empty) を返す
代替セマンティクスがB.3.3で提供されています。
  1. NormalCompletion(empty) を返す
  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. OrdinaryFunctionCreate(%Function.prototype%, FormalParameters , FunctionBody , non-lexical-this, scope) を closure とする
  3. MakeConstructor(closure) を実行する
  4. FunctionExpression に一致するソーステキスト を closure.[[SourceText]] にセットする
  5. closure を返す
  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. NewDeclarativeEnvironment(scope) を funcEnv とする
  3. funcEnv の EnvironmentRecord を envRec とする
  4. BindingIdentifier の StringValue を name とする
  5. envRec.CreateImmutableBinding(name, false) を実行する
  6. OrdinaryFunctionCreate(%Function.prototype%, FormalParameters , FunctionBody , non-lexical-this, funcEnv) を closure とする
  7. MakeConstructor(closure) を実行する
  8. SetFunctionName(closure, name) を実行する
  9. FunctionExpression に一致するソーステキスト を closure.[[SourceText]] にセットする
  10. envRec.InitializeBinding(name, closure) を実行する
  11. closure を返す
FunctionExpressionのBindingIdentifierは、FunctionExpressionのFunctionBody内から参照して、関数がそれ自体を再帰的に呼び出すことができます。 ただし、FunctionDeclarationとは異なり、FunctionExpressionのBindingIdentifierは参照できず、FunctionExpressionを囲むスコープには影響しません。
FunctionDeclarationまたはFunctionExpressionを使用して定義されたすべての関数は、コンストラクターとして使用される可能性を考慮して、"prototype"プロパティが自動的に作成されます。
  1. NormalCompletion(undefined) を返す

14.2 アロー関数定義(Arrow Function Definitions)

構文:

ArrowFunction[In, Yield, Await] :

ArrowParameters[?Yield, ?Await] [no LineTerminator here]=>ConciseBody[?In]
ConciseBody[In] :

[lookahead ≠ {]ExpressionBody[?In, ~Await]
{FunctionBody[~Yield, ~Await] }
ExpressionBody[In, Await] :

AssignmentExpression[?In, ~Yield, ?Await]

補足構文:

次のプロダクションのとき、

次の文法を使用して、CoverParenthesizedExpressionAndArrowParameterListの解釈を改善します。

ArrowFormalParameters[Yield, Await] :

(UniqueFormalParameters[?Yield, ?Await] )

14.2.1 静的セマンティクス:早期エラー(Static Semantics: Early Errors)

14.2.2 静的セマンティクス(Static Semantics): BoundNames

  1. CoverParenthesizedExpressionAndArrowParameterList の CoveredFormalsList を formals とする
  2. formals の BoundNames を返す

14.2.3 静的セマンティクス(Static Semantics): Contains

引数 symbol を使用。

  1. symbol が NewTarget 、 SuperProperty 、 SuperCall 、 super 、 this のどれでもないなら、 false を返す
  2. ArrowParameters Contains symbol が true なら、 true を返す
  3. ConciseBody Contains symbol を返す
通常、Containsは関数フォームの内部を調べません。 ただし、Containsは、ArrowFunction内のnew.target、this、およびsuperの使用状況を検出するために使用されます。
  1. CoverParenthesizedExpressionAndArrowParameterList の CoveredFormalsList を formals とする
  2. formals Contains symbol を返す

14.2.4 静的セマンティクス(Static Semantics): ContainsExpression

  1. false を返す
  1. CoverParenthesizedExpressionAndArrowParameterList の CoveredFormalsList を formals とする
  2. formals の ContainsExpression を返す

14.2.5 静的セマンティクス(Static Semantics): ContainsUseStrict

  1. false を返す

14.2.6 静的セマンティクス(Static Semantics): ExpectedArgumentCount

  1. 1 を返す
  1. CoverParenthesizedExpressionAndArrowParameterList の CoveredFormalsList を formals とする
  2. formals の ExpectedArgumentCount を返す

14.2.7 静的セマンティクス(Static Semantics): HasName

  1. false を返す

14.2.8 静的セマンティクス(Static Semantics): IsSimpleParameterList

  1. true を返す
  1. CoverParenthesizedExpressionAndArrowParameterList の CoveredFormalsList を formals とする
  2. formals の IsSimpleParameterList を返す

14.2.9 静的セマンティクス(Static Semantics): CoveredFormalsList

  1. ArrowParameters を返す

14.2.10 静的セマンティクス(Static Semantics): LexicallyDeclaredNames

  1. 空の新規List を返す

14.2.11 静的セマンティクス(Static Semantics): LexicallyScopedDeclarations

  1. 空の新規List を返す

14.2.12 静的セマンティクス(Static Semantics): VarDeclaredNames

  1. 空の新規List を返す

14.2.13 静的セマンティクス(Static Semantics): VarScopedDeclarations

  1. 空の新規List を返す

14.2.14 ランタイムセマンティクス(Runtime Semantics): IteratorBindingInitialization

引数 iteratorRecord と environment を使用。

environmentにundefinedが指定されると、PutValue操作で初期化値を割り当てます。 これは、非strict関数 の仮パラメータリストの場合です。 その場合、複数の同名のパラメーターに対応するために、正式なパラメーターバインディングが事前に初期化されます。
  1. Assert: iteratorRecord.[[Done]] は false
  2. IteratorStep(iteratorRecord) を next とする
  3. next が 突然の完了 なら、 true を iteratorRecord.[[Done]] にセットする
  4. ReturnIfAbrupt(next)
  5. next が false なら、 true を iteratorRecord.[[Done]] にセットする
  6. 5. と異なるなら、
    1. IteratorValue(next) を v とする
    2. v が 突然の完了 なら、 true を iteratorRecord.[[Done]] にセットする
    3. ReturnIfAbrupt(v)
  7. iteratorRecord.[[Done]] が true なら、 undefined を v とする
  8. 引数 v と environment を使用して BindingIdentifier の BindingInitialization の実行結果を返す
  1. CoverParenthesizedExpressionAndArrowParameterList の CoveredFormalsList を formals とする
  2. 引数 iteratorRecord と environment を使用して formals の IteratorBindingInitialization の実行結果を返す

14.2.15 ランタイムセマンティクス(Runtime Semantics): EvaluateBody

引数 functionObject と argumentsList を使用。

  1. ? FunctionDeclarationInstantiation(functionObject, argumentsList) を実行する
  2. ExpressionBody の 評価結果を返す

14.2.16 ランタイムセマンティクス(Runtime Semantics): NamedEvaluation

引数 name を使用。

  1. ArrowFunction の評価結果を closure とする
  2. SetFunctionName(closure, name) を実行する
  3. closure を返す

14.2.17 ランタイムセマンティクス:評価(Runtime Semantics: Evaluation)

  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. ArrowParameters の CoveredFormalsList を parameters とする
  3. OrdinaryFunctionCreate(%Function.prototype%, parameters, ConciseBody , lexical-this, scope) を closure とする
  4. ArrowFunction に一致するソーステキスト を closure.[[SourceText]] にセットする
  5. closure を返す
ArrowFunctionは、arguments、super、this、および、new.targetのローカルバインディングを定義しません。 ArrowFunction内のargumentsなどへの参照は、レキシカル的に囲んでいる環境のバインディングにて解決される必要があります。 通常、これは直接囲んでいる関数の関数環境です。 ArrowFunctionにsuperへの参照が含まれている場合でも、手順3で作成された関数オブジェクトはMakeMethodを実行してもメソッドになりません。 superを参照するArrowFunctionは、常に非ArrowFunction内に含まれ、superを実装するために必要な状態には、ArrowFunctionの関数オブジェクトによってキャプチャされたscopeを介してアクセスします。
  1. AssignmentExpression の評価結果を exprRef とする
  2. ? GetValue(exprRef) を exprValue とする
  3. Completion { [[Type]]: return, [[Value]]: exprValue, [[Target]]: empty } を返す

14.3 メソッド定義(Method Definitions)

構文:

MethodDefinition[Yield, Await] :

PropertyName[?Yield, ?Await] (UniqueFormalParameters[~Yield, ~Await] ){FunctionBody[~Yield, ~Await] }
GeneratorMethod[?Yield, ?Await]
AsyncMethod[?Yield, ?Await]
AsyncGeneratorMethod[?Yield, ?Await]
getPropertyName[?Yield, ?Await] (){FunctionBody[~Yield, ~Await] }
setPropertyName[?Yield, ?Await] (PropertySetParameterList ){FunctionBody[~Yield, ~Await] }

14.3.1 静的セマンティクス:早期エラー(Static Semantics: Early Errors)

14.3.2 静的セマンティクス(Static Semantics): ComputedPropertyContains

引数 symbol を使用。

  1. 引数 symbol を使用して PropertyName の ComputedPropertyContains の結果を返す

14.3.3 静的セマンティクス(Static Semantics): ExpectedArgumentCount

  1. FormalParameter の HasInitializer が true なら、 0 を返す
  2. 1 を返す

14.3.4 静的セマンティクス(Static Semantics): HasDirectSuper

  1. UniqueFormalParameters Contains SuperCall が true なら、 true を返す
  2. FunctionBody Contains SuperCall を返す
  1. FunctionBody Contains SuperCall を返す
  1. PropertySetParameterList Contains SuperCall が true なら、 true を返す
  2. FunctionBody Contains SuperCall を返す

14.3.5 静的セマンティクス(Static Semantics): PropName

  1. PropertyName の PropName を返す

14.3.6 静的セマンティクス(Static Semantics): SpecialMethod

  1. false を返す
  1. true を返す

14.3.7 ランタイムセマンティクス(Runtime Semantics): DefineMethod

引数 object と オプション引数 functionPrototype を使用。

  1. PropertyName の評価結果を propKey とする
  2. ReturnIfAbrupt(propKey)
  3. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  4. functionPrototype が存在するなら、
    1. functionPrototype を prototype とする
  5. 4. と異なるなら、
    1. %Function.prototype% を prototype とする
  6. OrdinaryFunctionCreate(prototype, UniqueFormalParameters , FunctionBody , non-lexical-this, scope) を closure とする
  7. MakeMethod(closure, object) を実行する
  8. MethodDefinition に一致するソーステキスト を closure.[[SourceText]] にセットする
  9. Record { [[Key]]: propKey, [[Closure]]: closure } を返す

14.3.8 ランタイムセマンティクス(Runtime Semantics): PropertyDefinitionEvaluation

引数 object と enumerable を使用。

  1. 引数 object を使用して MethodDefinition の ? DefineMethod を methodDef とする
  2. SetFunctionName(methodDef.[[Closure]], methodDef.[[Key]]) を実行する
  3. PropertyDescriptor型 { [[Value]]: methodDef.[[Closure]], [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true } を desc とする
  4. ? DefinePropertyOrThrow(object, methodDef.[[Key]], desc) を返す
  1. PropertyName の評価結果を propKey とする
  2. ReturnIfAbrupt(propKey)
  3. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  4. プロダクション FormalParameters : [empty] のインスタンスを formalParameterList とする
  5. OrdinaryFunctionCreate(%Function.prototype%, formalParameterList, FunctionBody , non-lexical-this, scope) を closure とする
  6. MakeMethod(closure, object) を実行する
  7. SetFunctionName(closure, propKey, "get") を実行する
  8. MethodDefinition に一致するソーステキスト を closure.[[SourceText]] にセットする
  9. PropertyDescriptor型 { [[Get]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true } を desc とする
  10. ? DefinePropertyOrThrow(object, propKey, desc) を返す
  1. PropertyName の評価結果を propKey とする
  2. ReturnIfAbrupt(propKey)
  3. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  4. OrdinaryFunctionCreate(%Function.prototype%, PropertySetParameterList , FunctionBody , non-lexical-this, scope) を closure とする
  5. MakeMethod(closure, object) を実行する
  6. SetFunctionName(closure, propKey, "set") を実行する
  7. MethodDefinition に一致するソーステキスト を closure.[[SourceText]] にセットする
  8. PropertyDescriptor型 { [[Set]]: closure, [[Enumerable]]: enumerable, [[Configurable]]: true } を desc とする
  9. ? DefinePropertyOrThrow(object, propKey, desc) を返す

14.4 ジェネレーター関数定義(Generator Function Definitions)

構文:

GeneratorMethod[Yield, Await] :

*PropertyName[?Yield, ?Await] (UniqueFormalParameters[+Yield, ~Await] ){GeneratorBody }
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 }
GeneratorBody :

FunctionBody[+Yield, ~Await]
YieldExpression[In, Await] :

yield
yield[no LineTerminator here]AssignmentExpression[?In, +Yield, ?Await]
yield[no LineTerminator here]*AssignmentExpression[?In, +Yield, ?Await]
yieldの直後の構文コンテキストでは、InputElementRegExpOrTemplateTail レキシカルゴールを使用する必要があります。
FormalParameters の一部の式が、ジェネレーターオブジェクトが再開可能になる前に評価されるため、ジェネレーター関数のFormalParameters内では、YieldExpressionを使用できません。
ジェネレータオブジェクトに関連する抽象操作は25.4.3で定義されています。

14.4.1 静的セマンティクス:早期エラー(Static Semantics: Early Errors)

14.4.2 静的セマンティクス(Static Semantics): BoundNames

  1. BindingIdentifier の BoundNames を返す
  1. « "*default*" » を返す
この仕様内で"*default*" は、export宣言を使用して定義されたホイスタブル無名関数の合成名として使用されます。

14.4.3 静的セマンティクス(Static Semantics): ComputedPropertyContains

引数 symbol を使用。

  1. 引数 symbol を使用して PropertyName の ComputedPropertyContains の結果を返す

14.4.4 静的セマンティクス(Static Semantics): Contains

引数 symbol を使用。

  1. false を返す
通常、下部構造に依存する静的セマンティックルールは、関数定義を調べません。

14.4.5 静的セマンティクス(Static Semantics): HasDirectSuper

  1. UniqueFormalParameters Contains SuperCall が true なら、 true を返す
  2. GeneratorBody Contains SuperCall を返す

14.4.6 静的セマンティクス(Static Semantics): HasName

  1. false を返す
  1. true を返す

14.4.7 静的セマンティクス(Static Semantics): IsConstantDeclaration

  1. false を返す

14.4.8 静的セマンティクス(Static Semantics): IsFunctionDefinition

  1. true を返す

14.4.9 静的セマンティクス(Static Semantics): PropName

  1. PropertyName の PropName を返す

14.4.10 ランタイムセマンティクス(Runtime Semantics): EvaluateBody

引数 functionObject と argumentsList を使用。

  1. ? FunctionDeclarationInstantiation(functionObject, argumentsList) を実行する
  2. ? OrdinaryCreateFromConstructor(functionObject, "%Generator.prototype%", « [[GeneratorState]], [[GeneratorContext]] ») を G とする
  3. GeneratorStart(G, FunctionBody ) を実行する
  4. Completion { [[Type]]: return, [[Value]]: G, [[Target]]: empty } を返す

14.4.11 ランタイムセマンティクス(Runtime Semantics): InstantiateFunctionObject

引数 scope を使用。

  1. BindingIdentifier の StringValue を name とする
  2. OrdinaryFunctionCreate(%Generator%, FormalParameters , GeneratorBody , non-lexical-this, scope) を F とする
  3. OrdinaryObjectCreate(%Generator.prototype%) を prototype とする
  4. DefinePropertyOrThrow(F, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  5. SetFunctionName(F, name) を実行する
  6. GeneratorDeclaration に一致するソーステキスト を F.[[SourceText]] にセットする
  7. F を返す
  1. OrdinaryFunctionCreate(%Generator% , FormalParameters , GeneratorBody , non-lexical-this, scope) を F とする
  2. OrdinaryObjectCreate(%Generator.prototype%) を prototype とする
  3. DefinePropertyOrThrow(F, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  4. SetFunctionName(F, "default") を実行する
  5. GeneratorDeclaration に一致するソーステキスト を F.[[SourceText]] にセットする
  6. F を返す
匿名のGeneratorDeclarationは、export default宣言の一部としてのみ発生するため、その関数コードは常にstrictモードコード です。

14.4.12 ランタイムセマンティクス(Runtime Semantics): PropertyDefinitionEvaluation

引数 object と enumerable を使用。

  1. PropertyName の評価結果を propKey とする
  2. ReturnIfAbrupt(propKey)
  3. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  4. OrdinaryFunctionCreate( %Generator% , UniqueFormalParameters , GeneratorBody , non-lexical-this, scope) を closure とする
  5. MakeMethod(closure, object) を実行する
  6. OrdinaryObjectCreate(%Generator.prototype%) を prototype とする
  7. DefinePropertyOrThrow(closure, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  8. SetFunctionName(closure, propKey) を実行する
  9. GeneratorMethod に一致するソーステキスト を closure.[[SourceText]] にセットする
  10. PropertyDescriptor型 { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true } を desc とする
  11. ? DefinePropertyOrThrow(object, propKey, desc) を返す

14.4.13 ランタイムセマンティクス(Runtime Semantics): NamedEvaluation

引数 name を使用。

  1. GeneratorExpression の評価結果を closure とする
  2. SetFunctionName(closure, name) を実行する
  3. closure を返す

14.4.14 ランタイムセマンティクス:評価(Runtime Semantics: Evaluation)

  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. OrdinaryFunctionCreate( %Generator% , FormalParameters , GeneratorBody , non-lexical-this, scope) を closure とする
  3. OrdinaryObjectCreate(%Generator.prototype%) を prototype とする
  4. DefinePropertyOrThrow(closure, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  5. GeneratorExpression に一致するソーステキスト を closure.[[SourceText]] にセットする
  6. closure を返す
  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. NewDeclarativeEnvironment(scope) を funcEnv とする
  3. funcEnv の EnvironmentRecord を envRec とする
  4. BindingIdentifier の StringValue を name とする
  5. envRec.CreateImmutableBinding(name, false) を実行する
  6. OrdinaryFunctionCreate( %Generator% , FormalParameters , GeneratorBody , non-lexical-this, funcEnv) を closure とする
  7. OrdinaryObjectCreate(%Generator.prototype%) を prototype とする
  8. DefinePropertyOrThrow(closure, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  9. SetFunctionName(closure, name) を実行する
  10. envRec.InitializeBinding(name, closure) を実行する
  11. GeneratorExpression に一致するソーステキスト を closure.[[SourceText]] にセットする
  12. closure を返す
GeneratorExpressionのBindingIdentifierは、GeneratorExpressionのFunctionBody内から参照して、ジェネレーターコードがそれ自体を再帰的に呼び出すことができます。 ただし、GeneratorDeclarationとは異なり、GeneratorExpressionのBindingIdentifierは、GeneratorExpressionを囲むスコープから参照することはできず、影響を与えません。
  1. ! GetGeneratorKind() を generatorKind とする
  2. generatorKind が async なら、 ? AsyncGeneratorYield(undefined) を返す
  3. ? GeneratorYield( CreateIterResultObject(undefined, false)) を返す
  1. ! GetGeneratorKind() を generatorKind とする
  2. AssignmentExpression の評価結果を exprRef とする
  3. ? GetValue(exprRef) を value とする
  4. generatorKind が async なら、 ? AsyncGeneratorYield(value) を返す
  5. ? GeneratorYield( CreateIterResultObject(value, false)) を返す
  1. ! GetGeneratorKind() を generatorKind とする
  2. AssignmentExpression の評価結果を exprRef とする
  3. ? GetValue(exprRef) を value とする
  4. ? GetIterator(value, generatorKind) を iteratorRecord とする
  5. iteratorRecord.[[Iterator]] を iterator とする
  6. NormalCompletion(undefined) を received とする
  7. 繰り返す、
    1. received.[[Type]] が normal なら、
      1. ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « received.[[Value]] ») を innerResult とする
      2. generatorKind が async なら、 ? Await(innerResult) を innerResult にセットする
      3. Type(innerResult) が Object型 でないなら、 TypeError例外をスローする
      4. ? IteratorComplete(innerResult) を done とする
      5. done が true なら、
        1. ? IteratorValue(innerResult) を返す
      6. generatorKind が async なら、 AsyncGeneratorYield(? IteratorValue(innerResult)) を received にセットする
      7. vi. と異なるなら、GeneratorYield(innerResult) を received にセットする
    2. a. と異なり、received.[[Type]] が throw なら、
      1. ? GetMethod(iterator, "throw") を throw とする
      2. throw が undefined でないなら、
        1. ? Call(throw, iterator, « received.[[Value]] ») を innerResult とする
        2. generatorKind が async なら、 ? Await(innerResult) を innerResult にセットする
        3. NOTE: 内部のイテレータのthrowメソッドからの例外が伝播される。 throwメソッドからの通常の完了は、内部のnextと同様に処理する
        4. Type(innerResult) が Object型 でないなら、 TypeError例外をスローする
        5. ? IteratorComplete(innerResult) を done とする
        6. done が true なら、
          1. ? IteratorValue(innerResult) を返す
        7. generatorKind が async なら、 AsyncGeneratorYield(? IteratorValue(innerResult)) を received にセットする
        8. 7. と異なるなら、 GeneratorYield(innerResult) を received にセットする
      3. ii. と異なるなら、
        1. NOTE: iterator にthrowメソッドがないなら、このthrowはyield *ループを終了する。 ただし、最初にiteratorをクリーンアップする必要がある。
        2. Completion { [[Type]]: normal, [[Value]]: empty, [[Target]]: empty } を closeCompletion とする
        3. generatorKind が async なら、 ? AsyncIteratorClose(iteratorRecord, closeCompletion) を実行する
        4. 3. と異なるなら、 ? IteratorClose(iteratorRecord, closeCompletion) を実行する
        5. NOTE: yield *プロトコル違反のため、TypeErrorをスローする。イテレーターにはthrowメソッドがない。
        6. TypeError例外をスローする
    3. b. と異なるなら、
      1. Assert: received.[[Type]] は return
      2. ? GetMethod(iterator, "return") を return とする
      3. return が undefined なら、
        1. generatorKind が async なら、 ? Await(received.[[Value]]) を received.[[Value]] にセットする
        2. Completion(received) を返す
      4. ? Call(return, iterator, « received.[[Value]] ») を innerReturnResult とする
      5. generatorKind が async なら、 ? Await(innerReturnResult) を innerReturnResult にセットする
      6. Type(innerReturnResult) が Object型 でないなら、 TypeError例外をスローする
      7. ? IteratorComplete(innerReturnResult) を done とする
      8. done が true なら、
        1. ? IteratorValue(innerReturnResult) を value とする
        2. Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty } を返す
      9. generatorKind が async なら、 AsyncGeneratorYield(? IteratorValue(innerReturnResult)) を received にセットする
      10. ix. と異なるなら、 GeneratorYield(innerReturnResult) を received にセットする

14.5 非同期ジェネレーター関数定義(Async Generator Function Definitions)

構文:

AsyncGeneratorMethod[Yield, Await] :

async[no LineTerminator here]*PropertyName[?Yield, ?Await] (UniqueFormalParameters[+Yield, +Await] ){AsyncGeneratorBody }
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 }
AsyncGeneratorBody :

FunctionBody[+Yield, +Await]
YieldExpressionおよびAwaitExpressionは、非同期ジェネレーター関数のFormalParameters内では使用できません。これは、FormalParametersの一部である式は、結果の非同期ジェネレーターオブジェクトが再開可能な状態になる前に評価されるためです。
非同期ジェネレータオブジェクトに関連する抽象操作が、25.5.3で定義されています。

14.5.1 静的セマンティクス:早期エラー(Static Semantics: Early Errors)

14.5.2 静的セマンティクス(Static Semantics): BoundNames

  1. BindingIdentifier の the BoundNames を返す
  1. « "*default*" » を返す
この仕様内で "*default*"は、エクスポート宣言を使用して定義されたホイスタブル無名関数の合成名として使用されます。

14.5.3 静的セマンティクス(Static Semantics): ComputedPropertyContains

引数 symbol を使用。

  1. 引数 symbol を使用して PropertyName の ComputedPropertyContains の結果を返す

14.5.4 静的セマンティクス(Static Semantics): Contains

引数 symbol を使用。

  1. false を返す
下部構造に依存する静的セマンティックルールは、通常、関数定義を調べません。

14.5.5 静的セマンティクス(Static Semantics): HasDirectSuper

  1. UniqueFormalParameters Contains SuperCall が true なら、 true を返す
  2. AsyncGeneratorBody Contains SuperCall を返す

14.5.6 静的セマンティクス(Static Semantics): HasName

  1. false を返す
  1. true を返す

14.5.7 静的セマンティクス(Static Semantics): IsConstantDeclaration

  1. false を返す

14.5.8 静的セマンティクス(Static Semantics): IsFunctionDefinition

  1. true を返す

14.5.9 静的セマンティクス(Static Semantics): PropName

  1. PropertyName の PropName を返す

14.5.10 ランタイムセマンティクス(Runtime Semantics): EvaluateBody

引数 functionObject と argumentsList を使用。

  1. ? FunctionDeclarationInstantiation(functionObject, argumentsList) を実行する
  2. ? OrdinaryCreateFromConstructor(functionObject, "%AsyncGenerator.prototype%", « [[AsyncGeneratorState]], [[AsyncGeneratorContext]], [[AsyncGeneratorQueue]] ») を generator とする
  3. ! AsyncGeneratorStart(generator, FunctionBody ) を実行する
  4. Completion { [[Type]]: return, [[Value]]: generator, [[Target]]: empty } を返す

14.5.11 ランタイムセマンティクス(Runtime Semantics): InstantiateFunctionObject

引数 scope を使用。

  1. BindingIdentifier の StringValue を name とする
  2. ! OrdinaryFunctionCreate(%AsyncGenerator%, FormalParameters , AsyncGeneratorBody , non-lexical-this, scope) を F とする
  3. ! OrdinaryObjectCreate(%AsyncGenerator.prototype%) を prototype とする
  4. ! DefinePropertyOrThrow(F, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  5. ! SetFunctionName(F, name) を実行する
  6. AsyncGeneratorDeclaration に一致するソーステキスト を F.[[SourceText]] にセットする
  7. F を返す
  1. OrdinaryFunctionCreate(%AsyncGenerator%, FormalParameters , AsyncGeneratorBody , non-lexical-this, scope) を F とする
  2. OrdinaryObjectCreate(%AsyncGenerator.prototype%) を prototype とする
  3. DefinePropertyOrThrow(F, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  4. SetFunctionName(F, "default") を実行する
  5. AsyncGeneratorDeclaration に一致するソーステキスト を F.[[SourceText]] にセットする
  6. F を返す
匿名のAsyncGeneratorDeclarationは、export default宣言の一部としてのみ発生します。

14.5.12 ランタイムセマンティクス(Runtime Semantics): PropertyDefinitionEvaluation

引数 object と enumerable を使用。

  1. PropertyName の評価結果を propKey とする
  2. ReturnIfAbrupt(propKey)
  3. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  4. ! OrdinaryFunctionCreate( %AsyncGenerator% , UniqueFormalParameters , AsyncGeneratorBody , non-lexical-this, scope) を closure とする
  5. ! MakeMethod(closure, object) を実行する
  6. ! OrdinaryObjectCreate(%AsyncGenerator.prototype%) を prototype とする
  7. ! DefinePropertyOrThrow(closure, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  8. ! SetFunctionName(closure, propKey) を実行する
  9. AsyncGeneratorMethod に一致するソーステキスト を closure.[[SourceText]] にセットする
  10. プロパティ記述子 { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true } を desc とする
  11. ? DefinePropertyOrThrow(object, propKey, desc) を返す

14.5.13 ランタイムセマンティクス(Runtime Semantics): NamedEvaluation

引数 name を使用。

  1. AsyncGeneratorExpression の評価結果を closure とする
  2. SetFunctionName(closure, name) を実行する
  3. closure を返す

14.5.14 ランタイムセマンティクス:評価(Runtime Semantics: Evaluation)

  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. ! OrdinaryFunctionCreate( %AsyncGenerator% , FormalParameters , AsyncGeneratorBody , non-lexical-this, scope) を closure とする
  3. ! OrdinaryObjectCreate(%AsyncGenerator.prototype%) を prototype とする
  4. ! DefinePropertyOrThrow(closure, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  5. AsyncGeneratorExpression に一致するソーステキスト を closure.[[SourceText]] にセットする
  6. closure を返す
  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. ! NewDeclarativeEnvironment(scope) を funcEnv とする
  3. funcEnv の EnvironmentRecord を envRec とする
  4. BindingIdentifier の StringValue を name とする
  5. ! envRec.CreateImmutableBinding(name, false) を実行する
  6. ! OrdinaryFunctionCreate( %AsyncGenerator% , FormalParameters , AsyncGeneratorBody , non-lexical-this, funcEnv) を closure とする
  7. ! OrdinaryObjectCreate(%AsyncGenerator.prototype%) を prototype とする
  8. ! DefinePropertyOrThrow(closure, "prototype",プロパティ記述子 { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する
  9. ! SetFunctionName(closure, name) を実行する
  10. ! envRec.InitializeBinding(name, closure) を実行する
  11. AsyncGeneratorExpression に一致するソーステキスト を closure.[[SourceText]] にセットする
  12. closure を返す
AsyncGeneratorExpressionのBindingIdentifierは、AsyncGeneratorExpressionのAsyncGeneratorBody内から参照して、ジェネレーターコードがそれ自体を再帰的に呼び出すことができます。 ただし、AsyncGeneratorDeclarationとは異なり、AsyncGeneratorExpressionのBindingIdentifierは、AsyncGeneratorExpressionを囲むスコープから参照することはできず、影響を与えません。

14.6 クラス定義(Class Definitions)

構文:

ClassDeclaration[Yield, Await, Default] :

classBindingIdentifier[?Yield, ?Await] ClassTail[?Yield, ?Await]
[+Default]classClassTail[?Yield, ?Await]
ClassExpression[Yield, Await] :

classBindingIdentifier[?Yield, ?Await]opt ClassTail[?Yield, ?Await]
ClassTail[Yield, Await] :

ClassHeritage[?Yield, ?Await]opt {ClassBody[?Yield, ?Await]opt }
ClassHeritage[Yield, Await] :

extendsLeftHandSideExpression[?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]
staticMethodDefinition[?Yield, ?Await]
;
クラス定義は常にstrictモードコード です。

14.6.1 静的セマンティクス:早期エラー(Static Semantics: Early Errors)

  • ClassHeritageが存在せず、次のアルゴリズムがtrueと評価された場合、構文エラーになります。
    1. ClassBody の ConstructorMethod を constructor とする
    2. constructor が empty なら、 false を返す
    3. constructor の HasDirectSuper を返す
  • ClassElementList の PrototypePropertyNameList に複数の "constructor" が含まれている場合は構文エラ。

14.6.2 静的セマンティクス(Static Semantics): BoundNames

  1. BindingIdentifier の BoundNames を返す
  1. « "*default*" » を返す

14.6.3 静的セマンティクス(Static Semantics): ConstructorMethod

  1. ClassElement が ClassElement : ; なら、 empty を返す
  2. ClassElement の IsStatic が true なら、 empty を返す
  3. ClassElement の PropName が "constructor" でないなら、 empty を返す
  4. ClassElement を返す
  1. ClassElementList の ConstructorMethod を head とする
  2. head が empty でないなら、 head を返す
  3. ClassElement が ClassElement : ; なら、 empty を返す
  4. ClassElement の IsStatic が true なら、 empty を返す
  5. ClassElement の PropName が "constructor" でないなら、 empty を返す
  6. ClassElement を返す
早期エラールールは、"constructor" という名前のメソッド定義が1つだけであり、それがアクセサープロパティまたはジェネレーター定義ではないことを確認します。

14.6.4 静的セマンティクス(Static Semantics): Contains

引数 symbol を使用。

  1. symbol が ClassBody なら、 true を返す
  2. symbol が ClassHeritage なら、
    1. ClassHeritage が存在するなら true を、異なるなら false を返す
  3. ClassHeritage Contains symbol を inHeritage とする
  4. inHeritage が true なら、 true を返す
  5. 引数 symbol を使用して ClassBody の ComputedPropertyContains の結果を返す
部分構造に依存する静的セマンティックルールは、通常、PropertyNameを除いてクラス本体を調べません。

14.6.5 静的セマンティクス(Static Semantics): ComputedPropertyContains

引数 symbol を使用。

  1. 引数 symbol を使用して ClassElementList の ComputedPropertyContains を inList とする
  2. inList が true なら、 true を返す
  3. 引数 symbol を使用して ClassElement の ComputedPropertyContains の結果を返す
  1. false を返す

14.6.6 静的セマンティクス(Static Semantics): HasName

  1. false を返す
  1. true を返す

14.6.7 静的セマンティクス(Static Semantics): IsConstantDeclaration

  1. false を返す

14.6.8 静的セマンティクス(Static Semantics): IsFunctionDefinition

  1. true を返す

14.6.9 静的セマンティクス(Static Semantics): IsStatic

  1. false を返す
  1. true を返す
  1. false を返す

14.6.10 静的セマンティクス(Static Semantics): NonConstructorMethodDefinitions

  1. ClassElement がClassElement : ; なら、 空の新規List を返す
  2. ClassElement の IsStatic が false で ClassElement の PropName が "constructor" なら、 空の新規List を返す
  3. ClassElement を含む List を返す
  1. ClassElementList の NonConstructorMethodDefinitions を list とする
  2. ClassElement が ClassElement : ; なら、 list を返す
  3. ClassElement の IsStatic が false で ClassElement の PropName が "constructor" なら、 list を返す
  4. list の最後に ClassElement を追加する
  5. list を返す

14.6.11 静的セマンティクス(Static Semantics): PrototypePropertyNameList

  1. ClassElement の PropName が empty なら、 空の新規List を返す
  2. ClassElement の IsStatic が true なら、 空の新規List を返す
  3. ClassElement の PropName を含む Listを返す
  1. ClassElementList の PrototypePropertyNameList を list とする
  2. ClassElement の PropName が empty なら、 list を返す
  3. ClassElement の IsStatic が true なら、 list を返す
  4. list の最後に ClassElement の PropName を追加する
  5. list を返す

14.6.12 静的セマンティクス(Static Semantics): PropName

  1. empty を返す

14.6.13 ランタイムセマンティクス(Runtime Semantics): ClassDefinitionEvaluation

引数 classBinding と className を使用。

  1. 実行中の実行コンテキスト の LexicalEnvironment を lex とする
  2. NewDeclarativeEnvironment(lex) を classScope とする
  3. classScope の EnvironmentRecord を classScopeEnvRec とする
  4. classBinding が undefined でないなら、
    1. classScopeEnvRec.CreateImmutableBinding(classBinding, true) を実行する
  5. ClassHeritageopt が 存在しないなら、
    1. %Object.prototype% を protoParent とする
    2. %Function.prototype% を constructorParent とする
  6. 5. と異なるなら、
    1. classScope を 実行中の実行コンテキスト の LexicalEnvironment にセットする
    2. ClassHeritage の評価結果を superclassRef とする
    3. lex を 実行中の実行コンテキスト の LexicalEnvironment にセットする
    4. ? GetValue(superclassRef) を superclass とする
    5. superclass が null なら、
      1. null を protoParent とする
      2. %Function.prototype% を constructorParent とする
    6. e. と異なるなり、 IsConstructor(superclass) が false なら、 TypeError例外をスローする
    7. f. と異なるなら、
      1. ? Get(superclass, "prototype") を protoParent とする
      2. Type(protoParent) が Object型 か Null なら、 TypeError例外をスローする
      3. superclass を constructorParent とする
  7. OrdinaryObjectCreate(protoParent) を proto とする
  8. ClassBodyopt が 存在しないなら、 empty を constructor とする
  9. 8. と異なるなら、 ClassBody の ConstructorMethod を constructor とする
  10. constructor が empty なら、
    1. ClassHeritageopt が 存在するなら、
      1. 次のソーステキストを解析した結果を constructor にセットする
        constructor(...args) { super(...args); }

        ※ゴールシンボル MethodDefinition[~Yield, ~Await] を使用

    2. a. と異なるなら、
      1. 次のソーステキストを解析した結果を constructor にセットする
        constructor() {}

        ※ゴールシンボル MethodDefinition[~Yield, ~Await] を使用

  11. classScope を 実行中の実行コンテキスト の LexicalEnvironment にセットする
  12. 引数 proto と constructorParent を使用して constructor の ! DefineMethod を constructorInfo とする
  13. constructorInfo.[[Closure]] を F とする
  14. MakeConstructor(F, false, proto) を実行する
  15. ClassHeritageopt が 存在するなら、 derived を F.[[ConstructorKind]] にセットする
  16. MakeClassConstructor(F) を実行する
  17. className が undefined でないなら、
    1. SetFunctionName(F, className) を実行する
  18. CreateMethodProperty(proto, "constructor", F) を実行する
  19. ClassBodyopt が 存在しないなら、 空の新規List を methods とする
  20. 19. と異なるなら、 ClassBody の NonConstructorMethodDefinitions を methods とする
  21. methods から順番に 各 ClassElement を m とし、 m ごとに次を実行する
    1. m の IsStatic が false なら、
      1. 引数 proto と false を使用して m の PropertyDefinitionEvaluation を status とする
    2. a. と異なるなら、
      1. 引数 F と false を使用して m の PropertyDefinitionEvaluation を status とする
    3. status が 突然の完了 なら、
      1. lex を 実行中の実行コンテキスト の LexicalEnvironment にセットする
      2. Completion(status) を返す
  22. lex を 実行中の実行コンテキスト の LexicalEnvironment にセットする
  23. classBinding が undefined でないなら、
    1. classScopeEnvRec.InitializeBinding(classBinding, F) を実行する
  24. F を返す

14.6.14 ランタイムセマンティクス(Runtime Semantics): BindingClassDeclarationEvaluation

  1. BindingIdentifier の StringValue を className とする
  2. 引数 className と className を使用して ClassTail の ? ClassDefinitionEvaluation を value とする
  3. ClassDeclaration に一致するソーステキスト を value.[[SourceText]] にセットする
  4. 実行中の実行コンテキスト の LexicalEnvironment を env とする
  5. ? InitializeBoundName(className, value, env) を実行する
  6. value を返す
  1. 引数 undefined と "default" を使用して ClassTail の ? ClassDefinitionEvaluation を value とする
  2. ClassDeclaration に一致するソーステキスト を value.[[SourceText]] にセットする
  3. value を返す
ClassDeclaration : class ClassTail は、ExportDeclaration の一部としてのみ発生しまう。バインディングの確立は、そのプロダクションの評価アクションの一部として処理されます。 (15.2.3.11)

14.6.15 ランタイムセマンティクス(Runtime Semantics): NamedEvaluation

引数 name を使用。

  1. 引数 undefined と name を使用して ClassTail の ClassDefinitionEvaluation の結果 を value とする
  2. ReturnIfAbrupt(value)
  3. ClassExpression に一致するソーステキスト を value.[[SourceText]] にセットする
  4. value を返す

14.6.16 ランタイムセマンティクス:評価(Runtime Semantics: Evaluation)

  1. ? ClassDeclaration の BindingClassDeclarationEvaluation を実行する
  2. NormalCompletion(empty) を返す
ClassDeclaration : class ClassTail は、ExportDeclaration の一部としてのみ発生し、直接評価されることはありません。
  1. BindingIdentifieropt が 存在しないなら、 undefined を className とする
  2. 3. と異なるなら、 BindingIdentifier の StringValue を className とする
  3. 引数 className と className を使用して ClassTail の ? ClassDefinitionEvaluation を value とする
  4. ClassExpression に一致するソーステキスト を value.[[SourceText]] にセットする
  5. value を返す

14.7 非同期関数定義(Async Function Definitions)

構文:

AsyncFunctionDeclaration[Yield, Await, Default] :

async[no LineTerminator here]functionBindingIdentifier[?Yield, ?Await] (FormalParameters[~Yield, +Await] ){AsyncFunctionBody }
[+Default]async[no LineTerminator here]function(FormalParameters[~Yield, +Await] ){AsyncFunctionBody }
AsyncFunctionExpression :

async[no LineTerminator here]function(FormalParameters[~Yield, +Await] ){AsyncFunctionBody }
async[no LineTerminator here]functionBindingIdentifier[~Yield, +Await] (FormalParameters[~Yield, +Await] ){AsyncFunctionBody }
AsyncMethod[Yield, Await] :

async[no LineTerminator here]PropertyName[?Yield, ?Await] (UniqueFormalParameters[~Yield, +Await] ){AsyncFunctionBody }
AsyncFunctionBody :

FunctionBody[~Yield, +Await]
AwaitExpression[Yield] :

awaitUnaryExpression[?Yield, +Await]
[Await]パラメーターが存在する場合、awaitはAwaitExpressionとして解析されます。 [Await]パラメーターは、次のコンテキストに存在します。

Moduleが構文上のゴールシンボルで、[Await]パラメーターが存在しない場合、awaitはキーワードとして解析され、その結果構文エラーになります。ゴールシンボルがScriptで、[Await]パラメーターがない場合、awaitは識別子として解析される可能性があります。 これには、次のコンテキストが含まれます。

YieldExpressionとは異なり、AwaitExpressionのオペランドを省略すると構文エラーです。

14.7.1 静的セマンティクス:早期エラー(Static Semantics: Early Errors)

14.7.2 静的セマンティクス(Static Semantics): BoundNames

  1. BindingIdentifier の the BoundNames を返す
  1. « "*default*" » を返す
"*default*"は、export宣言を使用して定義されたホイスタブル無名関数の合成名として、この仕様内で使用されます。

14.7.3 静的セマンティクス(Static Semantics): ComputedPropertyContains

引数 symbol を使用。

  1. 引数 symbol を使用して PropertyName の ComputedPropertyContains の結果を返す

14.7.4 静的セマンティクス(Static Semantics): Contains

引数 symbol を使用。

  1. false を返す

14.7.5 静的セマンティクス(Static Semantics): HasDirectSuper

  1. UniqueFormalParameters Contains SuperCall が true なら、 true を返す
  2. AsyncFunctionBody Contains SuperCall を返す

14.7.6 静的セマンティクス(Static Semantics): HasName

  1. false を返す
  1. true を返す

14.7.7 静的セマンティクス(Static Semantics): IsConstantDeclaration

  1. false を返す

14.7.8 静的セマンティクス(Static Semantics): IsFunctionDefinition

  1. true を返す

14.7.9 静的セマンティクス(Static Semantics): PropName

  1. PropertyName の PropName を返す

14.7.10 ランタイムセマンティクス(Runtime Semantics): InstantiateFunctionObject

引数 scope を使用。

  1. BindingIdentifier の StringValue を name とする
  2. ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, FormalParameters , AsyncFunctionBody , non-lexical-this, scope) を F とする
  3. ! SetFunctionName(F, name) を実行する
  4. AsyncFunctionDeclaration に一致するソーステキスト を F.[[SourceText]] にセットする
  5. F を返す
  1. ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, FormalParameters , AsyncFunctionBody , non-lexical-this, scope) を F とする
  2. ! SetFunctionName(F, "default") を実行する
  3. AsyncFunctionDeclaration に一致するソーステキスト を F.[[SourceText]] にセットする
  4. F を返す

14.7.11 ランタイムセマンティクス(Runtime Semantics): EvaluateBody

引数 functionObject と argumentsList を使用。

  1. ! NewPromiseCapability(%Promise%) を promiseCapability とする
  2. FunctionDeclarationInstantiation(functionObject, argumentsList) を declResult とする
  3. declResult が 突然の完了 でないなら、
    1. ! AsyncFunctionStart(promiseCapability, FunctionBody ) を実行する
  4. 3. と異なるなら、
    1. ! Call(promiseCapability.[[Reject]], undefined, « declResult.[[Value]] ») を実行する
  5. Completion { [[Type]]: return, [[Value]]: promiseCapability.[[Promise]], [[Target]]: empty } を返す

14.7.12 ランタイムセマンティクス(Runtime Semantics): PropertyDefinitionEvaluation

引数 object と enumerable を使用。

  1. PropertyName の評価結果を propKey とする
  2. ReturnIfAbrupt(propKey)
  3. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  4. ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, UniqueFormalParameters , AsyncFunctionBody , non-lexical-this, scope) を closure とする
  5. ! MakeMethod(closure, object) を実行する
  6. ! SetFunctionName(closure, propKey) を実行する
  7. AsyncMethod に一致するソーステキスト を closure.[[SourceText]] にセットする
  8. PropertyDescriptor型 { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true } を desc とする
  9. ? DefinePropertyOrThrow(object, propKey, desc) を返す

14.7.13 ランタイムセマンティクス(Runtime Semantics): NamedEvaluation

引数 name を使用。

  1. AsyncFunctionExpression の評価結果を closure とする
  2. SetFunctionName(closure, name) を実行する
  3. closure を返す

14.7.14 ランタイムセマンティクス:評価(Runtime Semantics: Evaluation)

  1. NormalCompletion(empty) を返す
  1. NormalCompletion(empty) を返す
  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, FormalParameters , AsyncFunctionBody , non-lexical-this, scope) を closure とする
  3. AsyncFunctionExpression に一致するソーステキスト を closure.[[SourceText]] にセットする
  4. closure を返す
  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. ! NewDeclarativeEnvironment(scope) を funcEnv とする
  3. funcEnv の EnvironmentRecord を envRec とする
  4. BindingIdentifier の StringValue を name とする
  5. ! envRec.CreateImmutableBinding(name, false) を実行する
  6. ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, FormalParameters , AsyncFunctionBody , non-lexical-this, funcEnv) を closure とする
  7. ! SetFunctionName(closure, name) を実行する
  8. ! envRec.InitializeBinding(name, closure) を実行する
  9. AsyncFunctionExpression に一致するソーステキスト を closure.[[SourceText]] にセットする
  10. closure を返す
  1. UnaryExpression の評価結果を exprRef とする
  2. ? GetValue(exprRef) を value とする
  3. ? Await(value) を返す

14.8 非同期アロー関数の定義(Async Arrow Function Definitions)

構文:

CoverCallExpressionAndAsyncArrowHead[Yield, Await] :

MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]

補足構文:

次のプロダクションのインスタンスを処理するとき

CoverCallExpressionAndAsyncArrowHeadの解釈は、次の文法で改善されます。

AsyncArrowHead :

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

14.8.1 静的セマンティクス:早期エラー(Static Semantics: Early Errors)

14.8.2 静的セマンティクス(Static Semantics): CoveredAsyncArrowHead

  1. CoverCallExpressionAndAsyncArrowHead によってカバーされている AsyncArrowHead を返す

14.8.3 静的セマンティクス(Static Semantics): BoundNames

  1. CoverCallExpressionAndAsyncArrowHead の CoveredAsyncArrowHead を head とする
  2. head の BoundNames を返す

14.8.4 静的セマンティクス(Static Semantics): Contains

引数 symbol を使用。

  1. symbol が NewTarget 、SuperProperty 、 SuperCall、 super、 this のどれかでないなら、 false を返す
  2. AsyncConciseBody Contains symbol を返す
  1. symbol が NewTarget 、 SuperProperty 、 SuperCall 、 super 、 this のどれかでないなら、 false を返す
  2. CoverCallExpressionAndAsyncArrowHead の CoveredAsyncArrowHead を head とする
  3. head Contains symbol が true なら、 true を返す
  4. AsyncConciseBody Contains symbol を返す
通常、Containsはほとんどの関数フォームの内部を調べません。 ただし、Containsは、AsyncArrowFunction内のnew.target、this、およびsuperの使用状況を検出するために使用されます。

14.8.5 静的セマンティクス(Static Semantics): ContainsExpression

  1. false を返す

14.8.6 静的セマンティクス(Static Semantics): ContainsUseStrict

  1. false を返す

14.8.7 静的セマンティクス(Static Semantics): ExpectedArgumentCount

  1. 1 を返す

14.8.8 静的セマンティクス(Static Semantics): HasName

  1. false を返す

14.8.9 静的セマンティクス(Static Semantics): IsSimpleParameterList

  1. true を返す
  1. CoverCallExpressionAndAsyncArrowHead の CoveredAsyncArrowHead を head とする
  2. head の IsSimpleParameterList を返す

14.8.10 静的セマンティクス(Static Semantics): LexicallyDeclaredNames

  1. 空の新規List を返す

14.8.11 静的セマンティクス(Static Semantics): LexicallyScopedDeclarations

  1. 空の新規List を返す

14.8.12 静的セマンティクス(Static Semantics): VarDeclaredNames

  1. 空の新規List を返す

14.8.13 静的セマンティクス(Static Semantics): VarScopedDeclarations

  1. 空の新規List を返す

14.8.14 ランタイムセマンティクス(Runtime Semantics): IteratorBindingInitialization

引数 iteratorRecord と environment を使用。

  1. Assert: iteratorRecord.[[Done]] は false
  2. IteratorStep(iteratorRecord) を next とする
  3. next が 突然の完了 なら、 true を iteratorRecord.[[Done]] にセットする
  4. ReturnIfAbrupt(next)
  5. next が false なら、 true を iteratorRecord.[[Done]] にセットする
  6. 5. と異なるなら、
    1. IteratorValue(next) を v とする
    2. v が 突然の完了 なら、 true を iteratorRecord.[[Done]] にセットする
    3. ReturnIfAbrupt(v)
  7. iteratorRecord.[[Done]] が true なら、 undefined を v とする
  8. 引数 v と environment を使用して BindingIdentifier の BindingInitialization の実行結果を返す

14.8.15 ランタイムセマンティクス(Runtime Semantics): EvaluateBody

引数 functionObject と argumentsList を使用。

  1. ! NewPromiseCapability(%Promise%) を promiseCapability とする
  2. FunctionDeclarationInstantiation(functionObject, argumentsList) を declResult とする
  3. declResult が 突然の完了 でないなら、
    1. ! AsyncFunctionStart(promiseCapability, ExpressionBody ) を実行する
  4. 3. と異なるなら、
    1. ! Call(promiseCapability.[[Reject]], undefined, « declResult.[[Value]] ») を実行する
  5. Completion { [[Type]]: return, [[Value]]: promiseCapability.[[Promise]], [[Target]]: empty } を返す

14.8.16 ランタイムセマンティクス(Runtime Semantics): NamedEvaluation

引数 name を使用。

  1. AsyncArrowFunction の評価結果を closure とする
  2. SetFunctionName(closure, name) を実行する
  3. closure を返す

14.8.17 ランタイムセマンティクス:評価(Runtime Semantics: Evaluation)

  1. 実行中の実行コンテキスト の the LexicalEnvironment を scope とする
  2. AsyncArrowBindingIdentifier を parameters とする
  3. ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, parameters, AsyncConciseBody , lexical-this, scope) を closure とする
  4. AsyncArrowFunction に一致するソーステキスト を closure.[[SourceText]] にセットする
  5. closure を返す
  1. 実行中の実行コンテキスト の LexicalEnvironment を scope とする
  2. CoverCallExpressionAndAsyncArrowHead の CoveredAsyncArrowHead を head とする
  3. head の ArrowFormalParameters を parameters とする
  4. ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, parameters, AsyncConciseBody , lexical-this, scope) を closure とする
  5. AsyncArrowFunction に一致するソーステキスト を closure.[[SourceText]] にセットする
  6. closure を返す

14.9 末尾呼び出し(Tail Position Calls)

14.9.1 静的セマンティクス(Static Semantics): IsInTailPosition ( call )

引数callを伴う抽象操作IsInTailPositionは、次の手順を実行します。

  1. Assert: call は パースノード
  2. call に一致するソースコードが 非strictコード なら、 false を返す
  3. call が FunctionBody 、 ConciseBody 、 AsyncConciseBody に含まれていないなら、 false を返す
  4. FunctionBody、ConciseBody、 AsyncConciseBody のうち、call が一番密接に含まれているものを body とする
  5. body が GeneratorBody の FunctionBody なら、 false を返す
  6. body が AsyncFunctionBody の FunctionBody なら、 false を返す
  7. body が AsyncGeneratorBody の FunctionBody なら、 false を返す
  8. body が AsyncConciseBody なら、 false を返す
  9. 引数 call を使用して body の HasCallInTailPosition の結果を返す
末尾呼び出しは、呼び出し元コンテキストのチェーンの監視を可能にする一般的な非標準言語拡張(9.2.4)のため、strictモードコード のみで定義されます。

14.9.2 静的セマンティクス(Static Semantics): HasCallInTailPosition

引数 call を使用。

call は、特定の範囲のソーステキストを表すパースノードです。 以降のアルゴリズムがcallを別のパースノードと比較する場合、同じソーステキストを表しているかどうかをテストします。

14.9.2.1 ステートメントルール(Statement Rules)

  1. 引数 call を使用して StatementList の HasCallInTailPosition を has とする
  2. has が true なら、 true を返す
  3. 引数 call を使用して StatementListItem の HasCallInTailPosition の実行結果を返す
Block :

{}
ReturnStatement :

return;
CaseBlock :

{}
  1. false を返す
  1. 引数 call を使用して、最初の Statement の HasCallInTailPosition を has とする
  2. has が true なら、 true を返す
  3. 引数 call を使用して、2番目の Statement の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して Statement の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して LabelledItem の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して Expression の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して CaseBlock の HasCallInTailPosition の実行結果を返す
  1. false を has とする
  2. 最初の CaseClauses が存在するなら、 引数 call を使用して、最初の CaseClauses の HasCallInTailPosition を has とする
  3. has が true なら、 true を返す
  4. 引数 call を使用して DefaultClause の HasCallInTailPosition を has とする
  5. has が true なら、 true を返す
  6. 2番目の CaseClauses が 存在するなら、 引数 call を使用して、2番目の CaseClauses の HasCallInTailPosition を has とする
  7. has を返す
  1. 引数 call を使用して CaseClauses の HasCallInTailPosition を has とする
  2. has が true なら、 true を返す
  3. 引数 call を使用して CaseClause の HasCallInTailPosition の実行結果を返す
  1. StatementList が存在するなら、 引数 call を使用して StatementList の HasCallInTailPosition の実行結果を返す
  2. false を返す
  1. 引数 call を使用して Catch の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して Finally の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して Block の HasCallInTailPosition の実行結果を返す

14.9.2.2 表示規則(Expression Rules)

呼び出し結果の戻り値GetValueが直後に続く潜在的な末尾呼び出しも、有効な末尾呼び出しです。 関数呼び出しは参照値を返すことができないため、このようなGetValue操作は常に実際の関数呼び出しの結果と同じ値を返します。
  1. false を返す
  1. 引数 call を使用して AssignmentExpression の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して 最初の AssignmentExpression の HasCallInTailPosition を has とする
  2. has が true なら、 true を返す
  3. 引数 call を使用して 2番目の AssignmentExpression の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して BitwiseORExpression の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して LogicalANDExpression の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して BitwiseORExpression の HasCallInTailPosition の実行結果を返す
  1. CallExpression が call なら、 true を返す
  2. false を返す
  1. 引数 call を使用して OptionalChain の HasCallInTailPosition の実行結果を返す
  1. false を返す
  1. OptionalChain が call なら、 true を返す
  2. false を返す
  1. MemberExpression が call なら、 true を返す
  2. false を返す
  1. CoverParenthesizedExpressionAndArrowParameterList の CoveredParenthesizedExpression を expr とする
  2. 引数 call を使用して expr の HasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して Expression の HasCallInTailPosition の実行結果を返す

14.9.3 ランタイムセマンティクス(Runtime Semantics): PrepareForTailCall ( )

抽象操作PrepareForTailCallは、次の手順を実行します。

  1. 実行中の実行コンテキスト を leafContext とする
  2. Suspend leafContext
  3. 実行コンテキストスタック から leafContext をポップする。 スタックの最上位にある 実行コンテキスト が 実行中の実行コンテキスト になる
  4. Assert: leafContext はこれ以上使用されない。実行中の実行コンテキストとしてアクティブ化されることはない

末尾呼び出しは、ターゲット関数を呼び出す前に、現在実行中の関数実行コンテキスト に関連付けられている一時的な内部リソースを解放するか、ターゲット関数をサポートするためにそれらのリソースを再利用する必要があります。leafContextはそれ以上使用できません。 実行中の実行コンテキストとしてアクティブ化されることはありません。

例:末尾呼び出しは、ターゲット関数のアクティブ化レコードのサイズが呼び出し元の関数のアクティブ化レコードのサイズを超える量だけ、実装のアクティブ化レコードスタックを増やす必要があります。 ターゲット関数のアクティブ化レコードが小さい場合、スタックの合計サイズは減少します。