24 Keyed Collections

24.1 Mapオブジェクト

Mapはkey/value pairのcollectionであり、keysとvaluesはいずれも任意のECMAScript language valueであってよい。distinctなkey valueは、Mapのcollection内の1つのkey/value pairにだけ出現してよい。distinctなkey valuesはSameValueZero比較algorithmのsemanticsを用いて識別される。

Mapは、平均的にcollection内のelements数に対してsublinearなaccess timeを提供するhash tableまたはその他のmechanismsを用いて実装されなければならない。この仕様で用いられるdata structureは、Mapのrequired observable semanticsをdescribeすることだけを意図している。viable implementation modelであることは意図されていない。

24.1.1 Map Constructor

Map constructorは:

  • %Map%である。
  • global object"Map" propertyのinitial valueである。
  • constructorとして呼び出されたとき、新しいMapをcreateしてinitializeする。
  • functionとして呼び出されることは意図されておらず、そのように呼び出された場合はexceptionをthrowする。
  • クラス定義の extends 句内の値として使用できる。指定された Map の動作を継承しようとするサブクラスコンストラクターは、Map.prototype の組み込みメソッドをサポートするために必要な内部状態でサブクラスインスタンスを作成し初期化するため、Map コンストラクターへの super 呼び出しを含めなければならない。

24.1.1.1 Map ( [ iterable ] )

このfunctionは、呼び出されたときに次のstepsを実行する:

  1. NewTargetがundefinedなら、TypeError例外をthrowする。
  2. mapを ? OrdinaryCreateFromConstructor(NewTarget, "%Map.prototype%", « [[MapData]] ») とする。
  3. map.[[MapData]]を新しい空のListに設定する。
  4. iterableundefinedまたはnullのどちらかなら、mapを返す。
  5. adderを ? Get(map, "set") とする。
  6. IsCallable(adder)がfalseなら、TypeError例外をthrowする。
  7. AddEntriesFromIterable(map, iterable, adder)を返す。
Note

parameter iterableがpresentである場合、それは%Symbol.iterator% methodを実装するobjectであることがexpectedされ、そのmethodは、first elementがMap keyとして使用されるvalueであり、second elementがそのkeyにassociateされるvalueであるtwo element array-like objectをproduceするiterator objectを返す。

24.1.1.2 AddEntriesFromIterable ( target, iterable, adder )

The abstract operation AddEntriesFromIterable takes arguments target (an Object), iterable (an ECMAScript language value, but not undefined or null), and adder (a function object) and returns either a normal completion containing an Object or a throw completion. adderは、targetをreceiverとしてinvokeされる。 It performs the following steps when called:

  1. iteratorRecordを ? GetIterator(iterable, sync) とする。
  2. 繰り返す、
    1. nextを ? IteratorStepValue(iteratorRecord) とする。
    2. nextdoneなら、targetを返す。
    3. nextがObjectでないなら、
      1. errorThrowCompletion(newly created TypeError object)とする。
      2. IteratorClose(iteratorRecord, error)を返す。
    4. keyCompletion(Get(next, "0"))とする。
    5. IfAbruptCloseIterator(key, iteratorRecord)。
    6. valueCompletion(Get(next, "1"))とする。
    7. IfAbruptCloseIterator(value, iteratorRecord)。
    8. statusCompletion(Call(adder, target, « key, value »))とする。
    9. IfAbruptCloseIterator(status, iteratorRecord)。
Note

parameter iterableは、%Symbol.iterator% methodを実装するobjectであることがexpectedされ、そのmethodは、first elementがMap keyとして使用されるvalueであり、second elementがそのkeyにassociateされるvalueであるtwo element array-like objectをproduceするiterator objectを返す。

24.1.2 Map Constructorのプロパティ

Map constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持つ。
  • 次のpropertiesを持つ:

24.1.2.1 Map.groupBy ( items, callback )

Note

callbackはtwo argumentsをacceptするfunctionであるべきである。groupByitems内の各elementについてascending orderでcallbackを1回callし、新しいMapをconstructする。callbackによりreturnedされた各valueはMap内のkeyとして使用される。そのような各keyについて、result Mapはkeyがそのkeyであり、valueがcallbackがそのkeyを返したすべてのelementsを含むarrayであるentryを持つ。

callbackはtwo arguments、すなわちelementのvalueとelementのindexでcallされる。

groupByのreturn valueはMapである。

このfunctionは、呼び出されたときに次のstepsを実行する:

  1. groupsを ? GroupBy(items, callback, collection) とする。
  2. mapを ! Construct(%Map%) とする。
  3. groupsの各Record { [[Key]], [[Elements]] } groupについて、以下を行う
    1. elementsCreateArrayFromList(group.[[Elements]])とする。
    2. entryRecord { [[Key]]: group.[[Key]], [[Value]]: elements }とする。
    3. entrymap.[[MapData]]へappendする。
  4. mapを返す。

24.1.2.2 Map.prototype

Map.prototypeのinitial valueはMap prototype objectである。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持つ。

24.1.2.3 get Map [ %Symbol.species% ]

Map[%Symbol.species%]は、set accessor functionがundefinedであるaccessor propertyである。そのget accessor functionは、呼び出されたときに次のstepsを実行する:

  1. this valueを返す。

このfunctionの"name" propertyのvalueは"get [Symbol.species]"である。

Note

derived collection objectsをcreateするmethodsは、derived objectsをcreateするために使用するconstructorをdetermineするため、%Symbol.species%をcallするべきである。Subclass constructor%Symbol.species%をover-rideしてdefault constructor assignmentを変更できる。

24.1.3 Map Prototype Objectのプロパティ

Map prototype objectは:

  • %Map.prototype%である。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持つ。
  • ordinary objectである。
  • [[MapData]] internal slotを持たない。

