Re: WindowProxy as the key in ES6 Set/Map/WeakSet/WeakMap

>> <iframe src="frame1.html"></iframe>
>> <script>
>> w = frames[0];
>> m = new Map;
>> m.set(w, 'hello');
>> w.location.href = 'frame2.html';
>> console.log(map.get(w))
>> </script>
>> What should be logged? In a brief discussion with Boris Zbarsky on IRC,
>> he suggested that this should come down to the use cases:
> Perhaps I'm missing something obvious but `w` is just an object, so the
> output would be "hello". Setting w.location.href just updates the value of
> a property in the object, it doesn't change the object's identity.
Yes, exactly. Setting the identity hash to a new value will result in
random behavior at best. Depending on the implementation, the key may or
may not be found after the identity hash changes, whenever the old and new
hash would collide in the map.

The "window proxy" is the only javascript visible object. You could
associate extra state in weak maps with the underlaying window as long as
you cannot enumerate the keys of weak maps, but you cannot use the
underlaying window as a key in regular maps. The unlaying object is
internal only and should never escape to JS. Otherwise that leads to
security leaks.

Received on Wednesday, 16 April 2014 13:03:03 UTC