[html5] r4098 - [] (0) Dramatically simplify <script defer> and <script async> handling. Fixing [...]

whatwg at whatwg.org whatwg at whatwg.org
Thu Oct 8 21:46:45 PDT 2009


Author: ianh
Date: 2009-10-08 21:46:44 -0700 (Thu, 08 Oct 2009)
New Revision: 4098

Modified:
   index
   source
Log:
[] (0) Dramatically simplify <script defer> and <script async> handling.
Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=7792

Modified: index
===================================================================
--- index	2009-10-09 03:28:02 UTC (rev 4097)
+++ index	2009-10-09 04:46:44 UTC (rev 4098)
@@ -12081,9 +12081,9 @@
   support <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> (and not <code title=attr-script-async><a href=#attr-script-async>async</a></code>) to fall back to the <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> behavior instead of the
   synchronous blocking behavior that is the default.</p>
 
-  <p>If the <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> attribute is
-  specified, the <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute
-  must also be specified.</p>
+  <p>If one or both of the <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> and <code title=attr-script-async><a href=#attr-script-async>async</a></code> attributes are specified, the
+  <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute must also be
+  specified.</p>
 
   <p>Changing the <code title=attr-script-src><a href=#attr-script-src>src</a></code>, <code title=attr-script-type><a href=#attr-script-type>type</a></code>, <code title=attr-script-charset><a href=#attr-script-charset>charset</a></code>, <code title=attr-script-async><a href=#attr-script-async>async</a></code>, and <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> attributes dynamically has no
   direct effect; these attribute are only used <span class=impl>at
@@ -12246,35 +12246,20 @@
     <p>Then, the first of the following options that describes the
     situation must be followed:</p>
 
-    <dl class=switch><dt>If the document is still being parsed, and the element has a
-     <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> attribute, and the
-     element has a <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute,
-     and the element does not have an <code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute</dt>
+    <dl class=switch><dt>If the element has a <code title=attr-script-src><a href=#attr-script-src>src</a></code>
+     attribute, and the element has a <code title=attr-script-defer><a href=#attr-script-defer>defer</a></code> attribute, and the element
+     has been flagged as <a href=#parser-inserted>"parser-inserted"</a>, and the
+     element does not have an <code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute</dt>
 
      <dd>The element must be added to the end of the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of
      scripts that will execute when the document has finished
-     parsing</a>.
+     parsing</a>.</dd>
 
-     </dd>
 
-
-     <dt>If the element has an <code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute and a <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute</dt>
-
-     <dd>The element must be added to the end of the <a href=#list-of-scripts-that-will-execute-asynchronously>list of
-     scripts that will execute asynchronously</a>.</dd>
-
-
-     <dt>If the element has an <code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute but no <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute, and the <a href=#list-of-scripts-that-will-execute-asynchronously>list
-     of scripts that will execute asynchronously</a> is not
-     empty</dt>
-
-     <dd>The element must be added to the end of the <a href=#list-of-scripts-that-will-execute-asynchronously>list of
-     scripts that will execute asynchronously</a>.</dd>
-
-
      <dt>If the element has a <code title=attr-script-src><a href=#attr-script-src>src</a></code>
-     attribute and has been flagged as
-     <a href=#parser-inserted>"parser-inserted"</a></dt>
+     attribute, and the element has been flagged as
+     <a href=#parser-inserted>"parser-inserted"</a>, and the element does not have an
+     <code title=attr-script-async><a href=#attr-script-async>async</a></code> attribute</dt>
 
      <dd>The element is the <dfn id=pending-external-script>pending external script</dfn>. (There
      can only be one such script at a time.)</dd>
@@ -12301,12 +12286,10 @@
   the resource has been <a href=#fetch title=fetch>fetched</a> (defined
   below) has been run.</p>
 
-  <p><dfn id=when-a-script-completes-loading>When a script completes loading</dfn>: If the
-  <code><a href=#script>script</a></code> element was added to one of the lists mentioned
-  above and the document is still being parsed, then the parser
-  handles it. Otherwise, the UA must run the following steps as the
-  <a href=#concept-task title=concept-task>task</a> that the <a href=#networking-task-source>networking
-  task source</a> places on the <a href=#task-queue>task queue</a>:</p>
+  <p><dfn id=when-a-script-completes-loading>When a script completes loading</dfn>: The UA must run the
+  following steps as the <a href=#concept-task title=concept-task>task</a> that
+  the <a href=#networking-task-source>networking task source</a> places on the <a href=#task-queue>task
+  queue</a>:</p>
 
   <dl class=switch><dt>If the <code><a href=#script>script</a></code> element was added to the <dfn id=list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list
    of scripts that will execute when the document has finished
