7 抽象操作

これらの操作はECMAScript言語の一部ではなく、ECMAScript言語の意味論を仕様化する助けのためだけにここで定義される。その他、より専門的な抽象操作は本仕様全体で定義されている。

7.1 型変換

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

BigInt型はECMAScript言語において暗黙の変換を持たない。プログラマは他の型から値を変換する際に明示的にBigIntを呼び出す必要がある。

7.1.1 ToPrimitive ( input: ECMAScript言語値, 省略可能 preferredType: string または number, ): ECMAScript言語値を含む normal completion あるいは throw completion

The abstract operation UNKNOWN takes UNPARSEABLE ARGUMENTS. input 引数を非 Object 型へ変換する。オブジェクトが複数の基本型へ変換可能な場合、オプションのヒント preferredType を使ってその型を優先できる。 It performs the following steps when called:

  1. input が Object であるなら
    1. exoticToPrim を ? GetMethod(input, %Symbol.toPrimitive%) とする。
    2. exoticToPrimundefined でないなら
      1. preferredType が存在しないなら
        1. hint"default" とする。
      2. そうでなく preferredTypestring なら
        1. hint"string" とする。
      3. それ以外
        1. アサート: preferredTypenumber である。
        2. hint"number" とする。
      4. result を ? Call(exoticToPrim, input, « hint ») とする。
      5. result が Object でないなら result を返す。
      6. TypeError 例外を投げる。
    3. preferredType が存在しないなら preferredTypenumber とする。
    4. OrdinaryToPrimitive(input, preferredType) を返す。
  2. input を返す。
Note

ヒントなしで ToPrimitive が呼び出された場合、一般的にはヒントが number であったかのように振る舞う。しかし、オブジェクトは %Symbol.toPrimitive% メソッドを定義することでこの挙動を上書きできる。本仕様で定義されるオブジェクトのうち既定の ToPrimitive 挙動を上書きするのは Date(21.4.4.45 参照)と Symbol オブジェクト(20.4.3.5 参照)のみである。Date はヒント不在を string として扱う。

7.1.1.1 OrdinaryToPrimitive ( O, hint )

The abstract operation OrdinaryToPrimitive takes arguments O (Object) and hint (string または number) and returns ECMAScript言語値を含む normal completion あるいは 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(O, name) とする。
    2. IsCallable(method) が true なら
      1. result を ? Call(method, O) とする。
      2. result が Object でないなら result を返す。
  4. TypeError 例外を投げる。

7.1.2 ToBoolean ( argument )

The abstract operation ToBoolean takes argument argument (ECMAScript言語値) and returns Boolean. argument を Boolean 型の値へ変換する。 It performs the following steps when called:

  1. argument が Boolean なら argument を返す。
  2. argumentundefined, null, +0𝔽, -0𝔽, NaN, 0, または空文字列のいずれかなら false を返す。
  3. Normative Optional
    ホストが Web ブラウザまたは [[IsHTMLDDA]] 内部スロット をサポートする場合
    1. argument が Object でかつ [[IsHTMLDDA]] 内部スロットを持つなら false を返す。
  4. true を返す。

7.1.3 ToNumeric ( value )

The abstract operation ToNumeric takes argument value (ECMAScript言語値) and returns Number または BigInt を含む normal completion あるいは throw completion. value を Number か BigInt に変換して返す。 It performs the following steps when called:

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

7.1.4 ToNumber ( argument )

The abstract operation ToNumber takes argument argument (ECMAScript言語値) and returns Number を含む normal completion あるいは throw completion. argument を Number 型の値へ変換する。 It performs the following steps when called:

  1. argument が Number なら argument を返す。
  2. argument が Symbol か BigInt のいずれかなら TypeError 例外を投げる。
  3. argumentundefined なら NaN を返す。
  4. argumentnull または false なら +0𝔽 を返す。
  5. argumenttrue なら 1𝔽 を返す。
  6. argument が String なら StringToNumber(argument) を返す。
  7. アサート: argument は Object である。
  8. primValue を ? ToPrimitive(argument, number) とする。
  9. アサート: primValue は Object でない。
  10. ToNumber(primValue) を返す。

7.1.4.1 文字列型への 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

上で明示的に定義されていない文法記号は数値リテラルの字句文法(12.9.3)で用いられる定義を持つ。

Note

StringNumericLiteral の構文と NumericLiteral の構文には次の差異がある:

7.1.4.1.1 StringToNumber ( str )

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

  1. literal を ParseText(str, StringNumericLiteral) とする。
  2. literal がエラーの List なら NaN を返す。
  3. literal の StringNumericValue を返す。

7.1.4.1.2 実行時意味論: StringNumericValue : Number

The syntax-directed operation UNKNOWN takes UNPARSEABLE ARGUMENTS.

Note

StringNumericLiteral を Number 値へ変換することは、NumericLiteral の NumericValue の決定(12.9.3 参照)と全体として類似するが、いくつか詳細は異なる。

It is defined piecewise over the following productions:

StringNumericLiteral ::: StrWhiteSpaceopt
  1. +0𝔽 を返す。
StringNumericLiteral ::: StrWhiteSpaceopt StrNumericLiteral StrWhiteSpaceopt
  1. StrNumericLiteral の StringNumericValue を返す。
StrNumericLiteral ::: NonDecimalIntegerLiteral
  1. 𝔽(NonDecimalIntegerLiteral の MV) を返す。
StrDecimalLiteral ::: - StrUnsignedDecimalLiteral
  1. aStrUnsignedDecimalLiteral の StringNumericValue とする。
  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 のコードポイント数とする。
  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 のコードポイント数とする。
  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 (数学的値) and returns Number. n を実装依存の方法で Number に変換する。この抽象操作において、桁は 0 でないか左側に 0 でない桁があり右側にも 0 でない桁がある場合に有効とみなされる。また「数学的値の表現が表す数学的値」とは「数学的値の10進表現」の逆写像とする。 It performs the following steps when called:

  1. n の10進表現が有効桁20桁以下なら 𝔽(n) を返す。
  2. option1n の10進表現において20桁目より後の各有効桁を 0 に置き換えた表現が表す数学的値とする。
  3. option2n の10進表現において20桁目より後の各有効桁を 0 に置き換え、20桁目を(必要なら桁上げしつつ)インクリメントした表現が表す数学的値とする。
  4. chosen を実装依存に option1 または option2 から選ぶ。
  5. 𝔽(chosen) を返す。

7.1.5 ToIntegerOrInfinity ( argument )

The abstract operation ToIntegerOrInfinity takes argument argument (ECMAScript言語値) and returns 整数, +∞, -∞ のいずれかを含む normal completion あるいは throw completion. argument を Number 値の小数部分切り捨て表現の整数、またはその Number 値が無限大の場合は +∞ / -∞ に変換する。 It performs the following steps when called:

  1. number を ? ToNumber(argument) とする。
  2. numberNaN, +0𝔽, -0𝔽 のいずれかなら 0 を返す。
  3. number+∞𝔽 なら +∞ を返す。
  4. number-∞𝔽 なら -∞ を返す。
  5. truncate((number)) を返す。
