[html5] r5616 - [giow] (2) Change how document.write() is ignored. Fixing http://www.w3.org/Bugs [...]

whatwg at whatwg.org whatwg at whatwg.org
Tue Oct 12 14:20:33 PDT 2010


Author: ianh
Date: 2010-10-12 14:20:32 -0700 (Tue, 12 Oct 2010)
New Revision: 5616

Modified:
   complete.html
   index
   source
Log:
[giow] (2) Change how document.write() is ignored.
Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=9767

Modified: complete.html
===================================================================
--- complete.html	2010-10-12 10:15:41 UTC (rev 5615)
+++ complete.html	2010-10-12 21:20:32 UTC (rev 5616)
@@ -11661,23 +11661,35 @@
 
    <dd>
 
-    <p>Adds the given string(s) to the <code><a href=#document>Document</a></code>'s input
-    stream. If necessary, calls the <code title=dom-document-open><a href=#dom-document-open>open()</a></code> method implicitly
-    first.</p>
+    <p>In general, adds the given string(s) to the
+    <code><a href=#document>Document</a></code>'s input stream.</p>
 
+    <p class=warning>This method has very idiosyncratic behavior. In
+    some cases, this method can affect the state of the <a href=#html-parser>HTML
+    parser</a> while the parser is running, resulting in a DOM that
+    does not correspond to the source of the document. In other cases,
+    the call can clear the current page first, as if <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> had been called.
+    In yet more cases, the method is simply ignored, or throws an
+    exception. To make matters worse, the exact behavior of this
+    method can in some cases be dependent on network latency, which
+    can lead to failures that are very hard to debug. <strong>For all
+    these reasons, use of this method is strongly
+    discouraged.</strong></p>
+
     <p>This method throws an <code><a href=#invalid_state_err>INVALID_STATE_ERR</a></code> exception
     when invoked on <a href=#xml-documents>XML documents</a>.</p>
 
-    <p>Unless called from the body of a <code><a href=#script>script</a></code> element
-    while the document is being parsed, or called on a script-created
-    document, calling this method will clear the current page first,
-    as if <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> had
-    been called.</p>
-
    </dd>
 
   </dl><div class=impl>
 
+  <p><code><a href=#document>Document</a></code> objects have an
+  <dfn id=ignore-destructive-writes-counter>ignore-destructive-writes counter</dfn>, which is used in
+  conjunction with the processing of <code><a href=#script>script</a></code> elements to
+  prevent external scripts from being able to use <code title=dom-document-write><a href=#dom-document-write>document.write()</a></code> to blow away the
+  document by implicitly calling <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code>. Initially, the
+  counter must be set to zero.</p>
+
   <p>The <dfn id=dom-document-write title=dom-document-write><code>document.write(...)</code></dfn>
   method must act as follows:</p>
 
@@ -11697,8 +11709,8 @@
    <li>
 
     <p>If the <a href=#insertion-point>insertion point</a> is undefined and the
-    <code><a href=#document>Document</a></code> has the <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a>
-    flag set, then abort these steps.</p>
+    <code><a href=#document>Document</a></code>'s <a href=#ignore-destructive-writes-counter>ignore-destructive-writes
+    counter</a> is greater than zero, then abort these steps.</p>
 
    </li>
 
@@ -14308,15 +14320,6 @@
   <a href=#parser-inserted>"parser-inserted"</a>, to let the parser know when to
   execute the script.</p>
 
-  <p>The fourth is a flag is the <dfn id=ignore-destructive-writes>"ignore-destructive-writes"</dfn> flag.
-  Initially, <code><a href=#script>script</a></code> elements must have this flag unset
-  (script blocks, when created, do not have a "ignore-destructive-writes"
-  flag). This flag is used to ensure that scripts <em>not</em>
-  inserted by the parser but inserted while a parser is active do not
-  blow away the document if they use the <code title=dom-document-write><a href=#dom-document-write>document.write()</a></code> API.
-  <code><a href=#document>Document</a></code> objects can also have this flag set; it's
-  propagated to the <code><a href=#document>Document</a></code> when the script runs.</p>
-
   <p>The last few pieces of state are <dfn id="the-script-block's-type"><var>the script block's
   type</var></dfn>, <dfn id="the-script-block's-character-encoding"><var>the script block's character
   encoding</var></dfn>, and <dfn id="the-script-block's-fallback-character-encoding"><var>the script block's fallback
