20 基本オブジェクト

20.1 Object オブジェクト

20.1.1 Object コンストラクタ

Object コンストラクタ:

  • %Object% である。
  • グローバルオブジェクト"Object" プロパティの初期値である。
  • コンストラクタとして呼び出されたときに新しい通常のオブジェクトを作成する。
  • コンストラクタとしてではなく関数として呼び出されたときに型変換を行う。
  • クラス定義の extends 節の値として使用されることがある。

20.1.1.1 Object ( value )

この関数は呼び出されたときに次の手順を実行する:

  1. NewTarget が undefined でもアクティブな関数オブジェクトでもない場合、次を行う:
    1. OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%") を返す。
  2. valueundefined または null のいずれかである場合、OrdinaryObjectCreate(%Object.prototype%) を返す。
  3. ToObject(value) を返す。

20.1.2 Object コンストラクタのプロパティ

Object コンストラクタ:

  • [[Prototype]] 内部スロットを持ち、その値は %Function.prototype% である。
  • 以下の追加プロパティを持つ:

20.1.2.1 Object.assign ( target, ...sources )

この関数は、1 個以上のソースオブジェクトから列挙可能な自身のプロパティのすべての値を target オブジェクトにコピーする。

呼び出されたときに次の手順を実行する:

  1. Let to be ? ToObject(target)(target をオブジェクトに変換する)。
  2. 引数が 1 個だけ渡された場合、to を返す。
  3. sources の各要素 nextSource について、次を行う:
    1. nextSourceundefined でも null でもない場合、次を行う:
      1. Let from be ! ToObject(nextSource)(ソースをオブジェクトに変換する)。
      2. Let keys be ? from.[[OwnPropertyKeys]]()(所有プロパティキーの一覧を取得する)。
      3. keys の各要素 nextKey について、次を行う:
        1. Let desc be ? from.[[GetOwnProperty]](nextKey)(当該キーのプロパティ記述子を取得する)。
        2. descundefined でなく、かつ desc.[[Enumerable]]true の場合、次を行う:
          1. Let propValue be ? Get(from, nextKey)(プロパティ値を取得する)。
          2. Perform ? Set(to, nextKey, propValue, true)(ターゲットに設定する)。
  4. to を返す。

この関数の "length" プロパティは 2𝔽 である。

20.1.2.2 Object.create ( proto, properties )

この関数は、指定されたプロトタイプを持つ新しいオブジェクトを作成する。

呼び出されたときに次の手順を実行する:

  1. proto がオブジェクトでなく、かつ protonull でもない場合、TypeError 例外を投げる。
  2. Let obj be OrdinaryObjectCreate(proto)(指定プロトタイプの通常オブジェクトを作成する)。
  3. propertiesundefined でない場合、次を行う:
    1. Return ? ObjectDefineProperties(obj, properties) を返す(プロパティ記述子で定義する)。
  4. obj を返す。

20.1.2.3 Object.defineProperties ( obj, properties )

この関数は、オブジェクトに自身のプロパティを追加し、または既存の自身のプロパティの属性を更新する。

呼び出されたときに次の手順を実行する:

  1. obj がオブジェクトでない場合、TypeError 例外を投げる。
  2. Return ? ObjectDefineProperties(obj, properties) を返す。

20.1.2.3.1 ObjectDefineProperties ( obj, properties )

The abstract operation ObjectDefineProperties takes arguments obj (an Object) and properties (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. Let props be ? ToObject(properties)(properties をオブジェクトに変換する)。
  2. Let keys be ? props.[[OwnPropertyKeys]]()props の所有プロパティキーを取得する)。
  3. Let descriptors be a new empty List(空の記述子リストを作る)。
  4. keys の各要素 nextKey について、次を行う:
    1. Let propDesc be ? props.[[GetOwnProperty]](nextKey)(当該キーのプロパティ記述子を取得する)。
    2. propDescundefined でなく、かつ propDesc.[[Enumerable]]true の場合、次を行う:
      1. Let descObj be ? Get(props, nextKey)(記述子オブジェクトを取得する)。
      2. Let desc be ? ToPropertyDescriptor(descObj)(プロパティ記述子に変換する)。
      3. Append the Record { [[Key]]: nextKey, [[Descriptor]]: desc } to descriptors(記述子リストに追加する)。
  5. descriptors の各要素 property について、次を行う:
    1. Perform ? DefinePropertyOrThrow(obj, property.[[Key]], property.[[Descriptor]])(対象オブジェクトに定義する/失敗すれば例外)。
  6. obj を返す。

20.1.2.4 Object.defineProperty ( obj, propertyKey, attributes )

この関数は、オブジェクトに自身のプロパティを追加し、または既存の自身のプロパティの属性を更新する。

呼び出されたときに次の手順を実行する:

  1. obj がオブジェクトでない場合、TypeError 例外を投げる。
  2. Let key be ? ToPropertyKey(propertyKey)(プロパティキーに変換する)。
  3. Let desc be ? ToPropertyDescriptor(attributes)(属性をプロパティ記述子に変換する)。
  4. Perform ? DefinePropertyOrThrow(obj, key, desc)(定義する、失敗すれば例外)。
  5. obj を返す。

20.1.2.5 Object.entries ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. Let coerced be ? ToObject(obj)(obj をオブジェクトに変換する)。
  2. Let entryList be ? EnumerableOwnProperties(coerced, key+value)(列挙可能な自身のキーと値の一覧を取得する)。
  3. Return CreateArrayFromList(entryList)(一覧から配列を作成して返す)。

20.1.2.6 Object.freeze ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. obj がオブジェクトでない場合、obj を返す。
  2. Let status be ? SetIntegrityLevel(obj, frozen)(完全凍結の整合性レベルを設定する)。
  3. statusfalse の場合、TypeError 例外を投げる。
  4. obj を返す。

20.1.2.7 Object.fromEntries ( iterable )

この関数は呼び出されたときに次の手順を実行する:

  1. Perform ? RequireObjectCoercible(iterable)(iterable がオブジェクトに変換可能であることを要求する)。
  2. Let obj be OrdinaryObjectCreate(%Object.prototype%)(%Object.prototype% をプロトタイプとする通常オブジェクトを作成する)。
  3. Assert: obj は拡張可能な通常オブジェクトで、所有プロパティを持たないことを主張する。
  4. Let closure be a new Abstract Closure with parameters (key, value) that captures obj and performs the following steps when called:
    1. Let propertyKey be ? ToPropertyKey(key)(キーをプロパティキーに変換する)。
    2. Perform ! CreateDataPropertyOrThrow(obj, propertyKey, value)(データプロパティを作成する、失敗すれば例外)。
    3. Return NormalCompletion(undefined).
  5. Let adder be CreateBuiltinFunction(closure, 2, "", « »)(上記クロージャを組み込み関数として作成する)。
  6. Return ? AddEntriesFromIterable(obj, iterable, adder)(反復可能からエントリを追加して結果を返す)。
Note
The function created for adder is never directly accessible to ECMAScript code.

20.1.2.8 Object.getOwnPropertyDescriptor ( obj, propertyKey )

この関数は呼び出されたときに次の手順を実行する:

  1. Let coerced be ? ToObject(obj)(obj をオブジェクトに変換する)。
  2. Let key be ? ToPropertyKey(propertyKey)(propertyKey をプロパティキーに変換する)。
  3. Let desc be ? coerced.[[GetOwnProperty]](key)(当該プロパティの内部記述子を取得する)。
  4. Return FromPropertyDescriptor(desc)(プロパティ記述子から外部表現を作成して返す)。

20.1.2.9 Object.getOwnPropertyDescriptors ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. Let coerced be ? ToObject(obj).
  2. Let ownKeys be ? coerced.[[OwnPropertyKeys]]()(所有プロパティキーを取得する)。
  3. Let descriptors be OrdinaryObjectCreate(%Object.prototype%)(記述子オブジェクトを作成する)。
  4. For each element key of ownKeys, do
    1. Let desc be ? coerced.[[GetOwnProperty]](key)(そのキーの内部プロパティ記述子を得る)。
    2. Let descriptor be FromPropertyDescriptor(desc)(外向きのプロパティ記述子に変換する)。
    3. If descriptor is not undefined, perform ! CreateDataPropertyOrThrow(descriptors, key, descriptor)(記述子オブジェクトにデータプロパティとして追加する)。
  5. Return descriptors(記述子オブジェクトを返す)。

