[whatwg] Location object identity and navigation behavior

Bobby Holley bobbyholley at gmail.com
Fri Nov 9 08:59:12 PST 2012


On Thu, Nov 8, 2012 at 6:09 PM, Adam Barth <w3c at adambarth.com> wrote:

> I'm not sure I quite understand what you mean here.  Can you describe
> an experiment that would distinguish these cases?  I looked at [1],
> but it was too complicated for me to understand quickly.
>
> Consider the following case:
>
> == Document A ==
> <script>
> Object.prototype.foo = "A1";
> window.location.bar = "A2";
>
> function f() {
>   var loc = window.location;
>   print(loc.foo); // print is a magic function that lets me see this value
>   print(loc.bar);
> }
> </script>
>
> == Document B ==
> <script>
> Object.prototype.foo = "B1";
> window.location.bar = "B2";
> </script>
>
> 1) Document A is displayed in browsing context X.
> 2) Browsing context X is navigated and now displays document B.
> 3) Function f is called.
>
> What values are printed?
>


Under the proposed behavior, both documents share the same Location object.
So when f() is called for on the navigated-away-from scope, loc.bar is "B2"
(assuming that print() is magic enough to get around origin restrictions).
"A2" is cleared on navigation per [3] (check out the automated tests in
Patch 7 in the bug), so if B2 was never set, loc.bar would be undefined.

As for loc.foo, our new implementation would give "B1", because the
Location object has entirely transplanted into the new Document's scope.
This seems sane to me, but it's certainly up for discussion. Matt, can you
add an expando on Object.prototype in your tests and see what happens?

Cheers,
bholley


More information about the whatwg mailing list