Note
𝔽(ToIntegerOrInfinity(x)) はいかなる x に対しても -0𝔽 を返さない。小数部の切り捨ては x を数学的値に変換した後に行われる。

7.1.6 ToInt32 ( argument )

The abstract operation ToInt32 takes argument argument (ECMAScript言語値) and returns 整数 Number を含む normal completion あるいは throw completion. argument𝔽(-231) から 𝔽(231 - 1) までの 232 個の整数 Number 値のいずれかに変換する。 It performs the following steps when called:

  1. number を ? ToNumber(argument) とする。
  2. number有限でない、または +0𝔽-0𝔽 のいずれかなら +0𝔽 を返す。
  3. inttruncate((number)) とする。
  4. int32bitint modulo 232 とする。
  5. int32bit ≥ 231 なら 𝔽(int32bit - 232) を返し、そうでなければ 𝔽(int32bit) を返す。
Note

上記 ToInt32 定義により:

  • ToInt32 抽象操作は冪等であり、その結果に再適用しても値は変わらない。
  • 全ての x について ToInt32(ToUint32(x)) は ToInt32(x) と同じ値。(この性質を保つため +∞𝔽-∞𝔽+0𝔽 に写る。)
  • ToInt32 は -0𝔽+0𝔽 に写す。

7.1.7 ToUint32 ( argument )

The abstract operation ToUint32 takes argument argument (ECMAScript言語値) and returns 整数 Number を含む normal completion あるいは throw completion. argument+0𝔽 から 𝔽(232 - 1) までの 232 個の整数 Number 値のいずれかに変換する。 It performs the following steps when called:

  1. number を ? ToNumber(argument) とする。
  2. number有限でない、または +0𝔽-0𝔽 のいずれかなら +0𝔽 を返す。
  3. inttruncate((number)) とする。
  4. int32bitint modulo 232 とする。
  5. 𝔽(int32bit) を返す。
Note

上記 ToUint32 定義により:

  • ステップ 5 が ToUint32 と ToInt32 の唯一の差異。
  • ToUint32 抽象操作は冪等である。
  • 全ての x について ToUint32(ToInt32(x)) は ToUint32(x) と同じ値。(この性質を保つため +∞𝔽-∞𝔽+0𝔽 に写る。)
  • ToUint32 は -0𝔽+0𝔽 に写す。

7.1.8 ToInt16 ( argument )

The abstract operation ToInt16 takes argument argument (ECMAScript言語値) and returns 整数 Number を含む normal completion あるいは throw completion. argument𝔽(-215) から 𝔽(215 - 1) までの 216 個の整数 Number 値のいずれかに変換する。 It performs the following steps when called:

  1. number を ? ToNumber(argument) とする。
  2. number有限でない、または +0𝔽-0𝔽 のいずれかなら +0𝔽 を返す。
  3. inttruncate((number)) とする。
  4. int16bitint modulo 216 とする。
  5. int16bit ≥ 215 なら 𝔽(int16bit - 216) を返し、そうでなければ 𝔽(int16bit) を返す。

7.1.9 ToUint16 ( argument )

The abstract operation ToUint16 takes argument argument (ECMAScript言語値) and returns 整数 Number を含む normal completion あるいは throw completion. argument+0𝔽 から 𝔽(216 - 1) までの 216 個の整数 Number 値のいずれかに変換する。 It performs the following steps when called:

  1. number を ? ToNumber(argument) とする。
  2. number有限でない、または +0𝔽-0𝔽 のいずれかなら +0𝔽 を返す。
  3. inttruncate((number)) とする。
  4. int16bitint modulo 216 とする。
  5. 𝔽(int16bit) を返す。
Note

上記 ToUint16 定義により:

  • ステップ 4 における 216 の代入が ToUint32 との唯一の差異。
  • ToUint16 は -0𝔽+0𝔽 に写す。

7.1.10 ToInt8 ( argument )

The abstract operation ToInt8 takes argument argument (ECMAScript言語値) and returns 整数 Number を含む normal completion あるいは throw completion. argument-128𝔽 から 127𝔽 までの 28 個の整数 Number 値のいずれかに変換する。 It performs the following steps when called:

  1. number を ? ToNumber(argument) とする。
  2. number有限でない、または +0𝔽-0𝔽 のいずれかなら +0𝔽 を返す。
  3. inttruncate((number)) とする。
  4. int8bitint modulo 28 とする。
  5. int8bit ≥ 27 なら 𝔽(int8bit - 28) を返し、そうでなければ 𝔽(int8bit) を返す。

7.1.11 ToUint8 ( argument )

The abstract operation ToUint8 takes argument argument (ECMAScript言語値) and returns 整数 Number を含む normal completion あるいは throw completion. argument+0𝔽 から 255𝔽 までの 28 個の整数 Number 値のいずれかに変換する。 It performs the following steps when called:

  1. number を ? ToNumber(argument) とする。
  2. number有限でない、または +0𝔽-0𝔽 のいずれかなら +0𝔽 を返す。
  3. inttruncate((number)) とする。
  4. int8bitint modulo 28 とする。
  5. 𝔽(int8bit) を返す。

7.1.12 ToUint8Clamp ( argument )

The abstract operation ToUint8Clamp takes argument argument (ECMAScript言語値) and returns 整数 Number を含む normal completion あるいは throw completion. argument+0𝔽 から 255𝔽 の範囲に丸め及びクランプし 28 個の整数 Number 値のいずれかにする。 It performs the following steps when called:

  1. number を ? ToNumber(argument) とする。
  2. numberNaN なら +0𝔽 を返す。
  3. mvnumber の拡張数学的値とする。
  4. clampedmv を 0 と 255 の間にクランプした結果とする。
  5. ffloor(clamped) とする。
  6. clamped < f + 0.5 なら 𝔽(f) を返す。
  7. clamped > f + 0.5 なら 𝔽(f + 1) を返す。
  8. f が偶数なら 𝔽(f) を返し、そうでなければ 𝔽(f + 1) を返す。
Note

他の多くの整数変換操作と異なり ToUint8Clamp は非整数値を切り捨てではなく丸める。また “round half to even” であり Math.round の “round half up” とは異なる。

7.1.13 ToBigInt ( argument )

The abstract operation ToBigInt takes argument argument (ECMAScript言語値) and returns BigInt を含む normal completion あるいは throw completion. argument を BigInt 値へ変換する。Number からの暗黙変換が必要となる場合は例外を投げる。 It performs the following steps when called:

  1. prim を ? ToPrimitive(argument, number) とする。
  2. Table 12 において prim が対応する値を返す。
Table 12: BigInt 変換
引数型 結果
Undefined TypeError 例外を投げる。
Null TypeError 例外を投げる。
Boolean primtrue なら 1n を、primfalse なら 0n を返す。
BigInt prim を返す。
Number TypeError 例外を投げる。
String
  1. nStringToBigInt(prim) とする。
  2. nundefined なら SyntaxError 例外を投げる。
  3. n を返す。
Symbol TypeError 例外を投げる。

7.1.14 StringToBigInt ( str )

