ページ表示設定

10 通常オブジェクトおよび特殊オブジェクトの動作

10.1 通常オブジェクトの内部メソッドと内部スロット

すべての通常オブジェクトは [[Prototype]] と呼ばれる内部スロットを持ちます。この内部スロットの値は null またはオブジェクトのいずれかであり、継承の実装に使用されます。propertyKey という名前のプロパティが通常オブジェクト obj には存在しないものの、その [[Prototype]] オブジェクトには存在すると仮定します。propertyKey が [[Prototype]] オブジェクト上のデータプロパティを参照する場合、obj は get アクセスのためにそれを継承し、propertyKey が obj のプロパティであるかのように動作します。propertyKey が [[Prototype]] オブジェクト上の書込み可能なデータプロパティを参照する場合、obj 上で propertyKey に set アクセスすると、obj 上に propertyKey という名前の新しいデータプロパティが作成されます。propertyKey が [[Prototype]] オブジェクト上の書込み不可のデータプロパティを参照する場合、obj 上での propertyKey への set アクセスは失敗します。propertyKey が [[Prototype]] オブジェクト上のアクセサープロパティを参照する場合、そのアクセサーは get アクセスと set アクセスの両方について obj に継承されます。

すべての通常オブジェクトは Boolean 値を持つ [[Extensible]] 内部スロットを持ち、6.1.7.3 で規定される拡張可能性に関する内部メソッドの不変条件を満たすために使用されます。すなわち、オブジェクトの [[Extensible]] 内部スロットの値が一度 false に設定されると、そのオブジェクトにプロパティを追加したり、そのオブジェクトの [[Prototype]] 内部スロットの値を変更したり、その後 [[Extensible]] の値を true に変更したりすることはできなくなります。

以下のアルゴリズムの説明では、obj は通常オブジェクト、propertyKey はプロパティキー値、value は任意の ECMAScript 言語値、propertyDesc は Property Descriptor Record であると仮定します。

各通常オブジェクト内部メソッドは、同様の名前を持つ抽象操作へ処理を委譲します。その抽象操作が別の内部メソッドに依存する場合、同様の名前を持つ抽象操作を直接呼び出すのではなく、obj に対してその内部メソッドが呼び出されます。この意味論により、通常オブジェクトの内部メソッドが特殊オブジェクトに適用された場合、その特殊オブジェクトで上書きされた内部メソッドが呼び出されることが保証されます。

10.1.1 [[GetPrototypeOf]] ( )

an ordinary object objの内部メソッド [[GetPrototypeOf]]。引数なし。戻り値:正常完了 (値:(Object または null))。 呼び出されると、次の手順を実行する。

  1. OrdinaryGetPrototypeOf(obj) を返す。

10.1.1.1 OrdinaryGetPrototypeOf ( obj )

抽象操作 OrdinaryGetPrototypeOf。引数 obj (Object)。戻り値:(Object または null)。 呼び出されると、次の手順を実行する。

  1. obj.[[Prototype]] を返す。

10.1.2 [[SetPrototypeOf]] ( proto )

an ordinary object objの内部メソッド [[SetPrototypeOf]]。引数 proto ((Object または null))。戻り値:正常完了 (値:Boolean)。 呼び出されると、次の手順を実行する。

  1. OrdinarySetPrototypeOf(obj, proto) を返す。

10.1.2.1 OrdinarySetPrototypeOf ( obj, proto )

抽象操作 OrdinarySetPrototypeOf。引数 obj (Object) および proto ((Object または null))。戻り値:Boolean。 呼び出されると、次の手順を実行する。

  1. current を obj.[[Prototype]] とする。
  2. SameValue(proto, current) が true である場合、true を返す。
  3. extensible を obj.[[Extensible]] とする。
  4. extensible が false である場合、false を返す。
  5. cursor を proto とする。
  6. done を false とする。
  7. done が false である間、次を繰り返す。
    1. cursor が null である場合、
      1. done を true に設定する。
    2. そうでなく、SameValue(cursor, obj) が true である場合、
      1. false を返す。
    3. そうでない場合、
      1. cursor.[[GetPrototypeOf]] が 10.1.1 で定義される通常オブジェクト内部メソッドでない場合、done を true に設定する。
      2. そうでない場合、cursor を cursor.[[Prototype]] に設定する。
  8. obj.[[Prototype]] を proto に設定する。
  9. true を返す。
注

手順 7 のループは、[[GetPrototypeOf]] および [[SetPrototypeOf]] に通常オブジェクトの定義を使用するオブジェクトのみを含むプロトタイプチェーンに循環が存在しないことを保証します。

10.1.3 [[IsExtensible]] ( )

an ordinary object objの内部メソッド [[IsExtensible]]。引数なし。戻り値:正常完了 (値:Boolean)。 呼び出されると、次の手順を実行する。

  1. OrdinaryIsExtensible(obj) を返す。

10.1.3.1 OrdinaryIsExtensible ( obj )

抽象操作 OrdinaryIsExtensible。引数 obj (Object)。戻り値:Boolean。 呼び出されると、次の手順を実行する。

  1. obj.[[Extensible]] を返す。

10.1.4 [[PreventExtensions]] ( )

an ordinary object objの内部メソッド [[PreventExtensions]]。引数なし。戻り値:正常完了 (値:true)。 呼び出されると、次の手順を実行する。

  1. OrdinaryPreventExtensions(obj) を返す。

10.1.4.1 OrdinaryPreventExtensions ( obj )

抽象操作 OrdinaryPreventExtensions。引数 obj (Object)。戻り値:true。 呼び出されると、次の手順を実行する。

  1. obj.[[Extensible]] を false に設定する。
  2. true を返す。

10.1.5 [[GetOwnProperty]] ( propertyKey )

an ordinary object objの内部メソッド [[GetOwnProperty]]。引数 propertyKey (プロパティキー)。戻り値:正常完了 (値:(プロパティ記述子 または undefined))。 呼び出されると、次の手順を実行する。

  1. OrdinaryGetOwnProperty(obj, propertyKey) を返す。

10.1.5.1 OrdinaryGetOwnProperty ( obj, propertyKey )

抽象操作 OrdinaryGetOwnProperty。引数 obj (Object) および propertyKey (プロパティキー)。戻り値:(プロパティ記述子 または undefined)。 呼び出されると、次の手順を実行する。

  1. obj がキー propertyKey を持つ自身のプロパティを持たない場合、undefined を返す。
  2. propertyDesc を、フィールドを持たない新しく作成された Property Descriptor とする。
  3. ownProperty を、キーが propertyKey である obj 自身のプロパティとする。
  4. ownProperty がデータプロパティである場合、
    1. propertyDesc.[[Value]] を ownProperty の [[Value]] 属性の値に設定する。
    2. propertyDesc.[[Writable]] を ownProperty の [[Writable]] 属性の値に設定する。
  5. そうでない場合、
    1. 表明: ownProperty はアクセサープロパティである。
    2. propertyDesc.[[Getter]] を ownProperty の [[Getter]] 属性の値に設定する。
    3. propertyDesc.[[Setter]] を ownProperty の [[Setter]] 属性の値に設定する。
  6. propertyDesc.[[Enumerable]] を ownProperty の [[Enumerable]] 属性の値に設定する。
  7. propertyDesc.[[Configurable]] を ownProperty の [[Configurable]] 属性の値に設定する。
  8. propertyDesc を返す。

10.1.6 [[DefineOwnProperty]] ( propertyKey, propertyDesc )

an ordinary object objの内部メソッド [[DefineOwnProperty]]。引数 propertyKey (プロパティキー) および propertyDesc (プロパティ記述子)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? OrdinaryDefineOwnProperty(obj, propertyKey, propertyDesc) を返す。

10.1.6.1 OrdinaryDefineOwnProperty ( obj, propertyKey, propertyDesc )

抽象操作 OrdinaryDefineOwnProperty。引数 obj (Object)、propertyKey (プロパティキー) および propertyDesc (プロパティ記述子)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. current を ? obj.[[GetOwnProperty]](propertyKey) とする。
  2. extensible を ? IsExtensible(obj) とする。
  3. ValidateAndApplyPropertyDescriptor(obj, propertyKey, extensible, propertyDesc, current) を返す。

10.1.6.2 IsCompatiblePropertyDescriptor ( extensible, propertyDesc, current )

抽象操作 IsCompatiblePropertyDescriptor。引数 extensible (Boolean)、propertyDesc (プロパティ記述子) および current ((プロパティ記述子 または undefined))。戻り値:Boolean。 呼び出されると、次の手順を実行する。

  1. ValidateAndApplyPropertyDescriptor(undefined, "", extensible, propertyDesc, current) を返す。

10.1.6.3 ValidateAndApplyPropertyDescriptor ( obj, propertyKey, extensible, propertyDesc, current )

抽象操作 ValidateAndApplyPropertyDescriptor。引数 obj ((Object または undefined))、propertyKey (プロパティキー)、extensible (Boolean)、propertyDesc (プロパティ記述子) および current ((プロパティ記述子 または undefined))。戻り値:Boolean。 指定された extensibility と現在のプロパティ current を持つオブジェクトのプロパティとして propertyDesc を適用しても 不変条件が維持される場合に限り true を返します。そのような適用が可能で、かつ obj が undefined でない場合、propertyKey という名前のプロパティに対して適用が実行されます(必要であれば作成されます)。 呼び出されると、次の手順を実行する。

  1. 表明: propertyKey はプロパティキーである。
  2. current が undefined である場合、
    1. extensible が false である場合、false を返す。
    2. obj が undefined である場合、true を返す。
    3. IsAccessorDescriptor(propertyDesc) が true である場合、
      1. オブジェクト obj に propertyKey という名前の自身のアクセサープロパティを作成する。その [[Getter]]、[[Setter]]、[[Enumerable]]、および [[Configurable]] 属性は、propertyDesc が対応するフィールドを持つ場合はそのフィールドの値に、そうでない場合は属性の 既定値に設定する。
    4. そうでない場合、
      1. オブジェクト obj に propertyKey という名前の自身のデータプロパティを作成する。その [[Value]]、[[Writable]]、[[Enumerable]]、および [[Configurable]] 属性は、propertyDesc が対応するフィールドを持つ場合はそのフィールドの値に、そうでない場合は属性の 既定値に設定する。
    5. true を返す。
  3. 表明: current は完全に設定された Property Descriptor である。
  4. propertyDesc がフィールドを1つも持たない場合、true を返す。
  5. current.[[Configurable]] が false である場合、
    1. propertyDesc が [[Configurable]] フィールドを持ち、propertyDesc.[[Configurable]] が true である場合、false を返す。
    2. propertyDesc が [[Enumerable]] フィールドを持ち、propertyDesc.[[Enumerable]] が current.[[Enumerable]] でない場合、false を返す。
    3. IsGenericDescriptor(propertyDesc) が false であり、IsAccessorDescriptor(propertyDesc) が IsAccessorDescriptor(current) でない場合、false を返す。
    4. IsAccessorDescriptor(current) が true である場合、
      1. propertyDesc が [[Getter]] フィールドを持ち、SameValue(propertyDesc.[[Getter]], current.[[Getter]]) が false である場合、false を返す。
      2. propertyDesc が [[Setter]] フィールドを持ち、SameValue(propertyDesc.[[Setter]], current.[[Setter]]) が false である場合、false を返す。
    5. そうでなく、current.[[Writable]] が false である場合、
      1. propertyDesc が [[Writable]] フィールドを持ち、propertyDesc.[[Writable]] が true である場合、false を返す。
      2. 注記: SameValue は、他の手段によって区別できる可能性がある NaN 値について true を返す。ここで返すことで、obj の既存のプロパティが変更されないことを保証する。
      3. propertyDesc が [[Value]] フィールドを持つ場合、SameValue(propertyDesc.[[Value]], current.[[Value]]) を返す。
  6. obj が undefined でない場合、
    1. IsDataDescriptor(current) が true であり、IsAccessorDescriptor(propertyDesc) が true である場合、
      1. propertyDesc が [[Configurable]] フィールドを持つ場合、configurable を propertyDesc.[[Configurable]] とする。そうでない場合、configurable を current.[[Configurable]] とする。
      2. propertyDesc が [[Enumerable]] フィールドを持つ場合、enumerable を propertyDesc.[[Enumerable]] とする。そうでない場合、enumerable を current.[[Enumerable]] とする。
      3. オブジェクト obj の propertyKey という名前のプロパティを、[[Configurable]] および [[Enumerable]] 属性がそれぞれ configurable および enumerable に設定され、[[Getter]] および [[Setter]] 属性が、propertyDesc が対応するフィールドを持つ場合はそのフィールドの値に、そうでない場合は属性の 既定値に設定されたアクセサープロパティに置換する。
    2. そうでなく、IsAccessorDescriptor(current) が true であり、IsDataDescriptor(propertyDesc) が true である場合、
      1. propertyDesc が [[Configurable]] フィールドを持つ場合、configurable を propertyDesc.[[Configurable]] とする。そうでない場合、configurable を current.[[Configurable]] とする。
      2. propertyDesc が [[Enumerable]] フィールドを持つ場合、enumerable を propertyDesc.[[Enumerable]] とする。そうでない場合、enumerable を current.[[Enumerable]] とする。
      3. オブジェクト obj の propertyKey という名前のプロパティを、[[Configurable]] および [[Enumerable]] 属性がそれぞれ configurable および enumerable に設定され、[[Value]] および [[Writable]] 属性が、propertyDesc が対応するフィールドを持つ場合はそのフィールドの値に、そうでない場合は属性の 既定値に設定されたデータプロパティに置換する。
    3. そうでない場合、
      1. propertyDesc の各フィールド名 fieldName について、オブジェクト obj の propertyKey という名前のプロパティの fieldName という名前の属性を、propertyDesc の fieldName フィールドの値に設定する。
  7. true を返す。

10.1.7 [[HasProperty]] ( propertyKey )

an ordinary object objの内部メソッド [[HasProperty]]。引数 propertyKey (プロパティキー)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? OrdinaryHasProperty(obj, propertyKey) を返す。

10.1.7.1 OrdinaryHasProperty ( obj, propertyKey )

抽象操作 OrdinaryHasProperty。引数 obj (Object) および propertyKey (プロパティキー)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. hasOwn を ? obj.[[GetOwnProperty]](propertyKey) とする。
  2. hasOwn が undefined でない場合、true を返す。
  3. parent を ? obj.[[GetPrototypeOf]]() とする。
  4. parent が null でない場合、
    1. ? parent.[[HasProperty]](propertyKey) を返す。
  5. false を返す。

10.1.8 [[Get]] ( propertyKey, receiver )

an ordinary object objの内部メソッド [[Get]]。引数 propertyKey (プロパティキー) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? OrdinaryGet(obj, propertyKey, receiver) を返す。

10.1.8.1 OrdinaryGet ( obj, propertyKey, receiver )

抽象操作 OrdinaryGet。引数 obj (Object)、propertyKey (プロパティキー) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyDesc を ? obj.[[GetOwnProperty]](propertyKey) とする。
  2. propertyDesc が undefined である場合、
    1. parent を ? obj.[[GetPrototypeOf]]() とする。
    2. parent が null である場合、undefined を返す。
    3. ? parent.[[Get]](propertyKey, receiver) を返す。
  3. IsDataDescriptor(propertyDesc) が true である場合、propertyDesc.[[Value]] を返す。
  4. 表明: IsAccessorDescriptor(propertyDesc) は true である。
  5. getter を propertyDesc.[[Getter]] とする。
  6. getter が undefined である場合、undefined を返す。
  7. ? Call(getter, receiver) を返す。

10.1.9 [[Set]] ( propertyKey, value, receiver )

an ordinary object objの内部メソッド [[Set]]。引数 propertyKey (プロパティキー)、value (ECMAScript 言語値) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? OrdinarySet(obj, propertyKey, value, receiver) を返す。

10.1.9.1 OrdinarySet ( obj, propertyKey, value, receiver )

抽象操作 OrdinarySet。引数 obj (Object)、propertyKey (プロパティキー)、value (ECMAScript 言語値) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ownDesc を ? obj.[[GetOwnProperty]](propertyKey) とする。
  2. ? OrdinarySetWithOwnDescriptor(obj, propertyKey, value, receiver, ownDesc) を返す。

10.1.9.2 OrdinarySetWithOwnDescriptor ( obj, propertyKey, value, receiver, ownDesc )

抽象操作 OrdinarySetWithOwnDescriptor。引数 obj (Object)、propertyKey (プロパティキー)、value (ECMAScript 言語値)、receiver (ECMAScript 言語値) および ownDesc ((プロパティ記述子 または undefined))。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ownDesc が undefined である場合、
    1. parent を ? obj.[[GetPrototypeOf]]() とする。
    2. parent が null でない場合、? parent.[[Set]](propertyKey, value, receiver) を返す。
    3. ownDesc を PropertyDescriptor { [[Value]]: undefined, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true } に設定する。
  2. IsDataDescriptor(ownDesc) が true である場合、
    1. ownDesc.[[Writable]] が false である場合、false を返す。
    2. receiver が Object でない場合、false を返す。
    3. existingDesc を ? receiver.[[GetOwnProperty]](propertyKey) とする。
    4. existingDesc が undefined である場合、
      1. 表明: receiver は現在 propertyKey プロパティを持っていない。
      2. ? CreateDataProperty(receiver, propertyKey, value) を返す。
    5. IsAccessorDescriptor(existingDesc) が true である場合、false を返す。
    6. existingDesc.[[Writable]] が false である場合、false を返す。
    7. valueDesc を PropertyDescriptor { [[Value]]: value } とする。
    8. ? receiver.[[DefineOwnProperty]](propertyKey, valueDesc) を返す。
  3. 表明: IsAccessorDescriptor(ownDesc) は true である。
  4. setter を ownDesc.[[Setter]] とする。
  5. setter が undefined である場合、false を返す。
  6. ? Call(setter, receiver, « value ») を実行する。
  7. true を返す。

10.1.10 [[Delete]] ( propertyKey )

an ordinary object objの内部メソッド [[Delete]]。引数 propertyKey (プロパティキー)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? OrdinaryDelete(obj, propertyKey) を返す。

10.1.10.1 OrdinaryDelete ( obj, propertyKey )