@@ -12316,6 +12299,13 @@
 
     <ol><li>
 
+      <p>If the script's <code>Document</code> is still being parsed,
+      then the parser handles it. Abort these steps.</p>
+
+     </li>
+
+     <li>
+
       <p>If the <code><a href=#script>script</a></code> element is not the first element
       in the list, then do nothing yet. Stop going through these
       steps.</p>
@@ -12344,49 +12334,6 @@
 
      </li>
 
-    </ol><p class=note>The scripts in the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of scripts that will
-    execute when the document has finished parsing</a> can also get
-    executed prematurely if the <code title=dom-innerHTML><a href=#dom-innerhtml>innerHTML</a></code> attribute is set on a node
-    in the document.</p>
-
-   </dd>
-
-   <dt>If the <code><a href=#script>script</a></code> element was added to the <dfn id=list-of-scripts-that-will-execute-asynchronously>list
-   of scripts that will execute asynchronously</dfn>:</dt>
-
-   <dd>
-
-    <ol><li>
-
-      <p>If the script is not the first element in the list, then do
-      nothing yet. Stop going through these steps.</p>
-
-     </li>
-
-     <li>
-
-      <p><a href=#executing-a-script-block title="executing a script block">Execute the script
-      block</a> (the first element in the list).</p>
-
-     </li>
-
-     <li>
-
-      <p>Remove the <code><a href=#script>script</a></code> element from the list
-      (i.e. shift out the first entry in the list).</p>
-
-     </li>
-
-     <li>
-
-      <p>If there are any more scripts in the list, and the element
-      now at the head of the list had no <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute when it was added
-      to the list, or had one, but its associated script has finished
-      loading, then jump back to step 2 to execute the script
-      associated with this element.</p>
-
-     </li>
-
     </ol></dd>
 
    <dt>If the <code><a href=#script>script</a></code> element was added to the <dfn id=list-of-scripts-that-will-execute-as-soon-as-possible>list
@@ -61192,13 +61139,7 @@
   <p>Before each step of the tokenizer, the user agent must first
   check the <a href=#parser-pause-flag>parser pause flag</a>. If it is true, then the
   tokenizer must abort the processing of any nested invocations of the
-  tokenizer, yielding control back to the caller. If it is false, then
-  the user agent may then check to see if either one of the scripts in
-  the <a href=#list-of-scripts-that-will-execute-as-soon-as-possible>list of scripts that will execute as soon as
-  possible</a> or the first script in the <a href=#list-of-scripts-that-will-execute-asynchronously>list of scripts
-  that will execute asynchronously</a>, has <a href=#completed-loading>completed
-  loading</a>. If one has, then it must be <a href=#executing-a-script-block title="executing a
-  script block">executed</a> and removed from its list.</p>
+  tokenizer, yielding control back to the caller.</p>
 
   <p>The tokenizer state machine consists of the states defined in the
   following subsections.</p>
@@ -66214,26 +66155,21 @@
 
   <p>First, the user agent must set the <a href=#current-document-readiness>current document
   readiness</a> to "interactive" and the <a href=#insertion-point>insertion
-  point</a> to undefined.</p>
+  point</a> to undefined.</p> <!-- this also synchronously fires an
+  event -->
 
   <p>Then, the user agent must then make a list of all the scripts
   that are in the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of scripts that will execute when the
-  document has finished parsing</a>, the <a href=#list-of-scripts-that-will-execute-asynchronously>list of scripts that
-  will execute asynchronously</a>, and the <a href=#list-of-scripts-that-will-execute-as-soon-as-possible>list of scripts
+  document has finished parsing</a> and the <a href=#list-of-scripts-that-will-execute-as-soon-as-possible>list of scripts
   that will execute as soon as possible</a>. This is the <dfn id=list-of-scripts-pending-after-the-parser-stopped>list
   of scripts pending after the parser stopped</dfn>.</p>
 
-  <p>The rules for <a href=#when-a-script-completes-loading>when a script completes loading</a> start
-  applying (script execution is no longer managed by the parser).</p>
+  <p>The document is no longer being parsed, so the rules for
+  <a href=#when-a-script-completes-loading>when a script completes loading</a> for the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of
+  scripts that will execute when the document has finished
+  parsing</a> start applying (script execution for that list is no
+  longer managed by the parser).</p>
 