@@ -14472,16 +14475,6 @@
 
     </ol></li>
 
-   <li>
-
-    <p>If the element's <code><a href=#document>Document</a></code> has an <a href=#active-parser>active
-    parser</a>, and the parser's <a href=#script-nesting-level>script nesting level</a>
-    is non-zero, but this <code><a href=#script>script</a></code> element does not have
-    the <a href=#parser-inserted>"parser-inserted"</a> flag set, the user agent must
-    set the element's <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a> flag.</p>
-
-   </li>
-
    <li id=script-processing-encoding>
 
     <p>If the <code><a href=#script>script</a></code> element has a <code title=attr-script-charset><a href=#attr-script-charset>charset</a></code> attribute, then let
@@ -14674,6 +14667,12 @@
    <!-- SCRIPT EXEC -->
    <dd>
 
+    <p>Executing the script block must consists of running the
+    following steps. For the purposes of these steps, the script is
+    considered to be from an <i>external file</i> if, while the
+    <a href=#running-a-script>running a script</a> algorithm above was running for this
+    script, the <code><a href=#script>script</a></code> element had a <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute specified.</p>
+
     <ol><li>
 
       <p>Initialize <dfn id="the-script-block's-source"><var>the script block's source</var></dfn> as
@@ -14779,19 +14778,11 @@
 
      <li>
 
-      <p>If the <code><a href=#script>script</a></code> element's
-      <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a> flag is set, then flag the
-      <code><a href=#document>Document</a></code> the <code><a href=#script>script</a></code> element was in
-      when the <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a> flag was set as being
-      itself <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a>. Let <var title="">neutralized doc</var> be that
+      <p>If the script is from an external file, then increment the
+      <a href=#ignore-destructive-writes-counter>ignore-destructive-writes counter</a> of the
+      <code><a href=#script>script</a></code> element's <code><a href=#document>Document</a></code>. Let <var title="">neutralized doc</var> be that
       <code><a href=#document>Document</a></code>.</p>
 
-      <!-- theorem: this can only happen when the parser nesting
-      levels of all parsers on this thread are zero, so any scripts
-      inserted while this is true will not themselves have the flag
-      said, so we don't have to worry about this being a counter
-      instead of just a boolean. -->
-
      </li>
 
      <li>
@@ -14808,8 +14799,9 @@
 
      <li>
 
-      <p>Remove the <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a> flag from <var title="">neutralized doc</var>, if it was set in the earlier
-      step.</p>
+      <p>Decrement the <a href=#ignore-destructive-writes-counter>ignore-destructive-writes counter</a>
+      of <var title="">neutralized doc</var>, if it was incremented in
+      the earlier step.</p>
 
      </li>
 

Modified: index
===================================================================
--- index	2010-10-12 10:15:41 UTC (rev 5615)
+++ index	2010-10-12 21:20:32 UTC (rev 5616)
@@ -11638,23 +11638,35 @@
 
    <dd>
 
-    <p>Adds the given string(s) to the <code><a href=#document>Document</a></code>'s input
-    stream. If necessary, calls the <code title=dom-document-open><a href=#dom-document-open>open()</a></code> method implicitly
-    first.</p>
+    <p>In general, adds the given string(s) to the
+    <code><a href=#document>Document</a></code>'s input stream.</p>
 
