<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>20379</bug_id>
          
          <creation_ts>2012-12-13 18:40:10 +0000</creation_ts>
          <short_desc>Should Window&apos;s &quot;document&quot; property return the Window&apos;s document?</short_desc>
          <delta_ts>2013-06-04 20:55:42 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#the-window-object</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>bzbarsky</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>80116</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-12-13 18:40:10 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html
Multipage: http://www.whatwg.org/C#the-window-object
Complete: http://www.whatwg.org/c#the-window-object

Comment:
Should Window&apos;s &quot;document&quot; property return the Window

Posted from: 173.48.81.109 by bzbarsky@mit.edu
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:20.0) Gecko/20121213 Firefox/20.0</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80117</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-13 18:41:27 +0000</bug_when>
    <thetext>Silly comment form submitting itself early...

What I meant to say was:

Should Window&apos;s &quot;document&quot; property really return the document of the currently active Window in the browsing context, or should it return the Window&apos;s document (if any)?  Seems to me like the latter would be preferable...

Note, though, that this would mean that window.document and bareword &quot;document&quot; have slightly different behavior.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80164</commentid>
    <comment_count>2</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2012-12-14 08:55:17 +0000</bug_when>
    <thetext>Having document and window.document be different seems confusing...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80165</commentid>
    <comment_count>3</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-14 08:57:17 +0000</bug_when>
    <thetext>Yes, but having:

  &lt;script&gt;
    var doc = document;
    function f() {
      alert(doc == document);
    }
  &lt;/script&gt;

start alerting false at some point is just as confusing...  Running script in navigated-from windows is just confusing; fact of life.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80762</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-31 05:07:26 +0000</bug_when>
    <thetext>Why would it mean than window.document and document would have different behaviour?

Bareword |document| is short for |this.document|; |window.document| is short for |this.window.document|. |this.window === this| always. |this| is a WindowProxy.

Since WindowProxy always return the Window of the active Document, and you can&apos;t get a reference to a raw Window ever, as far as I can tell it doesn&apos;t matter whether Window.document returns the Window&apos;s document (that is, always the active Document&apos;s Window&apos;s Document), or whether it returns the active Document. They&apos;re the same thing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80785</commentid>
    <comment_count>5</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-31 06:53:39 +0000</bug_when>
    <thetext>&gt; Bareword |document| is short for |this.document|

As a matter of fact, it&apos;s not in implementations.  Did you try it?  The former does a lookup on the ES global (the Window) while the latter does a lookup on the WindowProxy.

And they can&apos;t possibly be the same, note, because barewords are lookups on the scope chain, not on objects.  You can see this most clearly in with blocks and inside inline event handlers, where converting bareword &quot;foo&quot; lookup to &quot;this.foo&quot; would give totally different behavior.

I suggest you try testcases like the one in comment 3, where the frame containing that script is unloaded and then the function f is called, in some UAs to see how it behaves.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83977</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-03-05 00:40:00 +0000</bug_when>
    <thetext>bz: Do you have a test case showing this? I haven&apos;t been able to construct a test case that contradicts comment 4 when the scope chain is otherwise uninteresting.

(Note that the spec requires &quot;If the script&apos;s global object is a Window object, then in JavaScript, the ThisBinding of the global execution context for this script must be the Window object&apos;s WindowProxy object, rather than the global object.&quot;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83984</commentid>
    <comment_count>7</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-03-05 02:31:27 +0000</bug_when>
    <thetext>There&apos;s a testcase in http://lists.w3.org/Archives/Public/public-script-coord/2012OctDec/0328.html

But let me attach it here too, just so you can play with it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83985</commentid>
    <comment_count>8</comment_count>
      <attachid>1328</attachid>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-03-05 02:31:48 +0000</bug_when>
    <thetext>Created attachment 1328
Subframe for testcase</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83986</commentid>
    <comment_count>9</comment_count>
      <attachid>1329</attachid>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-03-05 02:33:11 +0000</bug_when>
    <thetext>Created attachment 1329
Testcase

You may have to save them both locally or put them on another server to test sanely because this Bugzilla is slightly HTML-attachment hostile.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83987</commentid>
    <comment_count>10</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-03-05 02:33:57 +0000</bug_when>
    <thetext>Note also that the ThisBinding and the scope chain are totally separate concepts, for what that&apos;s worth.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86485</commentid>
    <comment_count>11</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-04-22 17:36:05 +0000</bug_when>
    <thetext>Wow, I somehow was going through life assuming the ThisBinding was what was on the scope chain. Crazy. Sorry about that.

Ok, looks like all the browsers agree that it should return the Window&apos;s document.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>86486</commentid>
    <comment_count>12</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-04-22 17:40:41 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r7845.
Check-in comment: Match reality better. (Turns out parts of the spec already assumed this was defined this way anyway.)
http://html5.org/tools/web-apps-tracker?from=7844&amp;to=7845</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88663</commentid>
    <comment_count>13</comment_count>
    <who name="">contributor</who>
    <bug_when>2013-06-04 20:55:42 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r7899.
Check-in comment: Fix some typos or copypasta.
http://html5.org/tools/web-apps-tracker?from=7898&amp;to=7899</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1328</attachid>
            <date>2013-03-05 02:31:48 +0000</date>
            <delta_ts>2013-03-05 02:31:48 +0000</delta_ts>
            <desc>Subframe for testcase</desc>
            <filename>foo.html</filename>
            <type>text/html</type>
            <size>232</size>
            <attacher name="Boris Zbarsky">bzbarsky</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CiAgPHNjcmlwdD4KICAgIHZhciBkb2MgPSBkb2N1bWVudDsKICAgIGZ1
bmN0aW9uIGYoKSB7CiAgICAgIGFsZXJ0KChkb2MgPT0gZG9jdW1lbnQpICsgIlxuIiArCiAgICAg
ICAgICAgIChkb2MgPT0gdGhpcy5kb2N1bWVudCkgKyAiXG4iICsKICAgICAgICAgICAgZG9jLlVS
TCArICJcbiIgKwogICAgICAgICAgICB0aGlzLmRvY3VtZW50LlVSTCk7CiAgICB9CiAgPC9zY3Jp
cHQ+Cg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1329</attachid>
            <date>2013-03-05 02:33:11 +0000</date>
            <delta_ts>2013-03-05 02:33:11 +0000</delta_ts>
            <desc>Testcase</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>303</size>
            <attacher name="Boris Zbarsky">bzbarsky</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxpZnJhbWUgc3JjPSJodHRwczovL3d3dy53My5vcmcvQnVncy9QdWJs
aWMvYXR0YWNobWVudC5jZ2k/aWQ9MTMyOCI+PC9pZnJhbWU+CjxzY3JpcHQ+CiAgdmFyIGZ1bmM7
CiAgd2luZG93Lm9ubG9hZCA9IGZ1bmN0aW9uKCkgewogICAgZnVuYyA9IHdpbmRvd1swXS5mOwog
ICAgZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiaWZyYW1lIikub25sb2FkID0gZnVuY3Rpb24oKSB7
CiAgICAgIGZ1bmMoKTsKICAgIH0KICAgIHdpbmRvd1swXS5sb2NhdGlvbiA9ICJhYm91dDpibGFu
ayI7CiAgfQo8L3NjcmlwdD4K
</data>

          </attachment>
      

    </bug>

</bugzilla>