The abstract operation StringToBigInt takes argument str (String) and returns BigInt または undefined. It performs the following steps when called:

  1. literal を ParseText(str, StringIntegerLiteral) とする。
  2. literal がエラーの List なら undefined を返す。
  3. mvliteral の MV とする。
  4. アサート: mv整数
  5. (mv) を返す。

7.1.14.1 StringIntegerLiteral 文法

StringToBigInt は以下の文法を用いる。

構文

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

7.1.14.2 実行時意味論: MV

7.1.15 ToBigInt64 ( argument )

The abstract operation ToBigInt64 takes argument argument (ECMAScript言語値) and returns BigInt を含む normal completion あるいは throw completion. argument(-263) から (263 - 1) までの 264 個の BigInt 値のいずれかに変換する。 It performs the following steps when called:

  1. n を ? ToBigInt(argument) とする。
  2. int64bit(n) modulo 264 とする。
  3. int64bit ≥ 263 なら (int64bit - 264) を返し、そうでなければ (int64bit) を返す。

7.1.16 ToBigUint64 ( argument )

The abstract operation ToBigUint64 takes argument argument (ECMAScript言語値) and returns BigInt を含む normal completion あるいは throw completion. argument0 から (264 - 1) までの 264 個の BigInt 値のいずれかに変換する。 It performs the following steps when called:

  1. n を ? ToBigInt(argument) とする。
  2. int64bit(n) modulo 264 とする。
  3. (int64bit) を返す。

7.1.17 ToString ( argument )

The abstract operation ToString takes argument argument (ECMAScript言語値) and returns String を含む normal completion あるいは throw completion. argument を String 型の値へ変換する。 It performs the following steps when called:

  1. argument が String なら argument を返す。
  2. argument が Symbol なら TypeError 例外を投げる。
  3. argumentundefined なら "undefined" を返す。
  4. argumentnull なら "null" を返す。
  5. argumenttrue なら "true" を返す。
  6. argumentfalse なら "false" を返す。
  7. argument が Number なら Number::toString(argument, 10) を返す。
  8. argument が BigInt なら BigInt::toString(argument, 10) を返す。
  9. アサート: argument は Object である。
  10. primValue を ? ToPrimitive(argument, string) とする。
  11. アサート: primValue は Object でない。
  12. ToString(primValue) を返す。

7.1.18 ToObject ( argument )

The abstract operation ToObject takes argument argument (ECMAScript言語値) and returns Object を含む normal completion あるいは throw completion. argument を Object 型の値へ変換する。 It performs the following steps when called:

  1. argumentundefined または null のいずれかなら TypeError 例外を投げる。
  2. argument が Boolean なら [[BooleanData]] 内部スロットに argument を設定した新しい Boolean オブジェクトを返す。Boolean オブジェクトの説明は 20.3 を参照。
  3. argument が Number なら [[NumberData]] 内部スロットに argument を設定した新しい Number オブジェクトを返す。説明は 21.1 参照。
  4. argument が String なら [[StringData]] 内部スロットに argument を設定した新しい String オブジェクトを返す。説明は 22.1 参照。
  5. argument が Symbol なら [[SymbolData]] 内部スロットに argument を設定した新しい Symbol オブジェクトを返す。説明は 20.4 参照。
  6. argument が BigInt なら [[BigIntData]] 内部スロットに argument を設定した新しい BigInt オブジェクトを返す。説明は 21.2 参照。
  7. アサート: argument は Object である。
  8. argument を返す。

7.1.19 ToPropertyKey ( argument )

The abstract operation ToPropertyKey takes argument argument (ECMAScript言語値) and returns プロパティキーを含む normal completion あるいは throw completion. argumentプロパティキーとして使用可能な値へ変換する。 It performs the following steps when called:

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

7.1.20 ToLength ( argument )

The abstract operation ToLength takes argument argument (ECMAScript言語値) and returns 非負整数 Number を含む normal completion あるいは throw completion. argument配列風オブジェクトの length として適した非負整数 Number にクランプし切り捨てる。 It performs the following steps when called:

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

7.1.21 CanonicalNumericIndexString ( argument )

The abstract operation CanonicalNumericIndexString takes argument argument (String) and returns Number または undefined. argument"-0" であるか、ある Number 値 n について ToString(n) と正確に一致するなら、対応する Number 値を返す。それ以外は undefined を返す。 It performs the following steps when called:

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

正規数値文字列とは CanonicalNumericIndexString 抽象操作undefined を返さない任意の String のこと。

7.1.22 ToIndex ( value )

The abstract operation ToIndex takes argument value (ECMAScript言語値) and returns 非負整数を含む normal completion あるいは throw completion. value整数に変換し、それが非負かつ整数インデックスに対応するならその整数を返す。そうでなければ例外を投げる。 It performs the following steps when called:

  1. integer を ? ToIntegerOrInfinity(value) とする。
  2. integer が 0 から 253 - 1 までの範囲にないなら RangeError 例外を投げる。
  3. integer を返す。

7.2 テストおよび比較操作

7.2.1 RequireObjectCoercible ( argument )

The abstract operation RequireObjectCoercible takes argument argument (ECMAScript言語値) and returns unused を含む normal completion あるいは throw completion. argumentToObject により Object へ変換できない値ならエラーを投げる。 It performs the following steps when called:

  1. argumentundefined または null のいずれかなら TypeError 例外を投げる。
  2. unused を返す。

7.2.2 IsArray ( argument )

The abstract operation IsArray takes argument argument (ECMAScript言語値) and returns Boolean を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. argument が Object でないなら false を返す。
  2. argumentArray エキゾチックオブジェクトなら true を返す。
  3. argumentProxy エキゾチックオブジェクトなら
    1. ValidateNonRevokedProxy(argument) を実行する。
    2. proxyTargetargument.[[ProxyTarget]] とする。
    3. IsArray(proxyTarget) を返す。
  4. false を返す。

7.2.3 IsCallable ( argument )

The abstract operation IsCallable takes argument argument (ECMAScript言語値) and returns Boolean. argument[[Call]] 内部メソッドを持つ呼び出し可能関数か判定する。 It performs the following steps when called:

  1. argument が Object でないなら false を返す。
  2. argument[[Call]] 内部メソッドを持つなら true を返す。
  3. false を返す。

7.2.4 IsConstructor ( argument )

The abstract operation IsConstructor takes argument argument (ECMAScript言語値) and returns Boolean. argument[[Construct]] 内部メソッドを持つ関数オブジェクトか判定する。 It performs the following steps when called:

  1. argument が Object でないなら false を返す。
  2. argument[[Construct]] 内部メソッドを持つなら true を返す。
  3. false を返す。

7.2.5 IsExtensible ( O )

The abstract operation IsExtensible takes argument O (Object) and returns Boolean を含む normal completion あるいは throw completion. O に追加のプロパティを加えられるか判定する。 It performs the following steps when called:

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

7.2.6 IsRegExp ( argument )

The abstract operation IsRegExp takes argument argument (ECMAScript言語値) and returns Boolean を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. argument が Object でないなら false を返す。
  2. matcher を ? Get(argument, %Symbol.match%) とする。
  3. matcherundefined でないなら ToBoolean(matcher) を返す。
  4. argument[[RegExpMatcher]] 内部スロットを持つなら true を返す。
  5. false を返す。

