このページはECMAScript® 2020 Language Specification14 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ディレクティブ

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

ディレクティブ(命令)プロローグは、FunctionBodyScriptBodyModuleBodyの最初の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)

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

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

  1. BindingIdentifierBoundNames を返す
  1. « "*default*" » を返す
"*default*" は、export宣言を使用して定義されたホイスタブル無名関数の合成名として、この仕様内で使用されます。
  1. 空の新規List を返す
  1. FormalParameterListBoundNamesnames とする
  2. FunctionRestParameterBoundNamesnames に追加する
  3. names を返す
  1. FormalParameterListBoundNames を names とする
  2. FormalParameterBoundNamesnames に追加する
  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. FormalParameterListContainsExpressiontrue なら、 true を返す
  2. FunctionRestParameterContainsExpression を返す
  1. FormalParameterListContainsExpressiontrue なら、 true を返す
  2. FormalParameterContainsExpression を返す

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

引数 labelSet を使用。

  1. false を返す

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

引数 iterationSetlabelSet を使用。

  1. false を返す

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

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

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

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

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

  1. FormalParameterListHasInitializertrue なら、 true を返す
  2. FormalParameterHasInitializer を返す

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

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

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

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

  1. exprIsFunctionDefinitionfalse なら、 false を返す
  2. exprHasNamehasName とする
  3. hasNametrue なら、 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. FormalParameterListIsSimpleParameterListfalse なら、 false を返す
  2. FormalParameterIsSimpleParameterList を返す
  1. BindingElementIsSimpleParameterList を返す

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

  1. 空の新規List を返す
  1. StatementListTopLevelLexicallyDeclaredNames を返す

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

  1. 空の新規List を返す
  1. StatementListTopLevelLexicallyScopedDeclarations を返す

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

  1. 空の新規List を返す
  1. StatementListTopLevelVarDeclaredNames を返す

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

  1. 空の新規List を返す
  1. StatementListTopLevelVarScopedDeclarations を返す

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

引数 functionObjectargumentsList を使用。

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

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

引数 iteratorRecordenvironment を使用。

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

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

引数 scope を使用。

  1. BindingIdentifierStringValuename とする
  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  2. OrdinaryFunctionCreate(%Function.prototype%, FormalParameters , FunctionBody , non-lexical-this, scope) を closure とする
  3. MakeConstructor(closure) を実行する
  4. FunctionExpression一致するソーステキストclosure.[[SourceText]] にセットする
  5. closure を返す
  1. 実行中の実行コンテキストLexicalEnvironmentscope とする
  2. NewDeclarativeEnvironment(scope) を funcEnv とする
  3. funcEnvEnvironmentRecordenvRec とする
  4. BindingIdentifierStringValuename とする
  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 を返す
FunctionExpressionBindingIdentifierは、FunctionExpressionFunctionBody内から参照して、関数がそれ自体を再帰的に呼び出すことができます。 ただし、FunctionDeclarationとは異なり、FunctionExpressionBindingIdentifierは参照できず、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. CoverParenthesizedExpressionAndArrowParameterListCoveredFormalsListformals とする
  2. formalsBoundNames を返す

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

引数 symbol を使用。

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

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

  1. false を返す
  1. CoverParenthesizedExpressionAndArrowParameterListCoveredFormalsListformals とする
  2. formalsContainsExpression を返す

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

  1. false を返す

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

  1. 1 を返す
  1. CoverParenthesizedExpressionAndArrowParameterListCoveredFormalsListformals とする
  2. formalsExpectedArgumentCount を返す

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

  1. false を返す

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

  1. true を返す
  1. CoverParenthesizedExpressionAndArrowParameterListCoveredFormalsListformals とする
  2. formalsIsSimpleParameterList を返す

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

引数 iteratorRecordenvironment を使用。

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

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

