archives

« Bugzilla Issues Index

#2166 — 23.3.3.1, 23.4.3.2: Use the same approach to clear WeakMap/WeakSet


23.3.3.1 WeakMap.prototype.clear (), step 5:
23.4.3.2 WeakSet.prototype.clear (), steps 5-6:

WeakMap simply reassigns [[WeakMapData]] to a new empty List, whereas WeakSet iterates over all entries of [[WeakSetData]] to manually set the value to `empty`. This should be changed to use a single approach.


they are different because Maps are Iterable and WeakMaps are not. When a map is cleared, there may be existing MapIterators that have not completed. This form of clearing and the explicit indexing in the Map.iterator next ensures that what happens in this case is well defined.

I think I'll put a not in Map.prototype.clear explaining some of this


Re-opening:
Neither WeakMap [1] nor WeakSet [2] is iterable, so the justification for bug 1157 does not apply here.

[1] https://people.mozilla.org/~jorendorff/es6-draft.html#sec-weakmap.prototype.clear
[2] https://people.mozilla.org/~jorendorff/es6-draft.html#sec-weakset.prototype.clear


This bug is only about the difference for clear() in WeakMap compared to WeakSet. The clear() method for normal Map and Set must not be changed for exactly the reason you've given.


go it

fixed in rev21 editor's draft


fixed in rev21 draft