Removal of WeakMap/WeakSet clear

Katelyn Gadd kg at
Thu Dec 4 21:46:20 PST 2014

.NET's hashing protocol is weird and arguably it's some awful baggage
carried over from its Java influences. All instances, value or
reference type, have GetHashCode. For a given type there is the
'default' implementation, or you can provide a specific one. This
enables anything to be used as a key in a container like a

For reference types, GetHashCode's default implementation assigns an
object a semi-unique value that persists for the entire lifetime of
the instance. So in a non-moving GC you could use the pointer address,
but in a moving GC the runtime is basically assigning it a permanent
identifier that sticks with the instance somewhere. For value types,
the default hashing implementation basically walks over the whole type
and hashes the fields to create a hash for the value as a whole.

I'm surprised to hear that JS runtimes don't necessarily have ways to
'hash' a given JS value, but it makes sense. I can see how that is a
great reason for 'get me a hash for this value' to never actually
exist in the API, even if it's unfortunate that I have to recreate
that facility myself in runtimes that do have it.


On 4 December 2014 at 21:24, Steve Fink <sphink at> wrote:
> On 12/04/2014 08:00 PM, Katelyn Gadd wrote:
>> I do still use WeakMap in a few other places, for example to implement
>> Object.GetHashCode. This is a case where the transposed representation
>> is likely optimal - though in practice, I shouldn't need any sort of
>> container here, if only the hashing mechanisms clearly built into the
>> VM were exposed to user JS.
> If I am understanding correctly, I don't think there is any such hashing
> mechanism in the Spidermonkey VM. We hash on an object's pointer
> address, which can change during a moving GC. (We update any hashtables
> that incorporate an object's numeric address into their hash key
> computations.)
> I'm a little curious what you're generating the hashcode from. Is this
> mimicking a value object? If the contents of the object change, would
> you want the hashcode to change? Or are the "hashcodes" just
> incrementing numerical object ids?
> (Sorry for the tangent to the current thread.)
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list