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

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

From: Adam Klein <adamk@chromium.org>
Date: Tue, 15 Apr 2014 14:04:01 -0700
Message-ID: <CAEvLGc+hXnKTUtH3USNDPzgifYo5R+SQ+2-9-gDNayYA-LGWQA@mail.gmail.com>
To: public-script-coord@w3.org
Cc: Boris Zbarsky <bzbarsky@mit.edu>, Toon Verwaest <verwaest@chromium.org>, Adam Barth <abarth@chromium.org>
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:

<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,
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').

Thoughts?

- Adam
Received on Tuesday, 15 April 2014 21:04:29 UTC

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