7.2.7 静的意味論: IsStringWellFormedUnicode ( string: String, ): Boolean

The abstract operation UNKNOWN takes UNPARSEABLE ARGUMENTS. string6.1.4 に記述される UTF-16 符号化コードポイント列として解釈し、それが well formed な UTF-16 シーケンスか判定する。 It performs the following steps when called:

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

7.2.8 SameType ( x, y )

The abstract operation SameType takes arguments x (ECMAScript言語値) and y (ECMAScript言語値) and returns Boolean. 2つの引数が同じ型かどうか判定する。 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 (ECMAScript言語値) and y (ECMAScript言語値) and returns Boolean. 2つの引数が同じ値かどうか判定する。 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 (ECMAScript言語値) and y (ECMAScript言語値) and returns Boolean. 2つの引数が同じ値か(+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 (Number でない ECMAScript言語値) and y (Number でない ECMAScript言語値) and returns Boolean. It performs the following steps when called:

  1. アサート: SameType(x, y) は true
  2. xundefined または null のいずれかなら true を返す。
  3. x が BigInt なら
    1. BigInt::equal(x, y) を返す。
  4. x が String なら
    1. xy が同じ長さで同じ位置に同じコードユニットを持つなら true を返し、そうでなければ false を返す。
  5. x が Boolean なら
    1. xy がともに true またはともに false なら true を返し、そうでなければ false を返す。
  6. 注: 他の全ての ECMAScript 言語値は同一性で比較される。
  7. xy なら true を返し、そうでなければ false を返す。
Note 1
説明のため、一部のケースは必要ではないが個別に扱っている。
Note 2
"xy" の詳細は 5.2.7 で述べる。

7.2.12 IsLessThan ( x, y, LeftFirst )

The abstract operation IsLessThan takes arguments x (ECMAScript言語値), y (ECMAScript言語値), and LeftFirst (Boolean) and returns Boolean または undefined を含む normal completion あるいは throw completion. 比較 x < y の意味論を提供し、true / false / undefined(少なくとも一方が NaN を示す)を返す。LeftFirst フラグは副作用の可視性を伴う操作の順序を制御するために使われ、ECMAScript が左から右への評価順を規定しているため必要。LeftFirsttrue のとき xy より左に現れる式に対応し、false のときは逆でその場合操作は y が先に行われる。 It performs the following steps when called:

  1. LeftFirsttrue なら
    1. px を ? ToPrimitive(x, number) とする。
    2. py を ? ToPrimitive(y, number) とする。
  2. それ以外
    1. 注: 評価順維持のため順序を反転する必要がある。
    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) なる各整数 i について昇順で
      1. cxpx のインデックス i にあるコードユニットの数値とする。
      2. cypy のインデックス i にあるコードユニットの数値とする。
      3. cx < cy なら true を返す。
      4. cx > cy なら false を返す。
    4. lx < ly なら true を返し、そうでなければ false を返す。
  4. それ以外
    1. px が BigInt かつ py が String なら
      1. nyStringToBigInt(py) とする。
      2. nyundefined なら undefined を返す。
      3. BigInt::lessThan(px, ny) を返す。
    2. px が String かつ py が BigInt なら
      1. nxStringToBigInt(px) とする。
      2. nxundefined なら undefined を返す。
      3. BigInt::lessThan(nx, py) を返す。
    3. 注: px, py はプリミティブなので評価順は重要でない。
    4. nx を ? ToNumeric(px) とする。
    5. ny を ? ToNumeric(py) とする。
    6. SameType(nx, ny) が true なら
      1. nx が Number なら
        1. Number::lessThan(nx, ny) を返す。
      2. それ以外
        1. アサート: nx は BigInt。
        2. BigInt::lessThan(nx, ny) を返す。
    7. アサート: (nx が BigInt かつ ny が Number) または (nx が Number かつ ny が BigInt)。
    8. nx または nyNaN なら undefined を返す。
    9. nx-∞𝔽 または ny+∞𝔽 なら true を返す。
    10. nx+∞𝔽 または ny-∞𝔽 なら false を返す。
    11. (nx) < (ny) なら true を返し、そうでなければ false を返す。
Note 1

ステップ 3 は、加算演算子 + を扱うアルゴリズム(13.15.3)のステップ 1.c と、論理和ではなく論理積を用いる点で異なる。

Note 2

文字列の比較は UTF-16 コードユニット値列に対する単純な辞書式順序を使用する。Unicode 仕様で定義される文字や文字列の意味的な等価性や照合順序は考慮しない。そのため Unicode Standard 上正規等価だが正規化形式が異なる文字列は不等と判定され得る。またサロゲートペアを含む文字列ではコードユニット順序はコードポイント順序と異なる。

7.2.13 IsLooselyEqual ( x, y )

The abstract operation IsLooselyEqual takes arguments x (ECMAScript言語値) and y (ECMAScript言語値) and returns Boolean を含む normal completion あるいは 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. Normative Optional
    ホストが Web ブラウザまたは [[IsHTMLDDA]] 内部スロット をサポートする場合
    1. x が Object で [[IsHTMLDDA]] 内部スロットを持ち、yundefined または null なら true を返す。
    2. xundefined または nully が Object かつ [[IsHTMLDDA]] 内部スロットを持つなら 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. x有限でないまたは y有限でないなら false を返す。
    2. (x) = (y) なら true を返し、そうでなければ false を返す。
  14. false を返す。

7.2.14 IsStrictlyEqual ( x, y )

The abstract operation IsStrictlyEqual takes arguments x (ECMAScript言語値) and y (ECMAScript言語値) and returns 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

このアルゴリズムは符号付きゼロと NaN の扱いにおいて SameValue アルゴリズムと異なる。

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

7.3.1 MakeBasicObject ( internalSlotsList )

The abstract operation MakeBasicObject takes argument internalSlotsList (内部スロット名の List) and returns Object. 通常オブジェクトエキゾチックオブジェクトを含む、アルゴリズム的に作られる全ての ECMAScript オブジェクトの起源である。全オブジェクト生成で共通する手順を切り出し、生成を集約する。 It performs the following steps when called:

  1. internalSlotsListinternalSlotsList と « [[PrivateElements]] » のリスト結合に設定する。
  2. internalSlotsList 内の各名前に対応する内部スロットを持つ新規オブジェクト obj を作成する。
  3. 注: オブジェクトの内部メソッドと内部スロット で述べるように特記ない限り各内部スロットの初期値は undefined
  4. obj.[[PrivateElements]] を空の新しい List に設定する。
  5. obj の本質的内部メソッドを 10.1 で規定される既定の通常オブジェクト定義に設定する。
  6. アサート: 呼び出し側が obj[[GetPrototypeOf]][[SetPrototypeOf]] の両方を上書きしない場合、internalSlotsList[[Prototype]] を含む。
  7. アサート: 呼び出し側が obj[[SetPrototypeOf]], [[IsExtensible]], [[PreventExtensions]] の全てを上書きしない場合、internalSlotsList[[Extensible]] を含む。
  8. internalSlotsList[[Extensible]] を含むなら obj.[[Extensible]]true に設定する。
  9. obj を返す。