引数 functionObjectargumentsList を使用。

  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  2. ArrowParametersCoveredFormalsListparameters とする
  3. OrdinaryFunctionCreate(%Function.prototype%, parameters, ConciseBody , lexical-this, scope) を closure とする
  4. ArrowFunction一致するソーステキストclosure.[[SourceText]] にセットする
  5. closure を返す
ArrowFunctionは、argumentssuperthis、および、new.targetのローカルバインディングを定義しません。 ArrowFunction内のargumentsなどへの参照は、レキシカル的に囲んでいる環境のバインディングにて解決される必要があります。 通常、これは直接囲んでいる関数の関数環境です。 ArrowFunctionsuperへの参照が含まれている場合でも、手順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 を使用して PropertyNameComputedPropertyContains の結果を返す

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

  1. FormalParameterHasInitializertrue なら、 0 を返す
  2. 1 を返す

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

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

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

  1. PropertyNamePropName を返す

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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  4. functionPrototype が存在するなら、
    1. functionPrototypeprototype とする
  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

引数 objectenumerable を使用。

  1. 引数 object を使用して MethodDefinition? DefineMethodmethodDef とする
  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  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. BindingIdentifierBoundNames を返す
  1. « "*default*" » を返す
この仕様内で"*default*" は、export宣言を使用して定義されたホイスタブル無名関数の合成名として使用されます。

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

引数 symbol を使用。

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

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

引数 symbol を使用。

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

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

  1. UniqueFormalParameters Contains SuperCalltrue なら、 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. PropertyNamePropName を返す

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

引数 functionObjectargumentsList を使用。

  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. BindingIdentifierStringValuename とする
  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

引数 objectenumerable を使用。

  1. PropertyName の評価結果を propKey とする
  2. ReturnIfAbrupt(propKey)
  3. 実行中の実行コンテキストLexicalEnvironmentscope とする
  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  2. NewDeclarativeEnvironment(scope) を funcEnv とする
  3. funcEnvEnvironmentRecordenvRec とする
  4. BindingIdentifierStringValuename とする
  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 を返す
GeneratorExpressionBindingIdentifierは、GeneratorExpressionFunctionBody内から参照して、ジェネレーターコードがそれ自体を再帰的に呼び出すことができます。 ただし、GeneratorDeclarationとは異なり、GeneratorExpressionBindingIdentifierは、GeneratorExpressionを囲むスコープから参照することはできず、影響を与えません。
  1. ! GetGeneratorKind() を generatorKind とする
  2. generatorKindasync なら、 ? AsyncGeneratorYield(undefined) を返す
  3. ? GeneratorYield( CreateIterResultObject(undefined, false)) を返す
  1. ! GetGeneratorKind() を generatorKind とする
  2. AssignmentExpression の評価結果を exprRef とする
  3. ? GetValue(exprRef) を value とする
  4. generatorKindasync なら、 ? 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. generatorKindasync なら、 ? Await(innerResult) を innerResult にセットする
      3. Type(innerResult) が Object型 でないなら、 TypeError例外をスローする
      4. ? IteratorComplete(innerResult) を done とする
      5. donetrue なら、
        1. ? IteratorValue(innerResult) を返す
      6. generatorKindasync なら、 AsyncGeneratorYield(? IteratorValue(innerResult)) を received にセットする
      7. vi. と異なるなら、GeneratorYield(innerResult) を received にセットする
    2. a. と異なり、received.[[Type]] が throw なら、
      1. ? GetMethod(iterator, "throw") を throw とする
      2. throwundefined でないなら、
        1. ? Call(throw, iterator, « received.[[Value]] ») を innerResult とする
        2. generatorKindasync なら、 ? Await(innerResult) を innerResult にセットする
        3. NOTE: 内部のイテレータのthrowメソッドからの例外が伝播される。 throwメソッドからの通常の完了は、内部のnextと同様に処理する
        4. Type(innerResult) が Object型 でないなら、 TypeError例外をスローする
        5. ? IteratorComplete(innerResult) を done とする
        6. donetrue なら、
          1. ? IteratorValue(innerResult) を返す
        7. generatorKindasync なら、 AsyncGeneratorYield(? IteratorValue(innerResult)) を received にセットする
        8. 7. と異なるなら、 GeneratorYield(innerResult) を received にセットする
      3. ii. と異なるなら、
        1. NOTE: iteratorthrowメソッドがないなら、このthrowyield *ループを終了する。 ただし、最初にiteratorをクリーンアップする必要がある。
        2. Completion { [[Type]]: normal, [[Value]]: empty, [[Target]]: empty } を closeCompletion とする
        3. generatorKindasync なら、 ? 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. returnundefined なら、
        1. generatorKindasync なら、 ? Await(received.[[Value]]) を received.[[Value]] にセットする
        2. Completion(received) を返す
      4. ? Call(return, iterator, « received.[[Value]] ») を innerReturnResult とする
      5. generatorKindasync なら、 ? Await(innerReturnResult) を innerReturnResult にセットする
      6. Type(innerReturnResult) が Object型 でないなら、 TypeError例外をスローする
      7. ? IteratorComplete(innerReturnResult) を done とする
      8. donetrue なら、
        1. ? IteratorValue(innerReturnResult) を value とする
        2. Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty } を返す
      9. generatorKindasync なら、 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 を使用して PropertyNameComputedPropertyContains の結果を返す

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

