24 Keyed Collections

24.1 Map Objects

Maps는 keys와 values 모두 arbitrary ECMAScript language values일 수 있는 key/value pairs의 collections입니다. distinct key value는 Map의 collection 안에서 하나의 key/value pair에만 occur할 수 있습니다. Distinct key values는 SameValueZero comparison algorithm의 semantics를 사용하여 discriminated됩니다.

Maps는 collection 안의 elements 수에 대해 average로 sublinear인 access times를 제공하는 hash tables 또는 other mechanisms를 사용하여 implemented되어야 합니다. 이 specification에서 사용되는 data structure는 Maps의 required observable semantics를 describe하기 위한 것일 뿐입니다. viable implementation model로 intended되지 않습니다.

24.1.1 The Map Constructor

Map constructor는:

  • %Map%입니다.
  • global object"Map" property의 initial value입니다.
  • constructor로 called될 때 new Map을 create하고 initialize합니다.
  • function으로 called되도록 intended되지 않으며, such manner로 called될 때 exception을 throw합니다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 Map 동작을 상속하려는 서브클래스 생성자는 Map.prototype의 내장 메서드를 지원하는 데 필요한 내부 상태로 서브클래스 인스턴스를 생성하고 초기화하기 위해 Map 생성자에 대한 super 호출을 포함해야 한다.

24.1.1.1 Map ( [ iterable ] )

이 function은 called될 때 다음 steps를 수행합니다:

  1. NewTarget이 undefined이면, TypeError exception을 throw한다.
  2. map을 ? OrdinaryCreateFromConstructor(NewTarget, "%Map.prototype%", « [[MapData]] »)로 둔다.
  3. map.[[MapData]]를 새 empty List로 설정한다.
  4. iterableundefined 또는 null 중 하나이면, map을 반환한다.
  5. adder를 ? Get(map, "set")로 둔다.
  6. IsCallable(adder)가 false이면, TypeError exception을 throw한다.
  7. AddEntriesFromIterable(map, iterable, adder)를 반환한다.
Note