Note

本仕様内でエキゾチックオブジェクトArrayCreateBoundFunctionCreate のような抽象操作で、まず MakeBasicObject を呼び基本オブジェクトを得てから内部メソッドの一部または全部を上書きして作成される。エキゾチックオブジェクト生成をカプセル化するため、本質的内部メソッドはそれら操作以外では変更されない。

7.3.2 Get ( O, P )

The abstract operation Get takes arguments O (Object) and P (プロパティキー) and returns ECMAScript言語値を含む normal completion あるいは throw completion. オブジェクトの特定プロパティの値を取得するために使用される。 It performs the following steps when called:

  1. O.[[Get]](P, O) を返す。

7.3.3 GetV ( V, P )

The abstract operation GetV takes arguments V (ECMAScript言語値) and P (プロパティキー) and returns ECMAScript言語値を含む normal completion あるいは throw completion. ECMAScript言語値の特定プロパティの値を取得するために使用される。値がオブジェクトでない場合、値の型に適切なラッパーオブジェクトを用いてプロパティ探索が行われる。 It performs the following steps when called:

  1. O を ? ToObject(V) とする。
  2. O.[[Get]](P, V) を返す。

7.3.4 Set ( O, P, V, Throw )

The abstract operation Set takes arguments O (Object), P (プロパティキー), V (ECMAScript言語値), and Throw (Boolean) and returns unused を含む normal completion あるいは throw completion. オブジェクトの特定プロパティの値を設定するために用いられる。V は新しい値。 It performs the following steps when called:

  1. success を ? O.[[Set]](P, V, O) とする。
  2. successfalse かつ Throwtrue なら TypeError 例外を投げる。
  3. unused を返す。

7.3.5 CreateDataProperty ( O, P, V )

The abstract operation CreateDataProperty takes arguments O (Object), P (プロパティキー), and V (ECMAScript言語値) and returns Boolean を含む normal completion あるいは throw completion. オブジェクトの新しい自身プロパティを生成するために使用される。 It performs the following steps when called:

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

この抽象操作は ECMAScript の代入演算子で作られるプロパティと同じ既定属性を持つプロパティを生成する。通常プロパティは未存在であり、存在し非設定可能または O が拡張不可能なら [[DefineOwnProperty]]false を返す。

7.3.6 CreateDataPropertyOrThrow ( O, P, V )

The abstract operation CreateDataPropertyOrThrow takes arguments O (Object), P (プロパティキー), and V (ECMAScript言語値) and returns unused を含む normal completion あるいは throw completion. オブジェクトの新しい自身プロパティを生成する。要求された更新が行えない場合 TypeError を投げる。 It performs the following steps when called:

  1. success を ? CreateDataProperty(O, P, V) とする。
  2. successfalse なら TypeError 例外を投げる。
  3. unused を返す。
Note

属性は代入演算子によって生成されるプロパティの既定値と同じ。存在済みで非設定可能または O が拡張不可能なら [[DefineOwnProperty]]false を返し本操作は TypeError を投げる。

7.3.7 CreateNonEnumerableDataPropertyOrThrow ( O, P, V )

The abstract operation CreateNonEnumerableDataPropertyOrThrow takes arguments O (Object), P (プロパティキー), and V (ECMAScript言語値) and returns unused. 通常オブジェクトの列挙不可な新しい自身プロパティを生成する。 It performs the following steps when called:

  1. アサート: O は非設定可能プロパティを持たない通常で拡張可能なオブジェクト。
  2. newDesc を PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true } とする。
  3. DefinePropertyOrThrow(O, P, newDesc) を実行する。
  4. unused を返す。
Note

代入演算子既定と同じだが列挙不可。通常存在しないが存在しても DefinePropertyOrThrow は正常完了する。

7.3.8 DefinePropertyOrThrow ( O, P, desc )

The abstract operation DefinePropertyOrThrow takes arguments O (Object), P (プロパティキー), and desc (Property Descriptor) and returns unused を含む normal completion あるいは throw completion. オブジェクトの [[DefineOwnProperty]] 内部メソッドを呼び、要求された更新が行えない場合 TypeError を投げる。 It performs the following steps when called:

  1. success を ? O.[[DefineOwnProperty]](P, desc) とする。
  2. successfalse なら TypeError 例外を投げる。
  3. unused を返す。

7.3.9 DeletePropertyOrThrow ( O, P )

The abstract operation DeletePropertyOrThrow takes arguments O (Object) and P (プロパティキー) and returns unused を含む normal completion あるいは throw completion. オブジェクトの特定自身プロパティを削除する。プロパティが設定可能でない場合例外を投げる。 It performs the following steps when called:

  1. success を ? O.[[Delete]](P) とする。
  2. successfalse なら TypeError 例外を投げる。
  3. unused を返す。

7.3.10 GetMethod ( V, P )

The abstract operation GetMethod takes arguments V (ECMAScript言語値) and P (プロパティキー) and returns 関数オブジェクトまたは undefined を含む normal completion あるいは throw completion. プロパティ値が関数であることが期待される場合に ECMAScript 言語値の特定プロパティ値を取得する。 It performs the following steps when called:

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

7.3.11 HasProperty ( O, P )

The abstract operation HasProperty takes arguments O (Object) and P (プロパティキー) and returns Boolean を含む normal completion あるいは throw completion. オブジェクトが指定キーのプロパティ(自身または継承)を持つか判定する。 It performs the following steps when called:

  1. O.[[HasProperty]](P) を返す。

7.3.12 HasOwnProperty ( O, P )

The abstract operation HasOwnProperty takes arguments O (Object) and P (プロパティキー) and returns Boolean を含む normal completion あるいは throw completion. オブジェクトが指定キーの自身プロパティを持つか判定する。 It performs the following steps when called:

  1. desc を ? O.[[GetOwnProperty]](P) とする。
  2. descundefined なら false を返す。
  3. true を返す。

7.3.13 Call ( F: ECMAScript言語値, V: ECMAScript言語値, 省略可能 argumentsList: ECMAScript言語値の List, ): ECMAScript言語値を含む normal completion あるいは throw completion

The abstract operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 関数オブジェクト[[Call]] 内部メソッドを呼ぶために用いる。F が関数、Vthis 値、argumentsList が内部メソッドに渡す引数列。argumentsList が無ければ空の新 List を用いる。 It performs the following steps when called:

  1. argumentsList が存在しないなら argumentsList を空の新 List に設定する。
  2. IsCallable(F) が false なら TypeError 例外を投げる。
  3. F.[[Call]](V, argumentsList) を返す。

7.3.14 Construct ( F: constructor, 省略可能 argumentsList: ECMAScript言語値の List, 省略可能 newTarget: constructor, ): Object を含む normal completion あるいは throw completion

The abstract operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 関数オブジェクト[[Construct]] 内部メソッドを呼ぶために用いる。argumentsListnewTarget は内部メソッドに対応する引数として渡される。argumentsList が無い場合空の新 ListnewTarget が無い場合 F を用いる。 It performs the following steps when called:

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