引数 symbol を使用。

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

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

  1. UniqueFormalParameters Contains SuperCalltrue なら、 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. PropertyNamePropName を返す

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

引数 functionObjectargumentsList を使用。

  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. BindingIdentifierStringValuename とする
  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

引数 objectenumerable を使用。

  1. PropertyName の評価結果を propKey とする
  2. ReturnIfAbrupt(propKey)
  3. 実行中の実行コンテキストLexicalEnvironmentscope とする
  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  2. ! NewDeclarativeEnvironment(scope) を funcEnv とする
  3. funcEnvEnvironmentRecordenvRec とする
  4. BindingIdentifierStringValuename とする
  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 を返す
AsyncGeneratorExpressionBindingIdentifierは、AsyncGeneratorExpressionAsyncGeneratorBody内から参照して、ジェネレーターコードがそれ自体を再帰的に呼び出すことができます。 ただし、AsyncGeneratorDeclarationとは異なり、AsyncGeneratorExpressionBindingIdentifierは、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. ClassBodyConstructorMethodconstructor とする
    2. constructorempty なら、 false を返す
    3. constructorHasDirectSuper を返す
  • ClassElementListPrototypePropertyNameList に複数の "constructor" が含まれている場合は構文エラ。

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

  1. BindingIdentifierBoundNames を返す
  1. « "*default*" » を返す

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

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

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

引数 symbol を使用。

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

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

引数 symbol を使用。

  1. 引数 symbol を使用して ClassElementListComputedPropertyContainsinList とする
  2. inListtrue なら、 true を返す
  3. 引数 symbol を使用して ClassElementComputedPropertyContains の結果を返す
  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. ClassElementClassElement : ; なら、 空の新規List を返す
  2. ClassElementIsStaticfalseClassElementPropName"constructor" なら、 空の新規List を返す
  3. ClassElement を含む List を返す
  1. ClassElementListNonConstructorMethodDefinitionslist とする
  2. ClassElementClassElement : ; なら、 list を返す
  3. ClassElementIsStaticfalseClassElementPropName"constructor" なら、 list を返す
  4. list の最後に ClassElement を追加する
  5. list を返す

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

  1. ClassElementPropNameempty なら、 空の新規List を返す
  2. ClassElementIsStatictrue なら、 空の新規List を返す
  3. ClassElementPropName を含む Listを返す
  1. ClassElementListPrototypePropertyNameListlist とする
  2. ClassElementPropNameempty なら、 list を返す
  3. ClassElementIsStatictrue なら、 list を返す
  4. list の最後に ClassElementPropName を追加する
  5. list を返す

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

  1. empty を返す

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

