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

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