20.1.2.10 Object.getOwnPropertyNames ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. Return CreateArrayFromList(? GetOwnPropertyKeys(obj, string))(文字列キーの所有プロパティキー一覧から配列を作成して返す)。

20.1.2.11 Object.getOwnPropertySymbols ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. Return CreateArrayFromList(? GetOwnPropertyKeys(obj, symbol))(シンボルキーの所有プロパティキー一覧から配列を作成して返す)。

20.1.2.11.1 GetOwnPropertyKeys ( value, type )

The abstract operation GetOwnPropertyKeys takes arguments value (an ECMAScript language value) and type (string or symbol) and returns either a normal completion containing a List of property keys or a throw completion. It performs the following steps when called:

  1. Let obj be ? ToObject(value)(value をオブジェクトに変換する)。
  2. Let keys be ? obj.[[OwnPropertyKeys]]()(所有プロパティキー一覧を取得する)。
  3. Let nameList be a new empty List(空の名前リストを作成する)。
  4. For each element nextKey of keys, do
    1. If nextKey is a Symbol and type is symbol, or if nextKey is a String and type is string, then
      1. Append nextKey to nameList(条件に一致するキーを名前リストに追加する)。
  5. Return nameList(名前リストを返す)。

20.1.2.12 Object.getPrototypeOf ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. Let coerced be ? ToObject(obj)(obj をオブジェクトに変換する)。
  2. Return ? coerced.[[GetPrototypeOf]]()(プロトタイプを返す)。

20.1.2.13 Object.groupBy ( items, callback )

Note

callback は 2 つの引数を受け取る関数であるべきである。groupByitems の各要素に対して昇順で一度ずつ callback を呼び出し、新しいオブジェクトを構築する。callback が返す各値はプロパティキーへ強制変換される。そのようにして得られた各プロパティキーについて、結果オブジェクトはそのキーを持ち、対応する値はそのキーに強制された戻り値を持つすべての要素を含む配列である。

callback は 2 引数で呼び出される:要素の値と要素のインデックスである。

groupBy の返り値は %Object.prototype% を継承しないオブジェクトである。

この関数は呼び出されたときに次の手順を実行する:

  1. Let groups be ? GroupBy(items, callback, property)(グルーピング情報を取得する)。
  2. Let obj be OrdinaryObjectCreate(null)(プロトタイプが null の通常オブジェクトを作る)。
  3. For each Record { [[Key]], [[Elements]] } g of groups, do
    1. Let elements be CreateArrayFromList(g.[[Elements]])(要素リストから配列を作る)。
    2. Perform ! CreateDataPropertyOrThrow(obj, g.[[Key]], elements)(オブジェクトにデータプロパティを作成する)。
  4. Return obj(結果オブジェクトを返す)。

20.1.2.14 Object.hasOwn ( obj, propertyKey )

この関数は呼び出されたときに次の手順を実行する:

  1. Let coerced be ? ToObject(obj)(obj をオブジェクトに変換する)。
  2. Let key be ? ToPropertyKey(propertyKey)(propertyKey をプロパティキーに変換する)。
  3. Return ? HasOwnProperty(coerced, key)(所有プロパティかどうかを返す)。

20.1.2.15 Object.is ( value1, value2 )

この関数は呼び出されたときに次の手順を実行する:

  1. Return SameValue(value1, value2)(同値判定を返す)。

20.1.2.16 Object.isExtensible ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. If obj is not an Object, return false(オブジェクトでなければ false を返す)。
  2. Return ? IsExtensible(obj)(拡張可能性を返す)。

20.1.2.17 Object.isFrozen ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. If obj is not an Object, return true(オブジェクトでなければ true を返す)。
  2. Return ? TestIntegrityLevel(obj, frozen)(凍結レベルをテストして返す)。

20.1.2.18 Object.isSealed ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. If obj is not an Object, return true(オブジェクトでなければ true を返す)。
  2. Return ? TestIntegrityLevel(obj, sealed)(封印レベルをテストして返す)。

20.1.2.19 Object.keys ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. Let coerced be ? ToObject(obj)(obj をオブジェクトに変換する)。
  2. Let keyList be ? EnumerableOwnProperties(coerced, key)(列挙可能な自身のキー一覧を取得する)。
  3. Return CreateArrayFromList(keyList)(配列を作って返す)。

20.1.2.20 Object.preventExtensions ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. If obj is not an Object, return obj(オブジェクトでなければそのまま返す)。
  2. Let status be ? obj.[[PreventExtensions]]()(内部メソッドで拡張禁止を行う)。
  3. If status is false, throw a TypeError exception(失敗したら例外)。
  4. Return obj.

20.1.2.21 Object.prototype

Object.prototype の初期値は Object プロトタイプオブジェクトである。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.1.2.22 Object.seal ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. If obj is not an Object, return obj(オブジェクトでなければそのまま返す)。
  2. Let status be ? SetIntegrityLevel(obj, sealed)(封印レベルを設定する)。
  3. If status is false, throw a TypeError exception(失敗したら例外)。
  4. Return obj.

20.1.2.23 Object.setPrototypeOf ( obj, proto )

この関数は呼び出されたときに次の手順を実行する:

  1. Perform ? RequireObjectCoercible(obj)(obj がオブジェクト化可能であることを要求する)。
  2. If proto is not an Object and proto is not null, throw a TypeError exception(proto が不正なら例外)。
  3. If obj is not an Object, return objobj がオブジェクトでなければそのまま返す)。
  4. Let status be ? obj.[[SetPrototypeOf]](proto)(内部メソッドでプロトタイプを設定する)。
  5. If status is false, throw a TypeError exception(失敗したら例外)。
  6. Return obj.

20.1.2.24 Object.values ( obj )

この関数は呼び出されたときに次の手順を実行する:

  1. Let coerced be ? ToObject(obj)(オブジェクトに変換する)。
  2. Let valueList be ? EnumerableOwnProperties(coerced, value)(列挙可能な自身の値一覧を取得する)。
  3. Return CreateArrayFromList(valueList)(配列を作って返す)。

20.1.3 Object プロトタイプオブジェクトのプロパティ

Object プロトタイプオブジェクト は次のとおりである:

  • %Object.prototype% である。
  • [[Extensible]] 内部スロットを持ち、その値は true である。
  • 通常オブジェクトのために定義される内部メソッドを持つが、[[SetPrototypeOf]] メソッドは 10.4.7.1 に定義されたものと同じである。(したがって、これは不変プロトタイプのエキゾチックオブジェクトである。)
  • [[Prototype]] 内部スロットを持ち、その値は null である。

20.1.3.1 Object.prototype.constructor

Object.prototype.constructor の初期値は %Object% である。

20.1.3.2 Object.prototype.hasOwnProperty ( value )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let propertyKey be ? ToPropertyKey(value)(value をプロパティキーに変換する)。
  2. Let obj be ? ToObject(this value)(this 値をオブジェクトに変換する)。
  3. Return ? HasOwnProperty(obj, propertyKey)(所有プロパティかどうかを返す)。
Note

ステップ 12 の順序は、以前の仕様版でステップ 1 によって投げられる例外が、this 値が undefined または null の場合でも引き続き投げられるように選択されている。

20.1.3.3 Object.prototype.isPrototypeOf ( value )

このメソッドは呼び出されたときに次の手順を実行する:

  1. If value is not an Object, return falsevalue がオブジェクトでなければ false)。
  2. Let obj be ? ToObject(this value)(this 値をオブジェクトに変換する)。
  3. Repeat,
    1. Set value to ? value.[[GetPrototypeOf]]()(プロトタイプをたどる)。
    2. If value is null, return false(プロトタイプが null なら false)。
    3. If SameValue(obj, value) is true, return true(一致すれば true)。
Note

ステップ 12 の順序は、value がオブジェクトでなく this 値が undefined または null の場合に以前の仕様で規定された振る舞いを保持するために選択されている。

20.1.3.4 Object.prototype.propertyIsEnumerable ( value )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let propertyKey be ? ToPropertyKey(value)(value をプロパティキーに変換する)。
  2. Let obj be ? ToObject(this value)(this 値をオブジェクトに変換する)。
  3. Let desc be ? obj.[[GetOwnProperty]](propertyKey)(所有プロパティ記述子を取得する)。
  4. If desc is undefined, return false(定義されていなければ false)。
  5. Return desc.[[Enumerable]](列挙可能かどうかを返す)。
