Removal of WeakMap/WeakSet clear

Jason Orendorff jason.orendorff at
Tue Dec 9 15:29:19 PST 2014

On Wed, Dec 3, 2014 at 3:54 PM, David Bruant <bruant.d at> wrote:
>> There's something important that's implicit in this argument that I
>> still don't have yet. If you were using literally any other data
>> structure, any other object, passing a direct reference to it around
>> to untrusted code would not only be dumb, but obviously something the
>> ES spec should not try to defend against. Right? It would be goofy.
> Object.freeze and friends were added to the ES spec for the very purpose of
> being able to pass direct reference to an object and defend against unwanted
> mutations. à propos d'une
> Is Object.freeze goofy?

So you're saying it's *not* a security thing; you have no particular
threat model in mind. Hmm.

I really have trouble making sense of this, David. This line of
reasoning would make sense if you were arguing for (a) really
supporting immutable data structures in the stdlib; or (b) adding a
freeze() method on all the stdlib collections; or perhaps (c) making
Object.freeze somehow apply to the internal data in the new stdlib
collections. In fact all those things sound nice.

But as it stands we're talking about one mutation method on a kind of
object that already has a bunch of other mutation methods that you're
apparently OK with. I don't get it. I thought it had to do with the
invariant we were discussing before, and that's why I asked why that
particular invariant is useful... and then you didn't mention it at
all in your response.

> The ability to clear any WeakMap anytime needs to be equally justified in my
> opinion. I'm curious about plausible use cases.

Clearing a data structure is useful when your data structure is a
cache; WeakMaps are particularly useful for caches, as they do not
keep the keys in memory.

Consistency with the Map API is a separate justification. A program
migrating from Maps to WeakMaps might quite naturally end up wanting

> What about making 'clear' an own property of weakmaps and make it only
> capable of clearing the weakmap it's attached to?

I can't tell what this is meant to achieve.


More information about the es-discuss mailing list