parameter iterable이 present하면, 이는 two element array-like object를 produce하는 iterator object를 반환하는 %Symbol.iterator% method를 implement하는 object일 것으로 expected됩니다. 그 first element는 Map key로 사용될 value이고 second element는 그 key와 associate할 value입니다.

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. addertarget을 receiver로 하여 invoked됩니다. It performs the following steps when called:

  1. iteratorRecord를 ? GetIterator(iterable, sync)로 둔다.
  2. Repeat,
    1. next를 ? IteratorStepValue(iteratorRecord)로 둔다.
    2. nextdone이면, target을 반환한다.
    3. next가 Object가 아니면, 다음을 수행한다.
      1. errorThrowCompletion(a 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은 two element array-like object를 produce하는 iterator object를 반환하는 %Symbol.iterator% method를 implement하는 object일 것으로 expected됩니다. 그 first element는 Map key로 사용될 value이고 second element는 그 key와 associate할 value입니다.

24.1.2 Properties of the 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을 한 번씩 calls하고, new Map을 constructs합니다. callback에 의해 returned되는 each value는 Map 안의 key로 사용됩니다. such key마다, result Map은 key가 that key이고 value가 callback이 that key를 returned한 all elements를 containing하는 array인 entry를 가집니다.

callback은 two arguments, 즉 element의 value와 element의 index로 called됩니다.

groupBy의 return value는 Map입니다.

이 function은 called될 때 다음 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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는 default constructor assignment를 change하기 위해 %Symbol.species%를 over-ride할 수 있습니다.

24.1.3 Properties of the 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는 called될 때 다음 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

that List를 iterating하는 중간에 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는 called될 때 다음 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로 사용됩니다. Actual implementations는 internal data structures에서 entry를 physically removing하는 것과 같은 other actions를 취할 수 있습니다.

24.1.3.4 Map.prototype.entries ( )

이 method는 called될 때 다음 steps를 수행합니다:

  1. mapthis value로 둔다.
  2. CreateMapIterator(map, key+value)를 반환한다.

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

이 method는 called될 때 다음 steps를 수행합니다:

  1. mapthis value로 둔다.
  2. RequireInternalSlot(map, [[MapData]])를 수행한다.
  3. IsCallable(callback)가 false이면, TypeError exception을 throw한다.
  4. entriesmap.[[MapData]]로 둔다.
  5. entriesCountentries 안의 elements 수로 둔다.
  6. index를 0으로 둔다.
  7. Repeat, while 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 동안 increased되었을 수 있다.
      3. entriesCountentries 안의 elements 수로 설정한다.
  8. undefined를 반환한다.
Note

callback은 three arguments를 accept하는 function이어야 합니다. forEach는 Map 안에 present한 each key/value pair에 대해 key insertion order로 callback을 한 번씩 calls합니다. callback은 actually exist하는 Map의 keys에 대해서만 called되며, Map에서 deleted된 keys에 대해서는 called되지 않습니다.

thisArg parameter가 provided되면, callback의 each invocation에서 this value로 사용됩니다. provided되지 않으면, 대신 undefined가 사용됩니다.

callback은 three arguments, 즉 item의 value, item의 key, 그리고 traversed되는 Map으로 called됩니다.

forEach는 called된 object를 directly mutate하지 않지만, object는 callback calls에 의해 mutated될 수 있습니다. map의 [[MapData]]의 each entry는 한 번만 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가 again added되지 않는 한 visited되지 않습니다.

24.1.3.6 Map.prototype.get ( key )

이 method는 called될 때 다음 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는 called될 때 다음 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는 called될 때 다음 steps를 수행합니다:

  1. mapthis value로 둔다.
  2. RequireInternalSlot(map, [[MapData]])를 수행한다.
  3. IsCallable(callback)가 false이면, TypeError exception을 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는 called될 때 다음 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는 called될 때 다음 steps를 수행합니다:

  1. mapthis value로 둔다.
  2. CreateMapIterator(map, key)를 반환한다.

24.1.3.11 Map.prototype.set ( key, value )

이 method는 called될 때 다음 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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는 called될 때 다음 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 Properties of Map Instances

Map instances는 Map prototype object로부터 properties를 inherit하는 ordinary objects입니다. Map instances는 또한 [[MapData]] internal slot을 가집니다.

24.1.5 Map Iterator Objects

Map Iterator는 some specific Map instance object에 대한 specific iteration을 represents하는 object입니다. Map Iterator objects에 대한 named constructor는 없습니다. Instead, 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. such iterators를 return하는 Map methods용 iterator objects를 create하는 데 사용됩니다. It performs the following steps when called:

  1. RequireInternalSlot(map, [[MapData]])를 수행한다.
  2. mapkind를 capture하고 called될 때 다음 steps를 수행하는, parameters가 없는 새 Abstract Closure closure를 둔다:
    1. entriesmap.[[MapData]]로 둔다.
    2. index를 0으로 둔다.
    3. entriesCountentries 안의 elements 수로 둔다.
    4. Repeat, while index < entriesCount,
      1. entryentries[index]로 둔다.
      2. indexindex + 1로 설정한다.
      3. entry.[[Key]]empty가 아니면, 다음을 수행한다.
        1. kindkey이면, 다음을 수행한다.
          1. resultentry.[[Key]]로 둔다.
        2. Else if kindvalue이면, 다음을 수행한다.
          1. resultentry.[[Value]]로 둔다.
        3. Else,
          1. Assert: kindkey+value이다.
          2. resultCreateArrayFromListentry.[[Key]], entry.[[Value]] »)로 둔다.
        4. GeneratorYield(CreateIteratorResultObject(result, false))를 수행한다.
        5. NOTE: 이 abstract operation의 execution이 GeneratorYield에 의해 paused된 동안 entries 안의 elements 수가 increased되었을 수 있다.
        6. entriesCountentries 안의 elements 수로 설정한다.
    5. NormalCompletion(unused)을 반환한다.
  3. CreateIteratorFromClosure(closure, "%MapIteratorPrototype%", %MapIteratorPrototype%)를 반환한다.

