W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2014

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

From: Toon Verwaest <verwaest@chromium.org>
Date: Tue, 15 Apr 2014 23:32:13 +0200
Message-ID: <CANS-YRpAH+yvhm=Z4EigYjE4QRNfdVTmMMuFAFdC34rvB_HVjQ@mail.gmail.com>
To: Rick Waldron <waldron.rick@gmail.com>
Cc: Adam Klein <adamk@chromium.org>, "public-script-coord@w3.org" <public-script-coord@w3.org>, Boris Zbarsky <bzbarsky@mit.edu>, Toon Verwaest <verwaest@chromium.org>, Adam Barth <abarth@chromium.org>
>
>
>> <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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:21 UTC