Questioning WeakMap.prototype.clear

David Bruant bruant.d at
Mon Jan 21 08:44:56 PST 2013

Le 21/01/2013 17:16, Rick Waldron a écrit :
> On Mon, Jan 21, 2013 at 6:04 AM, David Bruant <bruant.d at 
> <mailto:bruant.d at>> wrote:
>     I think WeakMap.prototype.clear slipped through the crack without
>     being specifically discussed. Based on what's publicly available,
>     I don't see anyone noticed and discussed the fact that
>     WeakMap.prototype.clear questions the property that was true
>     before its adoption ("you can only modify a weakmap entry if you
>     have the key")
> I agree and disagree. I disagree because WeakMap.prototype.clear() 
> doesn't modify the weakmap entry in the same direct way, ie. 
> WeakMap.prototype.set, WeakMap.prototype.delete. On the other hand, I 
> agree because it provides (if the weakmap is exposed) a way to remove 
> an entry that might be used without any defense, ie. 
> WeakMap.prototype.has() or might leave the program in an unstable 
> state due to loss of some aggregate state information stored in the 
> weakmap.
> That being said, I support the inclusion of WeakMap.prototype.clear(), 
> because reasonable security and state defense expectations can be met by:
> 1. Not exposing a sensitive weakmap in program code
> 2. Defending against missing entries with has()
> Subjectively, #1 mitigates without nannying.
I thought more about how I use weakmaps and #1 is a thing I do naturally 
I don't believe in #2, because calls to .has everytime someone may have 
maliciously or by mistake called .clear is quite a cost.

I'd like to point out, that just based on what you wrote, you do not 
support the inclusion of WeakMap.prototype.clear, but rather you support 
its non-removal based on what I said.
Use cases for WeakMap.prototype.clear are... unclear.
In which conditions would one want to wipe out all entries?
If you're the only holder of the weakmap, creating a new one is 
equivalent to .clear (but allows to lazy GC the entries which sync 
.clear doesn't as easily).

More specifically, in which conditions would one want to wipe out all 
the entries they're oblivious to?


> Rick
>     I think the property I mentioned is cricial to weakmap integrity
>     and I think WeakMap.prototype.clear should be considered for
>     removal... or at least proper discussion since none really
>     happened from what I've found.
>     David
>     [1]
>     [2]
>     [3]
>     [4]
>     [5]
>     [6]
>     _______________________________________________
>     es-discuss mailing list
>     es-discuss at <mailto:es-discuss at>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list