+    <p class=warning>This method has very idiosyncratic behavior. In
+    some cases, this method can affect the state of the <a href=#html-parser>HTML
+    parser</a> while the parser is running, resulting in a DOM that
+    does not correspond to the source of the document. In other cases,
+    the call can clear the current page first, as if <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> had been called.
+    In yet more cases, the method is simply ignored, or throws an
+    exception. To make matters worse, the exact behavior of this
+    method can in some cases be dependent on network latency, which
+    can lead to failures that are very hard to debug. <strong>For all
+    these reasons, use of this method is strongly
+    discouraged.</strong></p>
+
     <p>This method throws an <code><a href=#invalid_state_err>INVALID_STATE_ERR</a></code> exception
     when invoked on <a href=#xml-documents>XML documents</a>.</p>
 
-    <p>Unless called from the body of a <code><a href=#script>script</a></code> element
-    while the document is being parsed, or called on a script-created
-    document, calling this method will clear the current page first,
-    as if <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> had
-    been called.</p>
-
    </dd>
 
   </dl><div class=impl>
 
+  <p><code><a href=#document>Document</a></code> objects have an
+  <dfn id=ignore-destructive-writes-counter>ignore-destructive-writes counter</dfn>, which is used in
+  conjunction with the processing of <code><a href=#script>script</a></code> elements to
+  prevent external scripts from being able to use <code title=dom-document-write><a href=#dom-document-write>document.write()</a></code> to blow away the
+  document by implicitly calling <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code>. Initially, the
+  counter must be set to zero.</p>
+
   <p>The <dfn id=dom-document-write title=dom-document-write><code>document.write(...)</code></dfn>
   method must act as follows:</p>
 
@@ -11674,8 +11686,8 @@
    <li>
 
     <p>If the <a href=#insertion-point>insertion point</a> is undefined and the
-    <code><a href=#document>Document</a></code> has the <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a>
-    flag set, then abort these steps.</p>
+    <code><a href=#document>Document</a></code>'s <a href=#ignore-destructive-writes-counter>ignore-destructive-writes
+    counter</a> is greater than zero, then abort these steps.</p>
 
    </li>
 
@@ -14285,15 +14297,6 @@
   <a href=#parser-inserted>"parser-inserted"</a>, to let the parser know when to
   execute the script.</p>
 
-  <p>The fourth is a flag is the <dfn id=ignore-destructive-writes>"ignore-destructive-writes"</dfn> flag.
-  Initially, <code><a href=#script>script</a></code> elements must have this flag unset
-  (script blocks, when created, do not have a "ignore-destructive-writes"
-  flag). This flag is used to ensure that scripts <em>not</em>
-  inserted by the parser but inserted while a parser is active do not
-  blow away the document if they use the <code title=dom-document-write><a href=#dom-document-write>document.write()</a></code> API.
-  <code><a href=#document>Document</a></code> objects can also have this flag set; it's
-  propagated to the <code><a href=#document>Document</a></code> when the script runs.</p>
-
   <p>The last few pieces of state are <dfn id="the-script-block's-type"><var>the script block's
   type</var></dfn>, <dfn id="the-script-block's-character-encoding"><var>the script block's character
   encoding</var></dfn>, and <dfn id="the-script-block's-fallback-character-encoding"><var>the script block's fallback
@@ -14449,16 +14452,6 @@
 
     </ol></li>
 
-   <li>
-
-    <p>If the element's <code><a href=#document>Document</a></code> has an <a href=#active-parser>active
-    parser</a>, and the parser's <a href=#script-nesting-level>script nesting level</a>
-    is non-zero, but this <code><a href=#script>script</a></code> element does not have
-    the <a href=#parser-inserted>"parser-inserted"</a> flag set, the user agent must
-    set the element's <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a> flag.</p>
-
-   </li>
-
    <li id=script-processing-encoding>
 
     <p>If the <code><a href=#script>script</a></code> element has a <code title=attr-script-charset><a href=#attr-script-charset>charset</a></code> attribute, then let