newTarget が無い場合、この操作は new F(...argumentsList) と同等。

7.3.15 SetIntegrityLevel ( O, level )

The abstract operation SetIntegrityLevel takes arguments O (Object) and level (sealed または frozen) and returns Boolean を含む normal completion あるいは throw completion. オブジェクトの自身プロパティ集合を固定するために使用。 It performs the following steps when called:

  1. status を ? O.[[PreventExtensions]]() とする。
  2. statusfalse なら false を返す。
  3. keys を ? O.[[OwnPropertyKeys]]() とする。
  4. levelsealed なら
    1. keys の各要素 k について
      1. DefinePropertyOrThrow(O, k, PropertyDescriptor { [[Configurable]]: false }) を実行する。
  5. それ以外
    1. アサート: levelfrozen
    2. keys の各要素 k について
      1. currentDesc を ? O.[[GetOwnProperty]](k) とする。
      2. currentDescundefined でないなら
        1. IsAccessorDescriptor(currentDesc) が true なら
          1. desc を PropertyDescriptor { [[Configurable]]: false } とする。
        2. それ以外
          1. desc を PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false } とする。
        3. DefinePropertyOrThrow(O, k, desc) を実行する。
  6. true を返す。

7.3.16 TestIntegrityLevel ( O, level )

The abstract operation TestIntegrityLevel takes arguments O (Object) and level (sealed または frozen) and returns Boolean を含む normal completion あるいは throw completion. オブジェクトの自身プロパティ集合が固定されているか判定する。 It performs the following steps when called:

  1. extensible を ? IsExtensible(O) とする。
  2. extensibletrue なら false を返す。
  3. 注: オブジェクトが拡張可能ならプロパティは調べない。
  4. keys を ? O.[[OwnPropertyKeys]]() とする。
  5. keys の各要素 k について
    1. currentDesc を ? O.[[GetOwnProperty]](k) とする。
    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 (ECMAScript言語値List) and returns Array. 要素が elements によって与えられる Array を生成する。 It performs the following steps when called:

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

7.3.18 LengthOfArrayLike ( obj )

The abstract operation LengthOfArrayLike takes argument obj (Object) and returns 非負整数を含む normal completion あるいは throw completion. 配列風オブジェクトの "length" プロパティの値を返す。 It performs the following steps when called:

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

配列風オブジェクトとはこの操作が normal completion を返す任意のオブジェクト。

Note 1
通常配列風オブジェクトは整数インデックス名プロパティを持つがこの定義の要件ではない。
Note 2
Array と String オブジェクトは配列風オブジェクトの例である。

7.3.19 CreateListFromArrayLike ( obj: ECMAScript言語値, 省略可能 validElementTypes: all または property-key, ): ECMAScript言語値の List を含む normal completion あるいは throw completion

The abstract operation UNKNOWN takes UNPARSEABLE ARGUMENTS. obj のインデックス付きプロパティから要素を取得して List 値を生成する。validElementTypes は要素として許可される値の型を示す。 It performs the following steps when called:

  1. validElementTypes が存在しないなら validElementTypesall とする。
  2. obj が Object でないなら TypeError 例外を投げる。
  3. len を ? LengthOfArrayLike(obj) とする。
  4. list を空の新 List とする。
  5. index を 0 とする。
  6. index < len の間繰り返す
    1. indexName を ! ToString(𝔽(index)) とする。
    2. next を ? Get(obj, indexName) とする。
    3. validElementTypesproperty-key かつ nextプロパティキーでないなら TypeError 例外を投げる。
    4. nextlist に追加する。
    5. indexindex + 1 に設定する。
  7. list を返す。

7.3.20 Invoke ( V: ECMAScript言語値, P: プロパティキー, 省略可能 argumentsList: ECMAScript言語値の List, ): ECMAScript言語値を含む normal completion あるいは throw completion

The abstract operation UNKNOWN takes UNPARSEABLE ARGUMENTS. ECMAScript言語値のメソッドプロパティを呼び出すために用いる。V はプロパティ探索点かつ呼び出しの this 値。argumentsList はメソッドに渡す引数列。省略時は空 List。 It performs the following steps when called:

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

7.3.21 OrdinaryHasInstance ( C, O )

The abstract operation OrdinaryHasInstance takes arguments C (ECMAScript言語値) and O (ECMAScript言語値) and returns Boolean を含む normal completion あるいは throw completion. OC により提供されるインスタンスオブジェクト継承パスから継承しているかの既定アルゴリズムを実装する。 It performs the following steps when called:

  1. IsCallable(C) が false なら false を返す。
  2. C[[BoundTargetFunction]] 内部スロットを持つなら
    1. BCC.[[BoundTargetFunction]] とする。
    2. InstanceofOperator(O, BC) を返す。
  3. O が Object でないなら false を返す。
  4. P を ? Get(C, "prototype") とする。
  5. P が Object でないなら TypeError 例外を投げる。
  6. 繰り返し
    1. O を ? O.[[GetPrototypeOf]]() に設定する。
    2. Onull なら false を返す。
    3. SameValue(P, O) が true なら true を返す。

7.3.22 SpeciesConstructor ( O, defaultConstructor )

The abstract operation SpeciesConstructor takes arguments O (Object) and defaultConstructor (constructor) and returns constructor を含む normal completion あるいは throw completion. O から派生する新オブジェクト生成に用いるべきコンストラクタを取得する。defaultConstructor%Symbol.species% プロパティが O から辿れない場合に使用するコンストラクタ。 It performs the following steps when called:

  1. C を ? Get(O, "constructor") とする。
  2. Cundefined なら defaultConstructor を返す。
  3. C が Object でないなら TypeError 例外を投げる。
  4. S を ? Get(C, %Symbol.species%) とする。
  5. Sundefined または null のいずれかなら defaultConstructor を返す。
  6. IsConstructor(S) が true なら S を返す。
  7. TypeError 例外を投げる。

7.3.23 EnumerableOwnProperties ( O, kind )

The abstract operation EnumerableOwnProperties takes arguments O (Object) and kind (key, value, key+value) and returns ECMAScript言語値List を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. ownKeys を ? O.[[OwnPropertyKeys]]() とする。
  2. results を空の新 List とする。
  3. ownKeys の各要素 key について
    1. key が String なら
      1. desc を ? O.[[GetOwnProperty]](key) とする。
      2. descundefined でなく desc.[[Enumerable]]true なら
        1. kindkey なら
          1. keyresults に追加する。
        2. それ以外
          1. value を ? Get(O, key) とする。
          2. kindvalue なら
            1. valueresults に追加する。
          3. それ以外
            1. アサート: kindkey+value
            2. entryCreateArrayFromListkey, value ») とする。
            3. entryresults に追加する。
  4. results を返す。

7.3.24 GetFunctionRealm ( obj )