24.1.5.2 The %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 Objects

Set objectsECMAScript language values의 collections입니다. Set은 each distinct value를 at most once contain할 수 있습니다. Distinct values는 SameValueZero comparison algorithm의 semantics를 사용하여 discriminated됩니다.

Set objects는 collection 안의 elements 수에 대해 average로 sublinear인 access times를 제공하는 hash tables 또는 other mechanisms를 사용하여 implemented되어야 합니다. 이 specification에서 사용되는 data structure는 Set objects의 required observable semantics를 describe하기 위한 것일 뿐입니다. viable implementation model로 intended되지 않습니다.

24.2.1 Abstract Operations For Set Objects

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]] an Object Set 또는 similar object입니다.
[[Size]] a non-negative integer or +∞ object의 reported size입니다.
[[Has]] a function object object의 has method입니다.
[[Keys]] a 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 exception을 throw한다.
  2. rawSize를 ? Get(obj, "size")로 둔다.
  3. numberSize를 ? ToNumber(rawSize)로 둔다.
  4. NOTE: rawSizeundefined이면, numberSizeNaN이 된다.
  5. numberSizeNaN이면, TypeError exception을 throw한다.
  6. intSize를 ! ToIntegerOrInfinity(numberSize)로 둔다.
  7. intSize < 0이면, RangeError exception을 throw한다.
  8. has를 ? Get(obj, "has")로 둔다.
  9. IsCallable(has)가 false이면, TypeError exception을 throw한다.
  10. keys를 ? Get(obj, "keys")로 둔다.
  11. IsCallable(keys)가 false이면, TypeError exception을 throw한다.
  12. new 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. Repeat, while 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 The Set Constructor

Set constructor는:

  • %Set%입니다.
  • global object"Set" property의 initial value입니다.
  • constructor로 called될 때 new Set object를 create하고 initialize합니다.
  • function으로 called되도록 intended되지 않으며, such manner로 called될 때 exception을 throw합니다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 Set 동작을 상속하려는 서브클래스 생성자는 Set.prototype의 내장 메서드를 지원하는 데 필요한 내부 상태로 서브클래스 인스턴스를 생성하고 초기화하기 위해 Set 생성자에 대한 super 호출을 포함해야 한다.

24.2.2.1 Set ( [ iterable ] )

이 function은 called될 때 다음 steps를 수행합니다:

  1. NewTarget이 undefined이면, TypeError exception을 throw한다.
  2. set을 ? OrdinaryCreateFromConstructor(NewTarget, "%Set.prototype%", « [[SetData]] »)로 둔다.
  3. set.[[SetData]]를 새 empty List로 설정한다.
  4. iterableundefined 또는 null 중 하나이면, set을 반환한다.
  5. adder를 ? Get(set, "add")로 둔다.
  6. IsCallable(adder)가 false이면, TypeError exception을 throw한다.
  7. iteratorRecord를 ? GetIterator(iterable, sync)로 둔다.
  8. Repeat,
    1. next를 ? IteratorStepValue(iteratorRecord)로 둔다.
    2. nextdone이면, set을 반환한다.
    3. statusCompletion(Call(adder, set, « next »))로 둔다.
    4. IfAbruptCloseIterator(status, iteratorRecord).

24.2.3 Properties of the 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이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 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는 default constructor assignment를 change하기 위해 %Symbol.species%를 over-ride할 수 있습니다.

24.2.4 Properties of the 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는 called될 때 다음 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는 called될 때 다음 steps를 수행합니다:

  1. setthis value로 둔다.
  2. RequireInternalSlot(set, [[SetData]])를 수행한다.
  3. set.[[SetData]]의 각 element entry에 대해, 다음을 수행한다.
    1. value가 entryset.[[SetData]]의 element를 value가 empty인 element로 replace한다.
  4. undefined를 반환한다.
