7 抽象操作

これらの操作はECMAScript言語の一部ではありません。これらは、ECMAScript言語の意味論の仕様を補助するためだけにここで定義されます。その他の、より特殊化された抽象操作は、この仕様全体にわたって定義されます。

7.1 型変換

ECMAScript言語は、必要に応じて自動的な型変換を暗黙に実行します。特定の構文の意味論を明確にするため、変換抽象操作の集合を定義することが有用です。変換抽象操作は多態的です。任意のECMAScript言語型の値を受け入れることができます。ただし、これらの操作では他の仕様型は使用されません。

BigInt型にはECMAScript言語における暗黙変換はありません。プログラマーは、他の型から値を変換するにはBigIntを明示的に呼び出さなければなりません。

7.1.1 ToPrimitive ( input [ , preferredType ] )

The abstract operation ToPrimitive takes argument input (an ECMAScript language value) and optional argument preferredType (string or number) and returns either a normal completion containing an ECMAScript language value or a throw completion. これはinput argumentを非Object型へ変換します。オブジェクトが複数のprimitive型へ変換可能である場合、optional hint preferredTypeを使用してその型を優先することがあります。 It performs the following steps when called:

  1. inputがObjectなら、
    1. exoticToPrimitiveを ? GetMethod(input, %Symbol.toPrimitive%) とする。
    2. exoticToPrimitiveundefinedでないなら、
      1. preferredTypeが存在しないなら、
        1. hint"default"とする。
      2. そうでなく、preferredTypestringなら、
        1. hint"string"とする。
      3. そうでなければ、
        1. Assert: preferredTypenumberである。
        2. hint"number"とする。
      4. resultを ? Call(exoticToPrimitive, input, « hint ») とする。
      5. resultがObjectでないなら、resultを返す。
      6. TypeError例外をthrowする。
    3. preferredTypeが存在しないなら、preferredTypenumberに設定する。
    4. OrdinaryToPrimitive(input, preferredType)を返す。
  2. inputを返す。
Note

ToPrimitiveがhintなしで呼び出された場合、一般にhintがnumberであるかのように振る舞います。ただし、オブジェクトは%Symbol.toPrimitive%メソッドを定義することでこの振る舞いを上書きできます。この仕様で定義されるオブジェクトのうち、Dates(21.4.4.45を参照)およびSymbol objects(20.4.3.5を参照)のみがデフォルトのToPrimitiveの振る舞いを上書きします。Datesはhintが存在しないことを、hintがstringであるかのように扱います。

7.1.1.1 OrdinaryToPrimitive ( obj, hint )

The abstract operation OrdinaryToPrimitive takes arguments obj (an Object) and hint (string or number) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. hintstringなら、
    1. methodNamesを« "toString", "valueOf" »とする。
  2. そうでなければ、
    1. methodNamesを« "valueOf", "toString" »とする。
  3. methodNamesの各要素nameについて、以下を行う
    1. methodを ? Get(obj, name) とする。
    2. IsCallable(method)がtrueなら、
      1. resultを ? Call(method, obj) とする。
      2. resultがObjectでないなら、resultを返す。
  4. TypeError例外をthrowする。

7.1.2 ToBoolean ( arg )

The abstract operation ToBoolean takes argument arg (an ECMAScript language value) and returns a Boolean. これはargBoolean型の値へ変換します。 It performs the following steps when called:

  1. argがBooleanなら、argを返す。
  2. argundefinednull+0𝔽-0𝔽NaN0、または空のStringのいずれかなら、falseを返す。
  3. hostがweb browserであるか、または他の方法で[[IsHTMLDDA]] Internal Slotをサポートするなら、
    1. argがObjectであり、arg[[IsHTMLDDA]] internal slotを持つなら、falseを返す。
  4. trueを返す。

7.1.3 ToNumeric ( arg )

The abstract operation ToNumeric takes argument arg (an ECMAScript language value) and returns either a normal completion containing either a Number or a BigInt, or a throw completion. これはargをNumberまたはBigIntへ変換して返します。 It performs the following steps when called:

  1. primitiveValueを ? ToPrimitive(arg, number) とする。
  2. primitiveValueがBigIntなら、primitiveValueを返す。
  3. ToNumber(primitiveValue)を返す。

7.1.4 ToNumber ( arg )

The abstract operation ToNumber takes argument arg (an ECMAScript language value) and returns either a normal completion containing a Number or a throw completion. これはargNumber型の値へ変換します。 It performs the following steps when called:

  1. argがNumberなら、argを返す。
  2. argがSymbolまたはBigIntのいずれかなら、TypeError例外をthrowする。
  3. argundefinedなら、NaNを返す。
  4. argnullまたはfalseのいずれかなら、+0𝔽を返す。
  5. argtrueなら、1𝔽を返す。
  6. argがStringなら、StringToNumber(arg)を返す。
  7. Assert: argはObjectである。
  8. primitiveValueを ? ToPrimitive(arg, number) とする。
  9. Assert: primitiveValueはObjectでない。
  10. ToNumber(primitiveValue)を返す。

7.1.4.1 String型に適用されるToNumber

抽象操作StringToNumberは、以下の文法を使用してString値をNumber値へ変換する方法を指定します。

構文

StringNumericLiteral ::: StrWhiteSpaceopt StrWhiteSpaceopt StrNumericLiteral StrWhiteSpaceopt StrWhiteSpace ::: StrWhiteSpaceChar StrWhiteSpaceopt StrWhiteSpaceChar ::: WhiteSpace LineTerminator StrNumericLiteral ::: StrDecimalLiteral NonDecimalIntegerLiteral[~Sep] StrDecimalLiteral ::: StrUnsignedDecimalLiteral + StrUnsignedDecimalLiteral - StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral ::: Infinity DecimalDigits[~Sep] . DecimalDigits[~Sep]opt ExponentPart[~Sep]opt . DecimalDigits[~Sep] ExponentPart[~Sep]opt DecimalDigits[~Sep] ExponentPart[~Sep]opt

