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: Rick Waldron <waldron.rick@gmail.com>
Date: Tue, 15 Apr 2014 17:20:21 -0400
Message-ID: <CAHfnhfrHjKZFL0UA45jJiEK-PmaSLTK-hC-AT6ivnayHTjP6mQ@mail.gmail.com>
To: Adam Klein <adamk@chromium.org>
Cc: "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>
On Tue, Apr 15, 2014 at 5:04 PM, Adam Klein <adamk@chromium.org> wrote:

> How should collections behave when handed a WindowProxy as a key? Consider:
>
> <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.


>
> <bz_moz> aklein: we should figure out use cases
> <bz_moz> aklein: like "associate stuff with this window" vs "associate
> stuff with the stuff currently in this window".  :(
>
> (link: http://krijnhoetmer.nl/irc-logs/whatwg/20140415#l-888)
>
> But it's difficult for me to tell what the "right" use case here is.
>
> Consider a case where a WeakMap is being used, instead of a Map, to store
> private state related to an object. Given that expando properties disappear
> when a WindowProxy is attached to a different Window after navigation,
>

Is it still the same object, or a newly created object?


>  perhaps it makes some logical sense that associations made via WeakMaps
> should also disappear (and thus the above will log undefined). This would
> also seem to be consistent with HTML's specification that "all operations
> that would be performed on [the WindowProxy] must be performed on the
> Window object of the browsing context's active document instead".
>
> Alternatively, if we are to think of the HTML WindowProxy as essentially
> implemented in terms of an ES6 Proxy, perhaps Ecmascript already tells us
> what to do here (which, I think, is to have the above log 'hello').
>

As long as the object has its own identity, which is implicit in JS, then
it's a valid key for WeakMap (or Map, but Map also allows other values as
keys).

Rick
Received on Tuesday, 15 April 2014 21:21:08 UTC

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