Note

that List를 iterating하는 중간에 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는 called될 때 다음 steps를 수행합니다:

  1. setthis value로 둔다.
  2. RequireInternalSlot(set, [[SetData]])를 수행한다.
  3. valueCanonicalizeKeyedCollectionKey(value)로 설정한다.
  4. set.[[SetData]]의 각 element entry에 대해, 다음을 수행한다.
    1. entryempty가 아니고 SameValue(entry, value)가 true이면, 다음을 수행한다.
      1. value가 entryset.[[SetData]]의 element를 value가 empty인 element로 replace한다.
      2. true를 반환한다.
  5. false를 반환한다.
Note

value empty는 entry가 deleted되었음을 indicate하기 위한 specification device로 사용됩니다. Actual implementations는 internal data structures에서 entry를 physically removing하는 것과 같은 other actions를 취할 수 있습니다.

24.2.4.5 Set.prototype.difference ( other )

이 method는 called될 때 다음 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. Repeat, while 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. Else,
    1. keysIterator를 ? GetIteratorFromMethod(otherRecord.[[SetObject]], otherRecord.[[Keys]])로 둔다.
    2. nextnot-started로 둔다.
    3. Repeat, while 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는 called될 때 다음 steps를 수행합니다:

  1. setthis value로 둔다.
  2. CreateSetIterator(set, key+value)를 반환한다.
Note

iteration purposes에서는, Set은 each entry가 its key와 value에 대해 same value를 가지는 Map과 similar하게 appears합니다.

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

이 method는 called될 때 다음 steps를 수행합니다:

  1. setthis value로 둔다.
  2. RequireInternalSlot(set, [[SetData]])를 수행한다.
  3. IsCallable(callback)가 false이면, TypeError exception을 throw한다.
  4. entriesset.[[SetData]]로 둔다.
  5. entriesCountentries 안의 elements 수로 둔다.
  6. index를 0으로 둔다.
  7. Repeat, while index < entriesCount,
    1. entryentries[index]로 둔다.
    2. indexindex + 1로 설정한다.
    3. entryempty가 아니면, 다음을 수행한다.
      1. Call(callback, thisArg, « entry, entry, set »)를 수행한다.
      2. NOTE: entries 안의 elements 수는 callback의 execution 동안 increased되었을 수 있다.
      3. entriesCountentries 안의 elements 수로 설정한다.
  8. undefined를 반환한다.
Note

callback은 three arguments를 accept하는 function이어야 합니다. forEachSet object 안에 present한 each value에 대해 value insertion order로 callback을 한 번씩 calls합니다. callback은 actually exist하는 Set의 values에 대해서만 called되며, set에서 deleted된 keys에 대해서는 called되지 않습니다.

thisArg parameter가 provided되면, callback의 each invocation에서 this value로 사용됩니다. provided되지 않으면, 대신 undefined가 사용됩니다.

callback은 three arguments로 called됩니다: first two arguments는 Set 안에 contained된 value입니다. same value가 both arguments로 passed됩니다. traversed되는 Set object는 third argument로 passed됩니다.

callback은 Map 및 Array용 forEach methods가 사용하는 call back functions와 consistent하기 위해 three arguments로 called됩니다. Sets에서는 each item value가 key이자 value인 것으로 considered됩니다.

forEach는 called된 object를 directly mutate하지 않지만, object는 callback calls에 의해 mutated될 수 있습니다.

Each value는 normally 한 번만 visited됩니다. However, value가 visited된 후 deleted되고 forEach call이 completes되기 전에 re-added되면 value는 revisited됩니다. forEach call이 begins된 후 visited되기 전에 deleted된 values는, forEach call이 completes되기 전에 value가 again added되지 않는 한 visited되지 않습니다. forEach call이 begins된 후 added된 new values는 visited됩니다.

24.2.4.8 Set.prototype.has ( value )