Note 1

このメソッドはプロトタイプ連鎖上のオブジェクトを考慮しない。

Note 2

ステップ 12 の順序は、以前の仕様版でステップ 1 によって投げられる可能性のある例外が、this 値が undefined または null の場合でも引き続き投げられるように選択されている。

20.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let thisValue be the this value(this 値を取得する)。
  2. Return ? Invoke(thisValue, "toString")(this に対して toString を呼び出して返す)。

このメソッドのオプション引数は使用されないが、ECMA-402 の toLocaleString メソッドで使われる引数パターンに対応させるために用意されている。ECMA-402 を含まない実装はこれらの引数位置を別の用途に使ってはならない。

Note 1

このメソッドはロケール依存の toString 振る舞いを持たないオブジェクトに対する一般的な toLocaleString 実装を提供する。ArrayNumberDate、および %TypedArray% は独自のロケール依存 toLocaleString メソッドを提供する。

Note 2

ECMA-402 はこのデフォルト実装に代わるものを意図的に提供していない。

20.1.3.6 Object.prototype.toString ( )

このメソッドは呼び出されたときに次の手順を実行する:

  1. If the this value is undefined, return "[object Undefined]"(this が undefined の場合、"[object Undefined]" を返す)。
  2. If the this value is null, return "[object Null]"(this が null の場合、"[object Null]" を返す)。
  3. Let obj be ! ToObject(this value)(this をオブジェクトに変換する)。
  4. Let isArray be ? IsArray(obj)(配列かどうかを判定する)。
  5. If isArray is true, let builtinTag be "Array"(配列ならタグを "Array" にする)。
  6. Else if obj has a [[ParameterMap]] internal slot, let builtinTag be "Arguments"(引数オブジェクトなら "Arguments")。
  7. Else if obj has a [[Call]] internal method, let builtinTag be "Function"(関数なら "Function")。
  8. Else if obj has an [[ErrorData]] internal slot, let builtinTag be "Error"(エラーなら "Error")。
  9. Else if obj has a [[BooleanData]] internal slot, let builtinTag be "Boolean"(Boolean オブジェクトなら "Boolean")。
  10. Else if obj has a [[NumberData]] internal slot, let builtinTag be "Number"(Number オブジェクトなら "Number")。
  11. Else if obj has a [[StringData]] internal slot, let builtinTag be "String"(String オブジェクトなら "String")。
  12. Else if obj has a [[DateValue]] internal slot, let builtinTag be "Date"(Date オブジェクトなら "Date")。
  13. Else if obj has a [[RegExpMatcher]] internal slot, let builtinTag be "RegExp"(RegExp オブジェクトなら "RegExp")。
  14. Else, let builtinTag be "Object"(それ以外は "Object")。
  15. Let tag be ? Get(obj, %Symbol.toStringTag%)(%Symbol.toStringTag% を取得する)。
  16. If tag is not a String, set tag to builtinTag(tag が文字列でなければ builtinTag を使う)。
  17. Return the string-concatenation of "[object ", tag, and "]"("[object " + tag + "]" を返す)。
Note

歴史的に、このメソッドは以前の仕様でいくつかの組み込みオブジェクトの名義的タイプタグとして使われていた [[Class]] 内部スロットの文字列値にアクセスするために使われることがあった。上記の toString の定義は、toString を特定の種類の組み込みオブジェクトの判定に使うレガシーコードとの互換性を保つ。これは他の種類の組み込みオブジェクトやプログラム定義オブジェクトに対する信頼できる型判定機構を提供するものではない。さらに、プログラムは %Symbol.toStringTag% を利用してそのようなレガシーな型判定の信頼性を損なうことができる。

20.1.3.7 Object.prototype.valueOf ( )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Return ? ToObject(this value)(this をオブジェクトに変換して返す)。

20.1.3.8 Object.prototype.__proto__

Object.prototype.__proto__ は属性 { [[Enumerable]]: false, [[Configurable]]: true } を持つアクセサプロパティである。[[Get]][[Set]] の属性は次のように定義される:

20.1.3.8.1 get Object.prototype.__proto__

[[Get]] 属性の値は引数を取らない組み込み関数であり、呼び出されたときに次の手順を実行する:

  1. Let obj be ? ToObject(this value)(this をオブジェクトに変換する)。
  2. Return ? obj.[[GetPrototypeOf]]()(プロトタイプを返す)。

20.1.3.8.2 set Object.prototype.__proto__

[[Set]] 属性の値は引数 proto を取る組み込み関数であり、呼び出されたときに次の手順を実行する:

  1. Let thisValue be the this value(this 値を得る)。
  2. Perform ? RequireObjectCoercible(thisValue)(this がオブジェクト化可能であることを要求する)。
  3. If proto is not an Object and proto is not null, return undefinedproto が不正なら undefined を返す)。
  4. If thisValue is not an Object, return undefined(this がオブジェクトでなければ undefined を返す)。
  5. Let status be ? thisValue.[[SetPrototypeOf]](proto)(内部 SetPrototypeOf を呼ぶ)。
  6. If status is false, throw a TypeError exception(失敗したら例外)。
  7. Return undefined.

20.1.3.9 レガシーな Object.prototype アクセサメソッド

20.1.3.9.1 Object.prototype.__defineGetter__ ( propertyKey, getter )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let obj be ? ToObject(this value)(this をオブジェクトに変換する)。
  2. If IsCallable(getter) is false, throw a TypeError exception(getter が呼び出し可能でない場合は例外)。
  3. Let desc be PropertyDescriptor { [[Get]]: getter, [[Enumerable]]: true, [[Configurable]]: true }(ゲッター記述子を作る)。
  4. Let key be ? ToPropertyKey(propertyKey)(キーに変換する)。
  5. Perform ? DefinePropertyOrThrow(obj, key, desc)(定義する、失敗すれば例外)。
  6. Return undefined.

