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

> 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:
http://www.w3.org/TR/XMLHttpRequest/#constructors

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().

<script>
  window.name = "InitWindow";
  var defaultDoc = window.document;

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

  window.onload = function() {
    document.open();

    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>");
    document.close();
  }
</script>


> 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
document.


Jungkee


> What should happen in this case?
> 
> -Boris

Received on Friday, 14 December 2012 11:49:39 UTC