抽象操作 OrdinaryDelete。引数 obj (Object) および propertyKey (プロパティキー)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyDesc を ? obj.[[GetOwnProperty]](propertyKey) とする。
  2. propertyDesc が undefined である場合、true を返す。
  3. propertyDesc.[[Configurable]] が true である場合、
    1. obj から名前 propertyKey の自身のプロパティを削除する。
    2. true を返す。
  4. false を返す。

10.1.11 [[OwnPropertyKeys]] ( )

an ordinary object objの内部メソッド [[OwnPropertyKeys]]。引数なし。戻り値:正常完了 (値:リスト (要素:プロパティキー))。 呼び出されると、次の手順を実行する。

  1. OrdinaryOwnPropertyKeys(obj) を返す。

10.1.11.1 OrdinaryOwnPropertyKeys ( obj )

抽象操作 OrdinaryOwnPropertyKeys。引数 obj (Object)。戻り値:リスト (要素:プロパティキー)。 呼び出されると、次の手順を実行する。

  1. keys を新しい空の List とする。
  2. obj の自身のプロパティキー propertyKey のうち、propertyKey が配列インデックスであるものについて、数値インデックスの昇順で、次を行う。
    1. propertyKey を keys に追加する。
  3. obj の自身のプロパティキー propertyKey のうち、propertyKey が String であり配列インデックスではないものについて、プロパティ作成時刻の昇順で、次を行う。
    1. propertyKey を keys に追加する。
  4. obj の自身のプロパティキー propertyKey のうち、propertyKey が Symbol であるものについて、プロパティ作成時刻の昇順で、次を行う。
    1. propertyKey を keys に追加する。
  5. keys を返す。

10.1.12 OrdinaryObjectCreate ( proto [ , additionalInternalSlotsList ] )

抽象操作 OrdinaryObjectCreate。引数 proto ((Object または null))および省略可能な引数 additionalInternalSlotsList (リスト (要素:内部スロット名))。戻り値:Object。 新しい通常オブジェクトの実行時作成を規定するために使用されます。additionalInternalSlotsList には、[[Prototype]] および [[Extensible]] に加えて、オブジェクトの一部として定義しなければならない追加の内部スロットの名前が含まれます。additionalInternalSlotsList が提供されない場合、新しい空の List が使用されます。 呼び出されると、次の手順を実行する。

  1. internalSlotsList を « [[Prototype]], [[Extensible]] » とする。
  2. additionalInternalSlotsList が存在する場合、internalSlotsList を internalSlotsList と additionalInternalSlotsList のリスト連結に設定する。
  3. obj を MakeBasicObject(internalSlotsList) とする。
  4. obj.[[Prototype]] を proto に設定する。
  5. obj を返す。
注

OrdinaryObjectCreate は MakeBasicObject を呼び出すこと以上の処理をほとんど行いませんが、その使用は特殊オブジェクトではなく通常オブジェクトを作成する意図を表します。そのため、この仕様内では、その後オブジェクトの内部メソッドを変更して結果が通常オブジェクトでなくなるようなアルゴリズムからは呼び出されません。特殊オブジェクトを作成する操作は MakeBasicObject を直接呼び出します。

10.1.13 OrdinaryCreateFromConstructor ( ctor, intrinsicDefaultProto [ , internalSlotsList ] )

抽象操作 OrdinaryCreateFromConstructor。引数 ctor (関数オブジェクト) および intrinsicDefaultProto (String)および省略可能な引数 internalSlotsList (リスト (要素:内部スロット名))。戻り値:(正常完了 (値:Object) または throw 完了)。 コンストラクターの "prototype" プロパティが存在する場合、そのプロパティから [[Prototype]] 値を取得した通常オブジェクトを作成します。それ以外の場合、intrinsicDefaultProto で指定されるイントリンシックが [[Prototype]] に使用されます。internalSlotsList には、オブジェクトの一部として定義しなければならない追加の内部スロット名が含まれます。internalSlotsList が提供されない場合、新しい空の List が使用されます。 呼び出されると、次の手順を実行する。

  1. 表明: intrinsicDefaultProto は、この仕様におけるイントリンシックオブジェクトの名前である。対応するオブジェクトは、オブジェクトの [[Prototype]] 値として使用されることを意図したイントリンシックでなければならない。
  2. proto を ? GetPrototypeFromConstructor(ctor, intrinsicDefaultProto) とする。
  3. internalSlotsList が存在する場合、slots を internalSlotsList とする。
  4. そうでない場合、slots を新しい空の List とする。
  5. OrdinaryObjectCreate(proto, slots) を返す。

10.1.14 GetPrototypeFromConstructor ( ctor, intrinsicDefaultProto )

抽象操作 GetPrototypeFromConstructor。引数 ctor (関数オブジェクト) および intrinsicDefaultProto (String)。戻り値:(正常完了 (値:Object) または throw 完了)。 特定のコンストラクターに対応するオブジェクトを作成する際に使用するべき [[Prototype]] 値を決定します。その値は、コンストラクターの "prototype" プロパティが存在する場合はそこから取得されます。それ以外の場合、intrinsicDefaultProto で指定されるイントリンシックが [[Prototype]] に使用されます。 呼び出されると、次の手順を実行する。

  1. 表明: intrinsicDefaultProto は、この仕様におけるイントリンシックオブジェクトの名前である。対応するオブジェクトは、オブジェクトの [[Prototype]] 値として使用されることを意図したイントリンシックでなければならない。
  2. proto を ? Get(ctor, "prototype") とする。
  3. proto が Object でない場合、
    1. realm を ? GetFunctionRealm(ctor) とする。
    2. proto を realm の intrinsicDefaultProto という名前のイントリンシックオブジェクトに設定する。
  4. proto を返す。
注

ctor が [[Prototype]] 値を提供しない場合、使用される既定値は実行中の実行コンテキストからではなく、ctor 関数の Realm から取得されます。

10.1.15 RequireInternalSlot ( obj, internalSlot )

抽象操作 RequireInternalSlot。引数 obj (ECMAScript 言語値) および internalSlot (内部スロット名)。戻り値:(正常完了 (値:unused) または throw 完了)。 obj が Object であり、かつ指定された内部スロットを持つ場合を除き、例外をスローします。 呼び出されると、次の手順を実行する。

  1. obj が Object でない場合、TypeError 例外をスローする。
  2. obj が internalSlot 内部スロットを持たない場合、TypeError 例外をスローする。
  3. unused を返す。

10.2 ECMAScript 関数オブジェクト

ECMAScript 関数オブジェクトは、レキシカル環境を閉包として取り込んだパラメーター化された ECMAScript コードをカプセル化し、そのコードの動的評価をサポートします。ECMAScript 関数オブジェクトは通常オブジェクトであり、他の通常オブジェクトと同じ内部スロットと内部メソッドを持ちます。ECMAScript 関数オブジェクトのコードは strict モードコード(11.2.2)または非 strict コードのいずれでもかまいません。コードが strict モードコードである ECMAScript 関数オブジェクトを strict 関数と呼びます。コードが strict モードコードでないものを 非 strict 関数と呼びます。

[[Extensible]] および [[Prototype]] に加えて、ECMAScript 関数オブジェクトは 表 26 に列挙される内部スロットも持ちます。

表 26: ECMAScript 関数オブジェクトの内部スロット
内部スロット 型 説明
[[Environment]] an Environment Record 関数が閉包として取り込んだ Environment Record です。関数のコードを評価するときに外側の環境として使用されます。
[[PrivateEnvironment]] a PrivateEnvironment Record or null 関数が閉包として取り込んだ Private Name の PrivateEnvironment Record です。この関数が構文上クラス内に含まれていない場合は null です。関数のコードを評価するとき、内側のクラスに対する外側の PrivateEnvironment として使用されます。
[[FormalParameters]] a Parse Node 関数の仮引数リストを定義するソーステキストのルート Parse Node です。
[[ECMAScriptCode]] a Parse Node 関数本体を定義するソーステキストのルート Parse Node です。
[[ConstructorKind]] base or derived 関数が派生クラスのコンストラクターであるかどうかを示します。
[[Realm]] a Realm Record 関数が作成された Realm であり、関数の評価中にアクセスされるイントリンシックオブジェクトを提供します。
[[ScriptOrModule]] a Script Record or a Module Record 関数が作成されたスクリプトまたはモジュールです。
[[ThisMode]] lexical, strict, or global 関数の仮引数およびコード本体内で this 参照をどのように解釈するかを定義します。lexical は、this がレキシカルに外側の関数の this 値を参照することを意味します。strict は、関数呼出しによって提供された this 値をそのまま使用することを意味します。global は、undefined または null の this 値をグローバルオブジェクトへの参照として解釈し、その他の this 値は最初に ToObject に渡されることを意味します。
[[Strict]] a Boolean strict 関数である場合は true、非 strict 関数である場合は false です。
[[HomeObject]] an Object or undefined 関数が super を使用する場合、これは、その [[GetPrototypeOf]] が super プロパティ検索を開始するオブジェクトを提供するオブジェクトです。
[[SourceText]] a sequence of Unicode code points 関数を定義するソーステキストです。
[[Fields]] a List of ClassFieldDefinition Records 関数がクラスである場合、クラスの非 static フィールドと対応する初期化子を表す Record のリストです。
[[PrivateMethods]] a List of PrivateElements 関数がクラスである場合、クラスの非 static プライベートメソッドおよびアクセサーを表すリストです。
[[ClassFieldInitializerName]] a String, a Symbol, a Private Name, or empty 関数がクラスフィールドの初期化子として作成された場合、フィールドの NamedEvaluation に使用する名前です。それ以外の場合は empty です。
[[IsClassConstructor]] a Boolean 関数がクラスコンストラクターであるかどうかを示します。(true の場合、関数の [[Call]] を呼び出すと直ちに TypeError 例外がスローされます。)

すべての ECMAScript 関数オブジェクトは、ここで定義される [[Call]] 内部メソッドを持ちます。コンストラクターでもある ECMAScript 関数は、さらに [[Construct]] 内部メソッドも持ちます。

10.2.1 [[Call]] ( thisArg, argList )

an ECMAScript function object funcの内部メソッド [[Call]]。引数 thisArg (ECMAScript 言語値) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. callerContext を実行中の実行コンテキストとする。
  2. calleeContext を PrepareForOrdinaryCall(func, undefined) とする。
  3. 表明: calleeContext は現在、実行中の実行コンテキストである。
  4. func.[[IsClassConstructor]] が true である場合、
    1. error を新しく作成された TypeError オブジェクトとする。
    2. 注記: error は calleeContext 内で、func に関連付けられた Realm Record を使用して作成される。
    3. calleeContext を実行コンテキストスタックから削除し、callerContext を実行中の実行コンテキストとして復元する。
    4. error をスローする。
  5. OrdinaryCallBindThis(func, calleeContext, thisArg) を実行する。
  6. result を Completion(OrdinaryCallEvaluateBody(func, argList)) とする。
  7. calleeContext を実行コンテキストスタックから削除し、callerContext を実行中の実行コンテキストとして復元する。
  8. result がスロー完了である場合、? result を返す。
  9. 表明: result は return 完了である。
  10. result.[[Value]] を返す。
注

手順 7 で calleeContext が実行コンテキストスタックから削除されるとき、それが中断され、アクセス可能な Generator による後の再開のため保持されている場合には、破棄してはなりません。

10.2.1.1 PrepareForOrdinaryCall ( func, newTarget )

抽象操作 PrepareForOrdinaryCall。引数 func (ECMAScript 関数オブジェクト) および newTarget ((Object または undefined))。戻り値:実行コンテキスト。 呼び出されると、次の手順を実行する。

  1. callerContext を実行中の実行コンテキストとする。
  2. calleeContext を新しい ECMAScript コード実行コンテキストとする。
  3. calleeContext の Function を func に設定する。
  4. calleeRealm を func.[[Realm]] とする。
  5. calleeContext の Realm を calleeRealm に設定する。
  6. calleeContext の ScriptOrModule を func.[[ScriptOrModule]] に設定する。
  7. localEnv を NewFunctionEnvironment(func, newTarget) とする。
  8. calleeContext の LexicalEnvironment を localEnv に設定する。
  9. calleeContext の VariableEnvironment を localEnv に設定する。
  10. calleeContext の PrivateEnvironment を func.[[PrivateEnvironment]] に設定する。
  11. callerContext がまだ中断されていない場合、callerContext を中断する。
  12. calleeContext を実行コンテキストスタックにプッシュする。これで calleeContext が実行中の実行コンテキストになる。
  13. 注記: この時点以降に生成されるすべての例外オブジェクトは calleeRealm に関連付けられる。
  14. calleeContext を返す。

10.2.1.2 OrdinaryCallBindThis ( func, calleeContext, thisArg )

抽象操作 OrdinaryCallBindThis。引数 func (ECMAScript 関数オブジェクト)、calleeContext (実行コンテキスト) および thisArg (ECMAScript 言語値)。戻り値:unused。 呼び出されると、次の手順を実行する。

  1. thisMode を func.[[ThisMode]] とする。
  2. thisMode が lexical である場合、unused を返す。
  3. calleeRealm を func.[[Realm]] とする。
  4. localEnv を calleeContext の LexicalEnvironment とする。
  5. thisMode が strict である場合、
    1. thisValue を thisArg とする。
  6. そうでない場合、
    1. thisArg が undefined または null のいずれかである場合、
      1. globalEnv を calleeRealm.[[GlobalEnv]] とする。
      2. 表明: globalEnv は Global Environment Record である。
      3. thisValue を globalEnv.[[GlobalThisValue]] とする。
    2. そうでない場合、
      1. thisValue を ! ToObject(thisArg) とする。
      2. 注記: ToObject は calleeRealm を使用してラッパーオブジェクトを生成する。
  7. 表明: localEnv は Function Environment Record である。
  8. 表明: localEnv.[[ThisBindingStatus]] が initialized ではないため、次の手順が中断完了を返すことはない。
  9. ! BindThisValue(localEnv, thisValue) を実行する。
  10. unused を返す。

10.2.1.3 Runtime Semantics: EvaluateBody

構文指向操作 EvaluateBody。引数 func (ECMAScript 関数オブジェクト) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(return 完了 または throw 完了)。 次の生成規則ごとに定義される。

FunctionBody : FunctionStatementList
  1. 引数 func および argList を指定した FunctionBody の ? EvaluateFunctionBody を返す。
ConciseBody : ExpressionBody
  1. 引数 func および argList を指定した ConciseBody の ? EvaluateConciseBody を返す。
GeneratorBody : FunctionBody
  1. 引数 func および argList を指定した GeneratorBody の ? EvaluateGeneratorBody を返す。
AsyncGeneratorBody : FunctionBody
  1. 引数 func および argList を指定した AsyncGeneratorBody の ? EvaluateAsyncGeneratorBody を返す。
AsyncFunctionBody : FunctionBody
  1. 引数 func および argList を指定した AsyncFunctionBody の ? EvaluateAsyncFunctionBody を返す。
AsyncConciseBody : ExpressionBody
  1. 引数 func および argList を指定した AsyncConciseBody の ? EvaluateAsyncConciseBody を返す。
Initializer : = AssignmentExpression
  1. 表明: argList は空である。
  2. 表明: func.[[ClassFieldInitializerName]] は empty ではない。
  3. IsAnonymousFunctionDefinition(AssignmentExpression) が true である場合、
    1. value を、引数 func.[[ClassFieldInitializerName]] を指定した Initializer の ? NamedEvaluation とする。
  4. そうでない場合、
    1. rhs を AssignmentExpression の ? Evaluation とする。
    2. value を ? GetValue(rhs) とする。
  5. ReturnCompletion(value) を返す。
注

フィールド初期化子は関数境界を構成しますが、FunctionDeclarationInstantiation を呼び出しても観測可能な効果がないため、省略されています。

ClassStaticBlockBody : ClassStaticBlockStatementList
  1. 表明: argList は空である。
  2. 引数 func を指定した ClassStaticBlockBody の ? EvaluateClassStaticBlockBody を返す。

10.2.1.4 OrdinaryCallEvaluateBody ( func, argList )

抽象操作 OrdinaryCallEvaluateBody。引数 func (ECMAScript 関数オブジェクト) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(return 完了 または throw 完了)。 呼び出されると、次の手順を実行する。

  1. 引数 func および argList を指定した func.[[ECMAScriptCode]] の ? EvaluateBody を返す。

10.2.2 [[Construct]] ( argList, newTarget )