-  <p>If any of the scripts in the <a href=#list-of-scripts-that-will-execute-as-soon-as-possible>list of scripts that will
-  execute as soon as possible</a> have <a href=#completed-loading>completed
-  loading</a>, or if the <a href=#list-of-scripts-that-will-execute-asynchronously>list of scripts that will execute
-  asynchronously</a> is not empty and the first script in that list
-  has <a href=#completed-loading>completed loading</a>, then the user agent must act as
-  if those scripts just completed loading, following the rules given
-  for that in the <code><a href=#script>script</a></code> element definition.</p>
-
   <p>If the <a href=#list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of scripts that will execute when the document
   has finished parsing</a> is not empty, and the first item in this
   list has already <a href=#completed-loading>completed loading</a>, then the user agent
@@ -66255,7 +66191,8 @@
   run the following steps:</p>
 
   <ol><li><a href=#queue-a-task>Queue a task</a> to set the <a href=#current-document-readiness>current document
-   readiness</a> to "complete".</li>
+   readiness</a> to "complete".</li> <!-- this also fires an event
+   synchronously during the task -->
 
    <li>If the <code>Document</code> is in a <a href=#browsing-context>browsing
    context</a>, then <a href=#queue-a-task>queue a task</a> to <a href=#fire-a-simple-event>fire a

Modified: source
===================================================================
--- source	2009-10-09 03:28:02 UTC (rev 4097)
+++ source	2009-10-09 04:46:44 UTC (rev 4098)
@@ -12787,9 +12787,11 @@
   title="attr-script-defer">defer</code> behavior instead of the
   synchronous blocking behavior that is the default.</p>
 
-  <p>If the <code title="attr-script-defer">defer</code> attribute is
-  specified, the <code title="attr-script-src">src</code> attribute
-  must also be specified.</p>
+  <p>If one or both of the <code
+  title="attr-script-defer">defer</code> and <code
+  title="attr-script-async">async</code> attributes are specified, the
+  <code title="attr-script-src">src</code> attribute must also be
+  specified.</p>
 
   <p>Changing the <code title="attr-script-src">src</code>, <code
   title="attr-script-type">type</code>, <code
@@ -12989,40 +12991,22 @@
 
     <dl class="switch">
 
-     <dt>If the document is still being parsed, and the element has a
-     <code title="attr-script-defer">defer</code> attribute, and the
-     element has a <code title="attr-script-src">src</code> attribute,
-     and the element does not have an <code
+     <dt>If the element has a <code title="attr-script-src">src</code>
+     attribute, and the element has a <code
+     title="attr-script-defer">defer</code> attribute, and the element
+     has been flagged as <span>"parser-inserted"</span>, and the
+     element does not have an <code
      title="attr-script-async">async</code> attribute</dt>
 
      <dd>The element must be added to the end of the <span>list of
      scripts that will execute when the document has finished
-     parsing</span>.
+     parsing</span>.</dd>
 
-     </dd>
 
-
-     <dt>If the element has an <code
-     title="attr-script-async">async</code> attribute and a <code
-     title="attr-script-src">src</code> attribute</dt>
-
-     <dd>The element must be added to the end of the <span>list of
-     scripts that will execute asynchronously</span>.</dd>
-
-
-     <dt>If the element has an <code
-     title="attr-script-async">async</code> attribute but no <code
-     title="attr-script-src">src</code> attribute, and the <span>list
-     of scripts that will execute asynchronously</span> is not
-     empty</dt>
-
-     <dd>The element must be added to the end of the <span>list of
-     scripts that will execute asynchronously</span>.</dd>
-
-
      <dt>If the element has a <code title="attr-script-src">src</code>
-     attribute and has been flagged as
-     <span>"parser-inserted"</span></dt>
+     attribute, and the element has been flagged as
+     <span>"parser-inserted"</span>, and the element does not have an
+     <code title="attr-script-async">async</code> attribute</dt>
 
      <dd>The element is the <dfn>pending external script</dfn>. (There
      can only be one such script at a time.)</dd>
@@ -13055,12 +13039,10 @@
   the resource has been <span title="fetch">fetched</span> (defined
   below) has been run.</p>
 
-  <p><dfn>When a script completes loading</dfn>: If the
-  <code>script</code> element was added to one of the lists mentioned
-  above and the document is still being parsed, then the parser
-  handles it. Otherwise, the UA must run the following steps as the
-  <span title="concept-task">task</span> that the <span>networking
-  task source</span> places on the <span>task queue</span>:</p>
+  <p><dfn>When a script completes loading</dfn>: The UA must run the
+  following steps as the <span title="concept-task">task</span> that
+  the <span>networking task source</span> places on the <span>task
+  queue</span>:</p>
 
   <dl class="switch">
 
@@ -13074,6 +13056,13 @@
 
      <li>
 