20.1.3.9.2 Object.prototype.__defineSetter__ ( propertyKey, setter )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let obj be ? ToObject(this value)(this をオブジェクトに変換する)。
  2. If IsCallable(setter) is false, throw a TypeError exception(setter が呼び出し可能でない場合は例外)。
  3. Let desc be PropertyDescriptor { [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: true }(セッター記述子を作る)。
  4. Let key be ? ToPropertyKey(propertyKey)(キーに変換する)。
  5. Perform ? DefinePropertyOrThrow(obj, key, desc)(定義する、失敗すれば例外)。
  6. Return undefined.

20.1.3.9.3 Object.prototype.__lookupGetter__ ( propertyKey )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let obj be ? ToObject(this value)(this をオブジェクトに変換する)。
  2. Let key be ? ToPropertyKey(propertyKey)(キーに変換する)。
  3. Repeat,
    1. Let desc be ? obj.[[GetOwnProperty]](key)(所有プロパティ記述子を取得する)。
    2. If desc is not undefined, then
      1. If IsAccessorDescriptor(desc) is true, return desc.[[Get]](アクセサ記述子ならゲッターを返す)。
      2. Return undefined(データプロパティなら undefined を返す)。
    3. Set obj to ? obj.[[GetPrototypeOf]]()(プロトタイプを次に進める)。
    4. If obj is null, return undefined(プロトタイプが尽きたら undefined)。

20.1.3.9.4 Object.prototype.__lookupSetter__ ( propertyKey )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let obj be ? ToObject(this value)(this をオブジェクトに変換する)。
  2. Let key be ? ToPropertyKey(propertyKey)(キーに変換する)。
  3. Repeat,
    1. Let desc be ? obj.[[GetOwnProperty]](key)(所有プロパティ記述子を取得する)。
    2. If desc is not undefined, then
      1. If IsAccessorDescriptor(desc) is true, return desc.[[Set]](アクセサ記述子ならセッターを返す)。
      2. Return undefined(データプロパティなら undefined を返す)。
    3. Set obj to ? obj.[[GetPrototypeOf]]()(プロトタイプを次に進める)。
    4. If obj is null, return undefined(尽きたら undefined)。

20.1.4 オブジェクトインスタンスのプロパティ

オブジェクトインスタンスは、Object プロトタイプオブジェクトから継承するもの以外に特別なプロパティを持たない。

20.2 関数オブジェクト

20.2.1 Function コンストラクタ

Function コンストラクタ:

  • %Function% である。
  • グローバルオブジェクト"Function" プロパティの初期値である。
  • コンストラクタではなく関数として呼び出されたときに新しい関数オブジェクトを作成・初期化する。したがって関数呼び出し Function(…) は同じ引数で new Function(…) と同等である。
  • クラス定義の extends 節の値として使用されることがある。指定された Function 振る舞いを継承することを意図するサブクラスのコンストラクタは、組み込み関数振る舞いに必要な内部スロットを持つサブクラスインスタンスを作成・初期化するために Function コンストラクタへの super 呼び出しを含まなければならない。ECMAScript の関数オブジェクトを定義するすべての構文は Function のインスタンスを生成する。組み込みの GeneratorFunction、AsyncFunction、AsyncGeneratorFunction を除き、Function サブクラスのインスタンスを作成する構文的方法はない。

20.2.1.1 Function ( ...parameterArgs, bodyArg )

最後の引数(存在する場合)は関数の本体(実行可能コード)を指定し、前の引数は形式パラメータを指定する。

この関数は呼び出されたときに次の手順を実行する:

  1. Let constructor be the active function object(アクティブな関数オブジェクトを取得する)。
  2. If bodyArg is not present, set bodyArg to the empty String(本体引数がなければ空文字列にする)。
  3. Return ? CreateDynamicFunction(constructor, NewTarget, normal, parameterArgs, bodyArg)(動的関数を作成して返す)。
Note

各形式パラメータに対して必ず 1 つの引数がある必要はない。例えば次の 3 つの式は同じ結果を生成する:

new Function("a", "b", "c", "return a+b+c")
new Function("a, b, c", "return a+b+c")
new Function("a,b", "c", "return a+b+c")

20.2.1.1.1 CreateDynamicFunction ( constructor, newTarget, kind, parameterArgs, bodyArg )

The abstract operation CreateDynamicFunction takes arguments constructor (a constructor), newTarget (a constructor or undefined), kind (normal, generator, async, or async-generator), parameterArgs (a List of ECMAScript language values), and bodyArg (an ECMAScript language value) and returns either a normal completion containing an ECMAScript function object or a throw completion. constructor はこの処理を行うコンストラクタ関数である。newTargetnew が最初に適用されたコンストラクタである。parameterArgsbodyArgconstructor に渡された引数値を反映する。 It performs the following steps when called:

  1. If newTarget is undefined, set newTarget to constructornewTarget が未定義なら constructor を使う)。
  2. If kind is normal, then
    1. Let prefix be "function".
    2. Let exprSym be the grammar symbol FunctionExpression.
    3. Let bodySym be the grammar symbol FunctionBody[~Yield, ~Await].
    4. Let parameterSym be the grammar symbol FormalParameters[~Yield, ~Await].
    5. Let fallbackProto be "%Function.prototype%".
  3. Else if kind is generator, then
    1. Let prefix be "function*".
    2. Let exprSym be the grammar symbol GeneratorExpression.
    3. Let bodySym be the grammar symbol GeneratorBody.
    4. Let parameterSym be the grammar symbol FormalParameters[+Yield, ~Await].
    5. Let fallbackProto be "%GeneratorFunction.prototype%".
  4. Else if kind is async, then
    1. Let prefix be "async function".
    2. Let exprSym be the grammar symbol AsyncFunctionExpression.
    3. Let bodySym be the grammar symbol AsyncFunctionBody.
    4. Let parameterSym be the grammar symbol FormalParameters[~Yield, +Await].
    5. Let fallbackProto be "%AsyncFunction.prototype%".
  5. Else,
    1. Assert: kind is async-generator.
    2. Let prefix be "async function*".
    3. Let exprSym be the grammar symbol AsyncGeneratorExpression.
    4. Let bodySym be the grammar symbol AsyncGeneratorBody.
    5. Let parameterSym be the grammar symbol FormalParameters[+Yield, +Await].
    6. Let fallbackProto be "%AsyncGeneratorFunction.prototype%".
  6. Let argCount be the number of elements in parameterArgs(パラメータ引数の数を得る)。
  7. Let parameterStrings be a new empty List(空の文字列リストを作る)。
  8. For each element arg of parameterArgs, do
    1. Append ? ToString(arg) to parameterStrings(各引数を文字列に変換してリストに追加)。
  9. Let bodyString be ? ToString(bodyArg)(本体引数を文字列にする)。
  10. Let currentRealm be the current Realm Record(現在の Realm レコードを取得)。
  11. Perform ? HostEnsureCanCompileStrings(currentRealm, parameterStrings, bodyString, false)(ホストにより文字列のコンパイル許可を確認)。
  12. Let parameterString be the empty String(パラメータ文字列を初期化)。
  13. If argCount > 0, then
    1. Set parameterString to parameterStrings[0].
    2. Let k be 1.
    3. Repeat, while k < argCount,
      1. Let nextArgString be parameterStrings[k].
      2. Set parameterString to the string-concatenation of parameterString, "," (a comma), and nextArgString(カンマで連結していく)。
      3. Set k to k + 1.
  14. Let bodyParseString be the string-concatenation of 0x000A (LINE FEED), bodyString, and 0x000A (LINE FEED)(本体のパース用文字列を生成)。
  15. Let sourceString be the string-concatenation of prefix, " anonymous(", parameterString, 0x000A (LINE FEED), ") {", bodyParseString, and "}"(ソース文字列を組み立てる)。
  16. Let sourceText be StringToCodePoints(sourceString)(コードポイント列に変換する)。
  17. Let parameters be ParseText(parameterString, parameterSym)(パラメータ文字列を構文解析する)。
  18. If parameters is a List of errors, throw a SyntaxError exception(パースエラーなら例外)。
  19. Let body be ParseText(bodyParseString, bodySym)(本体文字列を構文解析する)。
  20. If body is a List of errors, throw a SyntaxError exception(本体パースでエラーなら例外)。
  21. NOTE: パラメータと本体はそれぞれ単独で有効であることを保証するために別々に解析される。例えば new Function("/*", "*/ ) {") は関数にはならない。
  22. NOTE: このステップに到達した場合、sourceTextexprSym の構文を持たなければならない(ただしその逆は成り立たない)。次の 2 ステップの目的は exprSym に直接適用される Early Error ルールを強制することである。
  23. Let expr be ParseText(sourceText, exprSym)(ソース全体を構文解析)。
  24. If expr is a List of errors, throw a SyntaxError exception(構文エラーなら例外)。
  25. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto)(コンストラクタからプロトタイプを取得)。
  26. Let env be currentRealm.[[GlobalEnv]](グローバル環境を取得)。
  27. Let privateEnv be null(プライベート環境は null)。
  28. Let func be OrdinaryFunctionCreate(proto, sourceText, parameters, body, non-lexical-this, env, privateEnv)(関数オブジェクトを作成)。
  29. Perform SetFunctionName(func, "anonymous")(関数名を設定)。
  30. If kind is generator, then
    1. Let prototype be OrdinaryObjectCreate(%GeneratorPrototype%)(ジェネレータのプロトタイプを作成)。
    2. Perform ! DefinePropertyOrThrow(func, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).(prototype プロパティを定義)。
  31. Else if kind is async-generator, then
    1. Let prototype be OrdinaryObjectCreate(%AsyncGeneratorPrototype%)(非同期ジェネレータのプロトタイプを作成)。
    2. Perform ! DefinePropertyOrThrow(func, "prototype", PropertyDescriptor { [[Value]]: prototype, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }).(prototype を定義)。
  32. Else if kind is normal, then
    1. Perform MakeConstructor(func)(関数をコンストラクタにする)。
  33. NOTE: kindasync の関数は constructable でなく、[[Construct]] 内部メソッドや "prototype" プロパティを持たない。
  34. Return func(作成した関数を返す)。
Note

CreateDynamicFunction は、作成する関数のうち kindasync でないものに対して "prototype" プロパティを定義する。これは関数がコンストラクタとして使われる可能性に備えるためである。

20.2.2 Function コンストラクタのプロパティ

Function コンストラクタ:

  • それ自体が組み込みの関数オブジェクトである。
  • [[Prototype]] 内部スロットを持ち、その値は %Function.prototype% である。
  • "length" プロパティの値は 1𝔽 である。
  • 以下のプロパティを持つ:

20.2.2.1 Function.prototype

Function.prototype の値は Function プロトタイプオブジェクトである。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.2.3 Function プロトタイプオブジェクトのプロパティ