The abstract operation GetFunctionRealm takes argument obj (関数オブジェクト) and returns Realm Record を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. obj[[Realm]] 内部スロットを持つなら
    1. obj.[[Realm]] を返す。
  2. obj が bound function エキゾチックオブジェクトなら
    1. boundTargetFunctionobj.[[BoundTargetFunction]] とする。
    2. GetFunctionRealm(boundTargetFunction) を返す。
  3. objProxy エキゾチックオブジェクトなら
    1. ValidateNonRevokedProxy(obj) を実行する。
    2. proxyTargetobj.[[ProxyTarget]] とする。
    3. アサート: proxyTarget関数オブジェクト
    4. GetFunctionRealm(proxyTarget) を返す。
  4. 現在の Realm Record を返す。
Note

ステップ 4 に到達するのは [[Realm]] 内部スロットを持たない非標準 function エキゾチックオブジェクトの場合のみ。

7.3.25 CopyDataProperties ( target, source, excludedItems )

The abstract operation CopyDataProperties takes arguments target (Object), source (ECMAScript言語値), and excludedItems (プロパティキーList) and returns unused を含む normal completion あるいは 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 の各要素 e について
      1. SameValue(e, nextKey) が true なら
        1. excludedtrue に設定する。
    3. excludedfalse なら
      1. desc を ? from.[[GetOwnProperty]](nextKey) とする。
      2. descundefined でなく desc.[[Enumerable]]true なら
        1. propValue を ? Get(from, nextKey) とする。
        2. CreateDataPropertyOrThrow(target, nextKey, propValue) を実行する。
  5. unused を返す。
Note

ここに渡される target は常に新規作成オブジェクトで、エラー時に直接アクセスされない。

7.3.26 PrivateElementFind ( O, P )

The abstract operation PrivateElementFind takes arguments O (Object) and P (Private Name) and returns PrivateElement または empty. It performs the following steps when called:

  1. O.[[PrivateElements]]PrivateElement pe を含み pe.[[Key]]P であるなら
    1. pe を返す。
  2. empty を返す。

7.3.27 PrivateFieldAdd ( O, P, value )

The abstract operation PrivateFieldAdd takes arguments O (Object), P (Private Name), and value (ECMAScript言語値) and returns unused を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. ホストが Web ブラウザなら
    1. HostEnsureCanAddPrivateElement(O) を実行する。
  2. entryPrivateElementFind(O, P) とする。
  3. entryempty でないなら TypeError 例外を投げる。
  4. PrivateElement { [[Key]]: P, [[Kind]]: field, [[Value]]: value } を O.[[PrivateElements]] に追加する。
  5. unused を返す。

7.3.28 PrivateMethodOrAccessorAdd ( O, method )

The abstract operation PrivateMethodOrAccessorAdd takes arguments O (Object) and method (PrivateElement) and returns unused を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. アサート: method.[[Kind]]method または accessor のいずれか。
  2. ホストが Web ブラウザなら
    1. HostEnsureCanAddPrivateElement(O) を実行する。
  3. entryPrivateElementFind(O, method.[[Key]]) とする。
  4. entryempty でないなら TypeError 例外を投げる。
  5. methodO.[[PrivateElements]] に追加する。
  6. unused を返す。
Note

private メソッドとアクセサの値はインスタンス間で共有され、この操作は新しいコピーを作成しない。

7.3.29 HostEnsureCanAddPrivateElement ( O )

The host-defined abstract operation HostEnsureCanAddPrivateElement takes argument O (Object) and returns unused を含む normal completion あるいは throw completion. ホスト環境が特定のホスト定義エキゾチックオブジェクトへの private 要素追加を禁止できるようにする。

HostEnsureCanAddPrivateElement の実装は次の要件に従わなければならない:

既定実装は NormalCompletion(unused) を返す。

この抽象操作は Web ブラウザの ECMAScript ホストのみが呼び出す。

7.3.30 PrivateGet ( O, P )

The abstract operation PrivateGet takes arguments O (Object) and P (Private Name) and returns ECMAScript言語値を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. entryPrivateElementFind(O, P) とする。
  2. entryempty なら TypeError 例外を投げる。
  3. entry.[[Kind]]field または method のいずれかなら
    1. entry.[[Value]] を返す。
  4. アサート: entry.[[Kind]]accessor
  5. entry.[[Get]]undefined なら TypeError 例外を投げる。
  6. getterentry.[[Get]] とする。
  7. ? Call(getter, O) を返す。

7.3.31 PrivateSet ( O, P, value )

The abstract operation PrivateSet takes arguments O (Object), P (Private Name), and value (ECMAScript言語値) and returns unused を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. entryPrivateElementFind(O, P) とする。
  2. entryempty なら TypeError 例外を投げる。
  3. entry.[[Kind]]field なら
    1. entry.[[Value]]value に設定する。
  4. それ以外で entry.[[Kind]]method なら
    1. TypeError 例外を投げる。
  5. それ以外
    1. アサート: entry.[[Kind]]accessor
    2. entry.[[Set]]undefined なら TypeError 例外を投げる。
    3. setterentry.[[Set]] とする。
    4. ? Call(setter, O, « value ») を実行する。
  6. unused を返す。

7.3.32 DefineField ( receiver, fieldRecord )

The abstract operation DefineField takes arguments receiver (Object) and fieldRecord (ClassFieldDefinition Record) and returns unused を含む normal completion あるいは 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. アサート: fieldNameプロパティキー
    2. CreateDataPropertyOrThrow(receiver, fieldName, initValue) を実行する。
  7. unused を返す。

7.3.33 InitializeInstanceElements ( O, constructor )

The abstract operation InitializeInstanceElements takes arguments O (Object) and constructor (ECMAScript 関数オブジェクト) and returns unused を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. methodsconstructor.[[PrivateMethods]] とする。
  2. methods の各 PrivateElement method について
    1. PrivateMethodOrAccessorAdd(O, method) を実行する。
  3. fieldsconstructor.[[Fields]] とする。
  4. fields の各要素 fieldRecord について
    1. DefineField(O, fieldRecord) を実行する。
  5. unused を返す。

7.3.34 AddValueToKeyedGroup ( groups, key, value )

The abstract operation AddValueToKeyedGroup takes arguments groups ([[Key]] (ECMAScript言語値) と [[Elements]] (ECMAScript言語値List) フィールドを持つ RecordList), key (ECMAScript言語値), and value (ECMAScript言語値) and returns unused. It performs the following steps when called:

  1. groups の各 Record { [[Key]], [[Elements]] } g について
    1. SameValue(g.[[Key]], key) が true なら
      1. アサート: groups のうちこの条件を満たす要素は正確に1つ。
      2. valueg.[[Elements]] に追加する。
      3. unused を返す。
  2. groupRecord { [[Key]]: key, [[Elements]]: « value » } とする。
  3. groupgroups に追加する。
  4. unused を返す。

7.3.35 GroupBy ( items, callback, keyCoercion )

The abstract operation GroupBy takes arguments items (ECMAScript言語値), callback (ECMAScript言語値), and keyCoercion (property または collection) and returns [[Key]][[Elements]] フィールドを持つ RecordList を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. RequireObjectCoercible(items) を実行する。
  2. IsCallable(callback) が false なら TypeError 例外を投げる。
  3. groups を空の新 List とする。
  4. iteratorRecord を ? GetIterator(items, sync) とする。
  5. k を 0 とする。
  6. 繰り返し
    1. k ≥ 253 - 1 なら
      1. errorThrowCompletion(新規 TypeError オブジェクト) とする。
      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. アサート: keyCoercioncollection
      2. keyCanonicalizeKeyedCollectionKey(key) に設定する。
    9. AddValueToKeyedGroup(groups, key, value) を実行する。
    10. kk + 1 に設定する。

