Use cases for WeakMap

Erik Corry erik.corry at
Mon May 16 00:47:21 PDT 2011

2011/5/16 Brendan Eich <brendan at>:
> On May 16, 2011, at 12:18 AM, Erik Corry wrote:
>> 2011/5/16 Brendan Eich <brendan at>:
>>> On May 16, 2011, at 12:01 AM, Brendan Eich wrote:
>>>> On May 15, 2011, at 11:55 PM, Erik Corry wrote:
>>>>> 2011/5/16 Brendan Eich <brendan at>:
>>>>>> Not if the object is frozen.
>>>>> That shouldn't prevent you adding private names.  See earlier message
>>>>> in this thread.
>>>> Frozen means [[Extensible]] is false, so you can't add any properties, ...
>>> I'll go further: frozen means the implementation should be free to move the object and anything associated with its shallow-frozen key/value state into read-only memory, so the full force of 50-year-plus OS and hardware MMU protection can ensure [[Extensible]] really is false.
>> I think this would also preclude the most efficient implementation of
>> Weak Maps.  In fact I have a hard time seeing how you would GC weak
>> maps at all under these conditions.
> Why, because GC metadata has to go in the same page as the frozen object that might be a key in a weak map?

I think the objects used as keys in weak maps need to be somehow
annotated with this information so that the GC can clean up the weak
maps when the keys die.  This means that if you take an object that is
frozen and use it as a key in a weak map then it will need to be
mutated in some way and can't be on a read-only page.

Perhaps you have a different, efficient, implementation.  I can't see
us gaining much from putting frozen objects on read-only pages, thus I
can't accept it as a very strong argument about the way that frozen
objects should work together with a new feature.

> Weak maps are in Firefox nightlies. We're playing with page protection too (not for freezing, yet). This seems like a dare, but it also seems to be dodging my point in replying again: that private names cannot be used to extend frozen objects in the "[[Extensible]] = true" sense of the spec.

Is there a description anywhere about how you have implemented GC of weak maps?

> /be

More information about the es-discuss mailing list