Function プロトタイプオブジェクト は次のとおりである:

  • %Function.prototype% である。
  • それ自体が組み込み関数オブジェクトである。
  • 任意の引数を受け取り、呼び出されると undefined を返す。
  • [[Construct]] 内部メソッドを持たない;したがって new 演算子でコンストラクタとして使用できない。
  • [[Prototype]] 内部スロットを持ち、その値は %Object.prototype% である。
  • "prototype" プロパティを持たない。
  • "length" プロパティの値は +0𝔽 である。
  • "name" プロパティの値は空文字列である。
Note

Function プロトタイプオブジェクトは、ECMAScript 2015 以前に作成された ECMAScript コードとの互換性を確保するために関数オブジェクトとして指定されている。

20.2.3.1 Function.prototype.apply ( thisArg, argArray )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let func be the this value(this を func とする)。
  2. If IsCallable(func) is false, throw a TypeError exception(呼び出し可能でなければ例外)。
  3. If argArray is either undefined or null, then
    1. Perform PrepareForTailCall().
    2. Return ? Call(func, thisArg)(引数なしで呼び出す)。
  4. Let argList be ? CreateListFromArrayLike(argArray)(配列様オブジェクトから引数リストを作る)。
  5. Perform PrepareForTailCall().
  6. Return ? Call(func, thisArg, argList)(作成した引数リストで呼び出す)。
Note 1

thisArg の値は修飾されずに this 値として渡される。これは Edition 3 からの変更であり、Edition 3 では undefined または nullthisArgグローバルオブジェクトに置き換えられ、他の値には ToObject を適用して渡していた。thisArg は修飾されずに渡されるが、非 strict 関数は関数内部に入るときにこれらの変換を行う。

Note 2

もし func がアロー関数かバウンド関数エキゾチックオブジェクトである場合、thisArg はステップ 6 の Call によって無視される。

20.2.3.2 Function.prototype.bind ( thisArg, ...args )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let target be the this value(this を target とする)。
  2. If IsCallable(target) is false, throw a TypeError exception(呼び出し可能でなければ例外)。
  3. Let boundFunc be ? BoundFunctionCreate(target, thisArg, args)(バウンド関数を作成する)。
  4. Let length be 0(length を 0 に初期化)。
  5. Let targetHasLength be ? HasOwnProperty(target, "length")(ターゲットに length 自身プロパティがあるか確認)。
  6. If targetHasLength is true, then
    1. Let targetLen be ? Get(target, "length")(ターゲットの length を取得)。
    2. If targetLen is a Number, then
      1. If targetLen is +∞𝔽, then
        1. Set length to +∞.
      2. Else if targetLen is -∞𝔽, then
        1. Set length to 0.
      3. Else,
        1. Let targetLenAsInt be ! ToIntegerOrInfinity(targetLen)(整数に変換)。
        2. Assert: targetLenAsInt is finite(有限であることを主張)。
        3. Let argCount be the number of elements in args(バインドする引数の数)。
        4. Set length to max(targetLenAsInt - argCount, 0)(残りの引数数を length に設定)。
  7. Perform SetFunctionLength(boundFunc, length)(バウンド関数の length を設定)。
  8. Let targetName be ? Get(target, "name")(ターゲットの name を取得)。
  9. If targetName is not a String, set targetName to the empty String(文字列でなければ空文字)。
  10. Perform SetFunctionName(boundFunc, targetName, "bound")(名前を設定し "bound" を付加)。
  11. Return boundFunc(バウンド関数を返す)。
Note 1

Function.prototype.bind で作成された関数オブジェクトはエキゾチックオブジェクトである。また "prototype" プロパティを持たない。

Note 2

もし target がアロー関数かバウンド関数エキゾチックオブジェクトである場合、このメソッドに渡された thisArg は後続の func 呼び出しで使用されない。

20.2.3.3 Function.prototype.call ( thisArg, ...args )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let func be the this value(this を func とする)。
  2. If IsCallable(func) is false, throw a TypeError exception(呼び出し可能でなければ例外)。
  3. Perform PrepareForTailCall().
  4. Return ? Call(func, thisArg, args)(引数で呼び出す)。
Note 1

thisArg の値は修飾されずに this 値として渡される。これは Edition 3 からの変更である。非 strict 関数は関数内部に入るときにこれらの変換を行う。

Note 2

もし func がアロー関数かバウンド関数エキゾチックオブジェクトである場合、thisArg はステップ 4 の Call によって無視される。

20.2.3.4 Function.prototype.constructor

Function.prototype.constructor の初期値は %Function% である。

20.2.3.5 Function.prototype.toString ( )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let func be the this value(this を func とする)。
  2. If func is an Object, func has a [[SourceText]] internal slot, func.[[SourceText]] is a sequence of Unicode code points, and HostHasSourceTextAvailable(func) is true, then
    1. Return CodePointsToString(func.[[SourceText]])(ソーステキストが利用可能ならそれを返す)。
  3. If func is a built-in function object, return an implementation-defined String source code representation of func. The representation must have the syntax of a NativeFunction. Additionally, if func has an [[InitialName]] internal slot and func.[[InitialName]] is a String, the portion of the returned String that would be matched by NativeFunctionAccessoropt PropertyName must be func.[[InitialName]].
  4. If func is an Object and IsCallable(func) is true, return an implementation-defined String source code representation of func. The representation must have the syntax of a NativeFunction.
  5. Throw a TypeError exception(上に当てはまらなければ例外)。
NativeFunction : function NativeFunctionAccessoropt PropertyName[~Yield, ~Await]opt ( FormalParameters[~Yield, ~Await] ) { [ native code ] } NativeFunctionAccessor : get set

20.2.3.6 Function.prototype [ %Symbol.hasInstance% ] ( value )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let thisValue be the this value(this を取得する)。
  2. Return ? OrdinaryHasInstance(thisValue, value)(ordinary has-instance を実行して返す)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

Note

これは %Symbol.hasInstance% のデフォルト実装であり、多くの関数が継承する。instanceof 演算子は特定のコンストラクタのインスタンスか否かを判定するために %Symbol.hasInstance% を呼び出す。式

v instanceof F

は次と評価される:

F[%Symbol.hasInstance%](v)

コンストラクタ関数は関数上に異なる %Symbol.hasInstance% メソッドを公開することで instanceof によって認識されるオブジェクトを制御できる。

このプロパティはバウンド関数の対象関数をグローバルに公開するための改変を防ぐために書き換え不可かつ設定不可である。

The value of the "name" property of this method is "[Symbol.hasInstance]".

20.2.4 関数インスタンス

すべての Function インスタンスは ECMAScript の関数オブジェクトであり、Table 25 に列挙される内部スロットを持つ。Function.prototype.bind によって作られた関数オブジェクトは Table 26 に示される内部スロットを持つ。

関数インスタンスは以下のプロパティを持つ:

20.2.4.1 length

"length" プロパティの値は、関数が期待する典型的な引数の数を示す整数である。ただし、言語は別の数の引数で呼び出すことを許す。関数が "length" プロパティで指定された数以外の引数で呼び出された場合の振る舞いは関数による。このプロパティは属性 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true } を持つ。

20.2.4.2 name

"name" プロパティの値は関数を記述する文字列である。名前は意味論的な意味を持たないが、通常は ECMAScript ソーステキストの定義点で関数を参照するために使われる変数名やプロパティ名である。このプロパティは属性 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true } を持つ。

この仕様によって文脈上の名前が関連付けられていない匿名関数オブジェクトは、"name" プロパティとして空文字列を使用する。

20.2.4.3 prototype

コンストラクタとして使用できる関数インスタンスは "prototype" プロパティを持つ。そのような Function インスタンスが作成されるとき、別の通常オブジェクトが作成され、それが関数の "prototype" プロパティの初期値となる。指定がない限り、"prototype" プロパティの値はその関数がコンストラクタとして呼ばれたときに作成されるオブジェクトの [[Prototype]] 内部スロットを初期化するために使用される。

このプロパティは属性 { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false } を持つ。

Note

Function.prototype.bind で作成された関数、または MethodDefinitionGeneratorMethodAsyncGeneratorMethod ではないもの)や ArrowFunction を評価して作成された関数オブジェクトは "prototype" プロパティを持たない。

20.2.5 HostHasSourceTextAvailable ( func )