이 method는 called될 때 다음 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는 called될 때 다음 steps를 수행합니다:

  1. setthis value로 둔다.
  2. RequireInternalSlot(set, [[SetData]])를 수행한다.
  3. otherRecord를 ? GetSetRecord(other)로 둔다.
  4. resultSetData를 새 empty List로 둔다.
  5. SetDataSize(set.[[SetData]]) ≤ otherRecord.[[Size]]이면, 다음을 수행한다.
    1. thisSizeset.[[SetData]] 안의 elements 수로 둔다.
    2. index를 0으로 둔다.
    3. Repeat, while 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할 수 있으며, 이로 인해 same element가 이 iteration 동안 twice visited될 수 있다.
          2. SetDataHas(resultSetData, entry)가 false이면, 다음을 수행한다.
            1. entryresultSetData에 append한다.
        3. NOTE: set.[[SetData]] 안의 elements 수는 otherRecord.[[Has]]의 execution 동안 increased되었을 수 있다.
        4. thisSizeset.[[SetData]] 안의 elements 수로 설정한다.
  6. Else,
    1. keysIterator를 ? GetIteratorFromMethod(otherRecord.[[SetObject]], otherRecord.[[Keys]])로 둔다.
    2. nextnot-started로 둔다.
    3. Repeat, while nextdone이 아니면,
      1. next를 ? IteratorStepValue(keysIterator)로 설정한다.
      2. nextdone이 아니면, 다음을 수행한다.
        1. nextCanonicalizeKeyedCollectionKey(next)로 설정한다.
        2. inThisSetDataHas(set.[[SetData]], next)로 둔다.
        3. inThistrue이면, 다음을 수행한다.
          1. NOTE: other는 arbitrary object이므로, its "keys" iterator가 same value를 more than once produce할 수 있다.
          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는 called될 때 다음 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. Repeat, while 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 동안 increased되었을 수 있다.
        4. thisSizeset.[[SetData]] 안의 elements 수로 설정한다.
  5. Else,
    1. keysIterator를 ? GetIteratorFromMethod(otherRecord.[[SetObject]], otherRecord.[[Keys]])로 둔다.
    2. nextnot-started로 둔다.
    3. Repeat, while 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는 called될 때 다음 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. Repeat, while 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 동안 increased되었을 수 있다.
      4. thisSizeset.[[SetData]] 안의 elements 수로 설정한다.
  8. true를 반환한다.

24.2.4.12 Set.prototype.isSupersetOf ( other )

이 method는 called될 때 다음 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. Repeat, while 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은 each entry가 its key와 value에 대해 same value를 가지는 Map과 similar하게 appears합니다.

24.2.4.14 get Set.prototype.size

Set.prototype.size는 set accessor function이 undefinedaccessor property입니다. Its get accessor function은 called될 때 다음 steps를 수행합니다:

  1. setthis value로 둔다.
  2. RequireInternalSlot(set, [[SetData]])를 수행한다.
  3. sizeSetDataSize(set.[[SetData]])로 둔다.
  4. 𝔽(size)를 반환한다.

24.2.4.15 Set.prototype.symmetricDifference ( other )

이 method는 called될 때 다음 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. Repeat, while nextdone이 아니면,
    1. next를 ? IteratorStepValue(keysIterator)로 설정한다.
    2. nextdone이 아니면, 다음을 수행한다.
      1. nextCanonicalizeKeyedCollectionKey(next)로 설정한다.
      2. resultIndexSetDataIndex(resultSetData, next)로 둔다.
      3. resultIndexnot-found이면 alreadyInResultfalse로 둔다; else alreadyInResulttrue로 둔다.
      4. SetDataHas(set.[[SetData]], next)가 true이면, 다음을 수행한다.
        1. alreadyInResulttrue이면, resultSetData[resultIndex]를 empty로 설정한다.
      5. Else,
        1. alreadyInResultfalse이면, nextresultSetData에 append한다.
  8. resultOrdinaryObjectCreate(%Set.prototype%, « [[SetData]] »)로 둔다.
  9. result.[[SetData]]resultSetData로 설정한다.
  10. result를 반환한다.