@@ -14651,6 +14644,12 @@
    <!-- SCRIPT EXEC -->
    <dd>
 
+    <p>Executing the script block must consists of running the
+    following steps. For the purposes of these steps, the script is
+    considered to be from an <i>external file</i> if, while the
+    <a href=#running-a-script>running a script</a> algorithm above was running for this
+    script, the <code><a href=#script>script</a></code> element had a <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute specified.</p>
+
     <ol><li>
 
       <p>Initialize <dfn id="the-script-block's-source"><var>the script block's source</var></dfn> as
@@ -14756,19 +14755,11 @@
 
      <li>
 
-      <p>If the <code><a href=#script>script</a></code> element's
-      <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a> flag is set, then flag the
-      <code><a href=#document>Document</a></code> the <code><a href=#script>script</a></code> element was in
-      when the <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a> flag was set as being
-      itself <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a>. Let <var title="">neutralized doc</var> be that
+      <p>If the script is from an external file, then increment the
+      <a href=#ignore-destructive-writes-counter>ignore-destructive-writes counter</a> of the
+      <code><a href=#script>script</a></code> element's <code><a href=#document>Document</a></code>. Let <var title="">neutralized doc</var> be that
       <code><a href=#document>Document</a></code>.</p>
 
-      <!-- theorem: this can only happen when the parser nesting
-      levels of all parsers on this thread are zero, so any scripts
-      inserted while this is true will not themselves have the flag
-      said, so we don't have to worry about this being a counter
-      instead of just a boolean. -->
-
      </li>
 
      <li>
@@ -14785,8 +14776,9 @@
 
      <li>
 
-      <p>Remove the <a href=#ignore-destructive-writes>"ignore-destructive-writes"</a> flag from <var title="">neutralized doc</var>, if it was set in the earlier
-      step.</p>
+      <p>Decrement the <a href=#ignore-destructive-writes-counter>ignore-destructive-writes counter</a>
+      of <var title="">neutralized doc</var>, if it was incremented in
+      the earlier step.</p>
 
      </li>
 

Modified: source
===================================================================
--- source	2010-10-12 10:15:41 UTC (rev 5615)
+++ source	2010-10-12 21:20:32 UTC (rev 5616)
@@ -12092,26 +12092,40 @@
 
    <dd>
 
-    <p>Adds the given string(s) to the <code>Document</code>'s input
-    stream. If necessary, calls the <code
-    title="dom-document-open">open()</code> method implicitly
-    first.</p>
+    <p>In general, adds the given string(s) to the
+    <code>Document</code>'s input stream.</p>
 
+    <p class="warning">This method has very idiosyncratic behavior. In
+    some cases, this method can affect the state of the <span>HTML
+    parser</span> while the parser is running, resulting in a DOM that
+    does not correspond to the source of the document. In other cases,
+    the call can clear the current page first, as if <code
+    title="dom-document-open">document.open()</code> had been called.
+    In yet more cases, the method is simply ignored, or throws an
+    exception. To make matters worse, the exact behavior of this
+    method can in some cases be dependent on network latency, which
+    can lead to failures that are very hard to debug. <strong>For all
+    these reasons, use of this method is strongly
+    discouraged.</strong></p>
+
     <p>This method throws an <code>INVALID_STATE_ERR</code> exception
     when invoked on <span>XML documents</span>.</p>
 
-    <p>Unless called from the body of a <code>script</code> element
-    while the document is being parsed, or called on a script-created
-    document, calling this method will clear the current page first,
-    as if <code title="dom-document-open">document.open()</code> had
-    been called.</p>
-
    </dd>
 
   </dl>
 
   <div class="impl">
 
+  <p><code>Document</code> objects have an
+  <dfn>ignore-destructive-writes counter</dfn>, which is used in
+  conjunction with the processing of <code>script</code> elements to
+  prevent external scripts from being able to use <code
+  title="dom-document-write">document.write()</code> to blow away the
+  document by implicitly calling <code
+  title="dom-document-open">document.open()</code>. Initially, the
+  counter must be set to zero.</p>
+
   <p>The <dfn
   title="dom-document-write"><code>document.write(...)</code></dfn>
   method must act as follows:</p>