an ECMAScript function object funcの内部メソッド [[Construct]]。引数 argList (リスト (要素:ECMAScript 言語値)) および newTarget (コンストラクター)。戻り値:(正常完了 (値:Object) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. callerContext を実行中の実行コンテキストとする。
  2. kind を func.[[ConstructorKind]] とする。
  3. kind が base である場合、
    1. thisArg を ? OrdinaryCreateFromConstructor(newTarget, "%Object.prototype%") とする。
  4. calleeContext を PrepareForOrdinaryCall(func, newTarget) とする。
  5. 表明: calleeContext は現在、実行中の実行コンテキストである。
  6. kind が base である場合、
    1. OrdinaryCallBindThis(func, calleeContext, thisArg) を実行する。
    2. initializeResult を Completion(InitializeInstanceElements(thisArg, func)) とする。
    3. initializeResult が中断完了である場合、
      1. calleeContext を実行コンテキストスタックから削除し、callerContext を実行中の実行コンテキストとして復元する。
      2. ? initializeResult を返す。
  7. ctorEnv を calleeContext の LexicalEnvironment とする。
  8. result を Completion(OrdinaryCallEvaluateBody(func, argList)) とする。
  9. calleeContext を実行コンテキストスタックから削除し、callerContext を実行中の実行コンテキストとして復元する。
  10. result がスロー完了である場合、? result を返す。
  11. 表明: result は return 完了である。
  12. result.[[Value]] が Object である場合、result.[[Value]] を返す。
  13. kind が base である場合、thisArg を返す。
  14. result.[[Value]] が undefined でない場合、TypeError 例外をスローする。
  15. thisBinding を ? ctorEnv.GetThisBinding() とする。
  16. 表明: thisBinding は Object である。
  17. thisBinding を返す。

10.2.3 OrdinaryFunctionCreate ( proto, sourceText, paramList, body, thisMode, envRecord, privateEnv )

抽象操作 OrdinaryFunctionCreate。引数 proto (Object)、sourceText (a sequence of Unicode code points)、paramList (構文解析ノード)、body (構文解析ノード)、thisMode ((lexical-this または non-lexical-this))、envRecord (Environmentレコード) および privateEnv ((PrivateEnvironmentレコード または null))。戻り値:ECMAScript 関数オブジェクト。 既定の [[Call]] 内部メソッドを持ち、[[Construct]] 内部メソッドを持たない新しい関数の実行時作成を規定するために使用されます(ただし、MakeConstructor などの操作によって後から追加される場合があります)。sourceText は、作成される関数の構文上の定義のソーステキストです。 呼び出されると、次の手順を実行する。

  1. internalSlotsList を 表 26 に列挙される内部スロットとする。
  2. func を OrdinaryObjectCreate(proto, internalSlotsList) とする。
  3. func.[[Call]] を 10.2.1 で規定される定義に設定する。
  4. func.[[SourceText]] を sourceText に設定する。
  5. func.[[FormalParameters]] を paramList に設定する。
  6. func.[[ECMAScriptCode]] を body に設定する。
  7. strict を IsStrict(body) とする。
  8. func.[[Strict]] を strict に設定する。
  9. thisMode が lexical-this である場合、func.[[ThisMode]] を lexical に設定する。
  10. そうでなく、strict が true である場合、func.[[ThisMode]] を strict に設定する。
  11. そうでない場合、func.[[ThisMode]] を global に設定する。
  12. func.[[IsClassConstructor]] を false に設定する。
  13. func.[[Environment]] を envRecord に設定する。
  14. func.[[PrivateEnvironment]] を privateEnv に設定する。
  15. func.[[ScriptOrModule]] を GetActiveScriptOrModule() に設定する。
  16. func.[[Realm]] を現在の Realm Record に設定する。
  17. func.[[HomeObject]] を undefined に設定する。
  18. func.[[Fields]] を新しい空の List に設定する。
  19. func.[[PrivateMethods]] を新しい空の List に設定する。
  20. func.[[ClassFieldInitializerName]] を empty に設定する。
  21. length を paramList の ExpectedArgumentCount とする。
  22. SetFunctionLength(func, length) を実行する。
  23. func を返す。

10.2.4 AddRestrictedFunctionProperties ( func, realm )

抽象操作 AddRestrictedFunctionProperties。引数 func (関数オブジェクト) および realm (Realmレコード)。戻り値:unused。 呼び出されると、次の手順を実行する。

  1. 表明: realm.[[Intrinsics]].[[%ThrowTypeError%]] は存在し、初期化済みである。
  2. thrower を realm.[[Intrinsics]].[[%ThrowTypeError%]] とする。
  3. ! DefinePropertyOrThrow(func, "caller", PropertyDescriptor { [[Getter]]: thrower, [[Setter]]: thrower, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  4. ! DefinePropertyOrThrow(func, "arguments", PropertyDescriptor { [[Getter]]: thrower, [[Setter]]: thrower, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  5. unused を返す。

10.2.4.1 %ThrowTypeError% ( )

この関数は %ThrowTypeError% イントリンシックオブジェクトです。

これは、各 Realm について1回だけ定義される匿名の組込み関数オブジェクトです。

呼び出されたとき、次の手順を実行します。

  1. TypeError 例外をスローする。

この関数の [[Extensible]] 内部スロットの値は false です。

この関数の "length" プロパティは、属性 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false } を持ちます。

この関数の "name" プロパティは、属性 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false } を持ちます。

10.2.5 MakeConstructor ( func [ , writableProto [ , proto ] ] )

抽象操作 MakeConstructor。引数 func ((ECMAScript 関数オブジェクト または 組込み関数オブジェクト))および省略可能な引数 writableProto (Boolean) および proto (Object)。戻り値:unused。 func をコンストラクターに変換します。 呼び出されると、次の手順を実行する。

  1. func が ECMAScript 関数オブジェクトである場合、
    1. 表明: IsConstructor(func) は false である。
    2. 表明: func は "prototype" 自身のプロパティを持たない拡張可能なオブジェクトである。
    3. func.[[Construct]] を 10.2.2 で規定される定義に設定する。
  2. そうでない場合、
    1. func.[[Construct]] を 10.3.2 で規定される定義に設定する。
  3. func.[[ConstructorKind]] を base に設定する。
  4. writableProto が存在しない場合、writableProto を true に設定する。
  5. proto が存在しない場合、
    1. proto を OrdinaryObjectCreate(%Object.prototype%) に設定する。
    2. ! DefinePropertyOrThrow(proto, "constructor", PropertyDescriptor { [[Value]]: func, [[Writable]]: writableProto, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  6. ! DefinePropertyOrThrow(func, "prototype", PropertyDescriptor { [[Value]]: proto, [[Writable]]: writableProto, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  7. unused を返す。

10.2.6 MakeClassConstructor ( func )

抽象操作 MakeClassConstructor。引数 func (ECMAScript 関数オブジェクト)。戻り値:unused。 呼び出されると、次の手順を実行する。

  1. 表明: func.[[IsClassConstructor]] は false である。
  2. func.[[IsClassConstructor]] を true に設定する。
  3. unused を返す。

10.2.7 MakeMethod ( func, homeObj )

抽象操作 MakeMethod。引数 func (ECMAScript 関数オブジェクト) および homeObj (Object)。戻り値:unused。 func をメソッドとして設定します。 呼び出されると、次の手順を実行する。

  1. 表明: homeObj は通常オブジェクトである。
  2. func.[[HomeObject]] を homeObj に設定する。
  3. unused を返す。

10.2.8 DefineMethodProperty ( homeObj, name, closure, enumerable )

抽象操作 DefineMethodProperty。引数 homeObj (Object)、name ((プロパティキー または プライベート名))、closure (関数オブジェクト) および enumerable (Boolean)。戻り値:(正常完了 (値:(PrivateElement または empty)) または 中途完了)。 呼び出されると、次の手順を実行する。

  1. 表明: homeObj は通常の拡張可能なオブジェクトである。
  2. name が Private Name である場合、PrivateElement { [[Key]]: name, [[Kind]]: method, [[Value]]: closure } を返す。
  3. propertyDesc を PropertyDescriptor { [[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true } とする。
  4. ? DefinePropertyOrThrow(homeObj, name, propertyDesc) を実行する。
  5. 注記: DefinePropertyOrThrow が中断完了を返すのは、name が "prototype" であるクラス static メソッドを定義しようとする場合だけである。
  6. empty を返す。

10.2.9 SetFunctionName ( func, name [ , prefix ] )

抽象操作 SetFunctionName。引数 func (関数オブジェクト) および name ((プロパティキー または プライベート名))および省略可能な引数 prefix (String)。戻り値:unused。 func に "name" プロパティを追加します。 呼び出されると、次の手順を実行する。

  1. 表明: func は "name" 自身のプロパティを持たない拡張可能なオブジェクトである。
  2. name が Symbol である場合、
    1. description を name.[[Description]] とする。
    2. description が undefined である場合、name を空の String に設定する。
    3. そうでない場合、name を "["、description、および "]" の文字列連結に設定する。
  3. そうでなく、name が Private Name である場合、
    1. name を name.[[Description]] に設定する。
  4. initialName を name とする。
  5. prefix が存在する場合、
    1. prefixedName を prefix、コード単位 0x0020 (SPACE)、および name の文字列連結とする。
    2. initialName を prefixedName に設定する。
    3. Normative Optional, Legacy
      initialName を name または prefixedName のいずれかとして実装定義で選択する。
    4. name を prefixedName に設定する。
  6. func が [[InitialName]] 内部スロットを持つ場合、func.[[InitialName]] を initialName に設定する。
  7. ! DefinePropertyOrThrow(func, "name", PropertyDescriptor { [[Value]]: name, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  8. unused を返す。
注

func.[[InitialName]] に prefixedName を使用するかどうかの選択は、Function.prototype.toString ( ) の出力に影響します。手順 5.c で異なる組込み関数ごとに異なる選択を行うことは、推奨されないレガシー動作です。

10.2.10 SetFunctionLength ( func, length )

抽象操作 SetFunctionLength。引数 func (関数オブジェクト) および length ((非負整数 または +∞))。戻り値:unused。 func に "length" プロパティを追加します。 呼び出されると、次の手順を実行する。

  1. 表明: func は "length" 自身のプロパティを持たない拡張可能なオブジェクトである。
  2. ! DefinePropertyOrThrow(func, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  3. unused を返す。

10.2.11 FunctionDeclarationInstantiation ( func, argList )

抽象操作 FunctionDeclarationInstantiation。引数 func (ECMAScript 関数オブジェクト) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(正常完了 (値:unused) または throw 完了)。 func は、実行コンテキストが確立されている関数オブジェクトです。

注

ECMAScript 関数を評価するための実行コンテキストが確立されると、新しい Function Environment Record が作成され、各仮引数の束縛がその Environment Record にインスタンス化されます。関数本体内の各宣言もインスタンス化されます。関数の仮引数に既定値初期化子が含まれていない場合、本体の宣言は引数と同じ Environment Record にインスタンス化されます。既定値の引数初期化子が存在する場合、本体の宣言のために2つ目の Environment Record が作成されます。仮引数と関数は FunctionDeclarationInstantiation の一部として初期化されます。その他すべての束縛は、関数本体の評価中に初期化されます。

呼び出されたとき、次の手順を実行します。

  1. calleeContext を実行中の実行コンテキストとする。
  2. code を func.[[ECMAScriptCode]] とする。
  3. strict を func.[[Strict]] とする。
  4. formals を func.[[FormalParameters]] とする。
  5. paramNames を formals の BoundNames とする。
  6. paramNames に重複する項目がある場合、hasDuplicates を true とする。そうでない場合、hasDuplicates を false とする。
  7. simpleParamList を formals の IsSimpleParameterList とする。
  8. hasParamExprs を formals の ContainsExpression とする。
  9. variableNames を code の VarDeclaredNames とする。
  10. variableDecls を code の VarScopedDeclarations とする。
  11. lexicalNames を code の LexicallyDeclaredNames とする。
  12. funcNames を新しい空の List とする。
  13. funcsToInitialize を新しい空の List とする。
  14. variableDecls の各要素 variableDecl について、List の逆順で、次を行う。
    1. variableDecl が VariableDeclaration、ForBinding、BindingIdentifier のいずれでもない場合、
      1. 表明: variableDecl は FunctionDeclaration、GeneratorDeclaration、AsyncFunctionDeclaration、または AsyncGeneratorDeclaration のいずれかである。
      2. funcName を variableDecl の BoundNames の唯一の要素とする。
      3. funcNames が funcName を含まない場合、
        1. funcName を funcNames の先頭要素として挿入する。
        2. 注記: 同じ名前に複数の関数宣言がある場合、最後の宣言が使用される。
        3. variableDecl を funcsToInitialize の先頭要素として挿入する。
  15. argumentsObjNeeded を true とする。
  16. func.[[ThisMode]] が lexical である場合、
    1. 注記: アロー関数は arguments オブジェクトを持たない。
    2. argumentsObjNeeded を false に設定する。
  17. そうでなく、paramNames が "arguments" を含む場合、
    1. argumentsObjNeeded を false に設定する。
  18. そうでなく、hasParamExprs が false である場合、
    1. funcNames が "arguments" を含むか、lexicalNames が "arguments" を含む場合、
      1. argumentsObjNeeded を false に設定する。
  19. strict が true または hasParamExprs が false である場合、
    1. 注記: strict モードコード内の eval の呼出しは eval の外側から可視な新しい束縛を作成できないため、引数には単一の Environment Record だけでよい。
    2. envRecord を calleeContext の LexicalEnvironment とする。
  20. そうでない場合、
    1. 注記: 仮引数リスト内の direct eval 呼出しによって作成された束縛が、引数が宣言される環境の外側にあることを保証するため、別の Environment Record が必要である。
    2. calleeEnv を calleeContext の LexicalEnvironment とする。
    3. envRecord を NewDeclarativeEnvironment(calleeEnv) とする。
    4. 表明: calleeContext の VariableEnvironment と calleeEnv は同じ Environment Record である。
    5. calleeContext の LexicalEnvironment を envRecord に設定する。
  21. paramNames の各 String paramName について、次を行う。
    1. alreadyDeclared を ! envRecord.HasBinding(paramName) とする。
    2. 注記: 早期エラーにより、重複する引数名は、引数の既定値または rest 引数を持たない非 strict 関数においてのみ発生し得る。
    3. alreadyDeclared が false である場合、
      1. ! envRecord.CreateMutableBinding(paramName, false) を実行する。
      2. hasDuplicates が true である場合、
        1. ! envRecord.InitializeBinding(paramName, undefined) を実行する。
  22. argumentsObjNeeded が true である場合、
    1. strict が true または simpleParamList が false である場合、
      1. argumentsObj を CreateUnmappedArgumentsObject(argList) とする。
    2. そうでない場合、
      1. 注記: マップされた arguments オブジェクトは、rest 引数、引数の既定値初期化子、または分割代入された引数を持たない非 strict 関数に対してのみ提供される。
      2. argumentsObj を CreateMappedArgumentsObject(func, formals, argList, envRecord) とする。
    3. strict が true である場合、
      1. ! envRecord.CreateImmutableBinding("arguments", false) を実行する。
      2. 注記: strict モードコードでは、早期エラーによりこの束縛への代入が禁止されるため、その可変性は観測できない。
    4. そうでない場合、
      1. ! envRecord.CreateMutableBinding("arguments", false) を実行する。
    5. ! envRecord.InitializeBinding("arguments", argumentsObj) を実行する。
    6. paramBindings を paramNames と « "arguments" » のリスト連結とする。
  23. そうでない場合、
    1. paramBindings を paramNames とする。
  24. iteratorRecord を CreateListIteratorRecord(argList) とする。
  25. hasDuplicates が true である場合、
    1. usedEnv を undefined とする。
  26. そうでない場合、
    1. usedEnv を envRecord とする。
  27. 注記: 次の手順は ReturnCompletion を返すことができない。これは、式の位置でそのような完了が生じる唯一の方法は YieldExpression の使用によるものであり、これは 15.5.1 および 15.6.1 の早期エラー規則によって引数リスト内では禁止されているためである。
  28. 引数 iteratorRecord および usedEnv を指定した formals の ? IteratorBindingInitialization を実行する。
  29. hasParamExprs が false である場合、
    1. 注記: 引数とトップレベルの var には単一の Environment Record だけでよい。
    2. instantiatedVariableNames を List paramBindings のコピーとする。
    3. variableNames の各要素 name について、次を行う。
      1. instantiatedVariableNames が name を含まない場合、
        1. name を instantiatedVariableNames に追加する。
        2. ! envRecord.CreateMutableBinding(name, false) を実行する。
        3. ! envRecord.InitializeBinding(name, undefined) を実行する。
    4. variableEnv を envRecord とする。
  30. そうでない場合、
    1. 注記: 仮引数リスト内の式によって作成されたクロージャから関数本体内の宣言が見えないことを保証するため、別の Environment Record が必要である。
    2. variableEnv を NewDeclarativeEnvironment(envRecord) とする。
    3. calleeContext の VariableEnvironment を variableEnv に設定する。
    4. instantiatedVariableNames を新しい空の List とする。
    5. variableNames の各要素 name について、次を行う。
      1. instantiatedVariableNames が name を含まない場合、
        1. name を instantiatedVariableNames に追加する。
        2. ! variableEnv.CreateMutableBinding(name, false) を実行する。
        3. paramBindings が name を含まないか、funcNames が name を含む場合、
          1. initialValue を undefined とする。
        4. そうでない場合、
          1. initialValue を ! envRecord.GetBindingValue(name, false) とする。
        5. ! variableEnv.InitializeBinding(name, initialValue) を実行する。
        6. 注記: 仮引数と同じ名前を持つ var は、初期状態では対応する初期化済み引数と同じ値を持つ。
  31. strict が true である場合、
    1. lexicalEnv を variableEnv とする。
  32. そうでない場合、
    1. Normative Optional
      ホストが Web ブラウザーであるか、その他の方法で ブロックレベル関数宣言の Web Legacy 互換性意味論 をサポートする場合、
      1. code Contains x が true であるような任意の Block、CaseClause、または DefaultClause x の StatementList に直接含まれる各 FunctionDeclaration funcDecl について、次を行う。
        1. funcName を funcDecl の BindingIdentifier の StringValue とする。
        2. FunctionDeclaration funcDecl を、BindingIdentifier として funcName を持つ VariableStatement に置換しても func に対する早期エラーが生成されず、かつ paramNames が funcName を含まない場合、
          1. 注記: funcName の var 束縛は、それが VarDeclaredName、仮引数の名前、または別の FunctionDeclaration の名前のいずれでもない場合にのみ、ここでインスタンス化される。
          2. instantiatedVariableNames が funcName を含まず、funcName が "arguments" でない場合、
            1. ! variableEnv.CreateMutableBinding(funcName, false) を実行する。
            2. ! variableEnv.InitializeBinding(funcName, undefined) を実行する。
            3. funcName を instantiatedVariableNames に追加する。
          3. FunctionDeclaration funcDecl が評価されるとき、15.2.6 で提供される FunctionDeclaration Evaluation アルゴリズムの代わりに、次の手順を実行する。
            1. funcEnv を実行中の実行コンテキストの VariableEnvironment とする。
            2. blockEnv を実行中の実行コンテキストの LexicalEnvironment とする。
            3. funcObj を ! blockEnv.GetBindingValue(funcName, false) とする。
            4. ! funcEnv.SetMutableBinding(funcName, funcObj, false) を実行する。
            5. unused を返す。
    2. lexicalEnv を NewDeclarativeEnvironment(variableEnv) とする。
    3. 注記: 非 strict 関数はトップレベルのレキシカル宣言に別個の Environment Record を使用する。これにより、direct eval は eval コードによって導入された var スコープ宣言が、既存のトップレベルのレキシカルスコープ宣言と競合するかどうかを判定できる。strict direct eval は常にすべての宣言を新しい Environment Record に配置するため、strict 関数ではこれは不要である。
  33. calleeContext の LexicalEnvironment を lexicalEnv に設定する。
  34. lexicalDecls を code の LexicallyScopedDeclarations とする。
  35. lexicalDecls の各要素 lexicalDecl について、次を行う。
    1. 注記: レキシカル宣言された名前は、関数/ジェネレーター宣言、仮引数、または var 名と同じにはなれない。レキシカル宣言された名前は、ここではインスタンス化されるだけで初期化されない。
    2. lexicalDecl の BoundNames の各要素 name について、次を行う。
      1. lexicalDecl の IsConstantDeclaration が true である場合、
        1. ! lexicalEnv.CreateImmutableBinding(name, true) を実行する。
      2. そうでない場合、
        1. ! lexicalEnv.CreateMutableBinding(name, false) を実行する。
  36. privateEnv を calleeContext の PrivateEnvironment とする。
  37. funcsToInitialize の各 Parse Node funcDecl について、次を行う。
    1. funcName を funcDecl の BoundNames の唯一の要素とする。
    2. funcObj を、引数 lexicalEnv および privateEnv を指定した funcDecl の InstantiateFunctionObject とする。
    3. ! variableEnv.SetMutableBinding(funcName, funcObj, false) を実行する。
  38. unused を返す。

10.3 組込み関数オブジェクト

組込み関数オブジェクトは通常オブジェクトであり、10.1 で規定される通常オブジェクトの要件を満たさなければなりません。

すべての通常オブジェクトに必要な内部スロット(10.1 を参照)に加えて、組込み関数オブジェクトは次の内部スロットも持たなければなりません。

  • [[Realm]]。関数が作成された Realm を表す Realm Record。
  • [[InitialName]]。関数の初期名である String。20.2.3.5 によって使用されます。
  • [[Async]]。BuiltinCallOrConstruct において、その関数が async 関数の呼出しおよび構築動作を持つかどうかを示す Boolean。

特に指定されていない限り、組込み関数オブジェクトの [[Prototype]] 内部スロットの初期値は %Function.prototype% です。

組込み関数オブジェクトは、10.3.1 の定義に適合する [[Call]] 内部メソッドを持たなければなりません。

組込み関数オブジェクトが [[Construct]] 内部メソッドを持つのは、それが「constructor」と記述されている場合、またはこの仕様内の何らかのアルゴリズムがその [[Construct]] 内部メソッドを明示的に設定する場合に限ります。そのような [[Construct]] 内部メソッドは、10.3.2 の定義に適合しなければなりません。

実装は、この仕様で定義されていない追加の組込み関数オブジェクトを提供してもかまいません。

10.3.1 [[Call]] ( thisArg, argList )

a built-in function object funcの内部メソッド [[Call]]。引数 thisArg (ECMAScript 言語値) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? BuiltinCallOrConstruct(func, thisArg, argList, undefined) を返す。

10.3.2 [[Construct]] ( argList, newTarget )

a built-in function object func (when the method is present)の内部メソッド [[Construct]]。引数 argList (リスト (要素:ECMAScript 言語値)) および newTarget (コンストラクター)。戻り値:(正常完了 (値:Object) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. result を ? BuiltinCallOrConstruct(func, uninitialized, argList, newTarget) とする。
  2. 表明: result は Object である。
  3. result を返す。

10.3.3 BuiltinCallOrConstruct ( func, thisArg, argList, newTarget )

抽象操作 BuiltinCallOrConstruct。引数 func (組込み関数オブジェクト)、thisArg ((ECMAScript 言語値 または uninitialized))、argList (リスト (要素:ECMAScript 言語値)) および newTarget ((コンストラクター または undefined))。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. callerContext を実行中の実行コンテキストとする。
  2. callerContext がまだ中断されていない場合、callerContext を中断する。
  3. calleeContext を新しい実行コンテキストとする。
  4. calleeContext の Function を func に設定する。
  5. calleeRealm を func.[[Realm]] とする。
  6. calleeContext の Realm を calleeRealm に設定する。
  7. calleeContext の ScriptOrModule を null に設定する。
  8. calleeContext に必要な実装定義の初期化を実行する。
  9. calleeContext を実行コンテキストスタックにプッシュする。これで calleeContext が実行中の実行コンテキストになる。
  10. func.[[Async]] が true である場合、
    1. promiseCapability を ! NewPromiseCapability(%Promise%) とする。
    2. resultsClosure を、パラメーターを持たず、func、thisArg、argList、および newTarget を捕捉し、呼び出されたときに次の手順を実行する新しい Abstract Closure とする。
      1. result を、func の仕様に適合する方法で func を評価した結果である Completion Record とする。thisArg が uninitialized である場合、this 値は初期化されていない。そうでない場合、thisArg が this 値を提供する。argList が名前付きパラメーターを提供する。newTarget が NewTarget 値を提供する。
      2. 注記: func がこの文書で定義されている場合、「func の仕様」とは、アルゴリズム手順またはその他の手段によって規定されたその動作である。
      3. Completion(result) を返す。
    3. AsyncFunctionStart(promiseCapability, resultsClosure) を実行する。
    4. calleeContext を実行コンテキストスタックから削除し、callerContext を実行中の実行コンテキストとして復元する。
    5. promiseCapability.[[Promise]] を返す。
  11. result を、func の仕様に適合する方法で func を評価した結果である Completion Record とする。thisArg が uninitialized である場合、this 値は初期化されていない。そうでない場合、thisArg が this 値を提供する。argList が名前付きパラメーターを提供する。newTarget が NewTarget 値を提供する。
  12. 注記: func がこの文書で定義されている場合、「func の仕様」とは、アルゴリズム手順またはその他の手段によって規定されたその動作である。
  13. calleeContext を実行コンテキストスタックから削除し、callerContext を実行中の実行コンテキストとして復元する。
  14. ? result を返す。
注

calleeContext が実行コンテキストスタックから削除されるとき、それが中断され、アクセス可能な Generator による後の再開のため保持されている場合には、破棄してはなりません。

10.3.4 CreateBuiltinFunction ( behaviour, length, name, additionalInternalSlotsList [ , realm [ , proto [ , prefix [ , async ] ] ] ] )

抽象操作 CreateBuiltinFunction。引数 behaviour ((抽象クロージャ、a set of algorithm steps または some other definition of a function's behaviour provided in this specification))、length ((非負整数 または +∞))、name ((プロパティキー または プライベート名)) および additionalInternalSlotsList (リスト (要素:内部スロット名))および省略可能な引数 realm (Realmレコード)、proto ((Object または null))、prefix (String) および async (Boolean)。戻り値:組込み関数オブジェクト。 additionalInternalSlotsList には、オブジェクトの一部として定義しなければならない追加の内部スロット名が含まれます。この操作は組込み関数オブジェクトを作成します。 呼び出されると、次の手順を実行する。

  1. realm が存在しない場合、realm を現在の Realm Record に設定する。
  2. proto が存在しない場合、proto を realm.[[Intrinsics]].[[%Function.prototype%]] に設定する。
  3. async が存在しない場合、async を false に設定する。
  4. internalSlotsList を、これから作成される組込み関数オブジェクトについて 10.3 が要求するすべての内部スロット名を含む List とする。
  5. additionalInternalSlotsList の要素を internalSlotsList に追加する。
  6. func を新しい組込み関数オブジェクトとする。このオブジェクトは呼び出されると、提供された引数を behaviour で規定された対応するパラメーターの値として使用して、behaviour によって記述された動作を実行する。新しい関数オブジェクトは、名前が internalSlotsList の要素である内部スロットと、[[InitialName]] 内部スロットを持つ。
  7. func.[[Async]] を async に設定する。
  8. func.[[Prototype]] を proto に設定する。
  9. func.[[Extensible]] を true に設定する。
  10. func.[[Realm]] を realm に設定する。
  11. func.[[InitialName]] を null に設定する。
  12. SetFunctionLength(func, length) を実行する。
  13. prefix が存在しない場合、
    1. SetFunctionName(func, name) を実行する。
  14. そうでない場合、
    1. SetFunctionName(func, name, prefix) を実行する。
  15. func を返す。

この仕様で定義される各組込み関数は、CreateBuiltinFunction 抽象操作を呼び出すことによって作成されます。

10.4 組込み特殊オブジェクトの内部メソッドとスロット

この仕様では、いくつかの種類の組込み特殊オブジェクトを定義します。これらのオブジェクトは、いくつかの特定の状況を除いて、通常オブジェクトと概ね同様に動作します。以下の特殊オブジェクトは、以下で明示的に別途規定されている場合を除き、通常オブジェクトの内部メソッドを使用します。

10.4.1 束縛関数特殊オブジェクト

束縛関数特殊オブジェクトは、別の関数オブジェクトをラップする特殊オブジェクトです。束縛関数特殊オブジェクトは呼出し可能です([[Call]] 内部メソッドを持ち、[[Construct]] 内部メソッドを持つ場合があります)。束縛関数特殊オブジェクトを呼び出すと、通常はそれがラップしている関数が呼び出されます。

オブジェクトの [[Call]] および(該当する場合)[[Construct]] 内部メソッドが以下の実装を使用し、その他の必須内部メソッドが 10.1 にある定義を使用する場合、そのオブジェクトは 束縛関数特殊オブジェクトです。これらのメソッドは BoundFunctionCreate でインストールされます。

束縛関数特殊オブジェクトは、表 26 に列挙された ECMAScript 関数オブジェクトの内部スロットを持ちません。その代わり、[[Prototype]] および [[Extensible]] に加えて、表 27 に列挙される内部スロットを持ちます。

表 27: 束縛関数特殊オブジェクトの内部スロット
内部スロット 型 説明
[[BoundTargetFunction]] a callable Object ラップされる関数オブジェクトです。
[[BoundThis]] an ECMAScript language value ラップされた関数を呼び出すときに常に this 値として渡される値です。
[[BoundArguments]] a List of ECMAScript language values ラップされた関数の任意の呼出しに対する先頭の引数として使用される値を要素とする List です。

10.4.1.1 [[Call]] ( thisArg, argList )

a bound function exotic object funcの内部メソッド [[Call]]。引数 thisArg (ECMAScript 言語値) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. target を func.[[BoundTargetFunction]] とする。
  2. boundThis を func.[[BoundThis]] とする。
  3. boundArgs を func.[[BoundArguments]] とする。
  4. args を boundArgs と argList のリスト連結とする。
  5. ? Call(target, boundThis, args) を返す。

10.4.1.2 [[Construct]] ( argList, newTarget )

a bound function exotic object funcの内部メソッド [[Construct]]。引数 argList (リスト (要素:ECMAScript 言語値)) および newTarget (コンストラクター)。戻り値:(正常完了 (値:Object) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. target を func.[[BoundTargetFunction]] とする。
  2. 表明: IsConstructor(target) は true である。
  3. boundArgs を func.[[BoundArguments]] とする。
  4. args を boundArgs と argList のリスト連結とする。
  5. SameValue(func, newTarget) が true である場合、newTarget を target に設定する。
  6. ? Construct(target, args, newTarget) を返す。

10.4.1.3 BoundFunctionCreate ( targetFunc, boundThis, boundArgs )

抽象操作 BoundFunctionCreate。引数 targetFunc (関数オブジェクト)、boundThis (ECMAScript 言語値) および boundArgs (リスト (要素:ECMAScript 言語値))。戻り値:(正常完了 (値:関数オブジェクト) または throw 完了)。 新しい束縛関数特殊オブジェクトの作成を規定するために使用されます。 呼び出されると、次の手順を実行する。

  1. proto を ? targetFunc.[[GetPrototypeOf]]() とする。
  2. internalSlotsList を « [[Prototype]], [[Extensible]] » と 表 27 に列挙される内部スロットのリスト連結とする。
  3. obj を MakeBasicObject(internalSlotsList) とする。
  4. obj.[[Prototype]] を proto に設定する。
  5. obj.[[Call]] を 10.4.1.1 で規定されるとおりに設定する。
  6. IsConstructor(targetFunc) が true である場合、
    1. obj.[[Construct]] を 10.4.1.2 で規定されるとおりに設定する。
  7. obj.[[BoundTargetFunction]] を targetFunc に設定する。
  8. obj.[[BoundThis]] を boundThis に設定する。
  9. obj.[[BoundArguments]] を boundArgs に設定する。
  10. obj を返す。

10.4.2 Array 特殊オブジェクト

Array は、配列インデックスのプロパティキー(6.1.7 を参照)を特別に扱う特殊オブジェクトです。プロパティ名が配列インデックスであるプロパティは要素とも呼ばれます。すべての Array は構成不可の "length" プロパティを持ち、その値は常に数学的値が 232 より厳密に小さい非負の整数 Number です。"length" プロパティの値は、名前が配列インデックスであるすべての自身のプロパティ名より数値的に大きくなります。Array の自身のプロパティが作成または変更されるたびに、この不変条件を維持するため、必要に応じて他のプロパティが調整されます。具体的には、名前が配列インデックスである自身のプロパティが追加されるたびに、必要であれば "length" プロパティの値がその配列インデックスの数値より1大きい値に変更されます。また、"length" プロパティの値が変更されるたびに、新しい長さ以上の値を持つ配列インデックス名の自身のプロパティはすべて削除されます。この制約は Array 自身のプロパティにのみ適用され、そのプロトタイプから継承される可能性がある "length" または配列インデックスプロパティの影響を受けません。

オブジェクトの [[DefineOwnProperty]] 内部メソッドが以下の実装を使用し、その他の必須内部メソッドが 10.1 にある定義を使用する場合、そのオブジェクトは Array 特殊オブジェクト(または単に Array)です。これらのメソッドは ArrayCreate でインストールされます。

10.4.2.1 [[DefineOwnProperty]] ( propertyKey, propertyDesc )

an Array exotic object arrayの内部メソッド [[DefineOwnProperty]]。引数 propertyKey (プロパティキー) および propertyDesc (プロパティ記述子)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyKey が "length" である場合、? ArraySetLength(array, propertyDesc) を返す。
  2. propertyKey が配列インデックスである場合、
    1. lengthDesc を OrdinaryGetOwnProperty(array, "length") とする。
    2. 表明: lengthDesc は undefined ではない。
    3. 表明: IsDataDescriptor(lengthDesc) は true である。
    4. 表明: lengthDesc.[[Configurable]] は false である。
    5. length を lengthDesc.[[Value]] とする。
    6. 表明: length は非負の整数 Number である。
    7. index を ! ToUint32(propertyKey) とする。
    8. index ≥ length かつ lengthDesc.[[Writable]] が false である場合、false を返す。
    9. succeeded を ! OrdinaryDefineOwnProperty(array, propertyKey, propertyDesc) とする。
    10. succeeded が false である場合、false を返す。
    11. index ≥ length である場合、
      1. lengthDesc.[[Value]] を index + 1𝔽 に設定する。
      2. succeeded を ! OrdinaryDefineOwnProperty(array, "length", lengthDesc) に設定する。
      3. 表明: succeeded は true である。
    12. true を返す。
  3. ? OrdinaryDefineOwnProperty(array, propertyKey, propertyDesc) を返す。

10.4.2.2 ArrayCreate ( length [ , proto ] )

抽象操作 ArrayCreate。引数 length (非負整数)および省略可能な引数 proto (Object)。戻り値:(正常完了 (値:Arrayエキゾチックオブジェクト) または throw 完了)。 新しい Array の作成を規定するために使用されます。 呼び出されると、次の手順を実行する。

  1. length > 232 - 1 である場合、RangeError 例外をスローする。
  2. proto が存在しない場合、proto を %Array.prototype% に設定する。
  3. array を MakeBasicObject(« [[Prototype]], [[Extensible]] ») とする。
  4. array.[[Prototype]] を proto に設定する。
  5. array.[[DefineOwnProperty]] を 10.4.2.1 で規定されるとおりに設定する。
  6. ! OrdinaryDefineOwnProperty(array, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  7. array を返す。

10.4.2.3 ArraySpeciesCreate ( originalArray, length )

抽象操作 ArraySpeciesCreate。引数 originalArray (Object) および length (非負整数)。戻り値:(正常完了 (値:Object) または throw 完了)。 originalArray から派生したコンストラクター関数を使用して、新しい Array または類似オブジェクトを作成することを規定するために使用されます。コンストラクター関数が Array を返すことは強制しません。 呼び出されると、次の手順を実行する。

  1. isArray を ? IsArray(originalArray) とする。
  2. isArray が false である場合、? ArrayCreate(length) を返す。
  3. ctor を ? Get(originalArray, "constructor") とする。
  4. IsConstructor(ctor) が true である場合、
    1. thisRealm を現在の Realm Record とする。
    2. ctorRealm を ? GetFunctionRealm(ctor) とする。
    3. thisRealm と ctorRealm が同じ Realm Record でない場合、
      1. SameValue(ctor, ctorRealm.[[Intrinsics]].[[%Array%]]) が true である場合、ctor を undefined に設定する。
  5. ctor が Object である場合、
    1. ctor を ? Get(ctor, %Symbol.species%) に設定する。
    2. ctor が null である場合、ctor を undefined に設定する。
  6. ctor が undefined である場合、? ArrayCreate(length) を返す。
  7. IsConstructor(ctor) が false である場合、TypeError 例外をスローする。
  8. ? Construct(ctor, « 𝔽(length) ») を返す。
注

originalArray が実行中の実行コンテキストの Realm ではない Realm の標準組込み Array コンストラクターを使用して作成された場合、新しい Array は実行中の実行コンテキストの Realm を使用して作成されます。これにより、現在 ArraySpeciesCreate を使用して定義されている Array.prototype メソッドについて、歴史的にその動作を持っていた Web ブラウザーとの互換性が維持されます。

10.4.2.4 ArraySetLength ( array, propertyDesc )

抽象操作 ArraySetLength。引数 array (Array) および propertyDesc (プロパティ記述子)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyDesc が [[Value]] フィールドを持たない場合、
    1. ! OrdinaryDefineOwnProperty(array, "length", propertyDesc) を返す。
  2. newLengthDesc を propertyDesc のコピーとする。
  3. newLength を ? ToUint32(propertyDesc.[[Value]]) とする。
  4. numberLength を ? ToNumber(propertyDesc.[[Value]]) とする。
  5. SameValueZero(newLength, numberLength) が false である場合、RangeError 例外をスローする。
  6. newLengthDesc.[[Value]] を newLength に設定する。
  7. oldLengthDesc を OrdinaryGetOwnProperty(array, "length") とする。
  8. 表明: oldLengthDesc は undefined ではない。
  9. 表明: IsDataDescriptor(oldLengthDesc) は true である。
  10. 表明: oldLengthDesc.[[Configurable]] は false である。
  11. oldLength を oldLengthDesc.[[Value]] とする。
  12. newLength ≥ oldLength である場合、
    1. ! OrdinaryDefineOwnProperty(array, "length", newLengthDesc) を返す。
  13. oldLengthDesc.[[Writable]] が false である場合、false を返す。
  14. newLengthDesc が [[Writable]] フィールドを持たないか、newLengthDesc.[[Writable]] が true である場合、
    1. newWritable を true とする。
  15. そうでない場合、
    1. 注記: 要素を削除できない場合に備え、[[Writable]] 属性を false に設定するのを遅延する。
    2. newWritable を false とする。
    3. newLengthDesc.[[Writable]] を true に設定する。
  16. succeeded を ! OrdinaryDefineOwnProperty(array, "length", newLengthDesc) とする。
  17. succeeded が false である場合、false を返す。
  18. array の自身のプロパティキー propertyKey のうち、propertyKey が配列インデックスであり、! ToUint32(propertyKey) ≥ newLength であるものについて、数値インデックスの降順で、次を行う。
    1. deleteSucceeded を ! array.[[Delete]](propertyKey) とする。
    2. deleteSucceeded が false である場合、
      1. newLengthDesc.[[Value]] を ! ToUint32(propertyKey) + 1𝔽 に設定する。
      2. newWritable が false である場合、newLengthDesc.[[Writable]] を false に設定する。
      3. ! OrdinaryDefineOwnProperty(array, "length", newLengthDesc) を実行する。
      4. false を返す。
  19. newWritable が false である場合、
    1. succeeded を ! OrdinaryDefineOwnProperty(array, "length", PropertyDescriptor { [[Writable]]: false }) に設定する。
    2. 表明: succeeded は true である。
  20. true を返す。
注

手順 3 および 4 において、propertyDesc.[[Value]] がオブジェクトである場合、その valueOf メソッドは2回呼び出されます。これは、この仕様の第2版からこの効果を持つものとして規定されているレガシー動作です。

10.4.3 String 特殊オブジェクト

String オブジェクトは、String 値をカプセル化し、その String 値の個々のコード単位要素に対応する仮想的な整数インデックス付きデータプロパティを公開する特殊オブジェクトです。String 特殊オブジェクトは常に "length" という名前のデータプロパティを持ち、その値はカプセル化された String 値の長さです。コード単位データプロパティと "length" プロパティはどちらも書込み不可かつ構成不可です。

オブジェクトの [[GetOwnProperty]]、[[DefineOwnProperty]]、および [[OwnPropertyKeys]] 内部メソッドが以下の実装を使用し、その他の必須内部メソッドが 10.1 にある定義を使用する場合、そのオブジェクトは String 特殊オブジェクト(または単に String オブジェクト)です。これらのメソッドは StringCreate でインストールされます。

String 特殊オブジェクトは通常オブジェクトと同じ内部スロットを持ちます。さらに [[StringData]] 内部スロットも持ちます。

10.4.3.1 [[GetOwnProperty]] ( propertyKey )

a String exotic object stringの内部メソッド [[GetOwnProperty]]。引数 propertyKey (プロパティキー)。戻り値:正常完了 (値:(プロパティ記述子 または undefined))。 呼び出されると、次の手順を実行する。

  1. propertyDesc を OrdinaryGetOwnProperty(string, propertyKey) とする。
  2. propertyDesc が undefined でない場合、propertyDesc を返す。
  3. StringGetOwnProperty(string, propertyKey) を返す。

10.4.3.2 [[DefineOwnProperty]] ( propertyKey, propertyDesc )

a String exotic object stringの内部メソッド [[DefineOwnProperty]]。引数 propertyKey (プロパティキー) および propertyDesc (プロパティ記述子)。戻り値:正常完了 (値:Boolean)。 呼び出されると、次の手順を実行する。

  1. stringDesc を StringGetOwnProperty(string, propertyKey) とする。
  2. stringDesc が undefined でない場合、
    1. extensible を string.[[Extensible]] とする。
    2. IsCompatiblePropertyDescriptor(extensible, propertyDesc, stringDesc) を返す。
  3. ! OrdinaryDefineOwnProperty(string, propertyKey, propertyDesc) を返す。

10.4.3.3 [[OwnPropertyKeys]] ( )

a String exotic object objの内部メソッド [[OwnPropertyKeys]]。引数なし。戻り値:正常完了 (値:リスト (要素:プロパティキー))。 呼び出されると、次の手順を実行する。

  1. keys を新しい空の List とする。
  2. string を obj.[[StringData]] とする。
  3. 表明: string は String である。
  4. length を string の長さとする。
  5. 0 ≤ i < length を満たす各整数 i について、昇順で、次を行う。
    1. ! ToString(𝔽(i)) を keys に追加する。
  6. obj の自身のプロパティキー propertyKey のうち、propertyKey が配列インデックスであり、! ToIntegerOrInfinity(propertyKey) ≥ length であるものについて、数値インデックスの昇順で、次を行う。
    1. propertyKey を keys に追加する。
  7. obj の自身のプロパティキー propertyKey のうち、propertyKey が String であり配列インデックスではないものについて、プロパティ作成時刻の昇順で、次を行う。
    1. propertyKey を keys に追加する。
  8. obj の自身のプロパティキー propertyKey のうち、propertyKey が Symbol であるものについて、プロパティ作成時刻の昇順で、次を行う。
    1. propertyKey を keys に追加する。
  9. keys を返す。

10.4.3.4 StringCreate ( value, proto )

抽象操作 StringCreate。引数 value (String) および proto (Object)。戻り値:Stringエキゾチックオブジェクト。 新しい String 特殊オブジェクトの作成を規定するために使用されます。 呼び出されると、次の手順を実行する。

  1. string を MakeBasicObject(« [[Prototype]], [[Extensible]], [[StringData]] ») とする。
  2. string.[[Prototype]] を proto に設定する。
  3. string.[[StringData]] を value に設定する。
  4. string.[[GetOwnProperty]] を 10.4.3.1 で規定されるとおりに設定する。
  5. string.[[DefineOwnProperty]] を 10.4.3.2 で規定されるとおりに設定する。
  6. string.[[OwnPropertyKeys]] を 10.4.3.3 で規定されるとおりに設定する。
  7. length を value の長さとする。
  8. ! DefinePropertyOrThrow(string, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  9. string を返す。

10.4.3.5 StringGetOwnProperty ( string, propertyKey )

抽象操作 StringGetOwnProperty。引数 string (Stringエキゾチックオブジェクト) および propertyKey (プロパティキー)。戻り値:(プロパティ記述子 または undefined)。 呼び出されると、次の手順を実行する。

  1. propertyKey が String でない場合、undefined を返す。
  2. numericIndex を CanonicalNumericIndexString(propertyKey) とする。
  3. numericIndex が整数 Number でない場合、undefined を返す。
  4. numericIndex が -0𝔽 であるか、numericIndex < -0𝔽 である場合、undefined を返す。
  5. stringData を string.[[StringData]] とする。
  6. 表明: stringData は String である。
  7. length を stringData の長さとする。
  8. ℝ(numericIndex) ≥ length である場合、undefined を返す。
  9. resultString を stringData の ℝ(numericIndex) から ℝ(numericIndex) + 1 までの部分文字列とする。
  10. PropertyDescriptor { [[Value]]: resultString, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false } を返す。

10.4.4 Arguments 特殊オブジェクト

ほとんどの ECMAScript 関数は、そのコードから arguments オブジェクトを利用できるようにします。関数定義の特性に応じて、その arguments オブジェクトは通常オブジェクトまたは arguments 特殊オブジェクトのいずれかです。arguments 特殊オブジェクトは、その配列インデックスプロパティが、関連付けられた ECMAScript 関数の呼出しの仮引数束縛に対応付けられる特殊オブジェクトです。

オブジェクトの内部メソッドが以下の実装を使用し、ここで規定されていないものについて 10.1 にある定義を使用する場合、そのオブジェクトは arguments 特殊オブジェクトです。これらのメソッドは CreateMappedArgumentsObject でインストールされます。

注 1

CreateUnmappedArgumentsObject はこの箇条にまとめられていますが、arguments 特殊オブジェクトではなく通常オブジェクトを作成します。

arguments 特殊オブジェクトは通常オブジェクトと同じ内部スロットを持ちます。さらに [[ParameterMap]] 内部スロットも持ちます。通常の arguments オブジェクトも [[ParameterMap]] 内部スロットを持ち、その値は常に undefined です。通常の arguments オブジェクトでは、[[ParameterMap]] 内部スロットは Object.prototype.toString(20.1.3.6)によってそれらを arguments オブジェクトとして識別するためだけに使用されます。

注 2

arguments 特殊オブジェクトの整数インデックス付きデータプロパティのうち、数値名の値が対応する関数オブジェクトの仮引数の数より小さいものは、初期状態では関数の実行コンテキスト内の対応する引数束縛と値を共有します。これは、そのプロパティを変更すると対応する引数束縛の値も変更され、その逆も同様であることを意味します。この対応関係は、そのようなプロパティが削除された後で再定義された場合、またはそのプロパティがアクセサープロパティに変更された場合に失われます。arguments オブジェクトが通常オブジェクトである場合、そのプロパティ値は単に関数に渡された引数のコピーであり、プロパティ値と仮引数値の間に動的な関連はありません。

注 3

ParameterMap オブジェクトとそのプロパティ値は、arguments オブジェクトと引数束縛との対応関係を規定するための仕組みとして使用されます。ParameterMap オブジェクトおよびそのプロパティ値であるオブジェクトは、ECMAScript コードから直接観測できません。ECMAScript 実装は、規定された意味論を実装するためにそのようなオブジェクトを実際に作成または使用する必要はありません。

注 4

通常の arguments オブジェクトは、"callee" という名前の構成不可のアクセサープロパティを定義し、アクセス時に TypeError 例外をスローします。"callee" プロパティは、一部の非 strict 関数クラスに対してのみ作成される arguments 特殊オブジェクトでは、より具体的な意味を持ちます。通常版でこのプロパティを定義するのは、適合する ECMAScript 実装によって他の方法で定義されないことを保証するためです。

注 5

arguments 特殊オブジェクトの ECMAScript 実装には、歴史的に "caller" という名前のアクセサープロパティが含まれていました。ECMAScript 2017 より前、この仕様には通常の arguments オブジェクト上で例外をスローする "caller" プロパティの定義が含まれていました。実装がもはやこの拡張を含まなくなったため、ECMAScript 2017 では例外をスローする "caller" アクセサーの要件が削除されました。

10.4.4.1 [[GetOwnProperty]] ( propertyKey )

an arguments exotic object argsの内部メソッド [[GetOwnProperty]]。引数 propertyKey (プロパティキー)。戻り値:正常完了 (値:(プロパティ記述子 または undefined))。 呼び出されると、次の手順を実行する。

  1. propertyDesc を OrdinaryGetOwnProperty(args, propertyKey) とする。
  2. propertyDesc が undefined である場合、undefined を返す。
  3. map を args.[[ParameterMap]] とする。
  4. isMapped を ! HasOwnProperty(map, propertyKey) とする。
  5. isMapped が true である場合、
    1. propertyDesc.[[Value]] を ! Get(map, propertyKey) に設定する。
  6. propertyDesc を返す。

10.4.4.2 [[DefineOwnProperty]] ( propertyKey, propertyDesc )

an arguments exotic object argsの内部メソッド [[DefineOwnProperty]]。引数 propertyKey (プロパティキー) および propertyDesc (プロパティ記述子)。戻り値:正常完了 (値:Boolean)。 呼び出されると、次の手順を実行する。

  1. map を args.[[ParameterMap]] とする。
  2. isMapped を ! HasOwnProperty(map, propertyKey) とする。
  3. newArgDesc を propertyDesc とする。
  4. isMapped が true かつ IsDataDescriptor(propertyDesc) が true である場合、
    1. propertyDesc が [[Value]] フィールドを持たず、propertyDesc が [[Writable]] フィールドを持ち、propertyDesc.[[Writable]] が false である場合、
      1. newArgDesc を propertyDesc のコピーに設定する。
      2. newArgDesc.[[Value]] を ! Get(map, propertyKey) に設定する。
  5. allowed を ! OrdinaryDefineOwnProperty(args, propertyKey, newArgDesc) とする。
  6. allowed が false である場合、false を返す。
  7. isMapped が true である場合、
    1. IsAccessorDescriptor(propertyDesc) が true である場合、
      1. ! map.[[Delete]](propertyKey) を実行する。
    2. そうでない場合、
      1. propertyDesc が [[Value]] フィールドを持つ場合、
        1. 表明: arguments オブジェクトによってマップされる仮引数は常に書込み可能であるため、次の Set は成功する。
        2. ! Set(map, propertyKey, propertyDesc.[[Value]], false) を実行する。
      2. propertyDesc が [[Writable]] フィールドを持ち、propertyDesc.[[Writable]] が false である場合、
        1. ! map.[[Delete]](propertyKey) を実行する。
  8. true を返す。

10.4.4.3 [[Get]] ( propertyKey, receiver )

an arguments exotic object argsの内部メソッド [[Get]]。引数 propertyKey (プロパティキー) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. map を args.[[ParameterMap]] とする。
  2. isMapped を ! HasOwnProperty(map, propertyKey) とする。
  3. isMapped が false である場合、? OrdinaryGet(args, propertyKey, receiver) を返す。
  4. 表明: map は propertyKey に対する仮引数の対応付けを含む。
  5. ! Get(map, propertyKey) を返す。

10.4.4.4 [[Set]] ( propertyKey, value, receiver )

an arguments exotic object argsの内部メソッド [[Set]]。引数 propertyKey (プロパティキー)、value (ECMAScript 言語値) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. SameValue(args, receiver) が false である場合、
    1. isMapped を false とする。
  2. そうでない場合、
    1. map を args.[[ParameterMap]] とする。
    2. isMapped を ! HasOwnProperty(map, propertyKey) とする。
  3. isMapped が true である場合、
    1. 表明: arguments オブジェクトによってマップされる仮引数は常に書込み可能であるため、次の Set は成功する。
    2. ! Set(map, propertyKey, value, false) を実行する。
  4. ? OrdinarySet(args, propertyKey, value, receiver) を返す。

10.4.4.5 [[Delete]] ( propertyKey )

an arguments exotic object argsの内部メソッド [[Delete]]。引数 propertyKey (プロパティキー)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. map を args.[[ParameterMap]] とする。
  2. isMapped を ! HasOwnProperty(map, propertyKey) とする。
  3. result を ? OrdinaryDelete(args, propertyKey) とする。
  4. result が true かつ isMapped が true である場合、
    1. ! map.[[Delete]](propertyKey) を実行する。
  5. result を返す。

10.4.4.6 CreateUnmappedArgumentsObject ( argList )

抽象操作 CreateUnmappedArgumentsObject。引数 argList (リスト (要素:ECMAScript 言語値))。戻り値:通常オブジェクト。 呼び出されると、次の手順を実行する。

  1. length を argList の要素数とする。
  2. obj を OrdinaryObjectCreate(%Object.prototype%, « [[ParameterMap]] ») とする。
  3. obj.[[ParameterMap]] を undefined に設定する。
  4. ! DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  5. index を 0 とする。
  6. index < length の間、次を繰り返す。
    1. value を argList[index] とする。
    2. ! CreateDataPropertyOrThrow(obj, ! ToString(𝔽(index)), value) を実行する。
    3. index を index + 1 に設定する。
  7. ! DefinePropertyOrThrow(obj, %Symbol.iterator%, PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  8. ! DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Getter]]: %ThrowTypeError%, [[Setter]]: %ThrowTypeError%, [[Enumerable]]: false, [[Configurable]]: false }) を実行する。
  9. obj を返す。

10.4.4.7 CreateMappedArgumentsObject ( func, formals, argList, envRecord )

抽象操作 CreateMappedArgumentsObject。引数 func (ECMAScript 関数オブジェクト)、formals (構文解析ノード)、argList (リスト (要素:ECMAScript 言語値)) および envRecord (Environmentレコード)。戻り値:argumentsエキゾチックオブジェクト。 呼び出されると、次の手順を実行する。

  1. 表明: formals は rest 引数、束縛パターン、または初期化子を含まない。重複する識別子を含む場合がある。
  2. length を argList の要素数とする。
  3. obj を MakeBasicObject(« [[Prototype]], [[Extensible]], [[ParameterMap]] ») とする。
  4. obj.[[GetOwnProperty]] を 10.4.4.1 で規定されるとおりに設定する。
  5. obj.[[DefineOwnProperty]] を 10.4.4.2 で規定されるとおりに設定する。
  6. obj.[[Get]] を 10.4.4.3 で規定されるとおりに設定する。
  7. obj.[[Set]] を 10.4.4.4 で規定されるとおりに設定する。
  8. obj.[[Delete]] を 10.4.4.5 で規定されるとおりに設定する。
  9. obj.[[Prototype]] を %Object.prototype% に設定する。
  10. map を OrdinaryObjectCreate(null) とする。
  11. obj.[[ParameterMap]] を map に設定する。
  12. paramNames を formals の BoundNames とする。
  13. paramCount を paramNames の要素数とする。
  14. index を 0 とする。
  15. index < length の間、次を繰り返す。
    1. value を argList[index] とする。
    2. ! CreateDataPropertyOrThrow(obj, ! ToString(𝔽(index)), value) を実行する。
    3. index を index + 1 に設定する。
  16. ! DefinePropertyOrThrow(obj, "length", PropertyDescriptor { [[Value]]: 𝔽(length), [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  17. mappedNames を新しい空の List とする。
  18. index を paramCount - 1 に設定する。
  19. index ≥ 0 の間、次を繰り返す。
    1. name を paramNames[index] とする。
    2. mappedNames が name を含まない場合、
      1. name を mappedNames に追加する。
      2. index < length である場合、
        1. getter を MakeArgGetter(name, envRecord) とする。
        2. setter を MakeArgSetter(name, envRecord) とする。
        3. ! map.[[DefineOwnProperty]](! ToString(𝔽(index)), PropertyDescriptor { [[Setter]]: setter, [[Getter]]: getter, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
    3. index を index - 1 に設定する。
  20. ! DefinePropertyOrThrow(obj, %Symbol.iterator%, PropertyDescriptor { [[Value]]: %Array.prototype.values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  21. ! DefinePropertyOrThrow(obj, "callee", PropertyDescriptor { [[Value]]: func, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }) を実行する。
  22. obj を返す。

10.4.4.7.1 MakeArgGetter ( name, envRecord )

抽象操作 MakeArgGetter。引数 name (String) および envRecord (Environmentレコード)。戻り値:関数オブジェクト。 実行されると envRecord 内で name に束縛されている値を返す組込み関数オブジェクトを作成します。 呼び出されると、次の手順を実行する。

  1. getterClosure を、パラメーターを持たず、name および envRecord を捕捉し、呼び出されたときに次の手順を実行する新しい Abstract Closure とする。
    1. NormalCompletion(! envRecord.GetBindingValue(name, false)) を返す。
  2. getter を CreateBuiltinFunction(getterClosure, 0, "", « ») とする。
  3. 注記: getter は ECMAScript コードから直接アクセスされることはない。
  4. getter を返す。

10.4.4.7.2 MakeArgSetter ( name, envRecord )

抽象操作 MakeArgSetter。引数 name (String) および envRecord (Environmentレコード)。戻り値:関数オブジェクト。 実行されると envRecord 内で name に束縛されている値を設定する組込み関数オブジェクトを作成します。 呼び出されると、次の手順を実行する。

  1. setterClosure を、パラメーター (value) を持ち、name および envRecord を捕捉し、呼び出されたときに次の手順を実行する新しい Abstract Closure とする。
    1. NormalCompletion(! envRecord.SetMutableBinding(name, value, false)) を返す。
  2. setter を CreateBuiltinFunction(setterClosure, 1, "", « ») とする。
  3. 注記: setter は ECMAScript コードから直接アクセスされることはない。
  4. setter を返す。

10.4.5 TypedArray 特殊オブジェクト

TypedArray は、正準数値文字列であるプロパティキーを特別に処理する特殊オブジェクトです。そのうち範囲内の整数インデックスを、一様な型の要素へのインデックスとして使用し、残りについてはプロトタイプチェーンを走査することなく存在しないという不変条件を強制します。

注

任意の Number n に対する ToString(n) は正準数値文字列であるため、実装は実際に文字列変換を実行せずに Number を TypedArray のプロパティキーとして扱ってもかまいません。

TypedArray は通常オブジェクトと同じ内部スロットを持ち、さらに [[ViewedArrayBuffer]]、[[TypedArrayName]]、[[ContentType]]、[[ByteLength]]、[[ByteOffset]]、および [[ArrayLength]] 内部スロットを持ちます。

オブジェクトの [[PreventExtensions]]、[[GetOwnProperty]]、[[HasProperty]]、[[DefineOwnProperty]]、[[Get]]、[[Set]]、[[Delete]]、および [[OwnPropertyKeys]] 内部メソッドがこの節の定義を使用し、その他の必須内部メソッドが 10.1 にある定義を使用する場合、そのオブジェクトは TypedArray です。これらのメソッドは TypedArrayCreate によってインストールされます。

10.4.5.1 [[PreventExtensions]] ( )

a TypedArray objの内部メソッド [[PreventExtensions]]。引数なし。戻り値:正常完了 (値:Boolean)。 呼び出されると、次の手順を実行する。

  1. 注記: 6.1.7.3 で規定される拡張可能性に関する不変条件では、obj がプロパティを獲得する(または失った後で再獲得する)可能性がある場合、このメソッドが true を返すことは許されない。これは、基盤となるバッファがサイズ変更されたとき、整数インデックス名を持つプロパティについて発生する可能性がある。
  2. IsTypedArrayFixedLength(obj) が false である場合、false を返す。
  3. OrdinaryPreventExtensions(obj) を返す。

10.4.5.2 [[GetOwnProperty]] ( propertyKey )

a TypedArray objの内部メソッド [[GetOwnProperty]]。引数 propertyKey (プロパティキー)。戻り値:正常完了 (値:(プロパティ記述子 または undefined))。 呼び出されると、次の手順を実行する。

  1. propertyKey が String である場合、
    1. numericIndex を CanonicalNumericIndexString(propertyKey) とする。
    2. numericIndex が undefined でない場合、
      1. value を TypedArrayGetElement(obj, numericIndex) とする。
      2. value が undefined である場合、undefined を返す。
      3. PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true } を返す。
  2. OrdinaryGetOwnProperty(obj, propertyKey) を返す。

10.4.5.3 [[HasProperty]] ( propertyKey )

a TypedArray objの内部メソッド [[HasProperty]]。引数 propertyKey (プロパティキー)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyKey が String である場合、
    1. numericIndex を CanonicalNumericIndexString(propertyKey) とする。
    2. numericIndex が undefined でない場合、IsValidIntegerIndex(obj, numericIndex) を返す。
  2. ? OrdinaryHasProperty(obj, propertyKey) を返す。

10.4.5.4 [[DefineOwnProperty]] ( propertyKey, propertyDesc )

a TypedArray objの内部メソッド [[DefineOwnProperty]]。引数 propertyKey (プロパティキー) および propertyDesc (プロパティ記述子)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyKey が String である場合、
    1. numericIndex を CanonicalNumericIndexString(propertyKey) とする。
    2. numericIndex が undefined でない場合、
      1. IsValidIntegerIndex(obj, numericIndex) が false である場合、false を返す。
      2. propertyDesc が [[Configurable]] フィールドを持ち、propertyDesc.[[Configurable]] が false である場合、false を返す。
      3. propertyDesc が [[Enumerable]] フィールドを持ち、propertyDesc.[[Enumerable]] が false である場合、false を返す。
      4. IsAccessorDescriptor(propertyDesc) が true である場合、false を返す。
      5. propertyDesc が [[Writable]] フィールドを持ち、propertyDesc.[[Writable]] が false である場合、false を返す。
      6. propertyDesc が [[Value]] フィールドを持つ場合、? TypedArraySetElement(obj, numericIndex, propertyDesc.[[Value]]) を実行する。
      7. true を返す。
  2. ! OrdinaryDefineOwnProperty(obj, propertyKey, propertyDesc) を返す。

10.4.5.5 [[Get]] ( propertyKey, receiver )

a TypedArray objの内部メソッド [[Get]]。引数 propertyKey (プロパティキー) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyKey が String である場合、
    1. numericIndex を CanonicalNumericIndexString(propertyKey) とする。
    2. numericIndex が undefined でない場合、
      1. TypedArrayGetElement(obj, numericIndex) を返す。
  2. ? OrdinaryGet(obj, propertyKey, receiver) を返す。

10.4.5.6 [[Set]] ( propertyKey, value, receiver )

a TypedArray objの内部メソッド [[Set]]。引数 propertyKey (プロパティキー)、value (ECMAScript 言語値) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyKey が String である場合、
    1. numericIndex を CanonicalNumericIndexString(propertyKey) とする。
    2. numericIndex が undefined でない場合、
      1. SameValue(obj, receiver) が true である場合、
        1. ? TypedArraySetElement(obj, numericIndex, value) を実行する。
        2. true を返す。
      2. IsValidIntegerIndex(obj, numericIndex) が false である場合、true を返す。
  2. ? OrdinarySet(obj, propertyKey, value, receiver) を返す。

10.4.5.7 [[Delete]] ( propertyKey )

a TypedArray objの内部メソッド [[Delete]]。引数 propertyKey (プロパティキー)。戻り値:正常完了 (値:Boolean)。 呼び出されると、次の手順を実行する。

  1. propertyKey が String である場合、
    1. numericIndex を CanonicalNumericIndexString(propertyKey) とする。
    2. numericIndex が undefined でない場合、
      1. IsValidIntegerIndex(obj, numericIndex) が false である場合、true を返す。
      2. false を返す。
  2. ! OrdinaryDelete(obj, propertyKey) を返す。

10.4.5.8 [[OwnPropertyKeys]] ( )

a TypedArray objの内部メソッド [[OwnPropertyKeys]]。引数なし。戻り値:正常完了 (値:リスト (要素:プロパティキー))。 呼び出されると、次の手順を実行する。

  1. taRecord を MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst) とする。
  2. keys を新しい空の List とする。
  3. IsTypedArrayOutOfBounds(taRecord) が false である場合、
    1. length を TypedArrayLength(taRecord) とする。
    2. 0 ≤ i < length を満たす各整数 i について、昇順で、次を行う。
      1. ! ToString(𝔽(i)) を keys に追加する。
  4. obj の自身のプロパティキー propertyKey のうち、propertyKey が String であり整数インデックスではないものについて、プロパティ作成時刻の昇順で、次を行う。
    1. propertyKey を keys に追加する。
  5. obj の自身のプロパティキー propertyKey のうち、propertyKey が Symbol であるものについて、プロパティ作成時刻の昇順で、次を行う。
    1. propertyKey を keys に追加する。
  6. keys を返す。

10.4.5.9 TypedArray With Buffer Witness Record

TypedArray With Buffer Witness Record は、TypedArray と、その参照対象バッファのキャッシュ済みバイト長をカプセル化するために使用される Record です。参照対象バッファが拡張可能な SharedArrayBuffer である場合に、バイト長データブロックについて ReadSharedMemory イベントが1回だけ発生することを保証するために使用されます。

TypedArray With Buffer Witness Record は、表 28 に列挙されるフィールドを持ちます。

表 28: TypedArray With Buffer Witness Record のフィールド
フィールド名 値 意味
[[Object]] a TypedArray そのバッファのバイト長が読み込まれた TypedArray です。
[[CachedBufferByteLength]] a non-negative integer or detached Record が作成された時点でのオブジェクトの [[ViewedArrayBuffer]] のバイト長です。

10.4.5.10 MakeTypedArrayWithBufferWitnessRecord ( obj, order )

抽象操作 MakeTypedArrayWithBufferWitnessRecord。引数 obj (TypedArray) および order ((seq-cst または unordered))。戻り値:TypedArray With Buffer Witnessレコード。 呼び出されると、次の手順を実行する。

  1. buffer を obj.[[ViewedArrayBuffer]] とする。
  2. IsDetachedBuffer(buffer) が true である場合、
    1. byteLength を detached とする。
  3. そうでない場合、
    1. byteLength を ArrayBufferByteLength(buffer, order) とする。
  4. TypedArray With Buffer Witness Record { [[Object]]: obj, [[CachedBufferByteLength]]: byteLength } を返す。

10.4.5.11 TypedArrayCreate ( proto )

抽象操作 TypedArrayCreate。引数 proto (Object)。戻り値:TypedArray。 新しい TypedArray の作成を規定するために使用されます。 呼び出されると、次の手順を実行する。

  1. internalSlotsList を « [[Prototype]], [[Extensible]], [[ViewedArrayBuffer]], [[TypedArrayName]], [[ContentType]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] » とする。
  2. ta を MakeBasicObject(internalSlotsList) とする。
  3. ta.[[PreventExtensions]] を 10.4.5.1 で規定されるとおりに設定する。
  4. ta.[[GetOwnProperty]] を 10.4.5.2 で規定されるとおりに設定する。
  5. ta.[[HasProperty]] を 10.4.5.3 で規定されるとおりに設定する。
  6. ta.[[DefineOwnProperty]] を 10.4.5.4 で規定されるとおりに設定する。
  7. ta.[[Get]] を 10.4.5.5 で規定されるとおりに設定する。
  8. ta.[[Set]] を 10.4.5.6 で規定されるとおりに設定する。
  9. ta.[[Delete]] を 10.4.5.7 で規定されるとおりに設定する。
  10. ta.[[OwnPropertyKeys]] を 10.4.5.8 で規定されるとおりに設定する。
  11. ta.[[Prototype]] を proto に設定する。
  12. ta を返す。

10.4.5.12 TypedArrayByteLength ( taRecord )

抽象操作 TypedArrayByteLength。引数 taRecord (TypedArray With Buffer Witnessレコード)。戻り値:非負整数。 呼び出されると、次の手順を実行する。

  1. 表明: IsTypedArrayOutOfBounds(taRecord) は false である。
  2. obj を taRecord.[[Object]] とする。
  3. obj.[[ByteLength]] が auto でない場合、obj.[[ByteLength]] を返す。
  4. length を TypedArrayLength(taRecord) とする。
  5. elementSize を TypedArrayElementSize(obj) とする。
  6. 注記: 基盤となるバッファが elementSize の整数倍でないサイズに変更された場合でも、返されるバイト長は常に elementSize の整数倍である。
  7. length × elementSize を返す。

10.4.5.13 TypedArrayLength ( taRecord )

抽象操作 TypedArrayLength。引数 taRecord (TypedArray With Buffer Witnessレコード)。戻り値:非負整数。 呼び出されると、次の手順を実行する。

  1. 表明: IsTypedArrayOutOfBounds(taRecord) は false である。
  2. obj を taRecord.[[Object]] とする。
  3. obj.[[ArrayLength]] が auto でない場合、obj.[[ArrayLength]] を返す。
  4. 表明: IsFixedLengthArrayBuffer(obj.[[ViewedArrayBuffer]]) は false である。
  5. byteOffset を obj.[[ByteOffset]] とする。
  6. elementSize を TypedArrayElementSize(obj) とする。
  7. byteLength を taRecord.[[CachedBufferByteLength]] とする。
  8. 表明: byteLength は detached ではない。
  9. floor((byteLength - byteOffset) / elementSize) を返す。

10.4.5.14 IsTypedArrayOutOfBounds ( taRecord )

抽象操作 IsTypedArrayOutOfBounds。引数 taRecord (TypedArray With Buffer Witnessレコード)。戻り値:Boolean。 オブジェクトの数値プロパティのいずれかが、基盤となるバッファの範囲内に含まれないインデックスの値を参照するかどうかを検査します。 呼び出されると、次の手順を実行する。

  1. obj を taRecord.[[Object]] とする。
  2. bufferByteLength を taRecord.[[CachedBufferByteLength]] とする。
  3. IsDetachedBuffer(obj.[[ViewedArrayBuffer]]) が true である場合、
    1. 表明: bufferByteLength は detached である。
    2. true を返す。
  4. 表明: bufferByteLength は非負の整数である。
  5. byteOffsetStart を obj.[[ByteOffset]] とする。
  6. obj.[[ArrayLength]] が auto である場合、
    1. byteOffsetEnd を bufferByteLength とする。
  7. そうでない場合、
    1. elementSize を TypedArrayElementSize(obj) とする。
    2. arrayByteLength を obj.[[ArrayLength]] × elementSize とする。
    3. byteOffsetEnd を byteOffsetStart + arrayByteLength とする。
  8. 注記: [[ByteOffset]] が bufferByteLength である長さ0の TypedArray は範囲外とはみなされない。
  9. byteOffsetStart > bufferByteLength または byteOffsetEnd > bufferByteLength である場合、true を返す。
  10. false を返す。

10.4.5.15 IsTypedArrayFixedLength ( obj )

抽象操作 IsTypedArrayFixedLength。引数 obj (TypedArray)。戻り値:Boolean。 呼び出されると、次の手順を実行する。

  1. obj.[[ArrayLength]] が auto である場合、false を返す。
  2. buffer を obj.[[ViewedArrayBuffer]] とする。
  3. IsFixedLengthArrayBuffer(buffer) が false かつ IsSharedArrayBuffer(buffer) が false である場合、false を返す。
  4. true を返す。

10.4.5.16 IsValidIntegerIndex ( obj, index )

抽象操作 IsValidIntegerIndex。引数 obj (TypedArray) および index (Number)。戻り値:Boolean。 呼び出されると、次の手順を実行する。

  1. IsDetachedBuffer(obj.[[ViewedArrayBuffer]]) が true である場合、false を返す。
  2. index が整数 Number でない場合、false を返す。
  3. index が -0𝔽 であるか、index < -0𝔽 である場合、false を返す。
  4. taRecord を MakeTypedArrayWithBufferWitnessRecord(obj, unordered) とする。
  5. 注記: obj の基盤バッファが拡張可能な SharedArrayBuffer である場合、境界検査は同期操作ではない。
  6. IsTypedArrayOutOfBounds(taRecord) が true である場合、false を返す。
  7. length を TypedArrayLength(taRecord) とする。
  8. ℝ(index) ≥ length である場合、false を返す。
  9. true を返す。

10.4.5.17 TypedArrayGetElement ( obj, index )

抽象操作 TypedArrayGetElement。引数 obj (TypedArray) および index (Number)。戻り値:(Number、BigInt または undefined)。 呼び出されると、次の手順を実行する。

  1. IsValidIntegerIndex(obj, index) が false である場合、undefined を返す。
  2. offset を obj.[[ByteOffset]] とする。
  3. elementSize を TypedArrayElementSize(obj) とする。
  4. byteIndexInBuffer を (ℝ(index) × elementSize) + offset とする。
  5. elementType を TypedArrayElementType(obj) とする。
  6. GetValueFromBuffer(obj.[[ViewedArrayBuffer]], byteIndexInBuffer, elementType, true, unordered) を返す。

10.4.5.18 TypedArraySetElement ( obj, index, value )

抽象操作 TypedArraySetElement。引数 obj (TypedArray)、index (Number) および value (ECMAScript 言語値)。戻り値:(正常完了 (値:unused) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. obj.[[ContentType]] が bigint である場合、number を ? ToBigInt(value) とする。
  2. そうでない場合、number を ? ToNumber(value) とする。
  3. IsValidIntegerIndex(obj, index) が true である場合、
    1. offset を obj.[[ByteOffset]] とする。
    2. elementSize を TypedArrayElementSize(obj) とする。
    3. byteIndexInBuffer を (ℝ(index) × elementSize) + offset とする。
    4. elementType を TypedArrayElementType(obj) とする。
    5. SetValueInBuffer(obj.[[ViewedArrayBuffer]], byteIndexInBuffer, elementType, number, true, unordered) を実行する。
  4. unused を返す。
注

この操作は常に成功したように見えますが、TypedArray の末尾を越えて書き込もうとした場合、または切り離された ArrayBuffer を基盤とする TypedArray に書き込もうとした場合には効果がありません。

10.4.5.19 IsArrayBufferViewOutOfBounds ( obj )

抽象操作 IsArrayBufferViewOutOfBounds。引数 obj ((TypedArray または DataView))。戻り値:Boolean。 TypedArray の数値プロパティのいずれか、または DataView オブジェクトのメソッドが、基盤となるデータブロックの範囲内に含まれないインデックスの値を参照できるかどうかを検査します。この抽象操作は、上流仕様での利便性のために存在します。 呼び出されると、次の手順を実行する。

  1. obj が [[DataView]] 内部スロットを持つ場合、
    1. viewRecord を MakeDataViewWithBufferWitnessRecord(obj, seq-cst) とする。
    2. IsViewOutOfBounds(viewRecord) を返す。
  2. taRecord を MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst) とする。
  3. IsTypedArrayOutOfBounds(taRecord) を返す。

10.4.6 Module Namespace 特殊オブジェクト

Module Namespace 特殊オブジェクトは、ECMAScript Module からエクスポートされた束縛を公開する特殊オブジェクトです(16.2.3 を参照)。Module Namespace 特殊オブジェクトの String キー付き自身のプロパティと、Module によってエクスポートされる束縛名の間には1対1の対応関係があります。エクスポートされる束縛には、export * エクスポート項目を使用して間接的にエクスポートされる束縛も含まれます。String 値を持つ各自身のプロパティキーは、対応するエクスポートされた束縛名の StringValue です。これらが Module Namespace 特殊オブジェクトの唯一の String キー付きプロパティです。このような各プロパティは、属性 { [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: false } を持ちます。Module Namespace 特殊オブジェクトは拡張可能ではありません。

オブジェクトの [[GetPrototypeOf]]、[[SetPrototypeOf]]、[[IsExtensible]]、[[PreventExtensions]]、[[GetOwnProperty]]、[[DefineOwnProperty]]、[[HasProperty]]、[[Get]]、[[Set]]、[[Delete]]、および [[OwnPropertyKeys]] 内部メソッドがこの節の定義を使用し、その他の必須内部メソッドが 10.1 にある定義を使用する場合、そのオブジェクトは Module Namespace 特殊オブジェクトです。これらのメソッドは ModuleNamespaceCreate によってインストールされます。

Module Namespace 特殊オブジェクトは、表 29 で定義される内部スロットを持ちます。

表 29: Module Namespace 特殊オブジェクトの内部スロット
内部スロット 型 説明
[[Module]] a Module Record この名前空間がエクスポートを公開する Module Record です。
[[Exports]] a List of Strings このオブジェクトの自身のプロパティとして公開されるエクスポート名の String 値を要素とする List です。この List は辞書式コード単位順に従ってソートされます。

10.4.6.1 [[GetPrototypeOf]] ( )

a module namespace exotic objectの内部メソッド [[GetPrototypeOf]]。引数なし。戻り値:正常完了 (値:null)。 呼び出されると、次の手順を実行する。

  1. null を返す。

10.4.6.2 [[SetPrototypeOf]] ( proto )

a module namespace exotic object objの内部メソッド [[SetPrototypeOf]]。引数 proto ((Object または null))。戻り値:正常完了 (値:Boolean)。 呼び出されると、次の手順を実行する。

  1. ! SetImmutablePrototype(obj, proto) を返す。

10.4.6.3 [[IsExtensible]] ( )

a module namespace exotic objectの内部メソッド [[IsExtensible]]。引数なし。戻り値:正常完了 (値:false)。 呼び出されると、次の手順を実行する。

  1. false を返す。

10.4.6.4 [[PreventExtensions]] ( )

a module namespace exotic objectの内部メソッド [[PreventExtensions]]。引数なし。戻り値:正常完了 (値:true)。 呼び出されると、次の手順を実行する。

  1. true を返す。

10.4.6.5 [[GetOwnProperty]] ( propertyKey )

a module namespace exotic object objの内部メソッド [[GetOwnProperty]]。引数 propertyKey (プロパティキー)。戻り値:(正常完了 (値:(プロパティ記述子 または undefined)) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyKey が Symbol である場合、OrdinaryGetOwnProperty(obj, propertyKey) を返す。
  2. exports を obj.[[Exports]] とする。
  3. exports が propertyKey を含まない場合、undefined を返す。
  4. value を ? obj.[[Get]](propertyKey, obj) とする。
  5. PropertyDescriptor { [[Value]]: value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: false } を返す。

10.4.6.6 [[DefineOwnProperty]] ( propertyKey, propertyDesc )

a module namespace exotic object objの内部メソッド [[DefineOwnProperty]]。引数 propertyKey (プロパティキー) および propertyDesc (プロパティ記述子)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyKey が Symbol である場合、! OrdinaryDefineOwnProperty(obj, propertyKey, propertyDesc) を返す。
  2. current を ? obj.[[GetOwnProperty]](propertyKey) とする。
  3. current が undefined である場合、false を返す。
  4. propertyDesc が [[Configurable]] フィールドを持ち、propertyDesc.[[Configurable]] が true である場合、false を返す。
  5. propertyDesc が [[Enumerable]] フィールドを持ち、propertyDesc.[[Enumerable]] が false である場合、false を返す。
  6. IsAccessorDescriptor(propertyDesc) が true である場合、false を返す。
  7. propertyDesc が [[Writable]] フィールドを持ち、propertyDesc.[[Writable]] が false である場合、false を返す。
  8. propertyDesc が [[Value]] フィールドを持つ場合、SameValue(propertyDesc.[[Value]], current.[[Value]]) を返す。
  9. true を返す。

10.4.6.7 [[HasProperty]] ( propertyKey )

a module namespace exotic object objの内部メソッド [[HasProperty]]。引数 propertyKey (プロパティキー)。戻り値:正常完了 (値:Boolean)。 呼び出されると、次の手順を実行する。

  1. propertyKey が Symbol である場合、! OrdinaryHasProperty(obj, propertyKey) を返す。
  2. exports を obj.[[Exports]] とする。
  3. exports が propertyKey を含む場合、true を返す。
  4. false を返す。

10.4.6.8 [[Get]] ( propertyKey, receiver )

a module namespace exotic object objの内部メソッド [[Get]]。引数 propertyKey (プロパティキー) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. propertyKey が Symbol である場合、
    1. ! OrdinaryGet(obj, propertyKey, receiver) を返す。
  2. exports を obj.[[Exports]] とする。
  3. exports が propertyKey を含まない場合、undefined を返す。
  4. module を obj.[[Module]] とする。
  5. binding を module.ResolveExport(propertyKey) とする。
  6. 表明: binding は ResolvedBinding Record である。
  7. targetModule を binding.[[Module]] とする。
  8. 表明: targetModule は undefined ではない。
  9. binding.[[BindingName]] が namespace である場合、
    1. GetModuleNamespace(targetModule) を返す。
  10. targetEnv を targetModule.[[Environment]] とする。
  11. targetEnv が empty である場合、ReferenceError 例外をスローする。
  12. ? targetEnv.GetBindingValue(binding.[[BindingName]], true) を返す。
注

ResolveExport には副作用がありません。この操作が特定の exportName、resolveSet の組を引数として呼び出されるたびに、同じ結果を返さなければなりません。実装は、各 Module Namespace 特殊オブジェクトの [[Exports]] について ResolveExport の結果を事前計算またはキャッシュすることを選択してもかまいません。

10.4.6.9 [[Set]] ( propertyKey, value, receiver )

a module namespace exotic objectの内部メソッド [[Set]]。引数 propertyKey (プロパティキー)、value (ECMAScript 言語値) および receiver (ECMAScript 言語値)。戻り値:正常完了 (値:false)。 呼び出されると、次の手順を実行する。

  1. false を返す。

10.4.6.10 [[Delete]] ( propertyKey )

a module namespace exotic object objの内部メソッド [[Delete]]。引数 propertyKey (プロパティキー)。戻り値:正常完了 (値:Boolean)。 呼び出されると、次の手順を実行する。

  1. propertyKey が Symbol である場合、
    1. ! OrdinaryDelete(obj, propertyKey) を返す。
  2. exports を obj.[[Exports]] とする。
  3. exports が propertyKey を含む場合、false を返す。
  4. true を返す。

10.4.6.11 [[OwnPropertyKeys]] ( )

a module namespace exotic object objの内部メソッド [[OwnPropertyKeys]]。引数なし。戻り値:正常完了 (値:リスト (要素:プロパティキー))。 呼び出されると、次の手順を実行する。

  1. exports を obj.[[Exports]] とする。
  2. symbolKeys を OrdinaryOwnPropertyKeys(obj) とする。
  3. exports と symbolKeys のリスト連結を返す。

10.4.6.12 ModuleNamespaceCreate ( module, exports )

抽象操作 ModuleNamespaceCreate。引数 module (Moduleレコード) および exports (リスト (要素:String))。戻り値:module namespaceエキゾチックオブジェクト。 新しい Module Namespace 特殊オブジェクトの作成を規定するために使用されます。 呼び出されると、次の手順を実行する。

  1. 表明: module.[[Namespace]] は empty である。
  2. internalSlotsList を 表 29 に列挙される内部スロットとする。
  3. namespace を MakeBasicObject(internalSlotsList) とする。
  4. namespace の必須内部メソッドを 10.4.6 で規定される定義に設定する。
  5. namespace.[[Module]] を module に設定する。
  6. sortedExports を、exports の要素を辞書式コード単位順に従ってソートした要素を持つ List とする。
  7. namespace.[[Exports]] を sortedExports に設定する。
  8. 28.3 の定義に対応する namespace 自身のプロパティを作成する。
  9. module.[[Namespace]] を namespace に設定する。
  10. namespace を返す。

10.4.7 不変プロトタイプ特殊オブジェクト

不変プロトタイプ特殊オブジェクトは、初期化された後は変更されない [[Prototype]] 内部スロットを持つ特殊オブジェクトです。

オブジェクトの [[SetPrototypeOf]] 内部メソッドが以下の実装を使用する場合、そのオブジェクトは 不変プロトタイプ特殊オブジェクトです。(その他の必須内部メソッドは、対象となる具体的な不変プロトタイプ特殊オブジェクトに応じて、任意の実装を使用できます。)

注

他の特殊オブジェクトとは異なり、不変プロトタイプ特殊オブジェクトには専用の作成用抽象操作は提供されていません。これは、それらが %Object.prototype% とホスト環境でのみ使用され、ホスト環境では対象オブジェクトが他の点でも特殊である可能性があり、そのため独自の専用作成操作を必要とするためです。

10.4.7.1 [[SetPrototypeOf]] ( proto )

an immutable prototype exotic object objの内部メソッド [[SetPrototypeOf]]。引数 proto ((Object または null))。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? SetImmutablePrototype(obj, proto) を返す。

10.4.7.2 SetImmutablePrototype ( obj, proto )

抽象操作 SetImmutablePrototype。引数 obj (Object) および proto ((Object または null))。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. current を ? obj.[[GetPrototypeOf]]() とする。
  2. SameValue(proto, current) が true である場合、true を返す。
  3. false を返す。

10.5 Proxy オブジェクトの内部メソッドと内部スロット

Proxy オブジェクトは、その必須内部メソッドの一部が ECMAScript コードを使用して実装される特殊オブジェクトです。すべての Proxy オブジェクトは [[ProxyHandler]] と呼ばれる内部スロットを持ちます。[[ProxyHandler]] の値は、Proxy のハンドラーオブジェクトと呼ばれるオブジェクト、または null です。ハンドラーオブジェクトのメソッド(表 30 を参照)を使用して、Proxy オブジェクトの1つ以上の内部メソッドの実装を拡張できます。すべての Proxy オブジェクトは [[ProxyTarget]] と呼ばれる内部スロットも持ち、その値はオブジェクトまたは null のいずれかです。このオブジェクトを Proxy のターゲットオブジェクトと呼びます。

オブジェクトの必須内部メソッド(該当する場合は [[Call]] および [[Construct]] を含む)がこの節の定義を使用する場合、そのオブジェクトは Proxy 特殊オブジェクトです。これらの内部メソッドは ProxyCreate でインストールされます。

表 30: Proxy ハンドラーメソッド
内部メソッド ハンドラーメソッド
[[GetPrototypeOf]] getPrototypeOf
[[SetPrototypeOf]] setPrototypeOf
[[IsExtensible]] isExtensible
[[PreventExtensions]] preventExtensions
[[GetOwnProperty]] getOwnPropertyDescriptor
[[DefineOwnProperty]] defineProperty
[[HasProperty]] has
[[Get]] get
[[Set]] set
[[Delete]] deleteProperty
[[OwnPropertyKeys]] ownKeys
[[Call]] apply
[[Construct]] construct

Proxy オブジェクト内部メソッドの実装を提供するためにハンドラーメソッドが呼び出されると、Proxy のターゲットオブジェクトがパラメーターとしてハンドラーメソッドに渡されます。Proxy のハンドラーオブジェクトは、必ずしもすべての必須内部メソッドに対応するメソッドを持つとは限りません。ハンドラーオブジェクトが内部トラップに対応するメソッドを持たない場合、Proxy 上で内部メソッドを呼び出すと、Proxy のターゲットオブジェクト上の対応する内部メソッドが呼び出されます。

Proxy オブジェクトの [[ProxyHandler]] および [[ProxyTarget]] 内部スロットは、オブジェクトの作成時に常に初期化され、通常は変更できません。一部の Proxy オブジェクトは、その後取り消すことができる方法で作成されます。Proxy が取り消されると、その [[ProxyHandler]] および [[ProxyTarget]] 内部スロットは null に設定され、その Proxy オブジェクト上での以後の内部メソッド呼出しは TypeError 例外をスローします。

Proxy オブジェクトでは、任意の ECMAScript コードによって内部メソッドの実装を提供できるため、6.1.7.3 で定義される不変条件に違反するハンドラーメソッドを持つ Proxy オブジェクトを定義することが可能です。6.1.7.3 で定義される内部メソッド不変条件の一部は、必須の整合性不変条件です。これらの不変条件は、この節で規定される Proxy オブジェクト内部メソッドによって明示的に強制されます。ECMAScript 実装は、あらゆる可能な不変条件違反が存在しても堅牢でなければなりません。

以下のアルゴリズムの説明では、obj は ECMAScript Proxy オブジェクト、propertyKey はプロパティキー値、value は任意の ECMAScript 言語値、propertyDesc は Property Descriptor Record であると仮定します。

10.5.1 [[GetPrototypeOf]] ( )

a Proxy exotic object objの内部メソッド [[GetPrototypeOf]]。引数なし。戻り値:(正常完了 (値:(Object または null)) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "getPrototypeOf") とする。
  6. trap が undefined である場合、
    1. ? target.[[GetPrototypeOf]]() を返す。
  7. handlerProto を ? Call(trap, handler, « target ») とする。
  8. handlerProto が Object でも null でもない場合、TypeError 例外をスローする。
  9. extensibleTarget を ? IsExtensible(target) とする。
  10. extensibleTarget が true である場合、handlerProto を返す。
  11. targetProto を ? target.[[GetPrototypeOf]]() とする。
  12. SameValue(handlerProto, targetProto) が false である場合、TypeError 例外をスローする。
  13. handlerProto を返す。
注

Proxy オブジェクトの [[GetPrototypeOf]] は、次の不変条件を強制します。

  • [[GetPrototypeOf]] の結果は Object または null のいずれかでなければなりません。
  • ターゲットオブジェクトが拡張可能でない場合、Proxy オブジェクトに適用された [[GetPrototypeOf]] は、Proxy オブジェクトのターゲットオブジェクトに適用された [[GetPrototypeOf]] と同じ値を返さなければなりません。

10.5.2 [[SetPrototypeOf]] ( proto )

a Proxy exotic object objの内部メソッド [[SetPrototypeOf]]。引数 proto ((Object または null))。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "setPrototypeOf") とする。
  6. trap が undefined である場合、
    1. ? target.[[SetPrototypeOf]](proto) を返す。
  7. boolTrapResult を ToBoolean(? Call(trap, handler, « target, proto »)) とする。
  8. boolTrapResult が false である場合、false を返す。
  9. extensibleTarget を ? IsExtensible(target) とする。
  10. extensibleTarget が true である場合、true を返す。
  11. targetProto を ? target.[[GetPrototypeOf]]() とする。
  12. SameValue(proto, targetProto) が false である場合、TypeError 例外をスローする。
  13. true を返す。
注

Proxy オブジェクトの [[SetPrototypeOf]] は、次の不変条件を強制します。

  • [[SetPrototypeOf]] の結果は Boolean 値です。
  • ターゲットオブジェクトが拡張可能でない場合、引数値はターゲットオブジェクトに適用された [[GetPrototypeOf]] の結果と同じでなければなりません。

10.5.3 [[IsExtensible]] ( )

a Proxy exotic object objの内部メソッド [[IsExtensible]]。引数なし。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "isExtensible") とする。
  6. trap が undefined である場合、
    1. ? IsExtensible(target) を返す。
  7. boolTrapResult を ToBoolean(? Call(trap, handler, « target »)) とする。
  8. targetResult を ? IsExtensible(target) とする。
  9. boolTrapResult が targetResult でない場合、TypeError 例外をスローする。
  10. boolTrapResult を返す。
注

Proxy オブジェクトの [[IsExtensible]] は、次の不変条件を強制します。

  • [[IsExtensible]] の結果は Boolean 値です。
  • Proxy オブジェクトに適用された [[IsExtensible]] は、同じ引数で Proxy オブジェクトのターゲットオブジェクトに適用された [[IsExtensible]] と同じ値を返さなければなりません。

10.5.4 [[PreventExtensions]] ( )

a Proxy exotic object objの内部メソッド [[PreventExtensions]]。引数なし。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "preventExtensions") とする。
  6. trap が undefined である場合、
    1. ? target.[[PreventExtensions]]() を返す。
  7. boolTrapResult を ToBoolean(? Call(trap, handler, « target »)) とする。
  8. boolTrapResult が true である場合、
    1. extensibleTarget を ? IsExtensible(target) とする。
    2. extensibleTarget が true である場合、TypeError 例外をスローする。
  9. boolTrapResult を返す。
注

Proxy オブジェクトの [[PreventExtensions]] は、次の不変条件を強制します。

  • [[PreventExtensions]] の結果は Boolean 値です。
  • Proxy オブジェクトに適用された [[PreventExtensions]] が true を返すのは、Proxy オブジェクトのターゲットオブジェクトに適用された [[IsExtensible]] が false である場合に限ります。

10.5.5 [[GetOwnProperty]] ( propertyKey )

a Proxy exotic object objの内部メソッド [[GetOwnProperty]]。引数 propertyKey (プロパティキー)。戻り値:(正常完了 (値:(プロパティ記述子 または undefined)) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "getOwnPropertyDescriptor") とする。
  6. trap が undefined である場合、
    1. ? target.[[GetOwnProperty]](propertyKey) を返す。
  7. trapResultObj を ? Call(trap, handler, « target, propertyKey ») とする。
  8. trapResultObj が Object でも undefined でもない場合、TypeError 例外をスローする。
  9. targetDesc を ? target.[[GetOwnProperty]](propertyKey) とする。
  10. trapResultObj が undefined である場合、
    1. targetDesc が undefined である場合、undefined を返す。
    2. targetDesc.[[Configurable]] が false である場合、TypeError 例外をスローする。
    3. extensibleTarget を ? IsExtensible(target) とする。
    4. extensibleTarget が false である場合、TypeError 例外をスローする。
    5. undefined を返す。
  11. extensibleTarget を ? IsExtensible(target) とする。
  12. resultDesc を ? ToPropertyDescriptor(trapResultObj) とする。
  13. CompletePropertyDescriptor(resultDesc) を実行する。
  14. valid を IsCompatiblePropertyDescriptor(extensibleTarget, resultDesc, targetDesc) とする。
  15. valid が false である場合、TypeError 例外をスローする。
  16. resultDesc.[[Configurable]] が false である場合、
    1. targetDesc が undefined であるか、targetDesc.[[Configurable]] が true である場合、
      1. TypeError 例外をスローする。
    2. resultDesc が [[Writable]] フィールドを持ち、resultDesc.[[Writable]] が false である場合、
      1. 表明: targetDesc は [[Writable]] フィールドを持つ。
      2. targetDesc.[[Writable]] が true である場合、TypeError 例外をスローする。
  17. resultDesc を返す。
注

Proxy オブジェクトの [[GetOwnProperty]] は、次の不変条件を強制します。

  • [[GetOwnProperty]] の結果は Property Descriptor または undefined のいずれかでなければなりません。
  • ターゲットオブジェクトの構成不可の自身のプロパティとして存在するプロパティを、存在しないと報告することはできません。
  • 拡張可能でないターゲットオブジェクトの自身のプロパティとして存在するプロパティを、存在しないと報告することはできません。
  • ターゲットオブジェクトの自身のプロパティとして存在せず、かつターゲットオブジェクトが拡張可能でない場合、そのプロパティを存在すると報告することはできません。
  • ターゲットオブジェクトの構成不可の自身のプロパティとして存在する場合を除き、プロパティを構成不可と報告することはできません。
  • ターゲットオブジェクトの構成不可かつ書込み不可の自身のプロパティとして存在する場合を除き、プロパティを構成不可かつ書込み不可と報告することはできません。

10.5.6 [[DefineOwnProperty]] ( propertyKey, propertyDesc )

a Proxy exotic object objの内部メソッド [[DefineOwnProperty]]。引数 propertyKey (プロパティキー) および propertyDesc (プロパティ記述子)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "defineProperty") とする。
  6. trap が undefined である場合、
    1. ? target.[[DefineOwnProperty]](propertyKey, propertyDesc) を返す。
  7. propertyDescObj を FromPropertyDescriptor(propertyDesc) とする。
  8. boolTrapResult を ToBoolean(? Call(trap, handler, « target, propertyKey, propertyDescObj »)) とする。
  9. boolTrapResult が false である場合、false を返す。
  10. targetDesc を ? target.[[GetOwnProperty]](propertyKey) とする。
  11. extensibleTarget を ? IsExtensible(target) とする。
  12. propertyDesc が [[Configurable]] フィールドを持ち、propertyDesc.[[Configurable]] が false である場合、
    1. settingConfigurableFalse を true とする。
  13. そうでない場合、
    1. settingConfigurableFalse を false とする。
  14. targetDesc が undefined である場合、
    1. extensibleTarget が false である場合、TypeError 例外をスローする。
    2. settingConfigurableFalse が true である場合、TypeError 例外をスローする。
  15. そうでない場合、
    1. IsCompatiblePropertyDescriptor(extensibleTarget, propertyDesc, targetDesc) が false である場合、TypeError 例外をスローする。
    2. settingConfigurableFalse が true かつ targetDesc.[[Configurable]] が true である場合、TypeError 例外をスローする。
    3. IsDataDescriptor(targetDesc) が true、targetDesc.[[Configurable]] が false、かつ targetDesc.[[Writable]] が true である場合、
      1. propertyDesc が [[Writable]] フィールドを持ち、propertyDesc.[[Writable]] が false である場合、TypeError 例外をスローする。
  16. true を返す。
注

Proxy オブジェクトの [[DefineOwnProperty]] は、次の不変条件を強制します。

  • [[DefineOwnProperty]] の結果は Boolean 値です。
  • ターゲットオブジェクトが拡張可能でない場合、プロパティを追加することはできません。
  • 対応する構成不可のターゲットオブジェクト自身のプロパティが存在する場合を除き、プロパティを構成不可にすることはできません。
  • 対応する構成不可かつ書込み不可のターゲットオブジェクト自身のプロパティが存在する場合を除き、構成不可のプロパティを書込み不可にすることはできません。
  • プロパティに対応するターゲットオブジェクトのプロパティが存在する場合、そのプロパティの Property Descriptor を [[DefineOwnProperty]] を使用してターゲットオブジェクトに適用しても例外はスローされません。

10.5.7 [[HasProperty]] ( propertyKey )

a Proxy exotic object objの内部メソッド [[HasProperty]]。引数 propertyKey (プロパティキー)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "has") とする。
  6. trap が undefined である場合、
    1. ? target.[[HasProperty]](propertyKey) を返す。
  7. boolTrapResult を ToBoolean(? Call(trap, handler, « target, propertyKey »)) とする。
  8. boolTrapResult が false である場合、
    1. targetDesc を ? target.[[GetOwnProperty]](propertyKey) とする。
    2. targetDesc が undefined でない場合、
      1. targetDesc.[[Configurable]] が false である場合、TypeError 例外をスローする。
      2. extensibleTarget を ? IsExtensible(target) とする。
      3. extensibleTarget が false である場合、TypeError 例外をスローする。
  9. boolTrapResult を返す。
注

Proxy オブジェクトの [[HasProperty]] は、次の不変条件を強制します。

  • [[HasProperty]] の結果は Boolean 値です。
  • ターゲットオブジェクトの構成不可の自身のプロパティとして存在するプロパティを、存在しないと報告することはできません。
  • ターゲットオブジェクト自身のプロパティとして存在し、かつターゲットオブジェクトが拡張可能でない場合、そのプロパティを存在しないと報告することはできません。

10.5.8 [[Get]] ( propertyKey, receiver )

a Proxy exotic object objの内部メソッド [[Get]]。引数 propertyKey (プロパティキー) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "get") とする。
  6. trap が undefined である場合、
    1. ? target.[[Get]](propertyKey, receiver) を返す。
  7. trapResult を ? Call(trap, handler, « target, propertyKey, receiver ») とする。
  8. targetDesc を ? target.[[GetOwnProperty]](propertyKey) とする。
  9. targetDesc が undefined でなく、targetDesc.[[Configurable]] が false である場合、
    1. IsDataDescriptor(targetDesc) が true かつ targetDesc.[[Writable]] が false である場合、
      1. SameValue(trapResult, targetDesc.[[Value]]) が false である場合、TypeError 例外をスローする。
    2. IsAccessorDescriptor(targetDesc) が true かつ targetDesc.[[Getter]] が undefined である場合、
      1. trapResult が undefined でない場合、TypeError 例外をスローする。
  10. trapResult を返す。
注

Proxy オブジェクトの [[Get]] は、次の不変条件を強制します。

  • 対応するターゲットオブジェクトのプロパティが書込み不可かつ構成不可の自身のデータプロパティである場合、プロパティについて報告される値は、そのターゲットオブジェクトのプロパティ値と同じでなければなりません。
  • 対応するターゲットオブジェクトのプロパティが、[[Getter]] 属性として undefined を持つ構成不可の自身のアクセサープロパティである場合、プロパティについて報告される値は undefined でなければなりません。

10.5.9 [[Set]] ( propertyKey, value, receiver )

a Proxy exotic object objの内部メソッド [[Set]]。引数 propertyKey (プロパティキー)、value (ECMAScript 言語値) および receiver (ECMAScript 言語値)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "set") とする。
  6. trap が undefined である場合、
    1. ? target.[[Set]](propertyKey, value, receiver) を返す。
  7. boolTrapResult を ToBoolean(? Call(trap, handler, « target, propertyKey, value, receiver »)) とする。
  8. boolTrapResult が false である場合、false を返す。
  9. targetDesc を ? target.[[GetOwnProperty]](propertyKey) とする。
  10. targetDesc が undefined でなく、targetDesc.[[Configurable]] が false である場合、
    1. IsDataDescriptor(targetDesc) が true かつ targetDesc.[[Writable]] が false である場合、
      1. SameValue(value, targetDesc.[[Value]]) が false である場合、TypeError 例外をスローする。
    2. IsAccessorDescriptor(targetDesc) が true である場合、
      1. targetDesc.[[Setter]] が undefined である場合、TypeError 例外をスローする。
  11. true を返す。
注

Proxy オブジェクトの [[Set]] は、次の不変条件を強制します。

  • [[Set]] の結果は Boolean 値です。
  • 対応するターゲットオブジェクトのプロパティが書込み不可かつ構成不可の自身のデータプロパティである場合、そのプロパティ値と異なる値に変更することはできません。
  • 対応するターゲットオブジェクトのプロパティが、[[Setter]] 属性として undefined を持つ構成不可の自身のアクセサープロパティである場合、プロパティの値を設定することはできません。

10.5.10 [[Delete]] ( propertyKey )

a Proxy exotic object objの内部メソッド [[Delete]]。引数 propertyKey (プロパティキー)。戻り値:(正常完了 (値:Boolean) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "deleteProperty") とする。
  6. trap が undefined である場合、
    1. ? target.[[Delete]](propertyKey) を返す。
  7. boolTrapResult を ToBoolean(? Call(trap, handler, « target, propertyKey »)) とする。
  8. boolTrapResult が false である場合、false を返す。
  9. targetDesc を ? target.[[GetOwnProperty]](propertyKey) とする。
  10. targetDesc が undefined である場合、true を返す。
  11. targetDesc.[[Configurable]] が false である場合、TypeError 例外をスローする。
  12. extensibleTarget を ? IsExtensible(target) とする。
  13. extensibleTarget が false である場合、TypeError 例外をスローする。
  14. true を返す。
注

Proxy オブジェクトの [[Delete]] は、次の不変条件を強制します。

  • [[Delete]] の結果は Boolean 値です。
  • ターゲットオブジェクトの構成不可の自身のプロパティとして存在するプロパティを、削除されたと報告することはできません。
  • ターゲットオブジェクトの自身のプロパティとして存在し、かつターゲットオブジェクトが拡張可能でない場合、そのプロパティを削除されたと報告することはできません。

10.5.11 [[OwnPropertyKeys]] ( )

a Proxy exotic object objの内部メソッド [[OwnPropertyKeys]]。引数なし。戻り値:(正常完了 (値:リスト (要素:プロパティキー)) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "ownKeys") とする。
  6. trap が undefined である場合、
    1. ? target.[[OwnPropertyKeys]]() を返す。
  7. trapResultArray を ? Call(trap, handler, « target ») とする。
  8. trapResult を ? CreateListFromArrayLike(trapResultArray, property-key) とする。
  9. trapResult に重複する項目が含まれる場合、TypeError 例外をスローする。
  10. extensibleTarget を ? IsExtensible(target) とする。
  11. targetKeys を ? target.[[OwnPropertyKeys]]() とする。
  12. 表明: targetKeys はプロパティキーの List である。
  13. 表明: targetKeys は重複する項目を含まない。
  14. targetConfigurableKeys を新しい空の List とする。
  15. targetNonconfigurableKeys を新しい空の List とする。
  16. targetKeys の各要素 key について、次を行う。
    1. propertyDesc を ? target.[[GetOwnProperty]](key) とする。
    2. propertyDesc が undefined でなく、propertyDesc.[[Configurable]] が false である場合、
      1. key を targetNonconfigurableKeys に追加する。
    3. そうでない場合、
      1. key を targetConfigurableKeys に追加する。
  17. extensibleTarget が true かつ targetNonconfigurableKeys が空である場合、
    1. trapResult を返す。
  18. uncheckedResultKeys を、trapResult の要素を要素とする List とする。
  19. targetNonconfigurableKeys の各要素 key について、次を行う。
    1. uncheckedResultKeys が key を含まない場合、TypeError 例外をスローする。
    2. key を uncheckedResultKeys から削除する。
  20. extensibleTarget が true である場合、trapResult を返す。
  21. targetConfigurableKeys の各要素 key について、次を行う。
    1. uncheckedResultKeys が key を含まない場合、TypeError 例外をスローする。
    2. key を uncheckedResultKeys から削除する。
  22. uncheckedResultKeys が空でない場合、TypeError 例外をスローする。
  23. trapResult を返す。
注

Proxy オブジェクトの [[OwnPropertyKeys]] は、次の不変条件を強制します。

  • [[OwnPropertyKeys]] の結果は List です。
  • 返される List は重複する項目を含みません。
  • 返される List の各要素はプロパティキーです。
  • 結果の List は、ターゲットオブジェクトの構成不可のすべての自身のプロパティのキーを含まなければなりません。
  • ターゲットオブジェクトが拡張可能でない場合、結果の List はターゲットオブジェクト自身のすべてのプロパティキーを含み、それ以外の値を含んではなりません。

10.5.12 [[Call]] ( thisArg, argList )

a Proxy exotic object objの内部メソッド [[Call]]。引数 thisArg (ECMAScript 言語値) および argList (リスト (要素:ECMAScript 言語値))。戻り値:(正常完了 (値:ECMAScript 言語値) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. handler を obj.[[ProxyHandler]] とする。
  4. 表明: handler は Object である。
  5. trap を ? GetMethod(handler, "apply") とする。
  6. trap が undefined である場合、
    1. ? Call(target, thisArg, argList) を返す。
  7. argArray を CreateArrayFromList(argList) とする。
  8. ? Call(trap, handler, « target, thisArg, argArray ») を返す。
注

Proxy 特殊オブジェクトが [[Call]] 内部メソッドを持つのは、その [[ProxyTarget]] 内部スロットの初期値が [[Call]] 内部メソッドを持つオブジェクトである場合に限ります。

10.5.13 [[Construct]] ( argList, newTarget )

a Proxy exotic object objの内部メソッド [[Construct]]。引数 argList (リスト (要素:ECMAScript 言語値)) および newTarget (コンストラクター)。戻り値:(正常完了 (値:Object) または throw 完了)。 呼び出されると、次の手順を実行する。

  1. ? ValidateNonRevokedProxy(obj) を実行する。
  2. target を obj.[[ProxyTarget]] とする。
  3. 表明: IsConstructor(target) は true である。
  4. handler を obj.[[ProxyHandler]] とする。
  5. 表明: handler は Object である。
  6. trap を ? GetMethod(handler, "construct") とする。
  7. trap が undefined である場合、
    1. ? Construct(target, argList, newTarget) を返す。
  8. argArray を CreateArrayFromList(argList) とする。
  9. newObj を ? Call(trap, handler, « target, argArray, newTarget ») とする。
  10. newObj が Object でない場合、TypeError 例外をスローする。
  11. newObj を返す。
注 1

Proxy 特殊オブジェクトが [[Construct]] 内部メソッドを持つのは、その [[ProxyTarget]] 内部スロットの初期値が [[Construct]] 内部メソッドを持つオブジェクトである場合に限ります。

注 2

Proxy オブジェクトの [[Construct]] は、次の不変条件を強制します。

  • [[Construct]] の結果は Object でなければなりません。

10.5.14 ValidateNonRevokedProxy ( proxy )

抽象操作 ValidateNonRevokedProxy。引数 proxy (Proxyエキゾチックオブジェクト)。戻り値:(正常完了 (値:unused) または throw 完了)。 proxy が取り消されている場合、TypeError 例外をスローします。 呼び出されると、次の手順を実行する。

  1. proxy.[[ProxyTarget]] が null である場合、TypeError 例外をスローする。
  2. 表明: proxy.[[ProxyHandler]] は null ではない。
  3. unused を返す。

10.5.15 ProxyCreate ( target, handler )

抽象操作 ProxyCreate。引数 target (ECMAScript 言語値) および handler (ECMAScript 言語値)。戻り値:(正常完了 (値:Proxyエキゾチックオブジェクト) または throw 完了)。 新しい Proxy オブジェクトの作成を規定するために使用されます。 呼び出されると、次の手順を実行する。

  1. target が Object でない場合、TypeError 例外をスローする。
  2. handler が Object でない場合、TypeError 例外をスローする。
  3. proxy を MakeBasicObject(« [[ProxyHandler]], [[ProxyTarget]] ») とする。
  4. proxy の [[Call]] および [[Construct]] を除く必須内部メソッドを、10.5 で規定される定義に設定する。
  5. IsCallable(target) が true である場合、
    1. proxy.[[Call]] を 10.5.12 で規定されるとおりに設定する。
    2. IsConstructor(target) が true である場合、
      1. proxy.[[Construct]] を 10.5.13 で規定されるとおりに設定する。
  6. proxy.[[ProxyTarget]] を target に設定する。
  7. proxy.[[ProxyHandler]] を handler に設定する。
  8. proxy を返す。