+      <p>If the script's <code>Document</code> is still being parsed,
+      then the parser handles it. Abort these steps.</p>
+
+     </li>
+
+     <li>
+
       <p>If the <code>script</code> element is not the first element
       in the list, then do nothing yet. Stop going through these
       steps.</p>
@@ -13104,58 +13093,9 @@
 
     </ol>
 
-    <p class="note">The scripts in the <span>list of scripts that will
-    execute when the document has finished parsing</span> can also get
-    executed prematurely if the <code
-    title="dom-innerHTML">innerHTML</code> attribute is set on a node
-    in the document.</p>
-
    </dd>
 
    <dt>If the <code>script</code> element was added to the <dfn>list
-   of scripts that will execute asynchronously</dfn>:</dt>
-
-   <dd>
-
-    <ol>
-
-     <li>
-
-      <p>If the script is not the first element in the list, then do
-      nothing yet. Stop going through these steps.</p>
-
-     </li>
-
-     <li>
-
-      <p><span title="executing a script block">Execute the script
-      block</span> (the first element in the list).</p>
-
-     </li>
-
-     <li>
-
-      <p>Remove the <code>script</code> element from the list
-      (i.e. shift out the first entry in the list).</p>
-
-     </li>
-
-     <li>
-
-      <p>If there are any more scripts in the list, and the element
-      now at the head of the list had no <code
-      title="attr-script-src">src</code> attribute when it was added
-      to the list, or had one, but its associated script has finished
-      loading, then jump back to step 2 to execute the script
-      associated with this element.</p>
-
-     </li>
-
-    </ol>
-
-   </dd>
-
-   <dt>If the <code>script</code> element was added to the <dfn>list
    of scripts that will execute as soon as possible</dfn>:</dt>
 
    <dd>
@@ -78935,13 +78875,7 @@
   <p>Before each step of the tokenizer, the user agent must first
   check the <span>parser pause flag</span>. If it is true, then the
   tokenizer must abort the processing of any nested invocations of the
-  tokenizer, yielding control back to the caller. If it is false, then
-  the user agent may then check to see if either one of the scripts in
-  the <span>list of scripts that will execute as soon as
-  possible</span> or the first script in the <span>list of scripts
-  that will execute asynchronously</span>, has <span>completed
-  loading</span>. If one has, then it must be <span title="executing a
-  script block">executed</span> and removed from its list.</p>
+  tokenizer, yielding control back to the caller.</p>
 
   <p>The tokenizer state machine consists of the states defined in the
   following subsections.</p>
@@ -84524,26 +84458,21 @@
 
   <p>First, the user agent must set the <span>current document
   readiness</span> to "interactive" and the <span>insertion
-  point</span> to undefined.</p>
+  point</span> to undefined.</p> <!-- this also synchronously fires an
+  event -->
 
   <p>Then, the user agent must then make a list of all the scripts
   that are in the <span>list of scripts that will execute when the
-  document has finished parsing</span>, the <span>list of scripts that
-  will execute asynchronously</span>, and the <span>list of scripts
+  document has finished parsing</span> and the <span>list of scripts
   that will execute as soon as possible</span>. This is the <dfn>list
   of scripts pending after the parser stopped</dfn>.</p>
 
-  <p>The rules for <span>when a script completes loading</span> start
-  applying (script execution is no longer managed by the parser).</p>
+  <p>The document is no longer being parsed, so the rules for
+  <span>when a script completes loading</span> for the <span>list of
+  scripts that will execute when the document has finished
+  parsing</span> start applying (script execution for that list is no
+  longer managed by the parser).</p>
 
-  <p>If any of the scripts in the <span>list of scripts that will
-  execute as soon as possible</span> have <span>completed
-  loading</span>, or if the <span>list of scripts that will execute
-  asynchronously</span> is not empty and the first script in that list
-  has <span>completed loading</span>, then the user agent must act as
-  if those scripts just completed loading, following the rules given
-  for that in the <code>script</code> element definition.</p>
-
   <p>If the <span>list of scripts that will execute when the document
   has finished parsing</span> is not empty, and the first item in this
   list has already <span>completed loading</span>, then the user agent
@@ -84576,7 +84505,8 @@
   <ol>
 
    <li><span>Queue a task</span> to set the <span>current document
-   readiness</span> to "complete".</li>
+   readiness</span> to "complete".</li> <!-- this also fires an event
+   synchronously during the task -->
 
    <li>If the <code>Document</code> is in a <span>browsing
    context</span>, then <span>queue a task</span> to <span>fire a




More information about the Commit-Watchers mailing list