@@ -12134,8 +12148,8 @@
    <li>
 
     <p>If the <span>insertion point</span> is undefined and the
-    <code>Document</code> has the <span>"ignore-destructive-writes"</span>
-    flag set, then abort these steps.</p>
+    <code>Document</code>'s <span>ignore-destructive-writes
+    counter</span> is greater than zero, then abort these steps.</p>
 
    </li>
 
@@ -15135,16 +15149,6 @@
   <span>"parser-inserted"</span>, to let the parser know when to
   execute the script.</p>
 
-  <p>The fourth is a flag is the <dfn>"ignore-destructive-writes"</dfn> flag.
-  Initially, <code>script</code> elements must have this flag unset
-  (script blocks, when created, do not have a "ignore-destructive-writes"
-  flag). This flag is used to ensure that scripts <em>not</em>
-  inserted by the parser but inserted while a parser is active do not
-  blow away the document if they use the <code
-  title="dom-document-write">document.write()</code> API.
-  <code>Document</code> objects can also have this flag set; it's
-  propagated to the <code>Document</code> when the script runs.</p>
-
   <p>The last few pieces of state are <dfn><var>the script block's
   type</var></dfn>, <dfn><var>the script block's character
   encoding</var></dfn>, and <dfn><var>the script block's fallback
@@ -15335,16 +15339,6 @@
 
    </li>
 
-   <li>
-
-    <p>If the element's <code>Document</code> has an <span>active
-    parser</span>, and the parser's <span>script nesting level</span>
-    is non-zero, but this <code>script</code> element does not have
-    the <span>"parser-inserted"</span> flag set, the user agent must
-    set the element's <span>"ignore-destructive-writes"</span> flag.</p>
-
-   </li>
-
    <li id="script-processing-encoding">
 
     <p>If the <code>script</code> element has a <code
@@ -15556,6 +15550,13 @@
    <!-- SCRIPT EXEC -->
    <dd>
 
+    <p>Executing the script block must consists of running the
+    following steps. For the purposes of these steps, the script is
+    considered to be from an <i>external file</i> if, while the
+    <span>running a script</span> algorithm above was running for this
+    script, the <code>script</code> element had a <code
+    title="attr-script-src">src</code> attribute specified.</p>
+
     <ol>
 
      <li>
@@ -15682,20 +15683,12 @@
 
      <li>
 
-      <p>If the <code>script</code> element's
-      <span>"ignore-destructive-writes"</span> flag is set, then flag the
-      <code>Document</code> the <code>script</code> element was in
-      when the <span>"ignore-destructive-writes"</span> flag was set as being
-      itself <span>"ignore-destructive-writes"</span>. Let <var
+      <p>If the script is from an external file, then increment the
+      <span>ignore-destructive-writes counter</span> of the
+      <code>script</code> element's <code>Document</code>. Let <var
       title="">neutralized doc</var> be that
       <code>Document</code>.</p>
 
-      <!-- theorem: this can only happen when the parser nesting
-      levels of all parsers on this thread are zero, so any scripts
-      inserted while this is true will not themselves have the flag
-      said, so we don't have to worry about this being a counter
-      instead of just a boolean. -->
-
      </li>
 
      <li>
@@ -15712,9 +15705,9 @@
 
      <li>
 
-      <p>Remove the <span>"ignore-destructive-writes"</span> flag from <var
-      title="">neutralized doc</var>, if it was set in the earlier
-      step.</p>
+      <p>Decrement the <span>ignore-destructive-writes counter</span>
+      of <var title="">neutralized doc</var>, if it was incremented in
+      the earlier step.</p>
 
      </li>
 




More information about the Commit-Watchers mailing list