24.2.4.16 Set.prototype.union ( other )

이 method는 called될 때 다음 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. Repeat, while 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는 called될 때 다음 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 Properties of Set Instances

Set instances는 Set prototype object로부터 properties를 inherit하는 ordinary objects입니다. Set instances는 또한 [[SetData]] internal slot을 가집니다.

24.2.6 Set Iterator Objects

Set Iterator는 below에 defined된 structure를 가진 ordinary object이며, some specific Set instance object에 대한 specific iteration을 represents합니다. Set Iterator objects에 대한 named constructor는 없습니다. Instead, 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. such iterators를 return하는 Set methods용 iterator objects를 create하는 데 사용됩니다. It performs the following steps when called:

  1. RequireInternalSlot(set, [[SetData]])를 수행한다.
  2. setkind를 capture하고 called될 때 다음 steps를 수행하는, parameters가 없는 새 Abstract Closure closure를 둔다:
    1. index를 0으로 둔다.
    2. entriesset.[[SetData]]로 둔다.
    3. entriesCountentries 안의 elements 수로 둔다.
    4. Repeat, while index < entriesCount,
      1. entryentries[index]로 둔다.
      2. indexindex + 1로 설정한다.
      3. entryempty가 아니면, 다음을 수행한다.
        1. kindkey+value이면, 다음을 수행한다.
          1. resultCreateArrayFromListentry, entry »)로 둔다.
          2. GeneratorYield(CreateIteratorResultObject(result, false))를 수행한다.
        2. Else,
          1. Assert: kindvalue이다.
          2. GeneratorYield(CreateIteratorResultObject(entry, false))를 수행한다.
        3. NOTE: 이 abstract operation의 execution이 GeneratorYield에 의해 paused된 동안 entries 안의 elements 수가 increased되었을 수 있다.
        4. entriesCountentries 안의 elements 수로 설정한다.
    5. NormalCompletion(unused)을 반환한다.
  3. CreateIteratorFromClosure(closure, "%SetIteratorPrototype%", %SetIteratorPrototype%)를 반환한다.

24.2.6.2 The %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 Objects

WeakMaps는 keys가 objects 및/또는 symbols이고 values는 arbitrary ECMAScript language values일 수 있는 key/value pairs의 collections입니다. WeakMap은 specific key를 가진 key/value pair를 contain하는지 보기 위해 queried될 수 있지만, keys로 holding하는 values를 enumerating하기 위한 mechanism은 provided되지 않습니다. Certain conditions에서, live가 아닌 values는 9.9.3에 described된 것처럼 WeakMap keys로부터 removed됩니다.

implementation은 WeakMap의 key/value pair가 inaccessible하게 되는 time과 key/value pair가 WeakMap에서 removed되는 time 사이에 arbitrarily determined latency를 impose할 수 있습니다. 이 latency가 ECMAScript program에 observable하다면, program execution에 impact할 수 있는 indeterminacy의 source가 될 것입니다. 그 reason으로, ECMAScript implementation은 observer가 observed key를 present하도록 require하지 않는 WeakMap의 key를 observe하는 any means를 provide해서는 안 됩니다.

WeakMaps는 collection 안의 key/value pairs 수에 대해 average로 sublinear인 access times를 제공하는 hash tables 또는 other mechanisms를 사용하여 implemented되어야 합니다. 이 specification에서 사용되는 data structure는 WeakMaps의 required observable semantics를 describe하기 위한 것일 뿐입니다. viable implementation model로 intended되지 않습니다.

Note