7.3.36 SetterThatIgnoresPrototypeProperties ( thisValue, home, p, v )

The abstract operation SetterThatIgnoresPrototypeProperties takes arguments thisValue (ECMAScript言語値), home (Object), p (プロパティキー), and v (ECMAScript言語値) and returns unused を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. thisValue が Object でないなら
    1. TypeError 例外を投げる。
  2. SameValue(thisValue, home) が true なら
    1. 注: ここで投げることは strict mode で home オブジェクト上の非書き込み可能データプロパティへの代入をエミュレートする。
    2. TypeError 例外を投げる。
  3. desc を ? thisValue.[[GetOwnProperty]](p) とする。
  4. descundefined なら
    1. CreateDataPropertyOrThrow(thisValue, p, v) を実行する。
  5. それ以外
    1. Set(thisValue, p, v, true) を実行する。
  6. unused を返す。

7.4 イテレータオブジェクトに対する操作

共通反復インターフェイス(27.1)を参照。

7.4.1 Iterator Record

Iterator Record はイテレータまたは非同期イテレータとその next メソッドをカプセル化するための Record 値。

Iterator Record は Table 13 に示すフィールドを持つ。

Table 13: Iterator Record フィールド
フィールド名 意味
[[Iterator]] Object イテレータまたは非同期イテレータインターフェイスに準拠するオブジェクト。
[[NextMethod]] ECMAScript言語値 [[Iterator]] オブジェクトの next メソッド。
[[Done]] Boolean イテレータが完了またはクローズされたか。

7.4.2 GetIteratorDirect ( obj )

The abstract operation GetIteratorDirect takes argument obj (Object) and returns Iterator Record を含む normal completion あるいは 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 (ECMAScript言語値) and method (関数オブジェクト) and returns Iterator Record を含む normal completion あるいは throw completion. It performs the following steps when called:

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

7.4.4 GetIterator ( obj, kind )

The abstract operation GetIterator takes arguments obj (ECMAScript言語値) and kind (sync または async) and returns Iterator Record を含む normal completion あるいは 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 例外を投げる。
      3. syncIteratorRecord を ? GetIteratorFromMethod(obj, syncMethod) とする。
      4. CreateAsyncFromSyncIterator(syncIteratorRecord) を返す。
  2. それ以外
    1. method を ? GetMethod(obj, %Symbol.iterator%) とする。
  3. methodundefined なら TypeError 例外を投げる。
  4. GetIteratorFromMethod(obj, method) を返す。

7.4.5 GetIteratorFlattenable ( obj, primitiveHandling )

The abstract operation GetIteratorFlattenable takes arguments obj (ECMAScript言語値) and primitiveHandling (iterate-string-primitives または reject-primitives) and returns Iterator Record を含む normal completion あるいは throw completion. It performs the following steps when called:

  1. obj が Object でないなら
    1. primitiveHandlingreject-primitives なら TypeError 例外を投げる。
    2. アサート: primitiveHandlingiterate-string-primitives
    3. obj が String でないなら TypeError 例外を投げる。
  2. method を ? GetMethod(obj, %Symbol.iterator%) とする。
  3. methodundefined なら
    1. iteratorobj とする。
  4. それ以外
    1. iterator を ? Call(method, obj) とする。
  5. iterator が Object でないなら TypeError 例外を投げる。
  6. GetIteratorDirect(iterator) を返す。

7.4.6 IteratorNext ( iteratorRecord: Iterator Record, 省略可能 value: ECMAScript言語値, ): Object を含む normal completion あるいは throw completion

The abstract operation UNKNOWN takes UNPARSEABLE ARGUMENTS. 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 例外を投げる。
  6. result を返す。

7.4.7 IteratorComplete ( iteratorResult )

The abstract operation IteratorComplete takes argument iteratorResult (Object) and returns Boolean を含む normal completion あるいは 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 (Object) and returns ECMAScript言語値を含む normal completion あるいは 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 (Iterator Record) and returns Object または done を含む normal completion あるいは throw completion. iteratorRecord.[[NextMethod]] を呼び次の値を要求し、イテレータが終端なら 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 (Iterator Record) and returns ECMAScript言語値 または done を含む normal completion あるいは throw completion. iteratorRecord.[[NextMethod]] を呼び次の値を要求し、イテレータ終端なら 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 (Iterator Record) and completion (Completion Record) and returns Completion Record. イテレータが完了状態に達した際に通常行う処理を実行するよう通知する。 It performs the following steps when called:

  1. アサート: 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 例外を投げる。
  8. completion を返す。

7.4.12 IfAbruptCloseIterator ( value, iteratorRecord )

IfAbruptCloseIterator は Iterator Record を用いるアルゴリズム手順列の省略記法。次の形式のステップ:

  1. IfAbruptCloseIterator(value, iteratorRecord)。

は次と同じ意味を持つ:

  1. アサート: valueCompletion Record
  2. valueabrupt completion なら ? IteratorClose(iteratorRecord, value) を返す。
  3. それ以外なら value を ! value に設定する。

7.4.13 AsyncIteratorClose ( iteratorRecord, completion )

The abstract operation AsyncIteratorClose takes arguments iteratorRecord (Iterator Record) and completion (Completion Record) and returns Completion Record. 非同期イテレータが完了状態に達した際に通常行う処理を実行するよう通知する。 It performs the following steps when called:

  1. アサート: 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 例外を投げる。
  8. completion を返す。

7.4.14 CreateIteratorResultObject ( value, done )

The abstract operation CreateIteratorResultObject takes arguments value (ECMAScript言語値) and done (Boolean) and returns IteratorResult インターフェイスに準拠する Object. IteratorResult インターフェイスに準拠するオブジェクトを生成する。 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.15 CreateListIteratorRecord ( list )

The abstract operation CreateListIteratorRecord takes argument list (ECMAScript言語値List) and returns Iterator Record. list の連続要素を返す [[NextMethod]] を持つ Iterator Record を生成する。 It performs the following steps when called:

  1. closure をパラメータ無しで list をキャプチャし呼び出し時に次を行う新しい Abstract Closure とする:
    1. list の各要素 E について
      1. GeneratorYield(CreateIteratorResultObject(E, false)) を実行する。
    2. NormalCompletion(undefined) を返す。
  2. iteratorCreateIteratorFromClosure(closure, empty, %Iterator.prototype%) とする。
  3. Iterator Record { [[Iterator]]: iterator, [[NextMethod]]: %GeneratorPrototype.next%, [[Done]]: false } を返す。
Note

List イテレータオブジェクトは ECMAScript コードから直接アクセスできない。

7.4.16 IteratorToList ( iteratorRecord )

The abstract operation IteratorToList takes argument iteratorRecord (Iterator Record) and returns ECMAScript言語値List を含む normal completion あるいは throw completion. It performs the following steps when called:

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