24.1.3.1 Map.prototype.clear ( )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. RequireInternalSlot(map, [[MapData]])を実行する。
  3. map.[[MapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyに設定する。
    2. entry.[[Value]]emptyに設定する。
  4. undefinedを返す。
Note

そのListのiterationの途中でsuspendedされているexisting Map Iterator objectsが存在するかもしれないため、existing [[MapData]] Listはpreservedされる。

24.1.3.2 Map.prototype.constructor

Map.prototype.constructorのinitial valueは%Map%である。

24.1.3.3 Map.prototype.delete ( key )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. RequireInternalSlot(map, [[MapData]])を実行する。
  3. keyCanonicalizeKeyedCollectionKey(key)に設定する。
  4. map.[[MapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、
      1. entry.[[Key]]emptyに設定する。
      2. entry.[[Value]]emptyに設定する。
      3. trueを返す。
  5. falseを返す。
Note

value emptyは、entryがdeletedされたことをindicateするためのspecification deviceとして使用される。実際のimplementationsは、entryをinternal data structuresからphysically removingするなど、他のactionsを取ってもよい。

24.1.3.4 Map.prototype.entries ( )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. CreateMapIterator(map, key+value)を返す。

24.1.3.5 Map.prototype.forEach ( callback [ , thisArg ] )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. RequireInternalSlot(map, [[MapData]])を実行する。
  3. IsCallable(callback)がfalseなら、TypeError例外をthrowする。
  4. entriesmap.[[MapData]]とする。
  5. entriesCountentries内のelementsの数とする。
  6. indexを0とする。
  7. index < entriesCountの間、繰り返す
    1. entryentries[index]とする。
    2. indexindex + 1に設定する。
    3. entry.[[Key]]emptyでないなら、
      1. Call(callback, thisArg, « entry.[[Value]], entry.[[Key]], map »)を実行する。
      2. NOTE: entries内のelementsの数はcallbackのexecution中に増加しているかもしれない。
      3. entriesCountentries内のelementsの数に設定する。
  8. undefinedを返す。
Note

callbackはthree argumentsをacceptするfunctionであるべきである。forEachはMap内にpresentな各key/value pairについて、key insertion orderでcallbackを1回callする。callbackは、実際に存在するMapのkeysについてのみcallされ、Mapからdeletedされたkeysについてはcallされない。

thisArg parameterがprovidedされた場合、それはcallbackの各invocationにおけるthis valueとして使用される。providedされない場合、代わりにundefinedが使用される。

callbackはthree arguments、すなわちitemのvalue、itemのkey、およびtraversedされるMapでcallされる。

forEachは、それが呼び出されたobjectをdirectly mutateしないが、そのobjectはcallbackのcallsによってmutatedされるかもしれない。mapの[[MapData]]の各entryは1回だけvisitedされる。forEachへのcallがbeginsした後にaddedされたnew keysはvisitedされる。keyがvisitedされた後にdeletedされ、その後forEach callがcompletesする前にre-addedされた場合、そのkeyはrevisitedされる。forEachへのcallがbeginsした後、visitedされる前にdeletedされたkeysは、forEach callがcompletesする前にkeyが再びaddedされない限り、visitedされない。

24.1.3.6 Map.prototype.get ( key )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. RequireInternalSlot(map, [[MapData]])を実行する。
  3. keyCanonicalizeKeyedCollectionKey(key)に設定する。
  4. map.[[MapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、entry.[[Value]]を返す。
  5. undefinedを返す。

24.1.3.7 Map.prototype.getOrInsert ( key, value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. RequireInternalSlot(map, [[MapData]])を実行する。
  3. keyCanonicalizeKeyedCollectionKey(key)に設定する。
  4. map.[[MapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、entry.[[Value]]を返す。
  5. entryRecord { [[Key]]: key, [[Value]]: value }とする。
  6. entrymap.[[MapData]]へappendする。
  7. valueを返す。

24.1.3.8 Map.prototype.getOrInsertComputed ( key, callback )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. RequireInternalSlot(map, [[MapData]])を実行する。
  3. IsCallable(callback)がfalseなら、TypeError例外をthrowする。
  4. keyCanonicalizeKeyedCollectionKey(key)に設定する。
  5. map.[[MapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、entry.[[Value]]を返す。
  6. valueを ? Call(callback, undefined, « key ») とする。
  7. NOTE: Mapはcallbackのexecution中にmodifiedされているかもしれない。
  8. map.[[MapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、
      1. entry.[[Value]]valueに設定する。
      2. valueを返す。
  9. entryRecord { [[Key]]: key, [[Value]]: value }とする。
  10. entrymap.[[MapData]]へappendする。
  11. valueを返す。

24.1.3.9 Map.prototype.has ( key )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. RequireInternalSlot(map, [[MapData]])を実行する。
  3. keyCanonicalizeKeyedCollectionKey(key)に設定する。
  4. map.[[MapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、trueを返す。
  5. falseを返す。

24.1.3.10 Map.prototype.keys ( )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. CreateMapIterator(map, key)を返す。

24.1.3.11 Map.prototype.set ( key, value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. RequireInternalSlot(map, [[MapData]])を実行する。
  3. keyCanonicalizeKeyedCollectionKey(key)に設定する。
  4. map.[[MapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、
      1. entry.[[Value]]valueに設定する。
      2. mapを返す。
  5. entryRecord { [[Key]]: key, [[Value]]: value }とする。
  6. entrymap.[[MapData]]へappendする。
  7. mapを返す。

24.1.3.12 get Map.prototype.size

Map.prototype.sizeは、set accessor functionがundefinedであるaccessor propertyである。そのget accessor functionは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. RequireInternalSlot(map, [[MapData]])を実行する。
  3. countを0とする。
  4. map.[[MapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでないなら、countcount + 1に設定する。
  5. 𝔽(count)を返す。

24.1.3.13 Map.prototype.values ( )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. mapthis valueとする。
  2. CreateMapIterator(map, value)を返す。

24.1.3.14 Map.prototype [ %Symbol.iterator% ] ( )

%Symbol.iterator% propertyのinitial valueは、24.1.3.4でdefinedされる%Map.prototype.entries%である。

24.1.3.15 Map.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "Map"である。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持つ。

24.1.4 Map Instancesのプロパティ

Map instancesはMap prototype objectからpropertiesをinheritするordinary objectsである。Map instancesは[[MapData]] internal slotも持つ。

24.1.5 Map Iteratorオブジェクト

Map Iteratorは、あるspecific Map instance objectに対するspecific iterationをrepresentするobjectである。Map Iterator objectsにはnamed constructorは存在しない。代わりに、Map Iterator objectsはMap instance objectsのcertain methodsをcallingすることでcreatedされる。

24.1.5.1 CreateMapIterator ( map, kind )

The abstract operation CreateMapIterator takes arguments map (an ECMAScript language value) and kind (key+value, key, or value) and returns either a normal completion containing a Generator or a throw completion. Map methodsがreturnするそのようなiteratorsiterator objectsをcreateするために使用される。 It performs the following steps when called:

  1. RequireInternalSlot(map, [[MapData]])を実行する。
  2. closureを、parametersを持たず、mapおよびkindをcapturesし、呼び出されたときに次のstepsを実行する新しいAbstract Closureとする:
    1. entriesmap.[[MapData]]とする。
    2. indexを0とする。
    3. entriesCountentries内のelementsの数とする。
    4. index < entriesCountの間、繰り返す
      1. entryentries[index]とする。
      2. indexindex + 1に設定する。
      3. entry.[[Key]]emptyでないなら、
        1. kindkeyなら、
          1. resultentry.[[Key]]とする。
        2. そうでなく、kindvalueなら、
          1. resultentry.[[Value]]とする。
        3. そうでなければ、
          1. Assert: kindkey+valueである。
          2. resultCreateArrayFromListentry.[[Key]], entry.[[Value]] »)とする。
        4. GeneratorYield(CreateIteratorResultObject(result, false))を実行する。
        5. NOTE: このabstract operationのexecutionがGeneratorYieldによりpausedされている間に、entries内のelementsの数が増加しているかもしれない。
        6. entriesCountentries内のelementsの数に設定する。
    5. NormalCompletion(unused)を返す。
  3. CreateIteratorFromClosure(closure, "%MapIteratorPrototype%", %MapIteratorPrototype%)を返す。

24.1.5.2 %MapIteratorPrototype% Object

%MapIteratorPrototype% objectは:

24.1.5.2.1 %MapIteratorPrototype%.next ( )

  1. GeneratorResume(this value, empty, "%MapIteratorPrototype%")を返す。

24.1.5.2.2 %MapIteratorPrototype% [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "Map Iterator"である。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持つ。

24.2 Setオブジェクト

Set objectsECMAScript language valuesのcollectionsである。Setは各distinct valueを多くとも1回だけcontainできる。distinct valuesはSameValueZero comparison algorithmのsemanticsを用いて識別される。

Set objectsは、平均的にcollection内のelements数に対してsublinearなaccess timeを提供するhash tableまたはその他のmechanismsを用いて実装されなければならない。この仕様で用いられるdata structureは、Set objectsのrequired observable semanticsをdescribeすることだけを意図している。viable implementation modelであることは意図されていない。

24.2.1 Setオブジェクトの抽象操作

24.2.1.1 Set Records

Set Recordは、Setまたはsimilar objectのinterfaceをencapsulateするために使用されるRecord valueである。

Set RecordsはTable 72にlistedされるfieldsを持つ。

Table 72: Set Record Fields
Field Name Value Meaning
[[SetObject]] Object Setまたはsimilar object。
[[Size]] non-negative integerまたは+∞ objectのreported size。
[[Has]] function object objectのhas method。
[[Keys]] function object objectのkeys method。

24.2.1.2 GetSetRecord ( obj )

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

  1. objがObjectでないなら、TypeError例外をthrowする。
  2. rawSizeを ? Get(obj, "size") とする。
  3. numberSizeを ? ToNumber(rawSize) とする。
  4. NOTE: rawSizeundefinedなら、numberSizeNaNになる。
  5. numberSizeNaNなら、TypeError例外をthrowする。
  6. intSizeを ! ToIntegerOrInfinity(numberSize) とする。
  7. intSize < 0なら、RangeError例外をthrowする。
  8. hasを ? Get(obj, "has") とする。
  9. IsCallable(has)がfalseなら、TypeError例外をthrowする。
  10. keysを ? Get(obj, "keys") とする。
  11. IsCallable(keys)がfalseなら、TypeError例外をthrowする。
  12. 新しいSet Record { [[SetObject]]: obj, [[Size]]: intSize, [[Has]]: has, [[Keys]]: keys }を返す。

24.2.1.3 SetDataHas ( setData, value )

The abstract operation SetDataHas takes arguments setData (a List of either ECMAScript language values or empty) and value (an ECMAScript language value) and returns a Boolean. It performs the following steps when called:

  1. SetDataIndex(setData, value)がnot-foundなら、falseを返す。
  2. trueを返す。

24.2.1.4 SetDataIndex ( setData, value )

The abstract operation SetDataIndex takes arguments setData (a List of either ECMAScript language values or empty) and value (an ECMAScript language value) and returns a non-negative integer or not-found. It performs the following steps when called:

  1. valueCanonicalizeKeyedCollectionKey(value)に設定する。
  2. sizesetData内のelementsの数とする。
  3. indexを0とする。
  4. index < sizeの間、繰り返す
    1. elementsetData[index]とする。
    2. elementemptyでなく、elementvalueであるなら、
      1. indexを返す。
    3. indexindex + 1に設定する。
  5. not-foundを返す。

24.2.1.5 SetDataSize ( setData )

The abstract operation SetDataSize takes argument setData (a List of either ECMAScript language values or empty) and returns a non-negative integer. It performs the following steps when called:

  1. countを0とする。
  2. setDataの各element elementについて、以下を行う
    1. elementemptyでないなら、countcount + 1に設定する。
  3. countを返す。

24.2.2 Set Constructor

Set constructorは:

  • %Set%である。
  • global object"Set" propertyのinitial valueである。
  • constructorとして呼び出されたとき、新しいSet objectをcreateしてinitializeする。
  • functionとして呼び出されることは意図されておらず、そのように呼び出された場合はexceptionをthrowする。
  • クラス定義の extends 句内の値として使用できる。指定された Set の動作を継承しようとするサブクラスコンストラクターは、Set.prototype の組み込みメソッドをサポートするために必要な内部状態でサブクラスインスタンスを作成し初期化するため、Set コンストラクターへの super 呼び出しを含めなければならない。

24.2.2.1 Set ( [ iterable ] )

このfunctionは、呼び出されたときに次のstepsを実行する:

  1. NewTargetがundefinedなら、TypeError例外をthrowする。
  2. setを ? OrdinaryCreateFromConstructor(NewTarget, "%Set.prototype%", « [[SetData]] ») とする。
  3. set.[[SetData]]を新しい空のListに設定する。
  4. iterableundefinedまたはnullのどちらかなら、setを返す。
  5. adderを ? Get(set, "add") とする。
  6. IsCallable(adder)がfalseなら、TypeError例外をthrowする。
  7. iteratorRecordを ? GetIterator(iterable, sync) とする。
  8. 繰り返す、
    1. nextを ? IteratorStepValue(iteratorRecord) とする。
    2. nextdoneなら、setを返す。
    3. statusCompletion(Call(adder, set, « next »))とする。
    4. IfAbruptCloseIterator(status, iteratorRecord)。

24.2.3 Set Constructorのプロパティ

Set constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持つ。
  • 次のpropertiesを持つ:

24.2.3.1 Set.prototype

Set.prototypeのinitial valueはSet prototype objectである。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持つ。

24.2.3.2 get Set [ %Symbol.species% ]

Set[%Symbol.species%]は、set accessor functionがundefinedであるaccessor propertyである。そのget accessor functionは、呼び出されたときに次のstepsを実行する:

  1. this valueを返す。

このfunctionの"name" propertyのvalueは"get [Symbol.species]"である。

Note

derived collection objectsをcreateするmethodsは、derived objectsをcreateするために使用するconstructorをdetermineするため、%Symbol.species%をcallするべきである。Subclass constructor%Symbol.species%をover-rideしてdefault constructor assignmentを変更できる。

24.2.4 Set Prototype Objectのプロパティ

Set prototype objectは:

  • %Set.prototype%である。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持つ。
  • ordinary objectである。
  • [[SetData]] internal slotを持たない。

24.2.4.1 Set.prototype.add ( value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. valueCanonicalizeKeyedCollectionKey(value)に設定する。
  4. set.[[SetData]]の各element entryについて、以下を行う
    1. entryemptyでなく、SameValue(entry, value)がtrueなら、
      1. setを返す。
  5. valueset.[[SetData]]へappendする。
  6. setを返す。

24.2.4.2 Set.prototype.clear ( )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. set.[[SetData]]の各element entryについて、以下を行う
    1. valueがentryであるset.[[SetData]]のelementを、valueがemptyであるelementでreplaceする。
  4. undefinedを返す。
Note

そのListのiterationの途中でsuspendedされているexisting Set Iterator objectsが存在するかもしれないため、existing [[SetData]] Listはpreservedされる。

24.2.4.3 Set.prototype.constructor

Set.prototype.constructorのinitial valueは%Set%である。

24.2.4.4 Set.prototype.delete ( value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. valueCanonicalizeKeyedCollectionKey(value)に設定する。
  4. set.[[SetData]]の各element entryについて、以下を行う
    1. entryemptyでなく、SameValue(entry, value)がtrueなら、
      1. valueがentryであるset.[[SetData]]のelementを、valueがemptyであるelementでreplaceする。
      2. trueを返す。
  5. falseを返す。
Note

value emptyは、entryがdeletedされたことをindicateするためのspecification deviceとして使用される。実際のimplementationsは、entryをinternal data structuresからphysically removingするなど、他のactionsを取ってもよい。

24.2.4.5 Set.prototype.difference ( other )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. otherRecordを ? GetSetRecord(other) とする。
  4. resultSetDataset.[[SetData]]のcopyとする。
  5. SetDataSize(set.[[SetData]]) ≤ otherRecord.[[Size]]なら、
    1. thisSizeset.[[SetData]]内のelementsの数とする。
    2. indexを0とする。
    3. index < thisSizeの間、繰り返す
      1. entryresultSetData[index]とする。
      2. entryemptyでないなら、
        1. inOtherToBoolean(? Call(otherRecord.[[Has]], otherRecord.[[SetObject]], « entry »))とする。
        2. inOthertrueなら、
          1. resultSetData[index]をemptyに設定する。
      3. indexindex + 1に設定する。
  6. そうでなければ、
    1. keysIteratorを ? GetIteratorFromMethod(otherRecord.[[SetObject]], otherRecord.[[Keys]]) とする。
    2. nextnot-startedとする。
    3. nextdoneでない間、繰り返す
      1. nextを ? IteratorStepValue(keysIterator) に設定する。
      2. nextdoneでないなら、
        1. nextCanonicalizeKeyedCollectionKey(next)に設定する。
        2. valueIndexSetDataIndex(resultSetData, next)とする。
        3. valueIndexnot-foundでないなら、
          1. resultSetData[valueIndex]をemptyに設定する。
  7. resultOrdinaryObjectCreate(%Set.prototype%, « [[SetData]] »)とする。
  8. result.[[SetData]]resultSetDataに設定する。
  9. resultを返す。

24.2.4.6 Set.prototype.entries ( )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. CreateSetIterator(set, key+value)を返す。
Note

iteration purposesにおいて、Setは各entryがkeyとvalueに同じvalueを持つMapにsimilarに見える。

24.2.4.7 Set.prototype.forEach ( callback [ , thisArg ] )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. IsCallable(callback)がfalseなら、TypeError例外をthrowする。
  4. entriesset.[[SetData]]とする。
  5. entriesCountentries内のelementsの数とする。
  6. indexを0とする。
  7. index < entriesCountの間、繰り返す
    1. entryentries[index]とする。
    2. indexindex + 1に設定する。
    3. entryemptyでないなら、
      1. Call(callback, thisArg, « entry, entry, set »)を実行する。
      2. NOTE: entries内のelementsの数はcallbackのexecution中に増加しているかもしれない。
      3. entriesCountentries内のelementsの数に設定する。
  8. undefinedを返す。
Note

callbackはthree argumentsをacceptするfunctionであるべきである。forEachSet object内にpresentな各valueについて、value insertion orderでcallbackを1回callする。callbackは、実際に存在するSetのvaluesについてのみcallされ、setからdeletedされたkeysについてはcallされない。

thisArg parameterがprovidedされた場合、それはcallbackの各invocationにおけるthis valueとして使用される。providedされない場合、代わりにundefinedが使用される。

callbackはthree argumentsでcallされる:first two argumentsはSet内にcontainedされるvalueである。両方のargumentsには同じvalueがpassedされる。traversedされるSet objectがthird argumentとしてpassedされる。

MapおよびArrayのforEach methodsで使用されるcall back functionsとconsistentにするため、callbackはthree argumentsでcallされる。Setでは、各item valueはkeyとvalueの両方であるとconsideredされる。

forEachは、それが呼び出されたobjectをdirectly mutateしないが、そのobjectはcallbackのcallsによってmutatedされるかもしれない。

各valueは通常1回だけvisitedされる。しかし、valueがvisitedされた後にdeletedされ、その後forEach callがcompletesする前にre-addedされた場合、そのvalueはrevisitedされる。forEachへのcallがbeginsした後、visitedされる前にdeletedされたvaluesは、forEach callがcompletesする前にvalueが再びaddedされない限り、visitedされない。forEachへのcallがbeginsした後にaddedされたnew valuesはvisitedされる。

24.2.4.8 Set.prototype.has ( value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. valueCanonicalizeKeyedCollectionKey(value)に設定する。
  4. set.[[SetData]]の各element entryについて、以下を行う
    1. entryemptyでなく、SameValue(entry, value)がtrueなら、trueを返す。
  5. falseを返す。

24.2.4.9 Set.prototype.intersection ( other )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. otherRecordを ? GetSetRecord(other) とする。
  4. resultSetDataを新しい空のListとする。
  5. SetDataSize(set.[[SetData]]) ≤ otherRecord.[[Size]]なら、
    1. thisSizeset.[[SetData]]内のelementsの数とする。
    2. indexを0とする。
    3. index < thisSizeの間、繰り返す
      1. entryset.[[SetData]][index]とする。
      2. indexindex + 1に設定する。
      3. entryemptyでないなら、
        1. inOtherToBoolean(? Call(otherRecord.[[Has]], otherRecord.[[SetObject]], « entry »))とする。
        2. inOthertrueなら、
          1. NOTE: otherRecord.[[Has]]へのearlier callsがset.[[SetData]]のelementをremoveしてre-addすることがpossibleであり、それによりこのiteration中に同じelementがtwice visitedされる可能性がある。
          2. SetDataHas(resultSetData, entry)がfalseなら、
            1. entryresultSetDataへappendする。
        3. NOTE: set.[[SetData]]内のelementsの数はotherRecord.[[Has]]のexecution中に増加しているかもしれない。
        4. thisSizeset.[[SetData]]内のelementsの数に設定する。
  6. そうでなければ、
    1. keysIteratorを ? GetIteratorFromMethod(otherRecord.[[SetObject]], otherRecord.[[Keys]]) とする。
    2. nextnot-startedとする。
    3. nextdoneでない間、繰り返す
      1. nextを ? IteratorStepValue(keysIterator) に設定する。
      2. nextdoneでないなら、
        1. nextCanonicalizeKeyedCollectionKey(next)に設定する。
        2. inThisSetDataHas(set.[[SetData]], next)とする。
        3. inThistrueなら、
          1. NOTE: otherはarbitrary objectであるため、その"keys" iteratorが同じvalueを複数回produceすることがpossibleである。
          2. SetDataHas(resultSetData, next)がfalseなら、
            1. nextresultSetDataへappendする。
  7. resultOrdinaryObjectCreate(%Set.prototype%, « [[SetData]] »)とする。
  8. result.[[SetData]]resultSetDataに設定する。
  9. resultを返す。

24.2.4.10 Set.prototype.isDisjointFrom ( other )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. otherRecordを ? GetSetRecord(other) とする。
  4. SetDataSize(set.[[SetData]]) ≤ otherRecord.[[Size]]なら、
    1. thisSizeset.[[SetData]]内のelementsの数とする。
    2. indexを0とする。
    3. index < thisSizeの間、繰り返す
      1. entryset.[[SetData]][index]とする。
      2. indexindex + 1に設定する。
      3. entryemptyでないなら、
        1. inOtherToBoolean(? Call(otherRecord.[[Has]], otherRecord.[[SetObject]], « entry »))とする。
        2. inOthertrueなら、falseを返す。
        3. NOTE: set.[[SetData]]内のelementsの数はotherRecord.[[Has]]のexecution中に増加しているかもしれない。
        4. thisSizeset.[[SetData]]内のelementsの数に設定する。
  5. そうでなければ、
    1. keysIteratorを ? GetIteratorFromMethod(otherRecord.[[SetObject]], otherRecord.[[Keys]]) とする。
    2. nextnot-startedとする。
    3. nextdoneでない間、繰り返す
      1. nextを ? IteratorStepValue(keysIterator) に設定する。
      2. nextdoneでないなら、
        1. SetDataHas(set.[[SetData]], next)がtrueなら、
          1. IteratorClose(keysIterator, NormalCompletion(unused))を実行する。
          2. falseを返す。
  6. trueを返す。

24.2.4.11 Set.prototype.isSubsetOf ( other )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. otherRecordを ? GetSetRecord(other) とする。
  4. SetDataSize(set.[[SetData]]) > otherRecord.[[Size]]なら、falseを返す。
  5. thisSizeset.[[SetData]]内のelementsの数とする。
  6. indexを0とする。
  7. index < thisSizeの間、繰り返す
    1. entryset.[[SetData]][index]とする。
    2. indexindex + 1に設定する。
    3. entryemptyでないなら、
      1. inOtherToBoolean(? Call(otherRecord.[[Has]], otherRecord.[[SetObject]], « entry »))とする。
      2. inOtherfalseなら、falseを返す。
      3. NOTE: set.[[SetData]]内のelementsの数はotherRecord.[[Has]]のexecution中に増加しているかもしれない。
      4. thisSizeset.[[SetData]]内のelementsの数に設定する。
  8. trueを返す。

24.2.4.12 Set.prototype.isSupersetOf ( other )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. otherRecordを ? GetSetRecord(other) とする。
  4. SetDataSize(set.[[SetData]]) < otherRecord.[[Size]]なら、falseを返す。
  5. keysIteratorを ? GetIteratorFromMethod(otherRecord.[[SetObject]], otherRecord.[[Keys]]) とする。
  6. nextnot-startedとする。
  7. nextdoneでない間、繰り返す
    1. nextを ? IteratorStepValue(keysIterator) に設定する。
    2. nextdoneでないなら、
      1. SetDataHas(set.[[SetData]], next)がfalseなら、
        1. IteratorClose(keysIterator, NormalCompletion(unused))を実行する。
        2. falseを返す。
  8. trueを返す。

24.2.4.13 Set.prototype.keys ( )

"keys" propertyのinitial valueは、24.2.4.17でdefinedされる%Set.prototype.values%である。

Note

iteration purposesにおいて、Setは各entryがkeyとvalueに同じvalueを持つMapにsimilarに見える。

24.2.4.14 get Set.prototype.size

Set.prototype.sizeは、set accessor functionがundefinedであるaccessor propertyである。そのget accessor functionは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. sizeSetDataSize(set.[[SetData]])とする。
  4. 𝔽(size)を返す。

24.2.4.15 Set.prototype.symmetricDifference ( other )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. otherRecordを ? GetSetRecord(other) とする。
  4. keysIteratorを ? GetIteratorFromMethod(otherRecord.[[SetObject]], otherRecord.[[Keys]]) とする。
  5. resultSetDataset.[[SetData]]のcopyとする。
  6. nextnot-startedとする。
  7. nextdoneでない間、繰り返す
    1. nextを ? IteratorStepValue(keysIterator) に設定する。
    2. nextdoneでないなら、
      1. nextCanonicalizeKeyedCollectionKey(next)に設定する。
      2. resultIndexSetDataIndex(resultSetData, next)とする。
      3. resultIndexnot-foundなら、alreadyInResultfalseとする;そうでなければ、alreadyInResulttrueとする。
      4. SetDataHas(set.[[SetData]], next)がtrueなら、
        1. alreadyInResulttrueなら、resultSetData[resultIndex]をemptyに設定する。
      5. そうでなければ、
        1. alreadyInResultfalseなら、nextresultSetDataへappendする。
  8. resultOrdinaryObjectCreate(%Set.prototype%, « [[SetData]] »)とする。
  9. result.[[SetData]]resultSetDataに設定する。
  10. resultを返す。

24.2.4.16 Set.prototype.union ( other )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. RequireInternalSlot(set, [[SetData]])を実行する。
  3. otherRecordを ? GetSetRecord(other) とする。
  4. keysIteratorを ? GetIteratorFromMethod(otherRecord.[[SetObject]], otherRecord.[[Keys]]) とする。
  5. resultSetDataset.[[SetData]]のcopyとする。
  6. nextnot-startedとする。
  7. nextdoneでない間、繰り返す
    1. nextを ? IteratorStepValue(keysIterator) に設定する。
    2. nextdoneでないなら、
      1. nextCanonicalizeKeyedCollectionKey(next)に設定する。
      2. SetDataHas(resultSetData, next)がfalseなら、
        1. nextresultSetDataへappendする。
  8. resultOrdinaryObjectCreate(%Set.prototype%, « [[SetData]] »)とする。
  9. result.[[SetData]]resultSetDataに設定する。
  10. resultを返す。

24.2.4.17 Set.prototype.values ( )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. setthis valueとする。
  2. CreateSetIterator(set, value)を返す。

24.2.4.18 Set.prototype [ %Symbol.iterator% ] ( )

%Symbol.iterator% propertyのinitial valueは、24.2.4.17でdefinedされる%Set.prototype.values%である。

24.2.4.19 Set.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "Set"である。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持つ。

24.2.5 Set Instancesのプロパティ

Set instancesはSet prototype objectからpropertiesをinheritするordinary objectsである。Set instancesは[[SetData]] internal slotも持つ。

24.2.6 Set Iteratorオブジェクト

Set Iteratorは、下でdefinedされるstructureを持つordinary objectであり、あるspecific Set instance objectに対するspecific iterationをrepresentする。Set Iterator objectsにはnamed constructorは存在しない。代わりに、Set Iterator objectsはSet instance objectsのcertain methodsをcallingすることでcreatedされる。

24.2.6.1 CreateSetIterator ( set, kind )

The abstract operation CreateSetIterator takes arguments set (an ECMAScript language value) and kind (key+value or value) and returns either a normal completion containing a Generator or a throw completion. Set methodsがreturnするそのようなiteratorsiterator objectsをcreateするために使用される。 It performs the following steps when called:

  1. RequireInternalSlot(set, [[SetData]])を実行する。
  2. closureを、parametersを持たず、setおよびkindをcapturesし、呼び出されたときに次のstepsを実行する新しいAbstract Closureとする:
    1. indexを0とする。
    2. entriesset.[[SetData]]とする。
    3. entriesCountentries内のelementsの数とする。
    4. index < entriesCountの間、繰り返す
      1. entryentries[index]とする。
      2. indexindex + 1に設定する。
      3. entryemptyでないなら、
        1. kindkey+valueなら、
          1. resultCreateArrayFromListentry, entry »)とする。
          2. GeneratorYield(CreateIteratorResultObject(result, false))を実行する。
        2. そうでなければ、
          1. Assert: kindvalueである。
          2. GeneratorYield(CreateIteratorResultObject(entry, false))を実行する。
        3. NOTE: このabstract operationのexecutionがGeneratorYieldによりpausedされている間に、entries内のelementsの数が増加しているかもしれない。
        4. entriesCountentries内のelementsの数に設定する。
    5. NormalCompletion(unused)を返す。
  3. CreateIteratorFromClosure(closure, "%SetIteratorPrototype%", %SetIteratorPrototype%)を返す。

24.2.6.2 %SetIteratorPrototype% Object

%SetIteratorPrototype% objectは:

24.2.6.2.1 %SetIteratorPrototype%.next ( )

  1. GeneratorResume(this value, empty, "%SetIteratorPrototype%")を返す。

24.2.6.2.2 %SetIteratorPrototype% [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "Set Iterator"である。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持つ。

24.3 WeakMapオブジェクト

WeakMapはkey/value pairのcollectionsであり、keysはobjectsおよび/またはsymbolsであり、valuesは任意のECMAScript language valuesであってよい。WeakMapは、specific keyを持つkey/value pairをcontainするかどうかqueryできるが、keysとして保持しているvaluesをenumerateするmechanismはprovidedされない。certain conditionsでは、liveでないvaluesはWeakMap keysとしてremovedされる。これは9.9.3でdescribedされる。

implementationは、WeakMapのkey/value pairがinaccessibleになる時点と、そのkey/value pairがWeakMapからremovedされる時点との間に、arbitrarily determined latencyをimposeしてもよい。このlatencyがECMAScript programにobservableであったなら、それはprogram executionに影響し得るindeterminacyのsourceとなる。そのため、ECMAScript implementationは、observed keyをobserverにpresentすることをrequireしないWeakMapのkeyをobserveするmeansを一切provideしてはならない。

WeakMapは、平均的にcollection内のkey/value pairs数に対してsublinearなaccess timeを提供するhash tableまたはその他のmechanismsを用いて実装されなければならない。この仕様で用いられるdata structureは、WeakMapのrequired observable semanticsをdescribeすることだけを意図している。viable implementation modelであることは意図されていない。

Note

WeakMapおよびWeakSetは、WeakMapまたはWeakSet instanceが存在しない場合にobjectまたはsymbolがotherwise inaccessibleとなり、implementationのgarbage collection mechanismsによるresource reclamationのsubjectとなるときに、memory resourcesを“leak”しないmannerでstateをobjectまたはsymbolにdynamically associatingするためのmechanismsをprovideすることを意図している。このcharacteristicは、WeakMapまたはWeakSet instancesからkeysへのinverted per-object/symbol mappingを使用することでachievedできる。あるいは、各WeakMapまたはWeakSet instanceはそのkeyおよびvalue dataをinternally storeしてもよいが、このapproachはWeakMapまたはWeakSet implementationとgarbage collectorとのcoordinationをrequireする。以下のreferencesは、WeakMapおよびWeakSetのimplementationsにusefulであり得るmechanismをdescribeする:

Barry Hayes. 1997. Ephemerons: a new finalization mechanism. In Proceedings of the 12th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA '97), A. Michael Berman (Ed.). ACM, New York, NY, USA, 176-183, http://doi.acm.org/10.1145/263698.263733.

Alexandra Barros, Roberto Ierusalimschy, Eliminating Cycles in Weak Tables. Journal of Universal Computer Science - J.UCS, vol. 14, no. 21, pp. 3481-3497, 2008, http://www.jucs.org/jucs_14_21/eliminating_cycles_in_weak

24.3.1 WeakMap Constructor

WeakMap constructorは:

  • %WeakMap%である。
  • global object"WeakMap" propertyのinitial valueである。
  • constructorとして呼び出されたとき、新しいWeakMapをcreateしてinitializeする。
  • functionとして呼び出されることは意図されておらず、そのように呼び出された場合はexceptionをthrowする。
  • クラス定義の extends 句内の値として使用できる。指定された WeakMap の動作を継承しようとするサブクラスコンストラクターは、WeakMap.prototype の組み込みメソッドをサポートするために必要な内部状態でサブクラスインスタンスを作成し初期化するため、WeakMap コンストラクターへの super 呼び出しを含めなければならない。

24.3.1.1 WeakMap ( [ iterable ] )

このfunctionは、呼び出されたときに次のstepsを実行する:

  1. NewTargetがundefinedなら、TypeError例外をthrowする。
  2. mapを ? OrdinaryCreateFromConstructor(NewTarget, "%WeakMap.prototype%", « [[WeakMapData]] ») とする。
  3. map.[[WeakMapData]]を新しい空のListに設定する。
  4. iterableundefinedまたはnullのどちらかなら、mapを返す。
  5. adderを ? Get(map, "set") とする。
  6. IsCallable(adder)がfalseなら、TypeError例外をthrowする。
  7. AddEntriesFromIterable(map, iterable, adder)を返す。
Note

parameter iterableがpresentである場合、それは%Symbol.iterator% methodを実装するobjectであることがexpectedされ、そのmethodは、first elementがWeakMap keyとして使用されるvalueであり、second elementがそのkeyにassociateされるvalueであるtwo element array-like objectをproduceするiterator objectを返す。

24.3.2 WeakMap Constructorのプロパティ

WeakMap constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持つ。
  • 次のpropertiesを持つ:

24.3.2.1 WeakMap.prototype

WeakMap.prototypeのinitial valueはWeakMap prototype objectである。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持つ。

24.3.3 WeakMap Prototype Objectのプロパティ

WeakMap prototype objectは:

  • %WeakMap.prototype%である。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持つ。
  • ordinary objectである。
  • [[WeakMapData]] internal slotを持たない。

24.3.3.1 WeakMap.prototype.constructor

WeakMap.prototype.constructorのinitial valueは%WeakMap%である。

24.3.3.2 WeakMap.prototype.delete ( key )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. weakMapthis valueとする。
  2. RequireInternalSlot(weakMap, [[WeakMapData]])を実行する。
  3. CanBeHeldWeakly(key)がfalseなら、falseを返す。
  4. weakMap.[[WeakMapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、
      1. entry.[[Key]]emptyに設定する。
      2. entry.[[Value]]emptyに設定する。
      3. trueを返す。
  5. falseを返す。
Note

value emptyは、entryがdeletedされたことをindicateするためのspecification deviceとして使用される。実際のimplementationsは、entryをinternal data structuresからphysically removingするなど、他のactionsを取ってもよい。

24.3.3.3 WeakMap.prototype.get ( key )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. weakMapthis valueとする。
  2. RequireInternalSlot(weakMap, [[WeakMapData]])を実行する。
  3. CanBeHeldWeakly(key)がfalseなら、undefinedを返す。
  4. weakMap.[[WeakMapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、entry.[[Value]]を返す。
  5. undefinedを返す。

24.3.3.4 WeakMap.prototype.getOrInsert ( key, value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. weakMapthis valueとする。
  2. RequireInternalSlot(weakMap, [[WeakMapData]])を実行する。
  3. CanBeHeldWeakly(key)がfalseなら、TypeError例外をthrowする。
  4. weakMap.[[WeakMapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、entry.[[Value]]を返す。
  5. entryRecord { [[Key]]: key, [[Value]]: value }とする。
  6. entryweakMap.[[WeakMapData]]へappendする。
  7. valueを返す。

24.3.3.5 WeakMap.prototype.getOrInsertComputed ( key, callback )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. weakMapthis valueとする。
  2. RequireInternalSlot(weakMap, [[WeakMapData]])を実行する。
  3. CanBeHeldWeakly(key)がfalseなら、TypeError例外をthrowする。
  4. IsCallable(callback)がfalseなら、TypeError例外をthrowする。
  5. weakMap.[[WeakMapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、entry.[[Value]]を返す。
  6. valueを ? Call(callback, undefined, « key ») とする。
  7. NOTE: WeakMapはcallbackのexecution中にmodifiedされているかもしれない。
  8. weakMap.[[WeakMapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、
      1. entry.[[Value]]valueに設定する。
      2. valueを返す。
  9. entryRecord { [[Key]]: key, [[Value]]: value }とする。
  10. entryweakMap.[[WeakMapData]]へappendする。
  11. valueを返す。

24.3.3.6 WeakMap.prototype.has ( key )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. weakMapthis valueとする。
  2. RequireInternalSlot(weakMap, [[WeakMapData]])を実行する。
  3. CanBeHeldWeakly(key)がfalseなら、falseを返す。
  4. weakMap.[[WeakMapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、trueを返す。
  5. falseを返す。

24.3.3.7 WeakMap.prototype.set ( key, value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. weakMapthis valueとする。
  2. RequireInternalSlot(weakMap, [[WeakMapData]])を実行する。
  3. CanBeHeldWeakly(key)がfalseなら、TypeError例外をthrowする。
  4. weakMap.[[WeakMapData]]の各Record { [[Key]], [[Value]] } entryについて、以下を行う
    1. entry.[[Key]]emptyでなく、SameValue(entry.[[Key]], key)がtrueなら、
      1. entry.[[Value]]valueに設定する。
      2. weakMapを返す。
  5. entryRecord { [[Key]]: key, [[Value]]: value }とする。
  6. entryweakMap.[[WeakMapData]]へappendする。
  7. weakMapを返す。

24.3.3.8 WeakMap.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "WeakMap"である。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持つ。

24.3.4 WeakMap Instancesのプロパティ

WeakMap instancesはWeakMap prototype objectからpropertiesをinheritするordinary objectsである。WeakMap instancesは[[WeakMapData]] internal slotも持つ。

24.4 WeakSetオブジェクト

WeakSetはobjectsおよび/またはsymbolsのcollectionsである。distinct objectまたはsymbolはWeakSetのcollectionのelementとして1回だけ出現してよい。WeakSetはspecific valueをcontainするかどうかqueryできるが、保持しているvaluesをenumerateするmechanismはprovidedされない。certain conditionsでは、liveでないvaluesはWeakSet elementsとしてremovedされる。これは9.9.3でdescribedされる。

implementationは、WeakSet内にcontainedされるvalueがinaccessibleになる時点と、そのvalueがWeakSetからremovedされる時点との間に、arbitrarily determined latencyをimposeしてもよい。このlatencyがECMAScript programにobservableであったなら、それはprogram executionに影響し得るindeterminacyのsourceとなる。そのため、ECMAScript implementationは、observed valueをobserverにpresentすることをrequireしないparticular valueをWeakSetがcontainするかどうかをdetermineするmeansを一切provideしてはならない。

WeakSetは、平均的にcollection内のelements数に対してsublinearなaccess timeを提供するhash tableまたはその他のmechanismsを用いて実装されなければならない。この仕様で用いられるdata structureは、WeakSetのrequired observable semanticsをdescribeすることだけを意図している。viable implementation modelであることは意図されていない。

Note

24.3内のNOTEを参照。

24.4.1 WeakSet Constructor

WeakSet constructorは:

  • %WeakSet%である。
  • global object"WeakSet" propertyのinitial valueである。
  • constructorとして呼び出されたとき、新しいWeakSetをcreateしてinitializeする。
  • functionとして呼び出されることは意図されておらず、そのように呼び出された場合はexceptionをthrowする。
  • クラス定義の extends 句内の値として使用できる。指定された WeakSet の動作を継承しようとするサブクラスコンストラクターは、WeakSet.prototype の組み込みメソッドをサポートするために必要な内部状態でサブクラスインスタンスを作成し初期化するため、WeakSet コンストラクターへの super 呼び出しを含めなければならない。

24.4.1.1 WeakSet ( [ iterable ] )

このfunctionは、呼び出されたときに次のstepsを実行する:

  1. NewTargetがundefinedなら、TypeError例外をthrowする。
  2. setを ? OrdinaryCreateFromConstructor(NewTarget, "%WeakSet.prototype%", « [[WeakSetData]] ») とする。
  3. set.[[WeakSetData]]を新しい空のListに設定する。
  4. iterableundefinedまたはnullのどちらかなら、setを返す。
  5. adderを ? Get(set, "add") とする。
  6. IsCallable(adder)がfalseなら、TypeError例外をthrowする。
  7. iteratorRecordを ? GetIterator(iterable, sync) とする。
  8. 繰り返す、
    1. nextを ? IteratorStepValue(iteratorRecord) とする。
    2. nextdoneなら、setを返す。
    3. statusCompletion(Call(adder, set, « next »))とする。
    4. IfAbruptCloseIterator(status, iteratorRecord)。

24.4.2 WeakSet Constructorのプロパティ

WeakSet constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持つ。
  • 次のpropertiesを持つ:

24.4.2.1 WeakSet.prototype

WeakSet.prototypeのinitial valueはWeakSet prototype objectである。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持つ。

24.4.3 WeakSet Prototype Objectのプロパティ

WeakSet prototype objectは:

  • %WeakSet.prototype%である。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持つ。
  • ordinary objectである。
  • [[WeakSetData]] internal slotを持たない。

24.4.3.1 WeakSet.prototype.add ( value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. weakSetthis valueとする。
  2. RequireInternalSlot(weakSet, [[WeakSetData]])を実行する。
  3. CanBeHeldWeakly(value)がfalseなら、TypeError例外をthrowする。
  4. weakSet.[[WeakSetData]]の各element entryについて、以下を行う
    1. entryemptyでなく、SameValue(entry, value)がtrueなら、
      1. weakSetを返す。
  5. valueweakSet.[[WeakSetData]]へappendする。
  6. weakSetを返す。

24.4.3.2 WeakSet.prototype.constructor

WeakSet.prototype.constructorのinitial valueは%WeakSet%である。

24.4.3.3 WeakSet.prototype.delete ( value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. weakSetthis valueとする。
  2. RequireInternalSlot(weakSet, [[WeakSetData]])を実行する。
  3. CanBeHeldWeakly(value)がfalseなら、falseを返す。
  4. weakSet.[[WeakSetData]]の各element entryについて、以下を行う
    1. entryemptyでなく、SameValue(entry, value)がtrueなら、
      1. valueがentryであるweakSet.[[WeakSetData]]のelementを、valueがemptyであるelementでreplaceする。
      2. trueを返す。
  5. falseを返す。
Note

value emptyは、entryがdeletedされたことをindicateするためのspecification deviceとして使用される。実際のimplementationsは、entryをinternal data structuresからphysically removingするなど、他のactionsを取ってもよい。

24.4.3.4 WeakSet.prototype.has ( value )

このmethodは、呼び出されたときに次のstepsを実行する:

  1. weakSetthis valueとする。
  2. RequireInternalSlot(weakSet, [[WeakSetData]])を実行する。
  3. CanBeHeldWeakly(value)がfalseなら、falseを返す。
  4. weakSet.[[WeakSetData]]の各element entryについて、以下を行う
    1. entryemptyでなく、SameValue(entry, value)がtrueなら、trueを返す。
  5. falseを返す。

24.4.3.5 WeakSet.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "WeakSet"である。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持つ。

24.4.4 WeakSet Instancesのプロパティ

WeakSet instancesはWeakSet prototype objectからpropertiesをinheritするordinary objectsである。WeakSet instancesは[[WeakSetData]] internal slotも持つ。

24.5 Keyed Collectionsの抽象操作

24.5.1 CanonicalizeKeyedCollectionKey ( key )

The abstract operation CanonicalizeKeyedCollectionKey takes argument key (an ECMAScript language value) and returns an ECMAScript language value. It performs the following steps when called:

  1. key-0𝔽なら、+0𝔽を返す。
  2. keyを返す。