WeakMap 및 WeakSet은 WeakMap 또는 WeakSet instance가 없었다면 object 또는 symbol이 otherwise inaccessible해지고 implementation의 garbage collection mechanisms에 의한 resource reclamation의 대상이 되었을 경우 memory resources를 “leak”하지 않는 manner로 object 또는 symbol과 state를 dynamically associating하기 위한 mechanisms를 provide하도록 intended됩니다. 이 characteristic은 WeakMap 또는 WeakSet instances에서 keys로의 inverted per-object/symbol mapping을 사용하여 achieved될 수 있습니다. Alternatively, each WeakMap 또는 WeakSet instance는 internally its key 및 value data를 store할 수 있지만, 이 approach는 WeakMap 또는 WeakSet implementation과 garbage collector 사이의 coordination을 requires합니다. following 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 The WeakMap Constructor

WeakMap constructor는:

  • %WeakMap%입니다.
  • global object"WeakMap" property의 initial value입니다.
  • constructor로 called될 때 new WeakMap을 create하고 initialize합니다.
  • function으로 called되도록 intended되지 않으며, such manner로 called될 때 exception을 throw합니다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 WeakMap 동작을 상속하려는 서브클래스 생성자는 WeakMap.prototype의 내장 메서드를 지원하는 데 필요한 내부 상태로 서브클래스 인스턴스를 생성하고 초기화하기 위해 WeakMap 생성자에 대한 super 호출을 포함해야 한다.

24.3.1.1 WeakMap ( [ iterable ] )

이 function은 called될 때 다음 steps를 수행합니다:

  1. NewTarget이 undefined이면, TypeError exception을 throw한다.
  2. map을 ? OrdinaryCreateFromConstructor(NewTarget, "%WeakMap.prototype%", « [[WeakMapData]] »)로 둔다.
  3. map.[[WeakMapData]]를 새 empty List로 설정한다.
  4. iterableundefined 또는 null 중 하나이면, map을 반환한다.
  5. adder를 ? Get(map, "set")로 둔다.
  6. IsCallable(adder)가 false이면, TypeError exception을 throw한다.
  7. AddEntriesFromIterable(map, iterable, adder)를 반환한다.
Note

parameter iterable이 present하면, 이는 two element array-like object를 produce하는 iterator object를 반환하는 %Symbol.iterator% method를 implement하는 object일 것으로 expected됩니다. 그 first element는 WeakMap key로 사용될 value이고 second element는 그 key와 associate할 value입니다.

24.3.2 Properties of the 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 Properties of the 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는 called될 때 다음 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로 사용됩니다. Actual implementations는 internal data structures에서 entry를 physically removing하는 것과 같은 other actions를 취할 수 있습니다.

24.3.3.3 WeakMap.prototype.get ( key )

이 method는 called될 때 다음 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는 called될 때 다음 steps를 수행합니다:

  1. weakMapthis value로 둔다.
  2. RequireInternalSlot(weakMap, [[WeakMapData]])를 수행한다.
  3. CanBeHeldWeakly(key)가 false이면, TypeError exception을 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는 called될 때 다음 steps를 수행합니다:

  1. weakMapthis value로 둔다.
  2. RequireInternalSlot(weakMap, [[WeakMapData]])를 수행한다.
  3. CanBeHeldWeakly(key)가 false이면, TypeError exception을 throw한다.
  4. IsCallable(callback)가 false이면, TypeError exception을 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는 called될 때 다음 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는 called될 때 다음 steps를 수행합니다:

  1. weakMapthis value로 둔다.
  2. RequireInternalSlot(weakMap, [[WeakMapData]])를 수행한다.
  3. CanBeHeldWeakly(key)가 false이면, TypeError exception을 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 Properties of WeakMap Instances

WeakMap instances는 WeakMap prototype object로부터 properties를 inherit하는 ordinary objects입니다. WeakMap instances는 또한 [[WeakMapData]] internal slot을 가집니다.

24.4 WeakSet Objects

WeakSets는 objects 및/또는 symbols의 collections입니다. distinct object 또는 symbol은 WeakSet의 collection의 element로서 한 번만 occur할 수 있습니다. WeakSet은 specific value를 contain하는지 보기 위해 queried될 수 있지만, holding하는 values를 enumerating하기 위한 mechanism은 provided되지 않습니다. Certain conditions에서, live가 아닌 values는 9.9.3에 described된 것처럼 WeakSet elements로부터 removed됩니다.

