Questioning WeakMap.prototype.clear (was: Private symbols as WeakMap sugar)
Mark S. Miller
erights at google.com
Mon Jan 21 10:20:09 PST 2013
On Mon, Jan 21, 2013 at 3:04 AM, David Bruant <bruant.d at gmail.com> wrote:
> Le 21/01/2013 11:58, David Bruant a écrit :
>> Before the clear method, weakmaps had the following property: "you can
>> only modify a weakmap entry if you have the key". This property isn't true
>> anymore with .clear. This may be considered as abusive ambient authority.
> Let's see how this feature came to appear:
> Jason Orendorff talked about Map.prototype.clear  (Oct 22nd). Seen as a
> good idea. No discussion on whether it's a good idea for WeakMaps
> specifically. Nicholas Zakas briefly mentions it in November . No one
> replied to it specifically. I haven't seen any discussion about it in
> meeting notes . A brief mention of Set/Map.prototype.clear  as a
> review of the Oct 26th draft  (note, 4 days after Jason post, which is a
> very short amount of time) but nothing about WeakMap.prototype.clear.
> Implemented in Firefox soon after ...
> 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 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.
Hi David, thanks for raising this. Not having been able to take much
time lately, I had not been aware that a .clear method had been added.
I think it's a terrible idea. I like your explanation of why --
because of the simple property it breaks. Indeed, this violation
contradicts the main use case of WeakMaps -- for soft fields.
>  https://mail.mozilla.org/pipermail/es-discuss/2012-October/025962.html
>  https://mail.mozilla.org/pipermail/es-discuss/2012-November/026114.html
>  https://github.com/rwldrn/tc39-notes
>  http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts
>  https://bugzilla.mozilla.org/show_bug.cgi?id=814562
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss