?
u
m
/
Maps are collections of key/value pairs where both the keys and values may be arbitrary
Maps must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of elements in the collection. The data structure used in this specification is only intended to describe the required observable semantics of Maps. It is not intended to be a viable implementation model.
The Map
extends
clause of a class definition. Subclass super
call to the Map Map.prototype
built-in methods.When the Map
function is called with optional argument iterable, the following steps are taken:
If the parameter iterable is present, it is expected to be an object that implements an
The abstract operation AddEntriesFromIterable takes arguments target, iterable (an
The parameter iterable is expected to be an object that implements an
The Map
The initial value of Map.prototype
is the
This property has the attributes { [[Writable]]:
Map[@@species]
is an
The value of the
Methods that create derived collection objects should call
The Map prototype object:
The following steps are taken:
The initial value of Map.prototype.constructor
is
The following steps are taken:
The value
The following steps are taken:
When the forEach
method is called with one or two arguments, the following steps are taken:
callbackfn should be a function that accepts three arguments. forEach
calls callbackfn once for each key/value pair present in the Map, in key insertion order. callbackfn is called only for keys of the Map which actually exist; it is not called for keys that have been deleted from the Map.
If a thisArg parameter is provided, it will be used as the
callbackfn is called with three arguments: the value of the item, the key of the item, and the Map being traversed.
forEach
does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn. Each entry of a map's [[MapData]] is only visited once. New keys added after the call to forEach
begins are visited. A key will be revisited if it is deleted after it has been visited and then re-added before the forEach
call completes. Keys that are deleted after the call to forEach
begins and before being visited are not visited unless the key is added again before the forEach
call completes.
The following steps are taken:
The following steps are taken:
The following steps are taken:
The following steps are taken:
Map.prototype.size
is an
The following steps are taken:
The initial value of the
The initial value of the
This property has the attributes { [[Writable]]:
Map instances are
A Map Iterator is an object, that represents a specific iteration over some specific Map instance object. There is not a named
The abstract operation CreateMapIterator takes arguments map (an
The %MapIteratorPrototype% object:
The initial value of the
This property has the attributes { [[Writable]]:
Set objects are collections of
Set objects must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of elements in the collection. The data structure used in this specification is only intended to describe the required observable semantics of Set objects. It is not intended to be a viable implementation model.
The Set
extends
clause of a class definition. Subclass super
call to the Set Set.prototype
built-in methods.When the Set
function is called with optional argument iterable, the following steps are taken:
The Set
The initial value of Set.prototype
is the
This property has the attributes { [[Writable]]:
Set[@@species]
is an
The value of the
Methods that create derived collection objects should call
The Set prototype object:
The following steps are taken:
The following steps are taken:
The initial value of Set.prototype.constructor
is
The following steps are taken:
The value
The following steps are taken:
For iteration purposes, a Set appears similar to a Map where each entry has the same value for its key and value.
When the forEach
method is called with one or two arguments, the following steps are taken:
callbackfn should be a function that accepts three arguments. forEach
calls callbackfn once for each value present in the Set object, in value insertion order. callbackfn is called only for values of the Set which actually exist; it is not called for keys that have been deleted from the set.
If a thisArg parameter is provided, it will be used as the
callbackfn is called with three arguments: the first two arguments are a value contained in the Set. The same value is passed for both arguments. The Set object being traversed is passed as the third argument.
The callbackfn is called with three arguments to be consistent with the call back functions used by forEach
methods for Map and Array. For Sets, each item value is considered to be both the key and the value.
forEach
does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.
Each value is normally visited only once. However, a value will be revisited if it is deleted after it has been visited and then re-added before the forEach
call completes. Values that are deleted after the call to forEach
begins and before being visited are not visited unless the value is added again before the forEach
call completes. New values added after the call to forEach
begins are visited.
The following steps are taken:
The initial value of the
For iteration purposes, a Set appears similar to a Map where each entry has the same value for its key and value.
Set.prototype.size
is an
The following steps are taken:
The initial value of the
The initial value of the
This property has the attributes { [[Writable]]:
Set instances are
A Set Iterator is an
The abstract operation CreateSetIterator takes arguments set (an
The %SetIteratorPrototype% object:
The initial value of the
This property has the attributes { [[Writable]]:
WeakMaps are collections of key/value pairs where the keys are objects and values may be arbitrary
An implementation may impose an arbitrarily determined latency between the time a key/value pair of a WeakMap becomes inaccessible and the time when the key/value pair is removed from the WeakMap. If this latency was observable to ECMAScript program, it would be a source of indeterminacy that could impact program execution. For that reason, an ECMAScript implementation must not provide any means to observe a key of a WeakMap that does not require the observer to present the observed key.
WeakMaps must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of key/value pairs in the collection. The data structure used in this specification is only intended to describe the required observable semantics of WeakMaps. It is not intended to be a viable implementation model.
WeakMap and WeakSets are intended to provide mechanisms for dynamically associating state with an object in a manner that does not “leak” memory resources if, in the absence of the WeakMap or WeakSet, the object otherwise became inaccessible and subject to resource reclamation by the implementation's garbage collection mechanisms. This characteristic can be achieved by using an inverted per-object mapping of weak map instances to keys. Alternatively each weak map may internally store its key to value mappings but this approach requires coordination between the WeakMap or WeakSet implementation and the garbage collector. The following references describe mechanism that may be useful to implementations of WeakMap and WeakSets:
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
The WeakMap
extends
clause of a class definition. Subclass super
call to the WeakMap WeakMap.prototype
built-in methods.When the WeakMap
function is called with optional argument iterable, the following steps are taken:
If the parameter iterable is present, it is expected to be an object that implements an
The WeakMap
The initial value of WeakMap.prototype
is the
This property has the attributes { [[Writable]]:
The WeakMap prototype object:
The initial value of WeakMap.prototype.constructor
is
The following steps are taken:
The value
The following steps are taken:
The following steps are taken:
The following steps are taken:
The initial value of the
This property has the attributes { [[Writable]]:
WeakMap instances are
WeakSets are collections of objects. A distinct object may only occur once as an element of a WeakSet's collection. A WeakSet may be queried to see if it contains a specific object, but no mechanism is provided for enumerating the objects it holds. In certain conditions, objects which are not
An implementation may impose an arbitrarily determined latency between the time an object contained in a WeakSet becomes inaccessible and the time when the object is removed from the WeakSet. If this latency was observable to ECMAScript program, it would be a source of indeterminacy that could impact program execution. For that reason, an ECMAScript implementation must not provide any means to determine if a WeakSet contains a particular object that does not require the observer to present the observed object.
WeakSets must be implemented using either hash tables or other mechanisms that, on average, provide access times that are sublinear on the number of elements in the collection. The data structure used in this specification is only intended to describe the required observable semantics of WeakSets. It is not intended to be a viable implementation model.
See the NOTE in
The WeakSet
extends
clause of a class definition. Subclass super
call to the WeakSet WeakSet.prototype
built-in methods.When the WeakSet
function is called with optional argument iterable, the following steps are taken:
The WeakSet
The initial value of WeakSet.prototype
is the
This property has the attributes { [[Writable]]:
The WeakSet prototype object:
The following steps are taken:
The initial value of WeakSet.prototype.constructor
is
The following steps are taken:
The value
The following steps are taken:
The initial value of the
This property has the attributes { [[Writable]]:
WeakSet instances are