implementation은 WeakSet 안에 contained된 value가 inaccessible하게 되는 time과 value가 WeakSet에서 removed되는 time 사이에 arbitrarily determined latency를 impose할 수 있습니다. 이 latency가 ECMAScript program에 observable하다면, program execution에 impact할 수 있는 indeterminacy의 source가 될 것입니다. 그 reason으로, ECMAScript implementation은 observer가 observed value를 present하도록 require하지 않는 particular value를 WeakSet이 contains하는지 determine하는 any means를 provide해서는 안 됩니다.

WeakSets는 collection 안의 elements 수에 대해 average로 sublinear인 access times를 제공하는 hash tables 또는 other mechanisms를 사용하여 implemented되어야 합니다. 이 specification에서 사용되는 data structure는 WeakSets의 required observable semantics를 describe하기 위한 것일 뿐입니다. viable implementation model로 intended되지 않습니다.

Note

24.3NOTE를 참조하십시오.

24.4.1 The WeakSet Constructor

WeakSet constructor는:

  • %WeakSet%입니다.
  • global object"WeakSet" property의 initial value입니다.
  • constructor로 called될 때 new WeakSet을 create하고 initialize합니다.
  • function으로 called되도록 intended되지 않으며, such manner로 called될 때 exception을 throw합니다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 WeakSet 동작을 상속하려는 서브클래스 생성자는 WeakSet.prototype의 내장 메서드를 지원하는 데 필요한 내부 상태로 서브클래스 인스턴스를 생성하고 초기화하기 위해 WeakSet 생성자에 대한 super 호출을 포함해야 한다.

24.4.1.1 WeakSet ( [ iterable ] )

이 function은 called될 때 다음 steps를 수행합니다:

  1. NewTarget이 undefined이면, TypeError exception을 throw한다.
  2. set을 ? OrdinaryCreateFromConstructor(NewTarget, "%WeakSet.prototype%", « [[WeakSetData]] »)로 둔다.
  3. set.[[WeakSetData]]를 새 empty List로 설정한다.
  4. iterableundefined 또는 null 중 하나이면, set을 반환한다.
  5. adder를 ? Get(set, "add")로 둔다.
  6. IsCallable(adder)가 false이면, TypeError exception을 throw한다.
  7. iteratorRecord를 ? GetIterator(iterable, sync)로 둔다.
  8. Repeat,
    1. next를 ? IteratorStepValue(iteratorRecord)로 둔다.
    2. nextdone이면, set을 반환한다.
    3. statusCompletion(Call(adder, set, « next »))로 둔다.
    4. IfAbruptCloseIterator(status, iteratorRecord).

24.4.2 Properties of the 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 Properties of the 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는 called될 때 다음 steps를 수행합니다:

  1. weakSetthis value로 둔다.
  2. RequireInternalSlot(weakSet, [[WeakSetData]])를 수행한다.
  3. CanBeHeldWeakly(value)가 false이면, TypeError exception을 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는 called될 때 다음 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가 entryweakSet.[[WeakSetData]]의 element를 value가 empty인 element로 replace한다.
      2. true를 반환한다.
  5. false를 반환한다.
Note

value empty는 entry가 deleted되었음을 indicate하기 위한 specification device로 사용됩니다. Actual implementations는 internal data structures에서 entry를 physically removing하는 것과 같은 other actions를 취할 수 있습니다.

24.4.3.4 WeakSet.prototype.has ( value )

이 method는 called될 때 다음 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 Properties of WeakSet Instances

WeakSet instances는 WeakSet prototype object로부터 properties를 inherit하는 ordinary objects입니다. WeakSet instances는 또한 [[WeakSetData]] internal slot을 가집니다.

24.5 Abstract Operations for 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를 반환한다.