The host-defined abstract operation HostHasSourceTextAvailable takes argument func (a function object) and returns a Boolean. これはホスト環境が func のソーステキストの提供を防止できるようにする。

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

  • 引数に関して決定的でなければならない。特定の func を引数として呼び出した場合、常に同じ結果を返さなければならない。

HostHasSourceTextAvailable のデフォルト実装は true を返すことである。

20.3 Boolean オブジェクト

20.3.1 Boolean コンストラクタ

Boolean コンストラクタ:

  • %Boolean% である。
  • グローバルオブジェクト"Boolean" プロパティの初期値である。
  • コンストラクタとして呼び出されたときに新しい Boolean オブジェクトを作成・初期化する。
  • コンストラクタとしてではなく関数として呼び出されたときに型変換を行う。
  • クラス定義の extends 節の値として使用されることがある。指定された Boolean 振る舞いを継承することを意図するサブクラスのコンストラクタは、[[BooleanData]] 内部スロットを持つサブクラスインスタンスを作成・初期化するために Boolean コンストラクタへの super 呼び出しを含まなければならない。

20.3.1.1 Boolean ( value )

この関数は呼び出されたときに次の手順を実行する:

  1. Let b be ToBoolean(value)(値を真偽値に変換する)。
  2. If NewTarget is undefined, return b(NewTarget が undefined ならプリミティブ真偽値を返す)。
  3. Let obj be ? OrdinaryCreateFromConstructor(NewTarget, "%Boolean.prototype%", « [[BooleanData]] »)(コンストラクタから Boolean オブジェクトを作る)。
  4. Set obj.[[BooleanData]] to b(内部スロットに値を格納)。
  5. Return obj(オブジェクトを返す)。

20.3.2 Boolean コンストラクタのプロパティ

Boolean コンストラクタ:

  • [[Prototype]] 内部スロットを持ち、その値は %Function.prototype% である。
  • 以下のプロパティを持つ:

20.3.2.1 Boolean.prototype

Boolean.prototype の初期値は Boolean プロトタイプオブジェクトである。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.3.3 Boolean プロトタイプオブジェクトのプロパティ

Boolean プロトタイプオブジェクト は次のとおりである:

  • %Boolean.prototype% である。
  • 通常オブジェクトである。
  • 自身が Boolean オブジェクトであり、[[BooleanData]] 内部スロットを持ち、その値は false である。
  • [[Prototype]] 内部スロットを持ち、その値は %Object.prototype% である。

20.3.3.1 Boolean.prototype.constructor

Boolean.prototype.constructor の初期値は %Boolean% である。

20.3.3.2 Boolean.prototype.toString ( )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let b be ? ThisBooleanValue(this value)(this の Boolean 値を取得する)。
  2. If b is true, return "true"(真なら "true" を返す)。
  3. Return "false"(それ以外は "false" を返す)。

20.3.3.3 Boolean.prototype.valueOf ( )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Return ? ThisBooleanValue(this value)(this の Boolean 値を返す)。

20.3.3.3.1 ThisBooleanValue ( value )

The abstract operation ThisBooleanValue takes argument value (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. If value is a Boolean, return value(プリミティブ Boolean ならそのまま返す)。
  2. If value is an Object and value has a [[BooleanData]] internal slot, then
    1. Let b be value.[[BooleanData]](内部スロットの値を取得)。
    2. Assert: b is a Booleanb が Boolean であることを主張)。
    3. Return b(その値を返す)。
  3. Throw a TypeError exception(それ以外は例外)。

20.3.4 Boolean インスタンスのプロパティ

Boolean インスタンスは Boolean プロトタイプオブジェクトからプロパティを継承する通常オブジェクトである。Boolean インスタンスは [[BooleanData]] 内部スロットを持つ。[[BooleanData]] 内部スロットはその Boolean オブジェクトが表す Boolean 値である。

20.4 Symbol オブジェクト

20.4.1 Symbol コンストラクタ

Symbol コンストラクタ:

  • %Symbol% である。
  • グローバルオブジェクト"Symbol" プロパティの初期値である。
  • 関数として呼び出されたときに新しい Symbol 値を返す。
  • new 演算子で使用することを意図していない。
  • サブクラス化することを意図していない。
  • クラス定義の extends 節の値として使用されることがあるが、それに対する super 呼び出しは例外を引き起こす。

20.4.1.1 Symbol ( [ description ] )

この関数は呼び出されたときに次の手順を実行する:

  1. If NewTarget is not undefined, throw a TypeError exception(NewTarget が定義されている場合は例外)。
  2. If description is undefined, let descString be undefined(説明が undefined なら descString を undefined にする)。
  3. Else, let descString be ? ToString(description)(そうでなければ文字列化する)。
  4. Return a new Symbol whose [[Description]] is descString(説明を持つ新しい Symbol を返す)。

20.4.2 Symbol コンストラクタのプロパティ

Symbol コンストラクタ:

  • [[Prototype]] 内部スロットを持ち、その値は %Function.prototype% である。
  • 以下のプロパティを持つ:

20.4.2.1 Symbol.asyncIterator

Symbol.asyncIterator の初期値は既知のシンボル %Symbol.asyncIterator% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.2 Symbol.for ( key )

この関数は呼び出されたときに次の手順を実行する:

  1. Let stringKey be ? ToString(key)(キーを文字列に変換する)。
  2. For each element e of the GlobalSymbolRegistry List, do
    1. If e.[[Key]] is stringKey, return e.[[Symbol]](既に登録されていればそのシンボルを返す)。
  3. Assert: The GlobalSymbolRegistry List does not currently contain an entry for stringKey(登録されていないことを主張)。
  4. Let newSymbol be a new Symbol whose [[Description]] is stringKey(新しいシンボルを作る)。
  5. Append the GlobalSymbolRegistry Record { [[Key]]: stringKey, [[Symbol]]: newSymbol } to the GlobalSymbolRegistry List(登録リストに追加)。
  6. Return newSymbol(新しいシンボルを返す)。

GlobalSymbolRegistry List は追記のみ可能なグローバルに利用可能なリストである。すべての realm に共有される。任意の ECMAScript コードの評価より前に、これは新しい空リストとして初期化される。GlobalSymbolRegistry List の要素は Table 58 に定義される構造のレコードである。

Table 58: GlobalSymbolRegistry Record Fields
Field Name Value Usage
[[Key]] a String A string key used to globally identify a Symbol.
[[Symbol]] a Symbol A symbol that can be retrieved from any realm.

20.4.2.3 Symbol.hasInstance

Symbol.hasInstance の初期値は既知のシンボル %Symbol.hasInstance% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.4 Symbol.isConcatSpreadable

Symbol.isConcatSpreadable の初期値は既知のシンボル %Symbol.isConcatSpreadable% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.5 Symbol.iterator

Symbol.iterator の初期値は既知のシンボル %Symbol.iterator% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.6 Symbol.keyFor ( sym )

この関数は呼び出されたときに次の手順を実行する:

  1. If sym is not a Symbol, throw a TypeError exception(sym がシンボルでなければ例外)。
  2. Return KeyForSymbol(sym)(キーを返す)。

20.4.2.7 Symbol.match

Symbol.match の初期値は既知のシンボル %Symbol.match% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.8 Symbol.matchAll

Symbol.matchAll の初期値は既知のシンボル %Symbol.matchAll% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.9 Symbol.prototype

Symbol.prototype の初期値は Symbol プロトタイプオブジェクトである。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.10 Symbol.replace

Symbol.replace の初期値は既知のシンボル %Symbol.replace% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.11 Symbol.search

Symbol.search の初期値は既知のシンボル %Symbol.search% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.12 Symbol.species

Symbol.species の初期値は既知のシンボル %Symbol.species% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.13 Symbol.split

Symbol.split の初期値は既知のシンボル %Symbol.split% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.14 Symbol.toPrimitive

Symbol.toPrimitive の初期値は既知のシンボル %Symbol.toPrimitive% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.15 Symbol.toStringTag

Symbol.toStringTag の初期値は既知のシンボル %Symbol.toStringTag% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.2.16 Symbol.unscopables

Symbol.unscopables の初期値は既知のシンボル %Symbol.unscopables% である(Table 1)。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.4.3 Symbol プロトタイプオブジェクトのプロパティ