引数 classBindingclassName を使用。

  1. 実行中の実行コンテキストLexicalEnvironmentlex とする
  2. NewDeclarativeEnvironment(lex) を classScope とする
  3. classScopeEnvironmentRecordclassScopeEnvRec とする
  4. classBindingundefined でないなら、
    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. superclassnull なら、
      1. nullprotoParent とする
      2. %Function.prototype% を constructorParent とする
    6. e. と異なるなり、 IsConstructor(superclass) が false なら、 TypeError例外をスローする
    7. f. と異なるなら、
      1. ? Get(superclass, "prototype") を protoParent とする
      2. Type(protoParent) が Object型 か Null なら、 TypeError例外をスローする
      3. superclassconstructorParent とする
  7. OrdinaryObjectCreate(protoParent) を proto とする
  8. ClassBodyopt が 存在しないなら、 emptyconstructor とする
  9. 8. と異なるなら、 ClassBodyConstructorMethodconstructor とする
  10. constructorempty なら、
    1. ClassHeritageopt が 存在するなら、
      1. 次のソーステキストを解析した結果を constructor にセットする
        constructor(...args) { super(...args); }

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

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

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

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

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

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

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

引数 name を使用。

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

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

  1. ? ClassDeclarationBindingClassDeclarationEvaluation を実行する
  2. NormalCompletion(empty) を返す
