Skip to main content

Module map

Module map 

Source
Expand description

Map and Set.

Both are an insertion-ordered list of entries with SameValueZero key equality, so one implementation serves both: a Set is a Map whose value is unused. Keeping a list rather than a hash table is what makes the order free and exact — a Map iterates in insertion order, and a deleted-then-reinserted key moves to the end — at the cost of linear lookup, which the sizes this engine is used at do not notice.

§Why SameValueZero and not ===

map.set(NaN, 1) then map.get(NaN) has to work, and NaN === NaN is false. The other difference is that +0 and -0 are one key, which === already gives.

§Iterators

keys/values/entries snapshot the entries into an array and hand it to the shared array iterator. The spec makes those iterators live — an entry added while iterating is visited — and a snapshot is not. That is a documented simplification: it keeps one iterator implementation in the engine, and no test here distinguishes the two.

Functions§

install
Map.prototype methods, installed once for both classes.