Symbol プロトタイプオブジェクト は次のとおりである:

  • %Symbol.prototype% である。
  • 通常オブジェクトである。
  • Symbol インスタンスではなく、[[SymbolData]] 内部スロットを持たない。
  • [[Prototype]] 内部スロットを持ち、その値は %Object.prototype% である。

20.4.3.1 Symbol.prototype.constructor

Symbol.prototype.constructor の初期値は %Symbol% である。

20.4.3.2 get Symbol.prototype.description

Symbol.prototype.description は set アクセサが undefined のアクセサプロパティである。その get アクセサ関数は呼び出されたときに次の手順を実行する:

  1. Let s be the this value(this を取得)。
  2. Let sym be ? ThisSymbolValue(s)(this からシンボル値を取得)。
  3. Return sym.[[Description]](その説明を返す)。

20.4.3.3 Symbol.prototype.toString ( )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let sym be ? ThisSymbolValue(this value)(this のシンボル値を取得)。
  2. Return SymbolDescriptiveString(sym)(記述文字列を返す)。

20.4.3.3.1 SymbolDescriptiveString ( sym )

The abstract operation SymbolDescriptiveString takes argument sym (a Symbol) and returns a String. It performs the following steps when called:

  1. Let desc be sym.[[Description]](説明を取得)。
  2. If desc is undefined, set desc to the empty String(説明が undefined なら空文字にする)。
  3. Assert: desc is a String(文字列であることを主張)。
  4. Return the string-concatenation of "Symbol(", desc, and ")"("Symbol(" + desc + ")" を返す)。

20.4.3.4 Symbol.prototype.valueOf ( )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Return ? ThisSymbolValue(this value)(this のシンボル値を返す)。

20.4.3.4.1 ThisSymbolValue ( value )

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

  1. If value is a Symbol, return value(プリミティブ Symbol なら返す)。
  2. If value is an Object and value has a [[SymbolData]] internal slot, then
    1. Let s be value.[[SymbolData]](内部スロットのシンボルを取得)。
    2. Assert: s is a Symbol(シンボルであることを主張)。
    3. Return s(返す)。
  3. Throw a TypeError exception(それ以外は例外)。

20.4.3.5 Symbol.prototype [ %Symbol.toPrimitive% ] ( hint )

このメソッドは ECMAScript の演算子によって Symbol オブジェクトをプリミティブ値に変換するために呼び出される。

呼び出されたときに次の手順を実行する:

  1. Return ? ThisSymbolValue(this value)(this のシンボル値を返す)。
Note

引数は無視される。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

The value of the "name" property of this method is "[Symbol.toPrimitive]".

20.4.3.6 Symbol.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% プロパティの初期値は文字列 "Symbol" である。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

20.4.4 Symbol インスタンスのプロパティ

Symbol インスタンスは Symbol プロトタイプオブジェクトからプロパティを継承する通常オブジェクトである。Symbol インスタンスは [[SymbolData]] 内部スロットを持つ。[[SymbolData]] 内部スロットはこの Symbol オブジェクトが表す Symbol 値である。

20.4.5 シンボルのための抽象操作

20.4.5.1 KeyForSymbol ( sym )

The abstract operation KeyForSymbol takes argument sym (a Symbol) and returns a String or undefined. もし symGlobalSymbolRegistry List に含まれているなら、sym を登録するために使われた文字列を返す。 It performs the following steps when called:

  1. For each element e of the GlobalSymbolRegistry List, do
    1. If SameValue(e.[[Symbol]], sym) is true, return e.[[Key]](一致するエントリのキーを返す)。
  2. Assert: The GlobalSymbolRegistry List does not currently contain an entry for sym(登録されていないことを主張)。
  3. Return undefined(見つからなければ undefined を返す)。

20.5 Error オブジェクト

エラーオブジェクトのインスタンスは実行時エラーが発生したときに例外として投げられる。Error オブジェクトはユーザー定義の例外クラスの基底オブジェクトとしても使用され得る。

ECMAScript 実装が実行時エラーを検出したとき、それは 20.5.5 で定義された NativeError オブジェクトのいずれか、または 20.5.7 で定義された AggregateError オブジェクトの新しいインスタンスを投げる。

20.5.1 Error コンストラクタ

Error コンストラクタ:

  • %Error% である。
  • グローバルオブジェクト"Error" プロパティの初期値である。
  • コンストラクタとしてではなく関数として呼び出されたときに新しい Error オブジェクトを作成・初期化する。したがって関数呼び出し Error(…) は new Error(…) と同等である。
  • クラス定義の extends 節の値として使用されることがある。指定された Error 振る舞いを継承するサブクラスのコンストラクタは、[[ErrorData]] 内部スロットを持つサブクラスインスタンスを作成・初期化するために Error コンストラクタへの super 呼び出しを含まなければならない。

20.5.1.1 Error ( message [ , options ] )

この関数は呼び出されたときに次の手順を実行する:

  1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget(NewTarget が undefined ならアクティブ関数を使う)。
  2. Let obj be ? OrdinaryCreateFromConstructor(newTarget, "%Error.prototype%", « [[ErrorData]] »)(Error オブジェクトを作成)。
  3. If message is not undefined, then
    1. Let msg be ? ToString(message)(メッセージを文字列化)。
    2. Perform CreateNonEnumerableDataPropertyOrThrow(obj, "message", msg)(message プロパティを非列挙で作成)。
  4. Perform ? InstallErrorCause(obj, options)(cause オプションをインストール)。
  5. Return obj(オブジェクトを返す)。

20.5.2 Error コンストラクタのプロパティ

Error コンストラクタ:

  • [[Prototype]] 内部スロットを持ち、その値は %Function.prototype% である。
  • 以下のプロパティを持つ:

20.5.2.1 Error.isError ( arg )

この関数は呼び出されたときに次の手順を実行する:

  1. If arg is not an Object, return false(オブジェクトでなければ false)。
  2. If arg does not have an [[ErrorData]] internal slot, return false[[ErrorData]] がなければ false)。
  3. Return true(それ以外は true)。

20.5.2.2 Error.prototype

Error.prototype の初期値は Error プロトタイプオブジェクトである。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.5.3 Error プロトタイプオブジェクトのプロパティ

Error プロトタイプオブジェクト は次のとおりである:

  • %Error.prototype% である。
  • 通常オブジェクトである。
  • Error インスタンスではなく [[ErrorData]] 内部スロットを持たない。
  • [[Prototype]] 内部スロットを持ち、その値は %Object.prototype% である。

20.5.3.1 Error.prototype.constructor

Error.prototype.constructor の初期値は %Error% である。

20.5.3.2 Error.prototype.message

Error.prototype.message の初期値は空文字列である。

20.5.3.3 Error.prototype.name

Error.prototype.name の初期値は "Error" である。

20.5.3.4 Error.prototype.toString ( )

このメソッドは呼び出されたときに次の手順を実行する:

  1. Let obj be the this value(this を取得)。
  2. If obj is not an Object, throw a TypeError exception(オブジェクトでなければ例外)。
  3. Let name be ? Get(obj, "name")(name を取得)。
  4. If name is undefined, set name to "Error"; else set name to ? ToString(name)(name が undefined なら "Error"、そうでなければ文字列化)。
  5. Let msg be ? Get(obj, "message")(message を取得)。
  6. If msg is undefined, set msg to the empty String; else set msg to ? ToString(msg)(message が undefined なら空文字、そうでなければ文字列化)。
  7. If name is the empty String, return msg(name が空なら message を返す)。
  8. If msg is the empty String, return name(message が空なら name を返す)。
  9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE), and msg("name: message" を返す)。

20.5.4 Error インスタンスのプロパティ

Error インスタンスは Error プロトタイプオブジェクトからプロパティを継承する通常オブジェクトであり、[[ErrorData]] 内部スロットを持ち、その値は undefined である。[[ErrorData]] の唯一の指定用途は Object.prototype.toStringError.isError によって Error、AggregateError、NativeError のインスタンスを Error オブジェクトとして識別することである。

20.5.5 この標準で使用されるネイティブエラー型

以下の NativeError オブジェクトのいずれか、あるいは AggregateError オブジェクトの新しいインスタンスが実行時エラー検出時に投げられる。すべての NativeError オブジェクトは共通の構造を共有し、その構造は 20.5.6 に記述される。

20.5.5.1 EvalError

EvalError コンストラクタは %EvalError% である。

この例外は現在この仕様内では使用されていない。互換性のために残されている。

