W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2012

RE: [XHR] Need to define the behavior when the Window the XHR is created from does not have an associated document

From: Jungkee Song <jungkee.song@samsung.com>
Date: Fri, 14 Dec 2012 20:49:07 +0900
To: 'Boris Zbarsky' <bzbarsky@MIT.EDU>, public-webapps@w3.org
Message-id: <043301cdd9f1$0622ebb0$1268c310$%song@samsung.com>
> From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU]
> Sent: Friday, December 14, 2012 2:50 AM
> The spec currently says:
>    In environments where the global object is represented by the Window
>    object the XMLHttpRequest object has an associated XMLHttpRequest
>    document which is the document associated with the Window object for
>    which the XMLHttpRequest interface object was created.

In the latest version, the exact content above has been removed and the
concept of associated *document* is described in 4.2 Constructors section:

The logic stays the same.

> Now consider this testcase:
>    <script>
>      window.onload = function() {
>        document.open();
>        var xhr = new XMLHttpRequest();
>     }
>    </script>
> What is the "XMLHttpRequest document" in this case?  Note that
> document.open() creates a new Window object in this case, but the
> unqualified name lookup finds the XMLHttpRequest constructor on the old
> Window still.  

FWIW, document.open() does not create a new Window object but only opens the
document stream to write on. As I tried, the Window object and its Document
object stay the same before and after document.open().

  window.name = "InitWindow";
  var defaultDoc = window.document;

  console.log(defaultDoc.defaultView.name); // "InitWindow"

  window.onload = function() {

    console.log(defaultDoc === document);    // true
    console.log(document.defaultView.name); // "InitWindow"

    var xhr = new XMLHttpRequest(); // xhr's document specifies defaultDoc
which is exactly the current document object

    document.write("<p>" + document.defaultView.name + "</p>");

> In particular, in the case above this:
>    alert(XMLHttpRequest == window.XMLHttpRequest);
> alerts false per spec as far as I can tell, and the old Window is no
> longer associated with the document at this point.

In the above example, as both of the two global objects refer to the same
object, it results in "true".

Also, with window.open() scenario where there would be two distinct global
objects, I don't see any problem specifying XHR object's associated


> What should happen in this case?
> -Boris
Received on Friday, 14 December 2012 11:49:39 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:50 UTC