上で明示的に定義されていないすべてのgrammar symbolsは、numeric literalsのLexical Grammarで使用される定義を持ちます(12.9.3

Note

StringNumericLiteralNumericLiteralの構文の間には、いくつかの違いがあることに注意すべきです:

7.1.4.1.1 StringToNumber ( string )

The abstract operation StringToNumber takes argument string (a String) and returns a Number. It performs the following steps when called:

  1. literalParseText(string, StringNumericLiteral)とする。
  2. literalがerrorsのListなら、NaNを返す。
  3. literalStringNumericValueを返す。

7.1.4.1.2 Runtime Semantics: StringNumericValue

The syntax-directed operation StringNumericValue takes no arguments and returns a Number.

Note

StringNumericLiteralからNumber値への変換は、全体としてNumericLiteralNumericValueの決定(12.9.3を参照)に似ていますが、詳細の一部は異なります。

It is defined piecewise over the following productions:

StringNumericLiteral ::: StrWhiteSpaceopt
  1. +0𝔽を返す。
StringNumericLiteral ::: StrWhiteSpaceopt StrNumericLiteral StrWhiteSpaceopt
  1. StrNumericLiteralStringNumericValueを返す。
StrNumericLiteral ::: NonDecimalIntegerLiteral
  1. 𝔽(NonDecimalIntegerLiteralのMV)を返す。
StrDecimalLiteral ::: - StrUnsignedDecimalLiteral
  1. aStrUnsignedDecimalLiteralStringNumericValueとする。
  2. a+0𝔽なら、-0𝔽を返す。
  3. -aを返す。
StrUnsignedDecimalLiteral ::: Infinity
  1. +∞𝔽を返す。
StrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigitsopt ExponentPartopt
  1. aを最初のDecimalDigitsのMVとする。
  2. 2番目のDecimalDigitsが存在するなら、
    1. bを2番目のDecimalDigitsのMVとする。
    2. nを2番目のDecimalDigits内のcode pointsの数とする。
  3. そうでなければ、
    1. bを0とする。
    2. nを0とする。
  4. ExponentPartが存在するなら、eExponentPartのMVとする。そうでなければ、eを0とする。
  5. RoundMVResult((a + (b × 10-n)) × 10e)を返す。
StrUnsignedDecimalLiteral ::: . DecimalDigits ExponentPartopt
  1. bDecimalDigitsのMVとする。
  2. ExponentPartが存在するなら、eExponentPartのMVとする。そうでなければ、eを0とする。
  3. nDecimalDigits内のcode pointsの数とする。
  4. RoundMVResult(b × 10e - n)を返す。
StrUnsignedDecimalLiteral ::: DecimalDigits ExponentPartopt
  1. aDecimalDigitsのMVとする。
  2. ExponentPartが存在するなら、eExponentPartのMVとする。そうでなければ、eを0とする。
  3. RoundMVResult(a × 10e)を返す。

7.1.4.1.3 RoundMVResult ( n )

The abstract operation RoundMVResult takes argument n (a mathematical value) and returns a Number. これはnimplementation-definedな方法でNumberへ変換します。この抽象操作の目的では、digitは、それがzeroでない場合、またはその左にnon-zero digitがあり、かつその右にnon-zero digitがある場合にsignificantです。この抽象操作の目的では、mathematical valueの表現が“表すmathematical value”は、mathematical valueの“decimal representation”の逆です。 It performs the following steps when called:

  1. nのdecimal representationが20個以下のsignificant digitsを持つなら、𝔽(n)を返す。
  2. option1を、nのdecimal representation内の20番目以降の各significant digitを0 digitで置き換えた結果が表すmathematical valueとする。
  3. option2を、nのdecimal representation内の20番目以降の各significant digitを0 digitで置き換え、その後20番目の位置でそれをincrementした結果(必要に応じて繰り上がりを伴う)が表すmathematical valueとする。
  4. chosenoption1またはoption2のいずれかのimplementation-definedな選択とする。
  5. 𝔽(chosen)を返す。

7.1.5 ToIntegerOrInfinity ( arg )

The abstract operation ToIntegerOrInfinity takes argument arg (an ECMAScript language value) and returns either a normal completion containing either an integer, +∞, or -∞, or a throw completion. これはargを、そのNumber値の小数部を切り捨てたものを表すintegerへ、またはそのNumber値が無限である場合は+∞または-∞へ変換します。 It performs the following steps when called:

  1. numberを ? ToNumber(arg) とする。
  2. numberNaN+0𝔽、または-0𝔽のいずれかなら、0を返す。
  3. number+∞𝔽なら、+∞を返す。
  4. number-∞𝔽なら、-∞を返す。
  5. truncate((number))を返す。
Note
𝔽(ToIntegerOrInfinity(x))は、xの任意の値について決して-0𝔽を返しません。小数部の切り捨ては、xmathematical valueへ変換した後に実行されます。

7.1.6 ToFixedSizeInteger ( int, signed, bitWidth )

The abstract operation ToFixedSizeInteger takes arguments int (an integer, +∞, or -∞), signed (unsigned or signed), and bitWidth (a positive integer) and returns an integer. これはintを、signedunsignedの場合は0から2bitWidth - 1までの包含区間内の2bitWidth個のintegersの1つへ、またはsignedsignedの場合は-2bitWidth - 1から2bitWidth - 1 - 1までの包含区間内の2bitWidth個のintegersの1つへ写像します。 It performs the following steps when called:

  1. int = +∞またはint = -∞なら、0を返す。
  2. fixedIntint modulo 2bitWidthとする。
  3. NOTE: 次のステップはfixedIntのtwo's complement representationを変更しません。
  4. signedsignedかつfixedInt ≥ 2bitWidth - 1なら、fixedIntfixedInt - 2bitWidthに設定する。
  5. fixedIntを返す。
Note

ToFixedSizeIntegerはidempotentです。任意のECMAScript言語値xについて、ToFixedSizeInteger(ToFixedSizeInteger(x, signed, bitWidth), signed, bitWidth)はToFixedSizeInteger(x, signed, bitWidth)と同じです。実際、+∞および-∞は0へ写像されるため、この不変条件はsignedの反転後にも維持されます(例:ToFixedSizeInteger(ToFixedSizeInteger(x, signed, 32), unsigned, 32)はToFixedSizeInteger(x, unsigned, 32)と同じです)。

7.1.7 ToInt32 ( arg )

The abstract operation ToInt32 takes argument arg (an ECMAScript language value) and returns either a normal completion containing an integral Number or a throw completion. これはargを、𝔽(-231)から𝔽(231 - 1)までの包含区間内の、-0𝔽を除く232個のintegral Number値の1つへ変換します。 It performs the following steps when called:

  1. intを ? ToIntegerOrInfinity(arg) とする。
  2. 𝔽(ToFixedSizeInteger(int, signed, 32))を返す。

7.1.8 ToUint32 ( arg )

The abstract operation ToUint32 takes argument arg (an ECMAScript language value) and returns either a normal completion containing an integral Number or a throw completion. これはargを、+0𝔽から𝔽(232 - 1)までの包含区間内の232個のintegral Number値の1つへ変換します。 It performs the following steps when called:

  1. intを ? ToIntegerOrInfinity(arg) とする。
  2. 𝔽(ToFixedSizeInteger(int, unsigned, 32))を返す。

7.1.9 ToInt16 ( arg )

The abstract operation ToInt16 takes argument arg (an ECMAScript language value) and returns either a normal completion containing an integral Number or a throw completion. これはargを、𝔽(-215)から𝔽(215 - 1)までの包含区間内の、-0𝔽を除く216個のintegral Number値の1つへ変換します。 It performs the following steps when called:

  1. intを ? ToIntegerOrInfinity(arg) とする。
  2. 𝔽(ToFixedSizeInteger(int, signed, 16))を返す。

7.1.10 ToUint16 ( arg )

The abstract operation ToUint16 takes argument arg (an ECMAScript language value) and returns either a normal completion containing an integral Number or a throw completion. これはargを、+0𝔽から𝔽(216 - 1)までの包含区間内の216個のintegral Number値の1つへ変換します。 It performs the following steps when called:

  1. intを ? ToIntegerOrInfinity(arg) とする。
  2. 𝔽(ToFixedSizeInteger(int, unsigned, 16))を返す。

7.1.11 ToInt8 ( arg )

The abstract operation ToInt8 takes argument arg (an ECMAScript language value) and returns either a normal completion containing an integral Number or a throw completion. これはargを、-128𝔽から127𝔽までの包含区間内の、-0𝔽を除く28個のintegral Number値の1つへ変換します。 It performs the following steps when called:

  1. intを ? ToIntegerOrInfinity(arg) とする。
  2. 𝔽(ToFixedSizeInteger(int, signed, 8))を返す。

7.1.12 ToUint8 ( arg )

The abstract operation ToUint8 takes argument arg (an ECMAScript language value) and returns either a normal completion containing an integral Number or a throw completion. これはargを、+0𝔽から255𝔽までの包含区間内の28個のintegral Number値の1つへ変換します。 It performs the following steps when called:

  1. intを ? ToIntegerOrInfinity(arg) とする。
  2. 𝔽(ToFixedSizeInteger(int, unsigned, 8))を返す。

7.1.13 ToUint8Clamp ( arg )

The abstract operation ToUint8Clamp takes argument arg (an ECMAScript language value) and returns either a normal completion containing an integral Number or a throw completion. これはargをclampして丸め、+0𝔽から255𝔽までの包含区間内の28個のintegral Number値の1つへ変換します。 It performs the following steps when called:

  1. numberを ? ToNumber(arg) とする。
  2. numberNaNなら、+0𝔽を返す。
  3. mvnumberextended mathematical valueとする。
  4. clampedmvを0から255の間にclampした結果とする。
  5. ffloor(clamped)とする。
  6. clamped < f + 0.5なら、𝔽(f)を返す。
  7. clamped > f + 0.5なら、𝔽(f + 1)を返す。
  8. fがevenなら、𝔽(f)を返す。
  9. 𝔽(f + 1)を返す。
Note

他のほとんどのECMAScript整数変換操作とは異なり、ToUint8Clampは非整数値を切り捨てるのではなく丸めます。また、“round half to even”のtie-breakingを使用します。これはMath.roundの“round half up”のtie-breakingとは異なります。

7.1.14 ToBigInt ( arg )

The abstract operation ToBigInt takes argument arg (an ECMAScript language value) and returns either a normal completion containing a BigInt or a throw completion. これはargをBigInt値へ変換するか、Numberからの暗黙変換が必要な場合はthrowします。 It performs the following steps when called:

  1. primitiveを ? ToPrimitive(arg, number) とする。
  2. primitiveTable 12で対応する値を返す。
Table 12: BigInt Conversions
Argument Type 結果
Undefined TypeError例外をthrowする。
Null TypeError例外をthrowする。
Boolean primitivetrueなら1nを返し、primitivefalseなら0nを返す。
BigInt primitiveを返す。
Number TypeError例外をthrowする。
String
  1. nStringToBigInt(primitive)とする。
  2. nundefinedなら、SyntaxError例外をthrowする。
  3. nを返す。
Symbol TypeError例外をthrowする。

7.1.15 StringToBigInt ( string )

The abstract operation StringToBigInt takes argument string (a String) and returns a BigInt or undefined. It performs the following steps when called:

  1. literalParseText(string, StringIntegerLiteral)とする。
  2. literalがerrorsのListなら、undefinedを返す。
  3. mvliteralのMVとする。
  4. Assert: mvintegerである。
  5. (mv)を返す。

7.1.15.1 StringIntegerLiteral文法

StringToBigIntは以下の文法を使用します。

構文

StringIntegerLiteral ::: StrWhiteSpaceopt StrWhiteSpaceopt StrIntegerLiteral StrWhiteSpaceopt StrIntegerLiteral ::: SignedInteger[~Sep] NonDecimalIntegerLiteral[~Sep]

7.1.15.2 Runtime Semantics: MV

7.1.16 ToBigInt64 ( arg )

The abstract operation ToBigInt64 takes argument arg (an ECMAScript language value) and returns either a normal completion containing a BigInt or a throw completion. これはargを、(-263)から(263 - 1)までの包含区間内の264個のBigInt値の1つへ変換します。 It performs the following steps when called:

  1. int(? ToBigInt(arg))とする。
  2. (ToFixedSizeInteger(int, signed, 64))を返す。

7.1.17 ToBigUint64 ( arg )

The abstract operation ToBigUint64 takes argument arg (an ECMAScript language value) and returns either a normal completion containing a BigInt or a throw completion. これはargを、0から(264 - 1)までの包含区間内の264個のBigInt値の1つへ変換します。 It performs the following steps when called:

  1. int(? ToBigInt(arg))とする。
  2. (ToFixedSizeInteger(int, unsigned, 64))を返す。

7.1.18 ToString ( arg )

The abstract operation ToString takes argument arg (an ECMAScript language value) and returns either a normal completion containing a String or a throw completion. これはargString型の値へ変換します。 It performs the following steps when called:

  1. argがStringなら、argを返す。
  2. argがSymbolなら、TypeError例外をthrowする。
  3. argundefinedなら、"undefined"を返す。
  4. argnullなら、"null"を返す。
  5. argtrueなら、"true"を返す。
  6. argfalseなら、"false"を返す。
  7. argがNumberなら、Number::toString(arg, 10)を返す。
  8. argがBigIntなら、BigInt::toString(arg, 10)を返す。
  9. Assert: argはObjectである。
  10. primitiveValueを ? ToPrimitive(arg, string) とする。
  11. Assert: primitiveValueはObjectでない。
  12. ToString(primitiveValue)を返す。

7.1.19 ToObject ( arg )

The abstract operation ToObject takes argument arg (an ECMAScript language value) and returns either a normal completion containing an Object or a throw completion. これはargObject型の値へ変換します。 It performs the following steps when called:

  1. argundefinedまたはnullのいずれかなら、TypeError例外をthrowする。
  2. argがBooleanなら、[[BooleanData]] internal slotがargに設定された新しいBoolean objectを返す。Boolean objectsの説明については20.3を参照。
  3. argがNumberなら、[[NumberData]] internal slotがargに設定された新しいNumber objectを返す。Number objectsの説明については21.1を参照。
  4. argがStringなら、[[StringData]] internal slotがargに設定された新しいString objectを返す。String objectsの説明については22.1を参照。
  5. argがSymbolなら、[[SymbolData]] internal slotがargに設定された新しいSymbol objectを返す。Symbol objectsの説明については20.4を参照。
  6. argがBigIntなら、[[BigIntData]] internal slotがargに設定された新しいBigInt objectを返す。BigInt objectsの説明については21.2を参照。
  7. Assert: argはObjectである。
  8. argを返す。

7.1.20 ToPropertyKey ( arg )

The abstract operation ToPropertyKey takes argument arg (an ECMAScript language value) and returns either a normal completion containing a property key or a throw completion. これはargproperty keyとして使用できる値へ変換します。 It performs the following steps when called:

  1. keyを ? ToPrimitive(arg, string) とする。
  2. keyがSymbolなら、
    1. keyを返す。
  3. ToString(key)を返す。

7.1.21 ToLength ( arg )

The abstract operation ToLength takes argument arg (an ECMAScript language value) and returns either a normal completion containing a non-negative integral Number or a throw completion. これはargを、array-like objectのlengthとして使用するのに適したnon-negative integral Numberへclampして切り捨てます。 It performs the following steps when called:

  1. lengthを ? ToIntegerOrInfinity(arg) とする。
  2. length ≤ 0なら、+0𝔽を返す。
  3. 𝔽(min(length, 253 - 1))を返す。

7.1.22 CanonicalNumericIndexString ( arg )

The abstract operation CanonicalNumericIndexString takes argument arg (a String) and returns a Number or undefined. arg"-0"であるか、あるNumber値nについてToString(n)と正確に一致する場合、それぞれのNumber値を返します。そうでなければ、undefinedを返します。 It performs the following steps when called:

  1. arg"-0"なら、-0𝔽を返す。
  2. nを ! ToNumber(arg) とする。
  3. ToString(n)がargなら、nを返す。
  4. undefinedを返す。

canonical numeric stringとは、CanonicalNumericIndexString抽象操作がundefinedを返さない任意のStringです。

7.1.23 ToIndex ( arg )

The abstract operation ToIndex takes argument arg (an ECMAScript language value) and returns either a normal completion containing a non-negative integer or a throw completion. これはargintegerへ変換し、そのintegerがnon-negativeでありinteger indexに対応する場合はそのintegerを返します。そうでなければ、例外をthrowします。 It performs the following steps when called:

  1. intを ? ToIntegerOrInfinity(arg) とする。
  2. intが0から253 - 1までの包含区間内にないなら、RangeError例外をthrowする。
  3. intを返す。

7.2 テストおよび比較操作

7.2.1 RequireObjectCoercible ( arg )

The abstract operation RequireObjectCoercible takes argument arg (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. これはargToObjectを使用してObjectへ変換できない値である場合、エラーをthrowします。 It performs the following steps when called:

  1. argundefinedまたはnullのいずれかなら、TypeError例外をthrowする。
  2. unusedを返す。

7.2.2 IsArray ( arg )

The abstract operation IsArray takes argument arg (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. argがObjectでないなら、falseを返す。
  2. argArray exotic objectなら、trueを返す。
  3. argProxy exotic objectなら、
    1. ValidateNonRevokedProxy(arg)を実行する。
    2. proxyTargetarg.[[ProxyTarget]]とする。
    3. IsArray(proxyTarget)を返す。
  4. falseを返す。

7.2.3 IsCallable ( arg )

The abstract operation IsCallable takes argument arg (an ECMAScript language value) and returns a Boolean. これはarg[[Call]] internal methodを持つcallable functionであるかどうかを決定します。 It performs the following steps when called:

  1. argがObjectでないなら、falseを返す。
  2. arg[[Call]] internal methodを持つなら、trueを返す。
  3. falseを返す。

7.2.4 IsConstructor ( arg )

The abstract operation IsConstructor takes argument arg (an ECMAScript language value) and returns a Boolean. これはarg[[Construct]] internal methodを持つfunction objectであるかどうかを決定します。 It performs the following steps when called:

  1. argがObjectでないなら、falseを返す。
  2. arg[[Construct]] internal methodを持つなら、trueを返す。
  3. falseを返す。

7.2.5 IsExtensible ( obj )

The abstract operation IsExtensible takes argument obj (an Object) and returns either a normal completion containing a Boolean or a throw completion. これは追加のプロパティをobjへ追加できるかどうかを決定するために使用されます。 It performs the following steps when called:

  1. obj.[[IsExtensible]]()を返す。

7.2.6 IsRegExp ( arg )

The abstract operation IsRegExp takes argument arg (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. argがObjectでないなら、falseを返す。
  2. matcherを ? Get(arg, %Symbol.match%) とする。
  3. matcherundefinedでないなら、ToBoolean(matcher)を返す。
  4. arg[[RegExpMatcher]] internal slotを持つなら、trueを返す。
  5. falseを返す。

7.2.7 Static Semantics: IsStringWellFormedUnicode ( string )

The abstract operation IsStringWellFormedUnicode takes argument string (a String) and returns a Boolean. これは6.1.4で記述されるように、stringをUTF-16でエンコードされたcode pointsの列として解釈し、それがwell formedなUTF-16列であるかどうかを決定します。 It performs the following steps when called:

  1. lengthstringの長さとする。
  2. kを0とする。
  3. k < lengthの間、繰り返す
    1. codePointCodePointAt(string, k)とする。
    2. codePoint.[[IsUnpairedSurrogate]]trueなら、falseを返す。
    3. kk + codePoint.[[CodeUnitCount]]に設定する。
  4. trueを返す。

7.2.8 SameType ( x, y )

The abstract operation SameType takes arguments x (an ECMAScript language value) and y (an ECMAScript language value) and returns a Boolean. これは2つのargumentsが同じ型であるかどうかを決定します。 It performs the following steps when called:

  1. xundefinedかつyundefinedなら、trueを返す。
  2. xnullかつynullなら、trueを返す。
  3. xがBooleanかつyがBooleanなら、trueを返す。
  4. xがNumberかつyがNumberなら、trueを返す。
  5. xがBigIntかつyがBigIntなら、trueを返す。
  6. xがSymbolかつyがSymbolなら、trueを返す。
  7. xがStringかつyがStringなら、trueを返す。
  8. xがObjectかつyがObjectなら、trueを返す。
  9. falseを返す。

7.2.9 SameValue ( x, y )

The abstract operation SameValue takes arguments x (an ECMAScript language value) and y (an ECMAScript language value) and returns a Boolean. これは2つのargumentsが同じ値であるかどうかを決定します。 It performs the following steps when called:

  1. SameType(x, y)がfalseなら、falseを返す。
  2. xがNumberなら、
    1. Number::sameValue(x, y)を返す。
  3. SameValueNonNumber(x, y)を返す。
Note

このアルゴリズムは、すべてのNaN値を等価として扱い、+0𝔽-0𝔽を区別する点で、IsStrictlyEqualアルゴリズムと異なります。

7.2.10 SameValueZero ( x, y )

The abstract operation SameValueZero takes arguments x (an ECMAScript language value) and y (an ECMAScript language value) and returns a Boolean. これは2つのargumentsが同じ値であるかどうかを決定します(+0𝔽-0𝔽の違いを無視します)。 It performs the following steps when called:

  1. SameType(x, y)がfalseなら、falseを返す。
  2. xがNumberなら、
    1. Number::sameValueZero(x, y)を返す。
  3. SameValueNonNumber(x, y)を返す。
Note

SameValueZeroは、+0𝔽-0𝔽を等価として扱う点でのみSameValueと異なります。

7.2.11 SameValueNonNumber ( x, y )

The abstract operation SameValueNonNumber takes arguments x (an ECMAScript language value, but not a Number) and y (an ECMAScript language value, but not a Number) and returns a Boolean. It performs the following steps when called:

  1. Assert: SameType(x, y)はtrueである。
  2. xundefinedまたはnullのいずれかなら、trueを返す。
  3. xがBigIntなら、
    1. BigInt::equal(x, y)を返す。
  4. xがStringなら、
    1. xyが同じ長さを持ち、同じ位置に同じcode unitsを持つなら、trueを返す。
    2. falseを返す。
  5. xがBooleanなら、
    1. xtrueかつytrueなら、trueを返す。
    2. xfalseかつyfalseなら、trueを返す。
    3. falseを返す。
  6. NOTE: その他すべてのECMAScript言語値はidentityによって比較されます。
  7. xyなら、trueを返す。
  8. falseを返す。
Note 1
説明の目的で、このアルゴリズム内では、不要であってもいくつかの場合が別々に処理されます。
Note 2
x is y”が何を意味するかの詳細は、5.2.8に記されています。

7.2.12 IsLessThan ( x, y, leftFirst )

The abstract operation IsLessThan takes arguments x (an ECMAScript language value), y (an ECMAScript language value), and leftFirst (a Boolean) and returns either a normal completion containing either a Boolean or undefined, or a throw completion. これは比較x < yの意味論を提供し、truefalse、またはundefined(operandsを同じ数値型の比較可能な値へcoerceできなかったことを示す)を返します。leftFirstフラグは、xおよびyに対して潜在的に可視な副作用を持つ操作が実行される順序を制御するために使用されます。これは、ECMAScriptが式の左から右への評価を指定するため必要です。leftFirsttrueなら、xparameterはyparameterに対応する式の左側に現れる式に対応します。leftFirstfalseなら、その逆であり、操作はxより前にyに対して実行されなければなりません。 It performs the following steps when called:

  1. leftFirsttrueなら、
    1. pxを ? ToPrimitive(x, number) とする。
    2. pyを ? ToPrimitive(y, number) とする。
  2. そうでなければ、
    1. NOTE: 左から右への評価を保持するため、評価の順序を反転する必要があります。
    2. pyを ? ToPrimitive(y, number) とする。
    3. pxを ? ToPrimitive(x, number) とする。
  3. pxがStringかつpyがStringなら、
    1. lxpxの長さとする。
    2. lypyの長さとする。
    3. 0 ≤ i < min(lx, ly)である各integer iについて、昇順で、以下を行う
      1. cxpx内のindex iにあるcode unitの数値とする。
      2. cypy内のindex iにあるcode unitの数値とする。
      3. cx < cyなら、trueを返す。
      4. cx > cyなら、falseを返す。
    4. lx < lyなら、trueを返す。
    5. falseを返す。
  4. pxがBigIntかつpyがStringなら、
    1. nyStringToBigInt(py)とする。
    2. nyundefinedなら、undefinedを返す。
    3. BigInt::lessThan(px, ny)を返す。
  5. pxがStringかつpyがBigIntなら、
    1. nxStringToBigInt(px)とする。
    2. nxundefinedなら、undefinedを返す。
    3. BigInt::lessThan(nx, py)を返す。
  6. NOTE: pxpyはprimitive valuesであるため、評価順序は重要ではありません。
  7. nxを ? ToNumeric(px) とする。
  8. nyを ? ToNumeric(py) とする。
  9. SameType(nx, ny)がtrueなら、
    1. nxがNumberなら、Number::lessThan(nx, ny)を返す。
    2. Assert: nxはBigIntである。
    3. BigInt::lessThan(nx, ny)を返す。
  10. Assert: nxはBigIntかつnyはNumberである、またはnxはNumberかつnyはBigIntである。
  11. nxNaNまたはnyNaNなら、undefinedを返す。
  12. nx-∞𝔽またはny+∞𝔽なら、trueを返す。
  13. nx+∞𝔽またはny-∞𝔽なら、falseを返す。
  14. (nx) < (ny)なら、trueを返す。
  15. falseを返す。
Note 1

ステップ3は、+加算演算子を処理するアルゴリズム(13.15.3)内のステップ1.cとは、logical-or操作の代わりにlogical-and操作を使用する点で異なります。

Note 2

Stringsの比較は、UTF-16 code unit値の列に対する単純なlexicographic orderingを使用します。Unicode仕様で定義される文字または文字列の等価性およびcollating orderについての、より複雑で意味論志向の定義を使用しようとはしません。したがって、Unicode Standardに従ってcanonically equalであるString値でも、同じ正規化形式でない場合は等しくないと判定され得ます。また、surrogate pairsを含むStringsについては、code unitによるlexicographic orderingはcode pointによるorderingとは異なることにも注意してください。

7.2.13 IsLooselyEqual ( x, y )

The abstract operation IsLooselyEqual takes arguments x (an ECMAScript language value) and y (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. これは==演算子の意味論を提供します。 It performs the following steps when called:

  1. SameType(x, y)がtrueなら、
    1. IsStrictlyEqual(x, y)を返す。
  2. xnullかつyundefinedなら、trueを返す。
  3. xundefinedかつynullなら、trueを返す。
  4. hostがweb browserであるか、または他の方法で[[IsHTMLDDA]] Internal Slotをサポートするなら、
    1. xがObjectであり、x[[IsHTMLDDA]] internal slotを持ち、かつyundefinedまたはnullのいずれかなら、trueを返す。
    2. xundefinedまたはnullのいずれかであり、yがObjectであり、かつy[[IsHTMLDDA]] internal slotを持つなら、trueを返す。
  5. xがNumberかつyがStringなら、! IsLooselyEqual(x, ! ToNumber(y))を返す。
  6. xがStringかつyがNumberなら、! IsLooselyEqual(! ToNumber(x), y)を返す。
  7. xがBigIntかつyがStringなら、
    1. nStringToBigInt(y)とする。
    2. nundefinedなら、falseを返す。
    3. IsLooselyEqual(x, n)を返す。
  8. xがStringかつyがBigIntなら、! IsLooselyEqual(y, x)を返す。
  9. xがBooleanなら、! IsLooselyEqual(! ToNumber(x), y)を返す。
  10. yがBooleanなら、! IsLooselyEqual(x, ! ToNumber(y))を返す。
  11. xがString、Number、BigInt、またはSymbolのいずれかであり、yがObjectなら、! IsLooselyEqual(x, ? ToPrimitive(y))を返す。
  12. xがObjectであり、yがString、Number、BigInt、またはSymbolのいずれかなら、! IsLooselyEqual(? ToPrimitive(x), y)を返す。
  13. xがBigIntかつyがNumberである、またはxがNumberかつyがBigIntであるなら、
    1. xfiniteでない、またはyfiniteでないなら、falseを返す。
    2. (x) = (y)なら、trueを返す。
    3. falseを返す。
  14. falseを返す。

7.2.14 IsStrictlyEqual ( x, y )

The abstract operation IsStrictlyEqual takes arguments x (an ECMAScript language value) and y (an ECMAScript language value) and returns a Boolean. これは===演算子の意味論を提供します。 It performs the following steps when called:

  1. SameType(x, y)がfalseなら、falseを返す。
  2. xがNumberなら、
    1. Number::equal(x, y)を返す。
  3. SameValueNonNumber(x, y)を返す。
Note

このアルゴリズムは、signed zeroesおよびNaNsの扱いにおいてSameValueアルゴリズムと異なります。

7.3 オブジェクト上の操作

7.3.1 MakeBasicObject ( internalSlotsList )

The abstract operation MakeBasicObject takes argument internalSlotsList (a List of internal slot names) and returns an Object. これは、ordinary objectsexotic objectsの両方を含む、アルゴリズムによって作成されるすべてのECMAScriptオブジェクトの源です。すべてのオブジェクトの作成で使用される共通ステップを切り出し、オブジェクト作成を一元化します。 It performs the following steps when called:

  1. internalSlotsListを、internalSlotsListと« [[PrivateElements]] »のlist-concatenationに設定する。
  2. objを、internalSlotsList内の各名前に対するinternal slotを持つ新しく作成されたオブジェクトとする。
  3. NOTE: Object Internal Methods and Internal Slotsで記述されるように、各そのようなinternal slotの初期値は、別途指定されない限りundefinedです。
  4. obj.[[PrivateElements]]を新しい空のListに設定する。
  5. objのessential internal methodsを、10.1で指定されるデフォルトのordinary object定義に設定する。
  6. Assert: 呼び出し元がobj[[GetPrototypeOf]]および[[SetPrototypeOf]] essential internal methodsの両方を上書きしないなら、internalSlotsList[[Prototype]]を含む。
  7. Assert: 呼び出し元がobj[[SetPrototypeOf]][[IsExtensible]]、および[[PreventExtensions]] essential internal methodsのすべてを上書きしないなら、internalSlotsList[[Extensible]]を含む。
  8. internalSlotsList[[Extensible]]を含むなら、obj.[[Extensible]]trueに設定する。
  9. objを返す。
Note

この仕様内では、exotic objectsは、ArrayCreateBoundFunctionCreateなどの抽象操作で、まずMakeBasicObjectを呼び出して基本的な基礎オブジェクトを取得し、その後そのオブジェクトのinternal methodsの一部または全部を上書きすることによって作成されます。exotic object作成をカプセル化するため、そのオブジェクトのessential internal methodsは、それらの操作の外部では決して変更されません。

7.3.2 Get ( obj, propertyKey )

The abstract operation Get takes arguments obj (an Object) and propertyKey (a property key) and returns either a normal completion containing an ECMAScript language value or a throw completion. これは、オブジェクトの特定のプロパティの値を取得するために使用されます。 It performs the following steps when called:

  1. obj.[[Get]](propertyKey, obj)を返す。

7.3.3 GetV ( value, propertyKey )

The abstract operation GetV takes arguments value (an ECMAScript language value) and propertyKey (a property key) and returns either a normal completion containing an ECMAScript language value or a throw completion. これは、ECMAScript言語値の特定のプロパティの値を取得するために使用されます。値がオブジェクトでない場合、プロパティ検索はその値の型に適したwrapper objectを使用して実行されます。 It performs the following steps when called:

  1. objを ? ToObject(value) とする。
  2. obj.[[Get]](propertyKey, value)を返す。

7.3.4 Set ( obj, propertyKey, value, throw )

The abstract operation Set takes arguments obj (an Object), propertyKey (a property key), value (an ECMAScript language value), and throw (a Boolean) and returns either a normal completion containing unused or a throw completion. これは、オブジェクトの特定のプロパティの値を設定するために使用されます。valueはそのプロパティの新しい値です。 It performs the following steps when called:

  1. successを ? obj.[[Set]](propertyKey, value, obj) とする。
  2. successfalseかつthrowtrueなら、TypeError例外をthrowする。
  3. unusedを返す。

7.3.5 CreateDataProperty ( obj, propertyKey, value )

The abstract operation CreateDataProperty takes arguments obj (an Object), propertyKey (a property key), and value (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. これは、オブジェクトの新しいown propertyを作成するために使用されます。 It performs the following steps when called:

  1. newDescをPropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }とする。
  2. obj.[[DefineOwnProperty]](propertyKey, newDesc)を返す。
Note

この抽象操作は、ECMAScript言語の代入演算子によって作成されるプロパティに使用されるものと同じデフォルトに属性が設定されたプロパティを作成します。通常、そのプロパティはまだ存在しません。存在していてconfigurableでない場合、またはobjがextensibleでない場合、[[DefineOwnProperty]]falseを返します。

7.3.6 CreateDataPropertyOrThrow ( obj, propertyKey, value )

The abstract operation CreateDataPropertyOrThrow takes arguments obj (an Object), propertyKey (a property key), and value (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. これは、オブジェクトの新しいown propertyを作成するために使用されます。要求されたプロパティ更新を実行できない場合、TypeError例外をthrowします。 It performs the following steps when called:

  1. successを ? CreateDataProperty(obj, propertyKey, value) とする。
  2. successfalseなら、TypeError例外をthrowする。
  3. unusedを返す。
Note

この抽象操作は、ECMAScript言語の代入演算子によって作成されるプロパティに使用されるものと同じデフォルトに属性が設定されたプロパティを作成します。通常、そのプロパティはまだ存在しません。存在していてconfigurableでない場合、またはobjがextensibleでない場合、[[DefineOwnProperty]]falseを返し、この操作にTypeError例外をthrowさせます。

7.3.7 CreateNonEnumerableDataPropertyOrThrow ( obj, propertyKey, value )

The abstract operation CreateNonEnumerableDataPropertyOrThrow takes arguments obj (an Object), propertyKey (a property key), and value (an ECMAScript language value) and returns unused. これは、ordinary objectの新しいnon-enumerable own propertyを作成するために使用されます。 It performs the following steps when called:

  1. Assert: objはnon-configurable propertiesを持たないordinaryかつextensibleなオブジェクトである。
  2. newDescをPropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }とする。
  3. DefinePropertyOrThrow(obj, propertyKey, newDesc)を実行する。
  4. unusedを返す。
Note

この抽象操作は、enumerableでない点を除き、ECMAScript言語の代入演算子によって作成されるプロパティに使用されるものと同じデフォルトに属性が設定されたプロパティを作成します。通常、そのプロパティはまだ存在しません。存在する場合でも、DefinePropertyOrThrowは正常に完了することが保証されています。

7.3.8 DefinePropertyOrThrow ( obj, propertyKey, propertyDesc )

The abstract operation DefinePropertyOrThrow takes arguments obj (an Object), propertyKey (a property key), and propertyDesc (a Property Descriptor) and returns either a normal completion containing unused or a throw completion. これは、要求されたプロパティ更新を実行できない場合にTypeError例外をthrowする方法で、オブジェクトの[[DefineOwnProperty]] internal methodを呼び出すために使用されます。 It performs the following steps when called:

  1. successを ? obj.[[DefineOwnProperty]](propertyKey, propertyDesc) とする。
  2. successfalseなら、TypeError例外をthrowする。
  3. unusedを返す。

7.3.9 DeletePropertyOrThrow ( obj, propertyKey )

The abstract operation DeletePropertyOrThrow takes arguments obj (an Object) and propertyKey (a property key) and returns either a normal completion containing unused or a throw completion. これは、オブジェクトの特定のown propertyを削除するために使用されます。そのプロパティがconfigurableでない場合、例外をthrowします。 It performs the following steps when called:

  1. successを ? obj.[[Delete]](propertyKey) とする。
  2. successfalseなら、TypeError例外をthrowする。
  3. unusedを返す。

7.3.10 GetMethod ( value, propertyKey )

The abstract operation GetMethod takes arguments value (an ECMAScript language value) and propertyKey (a property key) and returns either a normal completion containing either a function object or undefined, or a throw completion. これは、ECMAScript言語値の特定のプロパティの値を、そのプロパティの値がfunctionであることが期待される場合に取得するために使用されます。 It performs the following steps when called:

  1. funcを ? GetV(value, propertyKey) とする。
  2. funcundefinedまたはnullのいずれかなら、undefinedを返す。
  3. IsCallable(func)がfalseなら、TypeError例外をthrowする。
  4. funcを返す。

7.3.11 HasProperty ( obj, propertyKey )

The abstract operation HasProperty takes arguments obj (an Object) and propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. これは、指定されたproperty keyを持つプロパティをオブジェクトが持っているかどうかを決定するために使用されます。そのプロパティはownまたはinheritedのいずれでもよいです。 It performs the following steps when called:

  1. obj.[[HasProperty]](propertyKey)を返す。

7.3.12 HasOwnProperty ( obj, propertyKey )

The abstract operation HasOwnProperty takes arguments obj (an Object) and propertyKey (a property key) and returns either a normal completion containing a Boolean or a throw completion. これは、指定されたproperty keyを持つown propertyをオブジェクトが持っているかどうかを決定するために使用されます。 It performs the following steps when called:

  1. propertyDescを ? obj.[[GetOwnProperty]](propertyKey) とする。
  2. propertyDescundefinedなら、falseを返す。
  3. trueを返す。

7.3.13 Call ( func, thisValue [ , argList ] )

The abstract operation Call takes arguments func (an ECMAScript language value) and thisValue (an ECMAScript language value) and optional argument argList (a List of ECMAScript language values) and returns either a normal completion containing an ECMAScript language value or a throw completion. これは、function object[[Call]] internal methodを呼び出すために使用されます。funcfunction objectthisValue[[Call]]this値であるECMAScript言語値argListはinternal methodの対応するargumentに渡される値です。argListが存在しない場合、新しい空のListがその値として使用されます。 It performs the following steps when called:

  1. argListが存在しないなら、argListを新しい空のListに設定する。
  2. IsCallable(func)がfalseなら、TypeError例外をthrowする。
  3. func.[[Call]](thisValue, argList)を返す。

7.3.14 Construct ( ctor [ , argList [ , newTarget ] ] )

The abstract operation Construct takes argument ctor (a constructor) and optional arguments argList (a List of ECMAScript language values) and newTarget (a constructor) and returns either a normal completion containing an Object or a throw completion. これは、function object[[Construct]] internal methodを呼び出すために使用されます。argListおよびnewTargetは、internal methodの対応するargumentsとして渡される値です。argListが存在しない場合、新しい空のListがその値として使用されます。newTargetが存在しない場合、ctorがその値として使用されます。 It performs the following steps when called:

  1. newTargetが存在しないなら、newTargetctorに設定する。
  2. argListが存在しないなら、argListを新しい空のListに設定する。
  3. ctor.[[Construct]](argList, newTarget)を返す。
Note

newTargetが存在しない場合、この操作はnew F(...argumentsList)と等価です。

7.3.15 SetIntegrityLevel ( obj, level )

The abstract operation SetIntegrityLevel takes arguments obj (an Object) and level (sealed or frozen) and returns either a normal completion containing a Boolean or a throw completion. これは、オブジェクトのown propertiesの集合を固定するために使用されます。 It performs the following steps when called:

  1. statusを ? obj.[[PreventExtensions]]() とする。
  2. statusfalseなら、falseを返す。
  3. keysを ? obj.[[OwnPropertyKeys]]() とする。
  4. levelsealedなら、
    1. keysの各要素keyについて、以下を行う
      1. DefinePropertyOrThrow(obj, key, PropertyDescriptor { [[Configurable]]: false })を実行する。
  5. そうでなければ、
    1. Assert: levelfrozenである。
    2. keysの各要素keyについて、以下を行う
      1. currentDescを ? obj.[[GetOwnProperty]](key) とする。
      2. currentDescundefinedでないなら、
        1. IsAccessorDescriptor(currentDesc)がtrueなら、
          1. propertyDescをPropertyDescriptor { [[Configurable]]: false }とする。
        2. そうでなければ、
          1. propertyDescをPropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }とする。
        3. DefinePropertyOrThrow(obj, key, propertyDesc)を実行する。
  6. trueを返す。

7.3.16 TestIntegrityLevel ( obj, level )

The abstract operation TestIntegrityLevel takes arguments obj (an Object) and level (sealed or frozen) and returns either a normal completion containing a Boolean or a throw completion. これは、オブジェクトのown propertiesの集合が固定されているかどうかを決定するために使用されます。 It performs the following steps when called:

  1. extensibleを ? IsExtensible(obj) とする。
  2. extensibletrueなら、falseを返す。
  3. NOTE: オブジェクトがextensibleである場合、そのプロパティは一切検査されません。
  4. keysを ? obj.[[OwnPropertyKeys]]() とする。
  5. keysの各要素keyについて、以下を行う
    1. currentDescを ? obj.[[GetOwnProperty]](key) とする。
    2. currentDescundefinedでないなら、
      1. currentDesc.[[Configurable]]trueなら、falseを返す。
      2. levelfrozenかつIsDataDescriptor(currentDesc)がtrueなら、
        1. currentDesc.[[Writable]]trueなら、falseを返す。
  6. trueを返す。

7.3.17 CreateArrayFromList ( elements )

The abstract operation CreateArrayFromList takes argument elements (a List of ECMAScript language values) and returns an Array. これは、elementsによって提供される要素を持つArrayを作成するために使用されます。 It performs the following steps when called:

  1. arrayを ! ArrayCreate(0) とする。
  2. nを0とする。
  3. elementsの各要素elementについて、以下を行う
    1. CreateDataPropertyOrThrow(array, ! ToString(𝔽(n)), element)を実行する。
    2. nn + 1に設定する。
  4. arrayを返す。

7.3.18 LengthOfArrayLike ( obj )

The abstract operation LengthOfArrayLike takes argument obj (an Object) and returns either a normal completion containing a non-negative integer or a throw completion. これは、array-like objectの"length"プロパティの値を返します。 It performs the following steps when called:

  1. (? ToLength(? Get(obj, "length")))を返す。

array-like objectとは、この操作がnormal completionを返す任意のオブジェクトです。

Note 1
通常、array-like objectはinteger index namesを持ついくつかのプロパティも持つでしょう。ただし、それはこの定義の要件ではありません。
Note 2
ArraysおよびString objectsはarray-like objectsの例です。

7.3.19 CreateListFromArrayLike ( obj [ , validElementTypes ] )

The abstract operation CreateListFromArrayLike takes argument obj (an ECMAScript language value) and optional argument validElementTypes (all or property-key) and returns either a normal completion containing a List of ECMAScript language values or a throw completion. これは、objのindexed propertiesによって提供される要素を持つList値を作成するために使用されます。validElementTypesは、要素として許可される値の型を示します。 It performs the following steps when called:

  1. validElementTypesが存在しないなら、validElementTypesallに設定する。
  2. objがObjectでないなら、TypeError例外をthrowする。
  3. lengthを ? LengthOfArrayLike(obj) とする。
  4. listを新しい空のListとする。
  5. indexを0とする。
  6. index < lengthの間、繰り返す
    1. indexNameを ! ToString(𝔽(index)) とする。
    2. nextを ? Get(obj, indexName) とする。
    3. validElementTypesproperty-keyであり、nextproperty keyでないなら、TypeError例外をthrowする。
    4. nextlistへappendする。
    5. indexindex + 1に設定する。
  7. listを返す。

7.3.20 Invoke ( value, propertyKey [ , argList ] )

The abstract operation Invoke takes arguments value (an ECMAScript language value) and propertyKey (a property key) and optional argument argList (a List of ECMAScript language values) and returns either a normal completion containing an ECMAScript language value or a throw completion. これは、ECMAScript言語値のmethod propertyを呼び出すために使用されます。valueは、そのプロパティの検索点としても、その呼び出しのthis値としても機能します。argListは、そのmethodに渡されるarguments valuesのリストです。argListが存在しない場合、新しい空のListがその値として使用されます。 It performs the following steps when called:

  1. argListが存在しないなら、argListを新しい空のListに設定する。
  2. funcを ? GetV(value, propertyKey) とする。
  3. Call(func, value, argList)を返す。

7.3.21 OrdinaryHasInstance ( ctor, instance )

The abstract operation OrdinaryHasInstance takes arguments ctor (an ECMAScript language value) and instance (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. これは、instancectorによって提供されるinstance object inheritance pathから継承しているかどうかを決定するデフォルトアルゴリズムを実装します。 It performs the following steps when called:

  1. IsCallable(ctor)がfalseなら、falseを返す。
  2. ctor[[BoundTargetFunction]] internal slotを持つなら、
    1. boundCtorctor.[[BoundTargetFunction]]とする。
    2. InstanceofOperator(instance, boundCtor)を返す。
  3. instanceがObjectでないなら、falseを返す。
  4. protoを ? Get(ctor, "prototype") とする。
  5. protoがObjectでないなら、TypeError例外をthrowする。
  6. 繰り返す
    1. instanceを ? instance.[[GetPrototypeOf]]() に設定する。
    2. instancenullなら、falseを返す。
    3. SameValue(proto, instance)がtrueなら、trueを返す。

7.3.22 SpeciesConstructor ( obj, defaultCtor )

The abstract operation SpeciesConstructor takes arguments obj (an Object) and defaultCtor (a constructor) and returns either a normal completion containing a constructor or a throw completion. これは、objから派生する新しいオブジェクトを作成するために使用されるべきconstructorを取得するために使用されます。defaultCtorは、objから開始してconstructor %Symbol.species%プロパティを見つけられない場合に使用するconstructorです。 It performs the following steps when called:

  1. ctorを ? Get(obj, "constructor") とする。
  2. ctorundefinedなら、defaultCtorを返す。
  3. ctorがObjectでないなら、TypeError例外をthrowする。
  4. speciesを ? Get(ctor, %Symbol.species%) とする。
  5. speciesundefinedまたはnullのいずれかなら、defaultCtorを返す。
  6. IsConstructor(species)がtrueなら、speciesを返す。
  7. TypeError例外をthrowする。

7.3.23 EnumerableOwnProperties ( obj, kind )

The abstract operation EnumerableOwnProperties takes arguments obj (an Object) and kind (key, value, or key+value) and returns either a normal completion containing a List of ECMAScript language values or a throw completion. It performs the following steps when called:

  1. ownKeysを ? obj.[[OwnPropertyKeys]]() とする。
  2. resultsを新しい空のListとする。
  3. ownKeysの各要素keyについて、以下を行う
    1. keyがStringなら、
      1. propertyDescを ? obj.[[GetOwnProperty]](key) とする。
      2. propertyDescundefinedでなく、かつpropertyDesc.[[Enumerable]]trueなら、
        1. kindkeyなら、
          1. keyresultsへappendする。
        2. そうでなければ、
          1. valueを ? Get(obj, key) とする。
          2. kindvalueなら、
            1. valueresultsへappendする。
          3. そうでなければ、
            1. Assert: kindkey+valueである。
            2. entryCreateArrayFromListkey, value »)とする。
            3. entryresultsへappendする。
  4. resultsを返す。

7.3.24 GetFunctionRealm ( func )

The abstract operation GetFunctionRealm takes argument func (a function object) and returns either a normal completion containing a Realm Record or a throw completion. It performs the following steps when called:

  1. func[[Realm]] internal slotを持つなら、
    1. func.[[Realm]]を返す。
  2. funcbound function exotic objectなら、
    1. boundTargetFuncfunc.[[BoundTargetFunction]]とする。
    2. GetFunctionRealm(boundTargetFunc)を返す。
  3. funcProxy exotic objectなら、
    1. ValidateNonRevokedProxy(func)を実行する。
    2. proxyTargetfunc.[[ProxyTarget]]とする。
    3. Assert: proxyTargetfunction objectである。
    4. GetFunctionRealm(proxyTarget)を返す。
  4. current Realm Recordを返す。
Note

ステップ4は、func[[Realm]] internal slotを持たないnon-standard function exotic objectである場合にのみ到達します。

7.3.25 CopyDataProperties ( target, source, excludedItems )

The abstract operation CopyDataProperties takes arguments target (an Object), source (an ECMAScript language value), and excludedItems (a List of property keys) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. sourceundefinedまたはnullのいずれかなら、unusedを返す。
  2. fromを ! ToObject(source) とする。
  3. keysを ? from.[[OwnPropertyKeys]]() とする。
  4. keysの各要素nextKeyについて、以下を行う
    1. excludedfalseとする。
    2. excludedItemsの各要素elementについて、以下を行う
      1. SameValue(element, nextKey)がtrueなら、
        1. excludedtrueに設定する。
    3. excludedfalseなら、
      1. propertyDescを ? from.[[GetOwnProperty]](nextKey) とする。
      2. propertyDescundefinedでなく、かつpropertyDesc.[[Enumerable]]trueなら、
        1. propertyValueを ? Get(from, nextKey) とする。
        2. CreateDataPropertyOrThrow(target, nextKey, propertyValue)を実行する。
  5. unusedを返す。
Note

ここで渡されるtargetは常に新しく作成されたオブジェクトであり、エラーがthrowされた場合に直接アクセスできません。

7.3.26 PrivateElementFind ( obj, privateName )

The abstract operation PrivateElementFind takes arguments obj (an Object) and privateName (a Private Name) and returns a PrivateElement or empty. It performs the following steps when called:

  1. obj.[[PrivateElements]]が、entry.[[Key]]privateNameであるようなPrivateElement entryを含むなら、
    1. entryを返す。
  2. emptyを返す。

7.3.27 PrivateFieldAdd ( obj, privateName, value )

The abstract operation PrivateFieldAdd takes arguments obj (an Object), privateName (a Private Name), and value (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. hostがweb browserなら、
    1. HostEnsureCanAddPrivateElement(obj)を実行する。
  2. entryPrivateElementFind(obj, privateName)とする。
  3. entryemptyでないなら、TypeError例外をthrowする。
  4. PrivateElement { [[Key]]: privateName, [[Kind]]: field, [[Value]]: value }をobj.[[PrivateElements]]へappendする。
  5. unusedを返す。

7.3.28 PrivateMethodOrAccessorAdd ( obj, method )

The abstract operation PrivateMethodOrAccessorAdd takes arguments obj (an Object) and method (a PrivateElement) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. Assert: method.[[Kind]]methodまたはaccessorのいずれかである。
  2. hostがweb browserなら、
    1. HostEnsureCanAddPrivateElement(obj)を実行する。
  3. entryPrivateElementFind(obj, method.[[Key]])とする。
  4. entryemptyでないなら、TypeError例外をthrowする。
  5. methodobj.[[PrivateElements]]へappendする。
  6. unusedを返す。
Note

private methodsおよびaccessorsの値は、インスタンス間で共有されます。この操作はmethodまたはaccessorの新しいcopyを作成しません。

7.3.29 HostEnsureCanAddPrivateElement ( obj )

The host-defined abstract operation HostEnsureCanAddPrivateElement takes argument obj (an Object) and returns either a normal completion containing unused or a throw completion. これは、host environmentsが特定のhost-defined exotic objectsへのprivate elementsの追加を防ぐことを可能にします。

HostEnsureCanAddPrivateElementの実装は、以下の要件に従わなければなりません:

  • objhost-defined exotic objectでない場合、この抽象操作はNormalCompletion(unused)を返し、他のステップを実行してはなりません。
  • 同じargumentでこの抽象操作を2回呼び出した場合、同じ種類のCompletion Recordを返さなければなりません。

HostEnsureCanAddPrivateElementのデフォルト実装は、NormalCompletion(unused)を返すことです。

この抽象操作は、web browsersであるECMAScript hostsによってのみ呼び出されます。

7.3.30 PrivateGet ( obj, privateName )

The abstract operation PrivateGet takes arguments obj (an Object) and privateName (a Private Name) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. entryPrivateElementFind(obj, privateName)とする。
  2. entryemptyなら、TypeError例外をthrowする。
  3. entry.[[Kind]]fieldまたはmethodのいずれかなら、
    1. entry.[[Value]]を返す。
  4. Assert: entry.[[Kind]]accessorである。
  5. entry.[[Get]]undefinedなら、TypeError例外をthrowする。
  6. getterentry.[[Get]]とする。
  7. Call(getter, obj)を返す。

7.3.31 PrivateSet ( obj, privateName, value )

The abstract operation PrivateSet takes arguments obj (an Object), privateName (a Private Name), and value (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. entryPrivateElementFind(obj, privateName)とする。
  2. entryemptyなら、TypeError例外をthrowする。
  3. entry.[[Kind]]methodなら、TypeError例外をthrowする。
  4. entry.[[Kind]]fieldなら、
    1. entry.[[Value]]valueに設定する。
  5. そうでなければ、
    1. Assert: entry.[[Kind]]accessorである。
    2. entry.[[Set]]undefinedなら、TypeError例外をthrowする。
    3. setterentry.[[Set]]とする。
    4. Call(setter, obj, « value »)を実行する。
  6. unusedを返す。

7.3.32 DefineField ( receiver, fieldRecord )

The abstract operation DefineField takes arguments receiver (an Object) and fieldRecord (a ClassFieldDefinition Record) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. fieldNamefieldRecord.[[Name]]とする。
  2. initializerfieldRecord.[[Initializer]]とする。
  3. initializeremptyでないなら、
    1. initValueを ? Call(initializer, receiver) とする。
  4. そうでなければ、
    1. initValueundefinedとする。
  5. fieldNamePrivate Nameなら、
    1. PrivateFieldAdd(receiver, fieldName, initValue)を実行する。
  6. そうでなければ、
    1. Assert: fieldNameproperty keyである。
    2. CreateDataPropertyOrThrow(receiver, fieldName, initValue)を実行する。
  7. unusedを返す。

7.3.33 InitializeInstanceElements ( obj, ctor )

The abstract operation InitializeInstanceElements takes arguments obj (an Object) and ctor (an ECMAScript function object or a built-in function object) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. methodsctor.[[PrivateMethods]]とする。
  2. methodsの各PrivateElement methodについて、以下を行う
    1. PrivateMethodOrAccessorAdd(obj, method)を実行する。
  3. fieldsctor.[[Fields]]とする。
  4. fieldsの各要素fieldRecordについて、以下を行う
    1. DefineField(obj, fieldRecord)を実行する。
  5. unusedを返す。

7.3.34 AddValueToKeyedGroup ( groups, key, value )

The abstract operation AddValueToKeyedGroup takes arguments groups (a List of Records with fields [[Key]] (an ECMAScript language value) and [[Elements]] (a List of ECMAScript language values)), key (an ECMAScript language value), and value (an ECMAScript language value) and returns unused. It performs the following steps when called:

  1. groupsの各Record { [[Key]], [[Elements]] } groupについて、以下を行う
    1. SameValue(group.[[Key]], key)がtrueなら、
      1. Assert: groupsのちょうど1つの要素がこの基準を満たす。
      2. valuegroup.[[Elements]]へappendする。
      3. unusedを返す。
  2. groupRecord { [[Key]]: key, [[Elements]]: « value » }とする。
  3. groupgroupsへappendする。
  4. unusedを返す。

7.3.35 GroupBy ( items, callback, keyCoercion )

The abstract operation GroupBy takes arguments items (an ECMAScript language value), callback (an ECMAScript language value), and keyCoercion (property or collection) and returns either a normal completion containing a List of Records with fields [[Key]] (an ECMAScript language value) and [[Elements]] (a List of ECMAScript language values), or a throw completion. It performs the following steps when called:

  1. RequireObjectCoercible(items)を実行する。
  2. IsCallable(callback)がfalseなら、TypeError例外をthrowする。
  3. groupsを新しい空のListとする。
  4. iteratorRecordを ? GetIterator(items, sync) とする。
  5. kを0とする。
  6. 繰り返す
    1. k ≥ 253 - 1なら、
      1. errorThrowCompletion(a newly created TypeError object)とする。
      2. IteratorClose(iteratorRecord, error)を返す。
    2. nextを ? IteratorStepValue(iteratorRecord) とする。
    3. nextdoneなら、
      1. groupsを返す。
    4. valuenextとする。
    5. keyCompletion(Call(callback, undefined, « value, 𝔽(k) »))とする。
    6. IfAbruptCloseIterator(key, iteratorRecord).
    7. keyCoercionpropertyなら、
      1. keyCompletion(ToPropertyKey(key))に設定する。
      2. IfAbruptCloseIterator(key, iteratorRecord).
    8. そうでなければ、
      1. Assert: keyCoercioncollectionである。
      2. keyCanonicalizeKeyedCollectionKey(key)に設定する。
    9. AddValueToKeyedGroup(groups, key, value)を実行する。
    10. kk + 1に設定する。

7.3.36 GetOptionsObject ( options )

The abstract operation GetOptionsObject takes argument options (an ECMAScript language value) and returns either a normal completion containing an Object or a throw completion. It performs the following steps when called:

  1. optionsundefinedなら、
    1. OrdinaryObjectCreate(null)を返す。
  2. optionsがObjectなら、
    1. optionsを返す。
  3. TypeError例外をthrowする。

7.3.37 SetterThatIgnoresPrototypeProperties ( thisValue, home, propertyKey, value )

The abstract operation SetterThatIgnoresPrototypeProperties takes arguments thisValue (an ECMAScript language value), home (an Object), propertyKey (a property key), and value (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. It performs the following steps when called:

  1. thisValueがObjectでないなら、
    1. TypeError例外をthrowする。
  2. SameValue(thisValue, home)がtrueなら、
    1. NOTE: ここでthrowすることは、strict mode codeにおいてhomeオブジェクト上のnon-writable data propertyへ代入することを模倣します。
    2. TypeError例外をthrowする。
  3. propertyDescを ? thisValue.[[GetOwnProperty]](propertyKey) とする。
  4. propertyDescundefinedなら、
    1. CreateDataPropertyOrThrow(thisValue, propertyKey, value)を実行する。
  5. そうでなければ、
    1. Set(thisValue, propertyKey, value, true)を実行する。
  6. unusedを返す。

7.4 Iterator Objects上の操作

Common Iteration Interfaces(27.1を参照)。

7.4.1 Iterator Records

Iterator Recordは、iteratorまたはasync iteratornextメソッドとともにカプセル化するために使用されるRecord値です。

Iterator Recordsは、Table 13に列挙されるフィールドを持ちます。

Table 13: Iterator Record Fields
フィールド名 意味
[[Iterator]] Object iterator interfaceまたはasync iterator interfaceに適合するオブジェクト。
[[NextMethod]] ECMAScript言語値 [[Iterator]]オブジェクトのnextメソッド。
[[Done]] Boolean iteratorが完了したか、または閉じられたかどうか。

7.4.2 GetIteratorDirect ( obj )

The abstract operation GetIteratorDirect takes argument obj (an Object) and returns either a normal completion containing an Iterator Record or a throw completion. It performs the following steps when called:

  1. nextMethodを ? Get(obj, "next") とする。
  2. iteratorRecordIterator Record { [[Iterator]]: obj, [[NextMethod]]: nextMethod, [[Done]]: false }とする。
  3. iteratorRecordを返す。

7.4.3 GetIteratorFromMethod ( obj, method )

The abstract operation GetIteratorFromMethod takes arguments obj (an ECMAScript language value) and method (a function object) and returns either a normal completion containing an Iterator Record or a throw completion. It performs the following steps when called:

  1. iteratorを ? Call(method, obj) とする。
  2. iteratorがObjectでないなら、TypeError例外をthrowする。
  3. GetIteratorDirect(iterator)を返す。

7.4.4 GetIterator ( obj, kind )

The abstract operation GetIterator takes arguments obj (an ECMAScript language value) and kind (sync or async) and returns either a normal completion containing an Iterator Record or a throw completion. It performs the following steps when called:

  1. kindasyncなら、
    1. methodを ? GetMethod(obj, %Symbol.asyncIterator%) とする。
    2. methodundefinedなら、
      1. syncMethodを ? GetMethod(obj, %Symbol.iterator%) とする。
      2. syncMethodundefinedなら、TypeError例外をthrowする。
      3. syncIteratorRecordを ? GetIteratorFromMethod(obj, syncMethod) とする。
      4. CreateAsyncFromSyncIterator(syncIteratorRecord)を返す。
  2. そうでなければ、
    1. methodを ? GetMethod(obj, %Symbol.iterator%) とする。
  3. methodundefinedなら、TypeError例外をthrowする。
  4. GetIteratorFromMethod(obj, method)を返す。

7.4.5 GetIteratorFlattenable ( obj, primitiveHandling )

The abstract operation GetIteratorFlattenable takes arguments obj (an ECMAScript language value) and primitiveHandling (iterate-string-primitives or reject-primitives) and returns either a normal completion containing an Iterator Record or a throw completion. It performs the following steps when called:

  1. objがObjectでないなら、
    1. primitiveHandlingreject-primitivesなら、TypeError例外をthrowする。
    2. Assert: primitiveHandlingiterate-string-primitivesである。
    3. objがStringでないなら、TypeError例外をthrowする。
  2. methodを ? GetMethod(obj, %Symbol.iterator%) とする。
  3. methodundefinedなら、
    1. iteratorobjとする。
  4. そうでなければ、
    1. iteratorを ? Call(method, obj) とする。
  5. iteratorがObjectでないなら、TypeError例外をthrowする。
  6. GetIteratorDirect(iterator)を返す。

7.4.6 IteratorNext ( iteratorRecord [ , value ] )

The abstract operation IteratorNext takes argument iteratorRecord (an Iterator Record) and optional argument value (an ECMAScript language value) and returns either a normal completion containing an Object or a throw completion. It performs the following steps when called:

  1. valueが存在しないなら、
    1. resultCompletion(Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]))とする。
  2. そうでなければ、
    1. resultCompletion(Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »))とする。
  3. resultthrow completionなら、
    1. iteratorRecord.[[Done]]trueに設定する。
    2. resultを返す。
  4. resultを ! result に設定する。
  5. resultがObjectでないなら、
    1. iteratorRecord.[[Done]]trueに設定する。
    2. TypeError例外をthrowする。
  6. resultを返す。

7.4.7 IteratorComplete ( iteratorResult )

The abstract operation IteratorComplete takes argument iteratorResult (an Object) and returns either a normal completion containing a Boolean or a throw completion. It performs the following steps when called:

  1. ToBoolean(? Get(iteratorResult, "done")))を返す。

7.4.8 IteratorValue ( iteratorResult )

The abstract operation IteratorValue takes argument iteratorResult (an Object) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. Get(iteratorResult, "value")を返す。

7.4.9 IteratorStep ( iteratorRecord )

The abstract operation IteratorStep takes argument iteratorRecord (an Iterator Record) and returns either a normal completion containing either an Object or done, or a throw completion. これは、iteratorRecord.[[NextMethod]]を呼び出すことでiteratorRecord.[[Iterator]]から次の値を要求し、iteratorが終端に到達したことを示すdone、または次の値が利用可能な場合はIteratorResultオブジェクトを返します。 It performs the following steps when called:

  1. resultを ? IteratorNext(iteratorRecord) とする。
  2. doneCompletion(IteratorComplete(result))とする。
  3. donethrow completionなら、
    1. iteratorRecord.[[Done]]trueに設定する。
    2. doneを返す。
  4. doneを ! done に設定する。
  5. donetrueなら、
    1. iteratorRecord.[[Done]]trueに設定する。
    2. doneを返す。
  6. resultを返す。

7.4.10 IteratorStepValue ( iteratorRecord )

The abstract operation IteratorStepValue takes argument iteratorRecord (an Iterator Record) and returns either a normal completion containing either an ECMAScript language value or done, or a throw completion. これは、iteratorRecord.[[NextMethod]]を呼び出すことでiteratorRecord.[[Iterator]]から次の値を要求し、iteratorが終端に到達したことを示すdone、または次の値が利用可能な場合はIteratorResultオブジェクトからの値を返します。 It performs the following steps when called:

  1. resultを ? IteratorStep(iteratorRecord) とする。
  2. resultdoneなら、
    1. doneを返す。
  3. valueCompletion(IteratorValue(result))とする。
  4. valuethrow completionなら、
    1. iteratorRecord.[[Done]]trueに設定する。
  5. valueを返す。

7.4.11 IteratorClose ( iteratorRecord, completion )

The abstract operation IteratorClose takes arguments iteratorRecord (an Iterator Record) and completion (a Completion Record) and returns a Completion Record. これは、iteratorが完了状態に到達したときに通常実行する任意の動作を実行すべきであることを、そのiteratorへ通知するために使用されます。 It performs the following steps when called:

  1. Assert: iteratorRecord.[[Iterator]]はObjectである。
  2. iteratoriteratorRecord.[[Iterator]]とする。
  3. innerResultCompletion(GetMethod(iterator, "return")))とする。
  4. innerResultnormal completionなら、
    1. returninnerResult.[[Value]]とする。
    2. returnundefinedなら、? completionを返す。
    3. innerResultCompletion(Call(return, iterator))に設定する。
  5. completionthrow completionなら、? completionを返す。
  6. innerResultthrow completionなら、? innerResultを返す。
  7. innerResult.[[Value]]がObjectでないなら、TypeError例外をthrowする。
  8. completionを返す。

7.4.12 IteratorCloseAll ( iterators, completion )

The abstract operation IteratorCloseAll takes arguments iterators (a List of Iterator Records) and completion (a Completion Record) and returns a Completion Record. It performs the following steps when called:

  1. iteratorsの各要素iteratorについて、Listの逆順で、以下を行う
    1. completionCompletion(IteratorClose(iterator, completion))に設定する。
  2. completionを返す。

7.4.13 IfAbruptCloseIterator ( value, iteratorRecord )

IfAbruptCloseIteratorは、Iterator Recordを使用する一連のアルゴリズムステップの省略表現です。次の形式のアルゴリズムステップ:

  1. IfAbruptCloseIterator(value, iteratorRecord).

は、次と同じことを意味します:

  1. Assert: valueCompletion Recordである。
  2. valueabrupt completionなら、? IteratorClose(iteratorRecord, value)を返す。
  3. valueを ! value に設定する。

7.4.14 IfAbruptCloseIterators ( value, iteratorRecords )

IfAbruptCloseIteratorsは、Iterator Recordsのリストを使用する一連のアルゴリズムステップの省略表現です。次の形式のアルゴリズムステップ:

  1. IfAbruptCloseIterators(value, iteratorRecords).

は、次と同じことを意味します:

  1. Assert: valueCompletion Recordである。
  2. valueabrupt completionなら、? IteratorCloseAll(iteratorRecords, value)を返す。
  3. valueを ! value に設定する。

7.4.15 AsyncIteratorClose ( iteratorRecord, completion )

The abstract operation AsyncIteratorClose takes arguments iteratorRecord (an Iterator Record) and completion (a Completion Record) and returns a Completion Record. これは、async iteratorが完了状態に到達したときに通常実行する任意の動作を実行すべきであることを、そのasync iteratorへ通知するために使用されます。 It performs the following steps when called:

  1. Assert: iteratorRecord.[[Iterator]]はObjectである。
  2. iteratoriteratorRecord.[[Iterator]]とする。
  3. innerResultCompletion(GetMethod(iterator, "return")))とする。
  4. innerResultnormal completionなら、
    1. returninnerResult.[[Value]]とする。
    2. returnundefinedなら、? completionを返す。
    3. innerResultCompletion(Call(return, iterator))に設定する。
    4. innerResultnormal completionなら、innerResultCompletion(Await(innerResult.[[Value]]))に設定する。
  5. completionthrow completionなら、? completionを返す。
  6. innerResultthrow completionなら、? innerResultを返す。
  7. innerResult.[[Value]]がObjectでないなら、TypeError例外をthrowする。
  8. completionを返す。

7.4.16 IfAbruptCloseAsyncIterator ( value, iteratorRecord )

IfAbruptCloseAsyncIteratorは、Iterator Recordを使用する一連のアルゴリズムステップの省略表現です。次の形式のアルゴリズムステップ:

  1. IfAbruptCloseAsyncIterator(value, iteratorRecord).

は、次と同じことを意味します:

  1. Assert: valueCompletion Recordである。
  2. valueabrupt completionなら、? AsyncIteratorClose(iteratorRecord, value)を返す。
  3. valueを ! value に設定する。

7.4.17 CreateIteratorResultObject ( value, done )

The abstract operation CreateIteratorResultObject takes arguments value (an ECMAScript language value) and done (a Boolean) and returns an Object that conforms to the IteratorResult interface. これはIteratorResult interfaceに適合するオブジェクトを作成します。 It performs the following steps when called:

  1. objOrdinaryObjectCreate(%Object.prototype%)とする。
  2. CreateDataPropertyOrThrow(obj, "value", value)を実行する。
  3. CreateDataPropertyOrThrow(obj, "done", done)を実行する。
  4. objを返す。

7.4.18 CreateListIteratorRecord ( list )

The abstract operation CreateListIteratorRecord takes argument list (a List of ECMAScript language values) and returns an Iterator Record. これは、[[NextMethod]]listの連続する要素を返すIterator Recordを作成します。 It performs the following steps when called:

  1. closureを、parametersを持たず、listをcaptureし、呼び出されたときに以下のステップを実行する新しいAbstract Closureとする:
    1. listの各要素valueについて、以下を行う
      1. GeneratorYield(CreateIteratorResultObject(value, false))を実行する。
    2. NormalCompletion(undefined)を返す。
  2. iteratorCreateIteratorFromClosure(closure, empty, %Iterator.prototype%)とする。
  3. Iterator Record { [[Iterator]]: iterator, [[NextMethod]]: %GeneratorPrototype.next%, [[Done]]: false }を返す。
Note

list iterator objectは、ECMAScriptコードから直接アクセス可能になることは決してありません。

7.4.19 IteratorToList ( iteratorRecord )

The abstract operation IteratorToList takes argument iteratorRecord (an Iterator Record) and returns either a normal completion containing a List of ECMAScript language values or a throw completion. It performs the following steps when called:

  1. valuesを新しい空のListとする。
  2. 繰り返す
    1. nextを ? IteratorStepValue(iteratorRecord) とする。
    2. nextdoneなら、
      1. valuesを返す。
    3. nextvaluesへappendする。

7.5 Disposable オブジェクトに対する操作

共通リソース管理インターフェイスを参照(27.2.1)。

7.5.1 DisposableResource レコード

DisposableResource レコードは、破棄可能なオブジェクトを、そのオブジェクトを破棄するために使用されるメソッドとともにカプセル化するために使用される Record 値である。DisposableResource レコードは、CreateDisposableResource 抽象操作によって生成される。

DisposableResource レコードは、Table 14 に列挙されるフィールドを持つ:

Table 14: DisposableResource レコードのフィールド
フィールド名 意味
[[ResourceValue]] Object または undefined 破棄される値。
[[Kind]] sync-dispose または async-dispose リソースが using 宣言または DisposableStack オブジェクトによって追加されたか(sync-dispose)、それとも await using 宣言または AsyncDisposableStack オブジェクトによって追加されたか(async-dispose)を示す。
[[DisposeMethod]] 関数オブジェクトまたは undefined リソースが破棄されるときに、[[ResourceValue]] をその this 値として呼び出される関数オブジェクト。

7.5.2 AddDisposableResource ( disposableResourceStack, value, kind [ , method ] )

The abstract operation AddDisposableResource takes arguments disposableResourceStack (DisposableResource レコードList), value (ECMAScript 言語値), and kind (sync-dispose または async-dispose) and optional argument method (関数オブジェクト) and returns unused を含む normal completion または throw completion. It performs the following steps when called:

  1. method が存在する場合、then
    1. Assert: valueundefined である。
    2. Let resource be ? CreateDisposableResource(undefined, kind, method).
  2. Else,
    1. valuenull または undefined のいずれかであり、かつ kindsync-dispose である場合、unused を返す。
    2. NOTE: valuenull または undefined のいずれかであり、かつ kindasync-dispose である場合、後でリソースが破棄されるときにも Await が実行されることを確保するため、そのリソースが評価されたことを記録する。
    3. Let resource be ? CreateDisposableResource(value, kind).
  3. resourcedisposableResourceStack に追加する。
  4. Return unused.

7.5.3 CreateDisposableResource ( value, kind [ , method ] )

The abstract operation CreateDisposableResource takes arguments value (ECMAScript 言語値) and kind (sync-dispose または async-dispose) and optional argument method (関数オブジェクト) and returns DisposableResource レコードを含む normal completion または throw completion. It performs the following steps when called:

  1. method が存在しない場合、then
    1. valuenull または undefined のいずれかである場合、then
      1. Set value to undefined.
      2. Set method to undefined.
    2. Else,
      1. Set method to ? GetDisposeMethod(value, kind).
      2. methodundefined である場合、TypeError 例外を投げる。
  2. Return the DisposableResource Record { [[ResourceValue]]: value, [[Kind]]: kind, [[DisposeMethod]]: method }.

7.5.4 GetDisposeMethod ( value, kind )

The abstract operation GetDisposeMethod takes arguments value (ECMAScript 言語値) and kind (sync-dispose または async-dispose) and returns 関数オブジェクトまたは undefined のいずれかを含む normal completion、または throw completion. It performs the following steps when called:

  1. value が Object でない場合、TypeError 例外を投げる。
  2. kindsync-dispose である場合、return ? GetMethod(value, %Symbol.dispose%).
  3. Assert: kindasync-dispose である。
  4. Let asyncMethod be ? GetMethod(value, %Symbol.asyncDispose%).
  5. asyncMethodundefined でない場合、asyncMethod を返す。
  6. Let syncMethod be ? GetMethod(value, %Symbol.dispose%).
  7. syncMethodundefined である場合、undefined を返す。
  8. Let closure be a new Abstract Closure with no parameters that captures syncMethod and performs the following steps when called:
    1. Let obj be the this value.
    2. Let promiseCapability be ! NewPromiseCapability(%Promise%).
    3. Let result be Completion(Call(syncMethod, obj)).
    4. IfAbruptRejectPromise(result, promiseCapability).
    5. Perform ! Call(promiseCapability.[[Resolve]], undefined, « undefined »).
    6. Return promiseCapability.[[Promise]].
  9. NOTE: この関数はユーザーコードから観測できない。この関数は、同期的な %Symbol.dispose% メソッドから返された Promise が await されないこと、および同期的な例外が rejected Promise に変換されることを確保するために使用される。
  10. Return CreateBuiltinFunction(closure, 0, "", « »).

7.5.5 DisposeResources ( disposableResourceStack, completion )

The abstract operation DisposeResources takes arguments disposableResourceStack (DisposableResource レコードList) and completion (ECMAScript 言語値または empty のいずれかを含む normal completion、または abrupt completion) and returns ECMAScript 言語値または empty のいずれかを含む normal completion、または abrupt completion. It performs the following steps when called:

  1. Let needsAwait be false.
  2. Let hasAwaited be false.
  3. Let outputCompletion be completion.
  4. disposableResourceStack の各要素 resource について、List の逆順で、do
    1. Let value be resource.[[ResourceValue]].
    2. Let kind be resource.[[Kind]].
    3. Let method be resource.[[DisposeMethod]].
    4. kindsync-dispose であり、needsAwaittrue であり、かつ hasAwaitedfalse である場合、then
      1. Perform ! Await(undefined).
      2. Set needsAwait to false.
    5. methodundefined でない場合、then
      1. Let result be Completion(Call(method, value)).
      2. resultnormal completion であり、かつ kindasync-dispose である場合、then
        1. Set result to Completion(Await(result.[[Value]])).
        2. Set hasAwaited to true.
      3. resultthrow completion である場合、then
        1. outputCompletionthrow completion である場合、then
          1. Set result to result.[[Value]].
          2. Let suppressed be outputCompletion.[[Value]].
          3. Let error be a newly created SuppressedError object.
          4. Perform CreateNonEnumerableDataPropertyOrThrow(error, "error", result).
          5. Perform CreateNonEnumerableDataPropertyOrThrow(error, "suppressed", suppressed).
          6. Set outputCompletion to ThrowCompletion(error).
        2. Else,
          1. Set outputCompletion to result.
    6. Else,
      1. Assert: kindasync-dispose である。
      2. Set needsAwait to true.
      3. NOTE: これは、await using 宣言の初期化値が null または undefined のいずれかであった場合にのみ起こり得ることを示す。
  5. needsAwaittrue であり、かつ hasAwaitedfalse である場合、then
    1. Perform ! Await(undefined).
  6. NOTE: この時点で disposableResourceStack は二度と使用されない。disposableResourceStack の内容は、ガベージコレクションなどにより、実装内で破棄できる。
  7. Return ? outputCompletion.