20.5.5.2 RangeError

RangeError コンストラクタは %RangeError% である。

許容される値の集合や範囲に入らない値を示す。

20.5.5.3 ReferenceError

ReferenceError コンストラクタは %ReferenceError% である。

無効な参照が検出されたことを示す。

20.5.5.4 SyntaxError

SyntaxError コンストラクタは %SyntaxError% である。

パースエラーが発生したことを示す。

20.5.5.5 TypeError

TypeError コンストラクタは %TypeError% である。

他のいずれの NativeError も失敗原因を適切に示すものではない場合に、不成功な操作を示すために使用される。

20.5.5.6 URIError

URIError コンストラクタは %URIError% である。

グローバル URI 処理関数のいずれかがその定義と互換性のない方法で使用されたことを示す。

20.5.6 NativeError オブジェクトの構造

これらの各オブジェクトは下記に示す構造を持ち、コンストラクタ名とプロトタイプオブジェクトの "name" プロパティに使用される名前だけが異なる。

各エラーオブジェクトについて、定義中の NativeError への参照は 20.5.5 から適切なエラーオブジェクト名に置き換えられるべきである。

20.5.6.1 NativeError コンストラクタ

NativeError コンストラクタ:

  • コンストラクタではなく関数として呼び出されたときに新しい NativeError オブジェクトを作成・初期化する。同一の引数で関数として呼ぶことはコンストラクタとして呼ぶことと等価である。したがって関数呼び出し NativeError(…) は new NativeError(…) と等しい。
  • クラス定義の extends 節の値として使用されることがある。指定された NativeError 振る舞いを継承しようとするサブクラスのコンストラクタは、[[ErrorData]] 内部スロットを持つサブクラスインスタンスを作成・初期化するために NativeError コンストラクタへの super 呼び出しを含まなければならない。

20.5.6.1.1 NativeError ( message [ , options ] )

NativeError 関数は呼び出されたときに次の手順を実行する:

  1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget(NewTarget を決定)。
  2. Let obj be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »)(オブジェクトを作成)。
  3. If message is not undefined, then
    1. Let msg be ? ToString(message)(メッセージを文字列化)。
    2. Perform CreateNonEnumerableDataPropertyOrThrow(obj, "message", msg)(message を非列挙プロパティとして作成)。
  4. Perform ? InstallErrorCause(obj, options)(cause オプションをインストール)。
  5. Return obj(作成したオブジェクトを返す)。

ステップ 2 で渡される文字列の実際の値は、定義される NativeError コンストラクタに対応して "%EvalError.prototype%", "%RangeError.prototype%", "%ReferenceError.prototype%", "%SyntaxError.prototype%", "%TypeError.prototype%", または "%URIError.prototype%" のいずれかである。

20.5.6.2 NativeError コンストラクタのプロパティ

NativeError コンストラクタ:

  • [[Prototype]] 内部スロットを持ち、その値は %Error% である。
  • "name" プロパティの値は文字列値 "NativeError" である。
  • 以下のプロパティを持つ:

20.5.6.2.1 NativeError.prototype

NativeError.prototype の初期値は NativeError プロトタイプオブジェクトである(20.5.6.3)。各 NativeError コンストラクタは別個のプロトタイプオブジェクトを持つ。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.5.6.3 NativeError プロトタイプオブジェクトのプロパティ

NativeError プロトタイプオブジェクト は次のとおりである:

  • 通常オブジェクトである。
  • Error インスタンスではなく [[ErrorData]] 内部スロットを持たない。
  • [[Prototype]] 内部スロットを持ち、その値は %Error.prototype% である。

20.5.6.3.1 NativeError.prototype.constructor

特定の NativeError コンストラクタに対するプロトタイプの "constructor" プロパティの初期値はそのコンストラクタ自体である。

20.5.6.3.2 NativeError.prototype.message

特定の NativeError コンストラクタに対するプロトタイプの "message" プロパティの初期値は空文字列である。

20.5.6.3.3 NativeError.prototype.name

特定の NativeError コンストラクタに対するプロトタイプの "name" プロパティの初期値は、そのコンストラクタ名の文字列である(NativeError の代わりに使用される名前)。

20.5.6.4 NativeError インスタンスのプロパティ

NativeError インスタンスはその NativeError プロトタイプオブジェクトからプロパティを継承する通常オブジェクトであり、[[ErrorData]] 内部スロットを持ち、その値は undefined である。[[ErrorData]] の唯一の指定用途は Object.prototype.toStringError.isError によって Error、AggregateError、または NativeError のインスタンスを識別することである。

20.5.7 AggregateError オブジェクト

20.5.7.1 AggregateError コンストラクタ

AggregateError コンストラクタ:

  • %AggregateError% である。
  • グローバルオブジェクト"AggregateError" プロパティの初期値である。
  • コンストラクタではなく関数として呼び出されたときに新しい AggregateError オブジェクトを作成・初期化する。したがって関数呼び出し AggregateError(…) は new AggregateError(…) と等しい。
  • クラス定義の extends 節の値として使用されることがある。指定された AggregateError 振る舞いを継承するサブクラスのコンストラクタは、[[ErrorData]] 内部スロットを持つサブクラスインスタンスを作成・初期化するために AggregateError コンストラクタへの super 呼び出しを含まなければならない。

20.5.7.1.1 AggregateError ( errors, message [ , options ] )

この関数は呼び出されたときに次の手順を実行する:

  1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget(NewTarget を決める)。
  2. Let obj be ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]] »)(AggregateError オブジェクトを作成)。
  3. If message is not undefined, then
    1. Let msg be ? ToString(message)(メッセージを文字列化)。
    2. Perform CreateNonEnumerableDataPropertyOrThrow(obj, "message", msg)(message を作成)。
  4. Perform ? InstallErrorCause(obj, options)(cause をインストール)。
  5. Let errorsList be ? IteratorToList(? GetIterator(errors, sync))(errors から同期イテレータを取得してリスト化)。
  6. Perform ! DefinePropertyOrThrow(obj, "errors", PropertyDescriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: CreateArrayFromList(errorsList) })(errors プロパティを作成)。
  7. Return obj(オブジェクトを返す)。

20.5.7.2 AggregateError コンストラクタのプロパティ

AggregateError コンストラクタ:

  • [[Prototype]] 内部スロットを持ち、その値は %Error% である。
  • 以下のプロパティを持つ:

20.5.7.2.1 AggregateError.prototype

AggregateError.prototype の初期値は %AggregateError.prototype% である。

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

20.5.7.3 AggregateError プロトタイプオブジェクトのプロパティ

AggregateError プロトタイプオブジェクト は次のとおりである:

  • %AggregateError.prototype% である。
  • 通常オブジェクトである。
  • Error インスタンスや AggregateError インスタンスではなく、[[ErrorData]] 内部スロットを持たない。
  • [[Prototype]] 内部スロットを持ち、その値は %Error.prototype% である。

20.5.7.3.1 AggregateError.prototype.constructor

AggregateError.prototype.constructor の初期値は %AggregateError% である。

20.5.7.3.2 AggregateError.prototype.message

AggregateError.prototype.message の初期値は空文字列である。

20.5.7.3.3 AggregateError.prototype.name

AggregateError.prototype.name の初期値は "AggregateError" である。

20.5.7.4 AggregateError インスタンスのプロパティ

AggregateError インスタンスは AggregateError プロトタイプオブジェクトからプロパティを継承する通常オブジェクトであり、[[ErrorData]] 内部スロットを持ち、その値は undefined である。[[ErrorData]] の唯一の指定用途は Object.prototype.toStringError.isError によって Error、AggregateError、または NativeError のインスタンスを識別することである。

20.5.8 エラーオブジェクトの抽象操作

20.5.8.1 InstallErrorCause ( obj, options )

The abstract operation InstallErrorCause takes arguments obj (an Object) and options (an ECMAScript language value) and returns either a normal completion containing unused or a throw completion. これは options"cause" プロパティが存在する場合に obj"cause" プロパティを作成するために使用される。 It performs the following steps when called:

  1. If options is an Object and ? HasProperty(options, "cause") is true, then
    1. Let cause be ? Get(options, "cause")(options.cause を取得)。
    2. Perform CreateNonEnumerableDataPropertyOrThrow(obj, "cause", cause)(cause を非列挙プロパティとして作成)。
  2. Return unused(何も返さない)。