ClassDeclaration class ClassTail は、ExportDeclaration の一部としてのみ発生し、直接評価されることはありません。
  1. BindingIdentifieropt が 存在しないなら、 undefinedclassName とする
  2. 3. と異なるなら、 BindingIdentifierStringValueclassName とする
  3. 引数 classNameclassName を使用して ClassTail? ClassDefinitionEvaluationvalue とする
  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]パラメーターが存在する場合、awaitAwaitExpressionとして解析されます。 [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 を使用して PropertyNameComputedPropertyContains の結果を返す

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

引数 symbol を使用。

  1. false を返す

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

  1. UniqueFormalParameters Contains SuperCalltrue なら、 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. PropertyNamePropName を返す

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

引数 scope を使用。

  1. BindingIdentifierStringValuename とする
  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

引数 functionObjectargumentsList を使用。

  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

引数 objectenumerable を使用。

  1. PropertyName の評価結果を propKey とする
  2. ReturnIfAbrupt(propKey)
  3. 実行中の実行コンテキストLexicalEnvironmentscope とする
  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  2. ! OrdinaryFunctionCreate(%AsyncFunction.prototype%, FormalParameters , AsyncFunctionBody , non-lexical-this, scope) を closure とする
  3. AsyncFunctionExpression一致するソーステキストclosure.[[SourceText]] にセットする
  4. closure を返す
  1. 実行中の実行コンテキストLexicalEnvironmentscope とする
  2. ! NewDeclarativeEnvironment(scope) を funcEnv とする
  3. funcEnvEnvironmentRecordenvRec とする
  4. BindingIdentifierStringValuename とする
  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. CoverCallExpressionAndAsyncArrowHeadCoveredAsyncArrowHeadhead とする
  2. headBoundNames を返す

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

引数 symbol を使用。

  1. symbolNewTargetSuperPropertySuperCallsuperthis のどれかでないなら、 false を返す
  2. AsyncConciseBody Contains symbol を返す
  1. symbolNewTargetSuperPropertySuperCallsuperthis のどれかでないなら、 false を返す
  2. CoverCallExpressionAndAsyncArrowHeadCoveredAsyncArrowHeadhead とする
  3. head Contains symboltrue なら、 true を返す
  4. AsyncConciseBody Contains symbol を返す
通常、Containsはほとんどの関数フォームの内部を調べません。 ただし、Containsは、AsyncArrowFunction内のnew.targetthis、および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. CoverCallExpressionAndAsyncArrowHeadCoveredAsyncArrowHeadhead とする
  2. headIsSimpleParameterList を返す

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

引数 iteratorRecordenvironment を使用。

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

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

引数 functionObjectargumentsList を使用。

  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. 実行中の実行コンテキストLexicalEnvironmentscope とする
  2. CoverCallExpressionAndAsyncArrowHeadCoveredAsyncArrowHeadhead とする
  3. headArrowFormalParametersparameters とする
  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. callFunctionBodyConciseBodyAsyncConciseBody に含まれていないなら、 false を返す
  4. FunctionBodyConciseBodyAsyncConciseBody のうち、call が一番密接に含まれているものを body とする
  5. bodyGeneratorBodyFunctionBody なら、 false を返す
  6. bodyAsyncFunctionBodyFunctionBody なら、 false を返す
  7. bodyAsyncGeneratorBodyFunctionBody なら、 false を返す
  8. bodyAsyncConciseBody なら、 false を返す
  9. 引数 call を使用して bodyHasCallInTailPosition の結果を返す
末尾呼び出しは、呼び出し元コンテキストのチェーンの監視を可能にする一般的な非標準言語拡張(9.2.4)のため、strictモードコード のみで定義されます。

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

引数 call を使用。

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

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

  1. 引数 call を使用して StatementListHasCallInTailPositionhas とする
  2. hastrue なら、 true を返す
  3. 引数 call を使用して StatementListItemHasCallInTailPosition の実行結果を返す
Block :

{}
ReturnStatement :

return;
CaseBlock :

{}
  1. false を返す
  1. 引数 call を使用して、最初の StatementHasCallInTailPositionhas とする
  2. hastrue なら、 true を返す
  3. 引数 call を使用して、2番目の StatementHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して StatementHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して LabelledItemHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して ExpressionHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して CaseBlockHasCallInTailPosition の実行結果を返す
  1. falsehas とする
  2. 最初の CaseClauses が存在するなら、 引数 call を使用して、最初の CaseClausesHasCallInTailPosition を has とする
  3. hastrue なら、 true を返す
  4. 引数 call を使用して DefaultClauseHasCallInTailPositionhas とする
  5. hastrue なら、 true を返す
  6. 2番目の CaseClauses が 存在するなら、 引数 call を使用して、2番目の CaseClausesHasCallInTailPositionhas とする
  7. has を返す
  1. 引数 call を使用して CaseClausesHasCallInTailPositionhas とする
  2. hastrue なら、 true を返す
  3. 引数 call を使用して CaseClauseHasCallInTailPosition の実行結果を返す
  1. StatementList が存在するなら、 引数 call を使用して StatementListHasCallInTailPosition の実行結果を返す
  2. false を返す
  1. 引数 call を使用して CatchHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して FinallyHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して BlockHasCallInTailPosition の実行結果を返す

14.9.2.2 表示規則(Expression Rules)

呼び出し結果の戻り値GetValueが直後に続く潜在的な末尾呼び出しも、有効な末尾呼び出しです。 関数呼び出しは参照値を返すことができないため、このようなGetValue操作は常に実際の関数呼び出しの結果と同じ値を返します。
  1. false を返す
  1. 引数 call を使用して AssignmentExpressionHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して 最初の AssignmentExpressionHasCallInTailPositionhas とする
  2. hastrue なら、 true を返す
  3. 引数 call を使用して 2番目の AssignmentExpressionHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して BitwiseORExpressionHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して LogicalANDExpressionHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して BitwiseORExpressionHasCallInTailPosition の実行結果を返す
  1. CallExpressioncall なら、 true を返す
  2. false を返す
  1. 引数 call を使用して OptionalChainHasCallInTailPosition の実行結果を返す
  1. false を返す
  1. OptionalChaincall なら、 true を返す
  2. false を返す
  1. MemberExpressioncall なら、 true を返す
  2. false を返す
  1. CoverParenthesizedExpressionAndArrowParameterListCoveredParenthesizedExpressionexpr とする
  2. 引数 call を使用して exprHasCallInTailPosition の実行結果を返す
  1. 引数 call を使用して ExpressionHasCallInTailPosition の実行結果を返す

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

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

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

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

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