[html5] r6543 - [giow] (0) Add script.readyState and fire 'readystatechange' in some cases. Not [...]

whatwg at whatwg.org whatwg at whatwg.org
Wed Sep 7 14:54:55 PDT 2011


Author: ianh
Date: 2011-09-07 14:54:53 -0700 (Wed, 07 Sep 2011)
New Revision: 6543

Modified:
   complete.html
   index
   source
Log:
[giow] (0) Add script.readyState and fire 'readystatechange' in some cases. Not 100% IE compatible because IE is pretty inconsistent here. Should be compatible with legacy content though, both in browsers that do script prefetch and those that don't.
Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=13965

Modified: complete.html
===================================================================
--- complete.html	2011-09-06 07:21:39 UTC (rev 6542)
+++ complete.html	2011-09-07 21:54:53 UTC (rev 6543)
@@ -239,7 +239,7 @@
 
   <header class=head id=head><p><a class=logo href=http://www.whatwg.org/><img alt=WHATWG height=101 src=/images/logo width=101></a></p>
    <hgroup><h1>Web Applications 1.0</h1>
-    <h2 class="no-num no-toc">Living Standard — Last Updated 6 September 2011</h2>
+    <h2 class="no-num no-toc">Living Standard — Last Updated 7 September 2011</h2>
    </hgroup><dl><dt>Multiple-page version:</dt>
     <dd><a href=http://www.whatwg.org/specs/web-apps/current-work/complete/>http://www.whatwg.org/specs/web-apps/current-work/complete/</a></dd>
     <dt>One-page version:</dt>
@@ -15215,6 +15215,8 @@
            attribute DOMString <a href=#dom-script-type title=dom-script-type>type</a>;
            attribute DOMString <a href=#dom-script-charset title=dom-script-charset>charset</a>;
            attribute DOMString <a href=#dom-script-text title=dom-script-text>text</a>;
+
+  readonly attribute DOMString <a href=#dom-script-readystate title=dom-script-readyState>readyState</a>;
 };</pre>
    </dd>
   </dl><p>The <code><a href=#the-script-element>script</a></code> element allows authors to include dynamic
@@ -15339,6 +15341,38 @@
   <a href=#parser-inserted>"parser-inserted"</a>, to let the parser know when to
   execute the script.</p>
 
+  <p>The fifth is the <dfn id=concept-script-state title=concept-script-state>current
+  status</dfn> of the script. This is a string. When the element is
+  created, if the user agent does not intend to prefetch the script
+  (i.e. the script, if any, will only be obtained once the
+  <a href=#prepare-a-script>prepare a script</a> algorithm requires it to be fetched),
+  then the <a href=#concept-script-state title=concept-script-state>current status</a>
+  must be set to "<code title="">loaded</code>". If the user agent
+  <em>does</em> intend to prefetch the script (if any), <a href=#scriptPrefetch>as allowed</a> in the <a href=#prepare-a-script>prepare a
+  script</a> algorithm below, the <a href=#concept-script-state title=concept-script-state>current status</a> must be set to
+  "<code title="">uninitialized</code>" when the element is created.
+  When the user agent begins to prefetch the script, it must set the
+  <a href=#concept-script-state title=concept-script-state>current status</a> to "<code title="">loading</code>". Once the script is fetched, the user agent
+  must <a href=#queue-a-task>queue a task</a> that, if the <a href=#prepare-a-script>prepare a
+  script</a> algorithm has still not started and the fetched script
+  is still the appropriate script, sets the <a href=#concept-script-state title=concept-script-state>current status</a> to "<code title="">loaded</code>" and <a href=#fire-a-simple-event title="fire a simple event">fires
+  a simple event</a> named <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> at the
+  element. If the script to be loaded changes while the script is
+  being prefetched, then the user agent must prefetch the new script
+  (if any), without changing the <a href=#concept-script-state title=concept-script-state>current status</a>. If no script is
+  ever successfully fetched (e.g. because the element is an inline
+  script) then the transition to "<code title="">loaded</code>" is
+  skipped, and so the <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> event does
+  not fire for this transition (it still fires when the <a href=#concept-script-state title=concept-script-state>current status</a> is set to "<code title="">complete</code>" later, however). If the script to be
+  loaded changes after a script has been successfully prefetched, the
+  user agent may prefetch the new script but must not change the <a href=#concept-script-state title=concept-script-state>current status</a> or fire any
+  events as a result. If the user agent changes its mind and decides
+  to not bother prefetching the script after all, the user agent must
+  <a href=#queue-a-task>queue a task</a> that, if the <a href=#prepare-a-script>prepare a
+  script</a> algorithm has still not started, sets the <a href=#concept-script-state title=concept-script-state>current status</a> to "<code title="">loaded</code>" and <a href=#fire-a-simple-event title="fire a simple event">fires
+  a simple event</a> named <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> at the
+  element.</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
@@ -15572,10 +15606,31 @@
     user agent must act as if it had received an empty HTTP 400
     response.</p>
 
-    <p>For performance reasons, user agents may start fetching the
-    script as soon as the attribute is set, instead, in the hope that
-    the element will be inserted into the document. Either way, once
-    the element is <a href=#insert-an-element-into-a-document title="insert an element into a
+    <p>If the <a href=#concept-script-state title=concept-script-state>current status</a>
+    of the element at this stage is still "<code title="">uninitialized</code>" (meaning that the user agent
+    intended to prefetch the script as described in the next
+    paragraph, but the <a href=#prepare-a-script>prepare a script</a> algorithm was
+    started before it had a chance to do so), then, if a
+    <a href=#fetch>fetch</a> attempt was started in this step, the user
+    agent must set the <a href=#concept-script-state title=concept-script-state>current
+    status</a> to "<code title="">loading</code>" <!--and
+    <span>queue a task</span> to <span>fire a simple event</span>
+    named <code title="event-readystatechange">readystatechange</code>
+    at the element-->. <!--(If the fetching is started as part of a
+    prefetch, then no <code
+    title="event-readystatechange">readystatechange</code> is fired
+    when <span title="concept-script-state">current status</span> is
+    set to "<code title="">loading</code>".)--></p> <!-- commented out
+    text is what IE does, but IE actually does stuff even more
+    complicated than that which I haven't tried to match exactly here
+    since it's just arcane -->
+
+    <p id=scriptPrefetch>For performance reasons, user agents may
+    start fetching the script as soon as the attribute is set,
+    instead, in the hope that the element will be inserted into the
+    document (user agents that do this have <a href=#concept-script-state title=concept-script-state>requirements</a> relating to what
+    events are to be fired during the process). Either way, once the
+    element is <a href=#insert-an-element-into-a-document title="insert an element into a
     document">inserted into the document</a>, the load must have
     started. If the UA performs such prefetching, but the element is
     never inserted in the document, or the <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute is dynamically
@@ -15759,6 +15814,18 @@
 
   <ol><li>
 
+    <p>If the <a href=#concept-script-state title=concept-script-state>current status</a>
+    of the element at this stage is "<code title="">loading</code>"
+    (meaning that the user agent intended to <a href=#scriptPrefetch>prefetch the script</a> as allowed by the
+    <a href=#prepare-a-script>prepare a script</a> algorithm, but the fetch was not
+    completed before that algorithm was started), then the user agent
+    must set the <a href=#concept-script-state title=concept-script-state>current
+    status</a> to "<code title="">loaded</code>".</p>
+
+   </li>
+
+   <li>
+
     <p>If the element is flagged as <a href=#parser-inserted>"parser-inserted"</a>,
     but the element's <code><a href=#document>Document</a></code> is not the
     <code><a href=#document>Document</a></code> of the parser that created the element, then
@@ -15773,9 +15840,21 @@
     <dl class=switch><dt>If the load resulted in an error (for example a DNS error, or
      an HTTP 404 error)</dt>
 
-     <dd><p>Executing the script block must just consist of <a href=#fire-a-simple-event title="fire a simple event">firing a simple event</a> named
-     <code title=event-error>error</code> at the element.</dd>
+     <dd>
 
+      <p>Executing the script block must consist of running the following steps:</p>
+
+      <ol><li><p>Set the <a href=#concept-script-state title=concept-script-state>current
+       status</a> to "<code title="">complete</code>".</li>
+
+       <li><p><a href=#fire-a-simple-event>Fire a simple event</a> named <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> at the
+       element.</li>
+
+       <li><p><a href=#fire-a-simple-event>Fire a simple event</a> named <code title=event-error>error</code> at the element.</li>
+
+      </ol></dd>
+
+
      <dt>If the load was successful</dt>
 
      <!-- SCRIPT EXEC -->
@@ -15905,6 +15984,9 @@
 
        </li>
 
+       <li><p>Set the <a href=#concept-script-state title=concept-script-state>current
+       status</a> to "<code title="">interactive</code>".</li>
+
        <li>
 
         <p><a href=#create-a-script-from-a-node title="create a script from a node">Create a
@@ -15925,6 +16007,12 @@
 
        </li>
 
+       <li><p>Set the <a href=#concept-script-state title=concept-script-state>current
+       status</a> to "<code title="">complete</code>".</li>
+
+       <li><p><a href=#fire-a-simple-event>Fire a simple event</a> named <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> at the
+       element.</li>
+
        <li>
 
         <p>If the script is from an external file, <a href=#fire-a-simple-event>fire a simple
@@ -15971,6 +16059,51 @@
 
    </dd>
 
+
+   <dt><var title="">script</var> . <code title=dom-script-readyState><a href=#dom-script-readystate>readyState</a></code></dt>
+
+   <dd>
+
+    <p>Returns the current state of the element. The value is one of
+    the following:</p>
+
+    <dl><dt>"<code title="">uninitialized</code>"</dt>
+
+     <dd><p>The script file, if any, has not yet been loaded, but the
+     user agent will try to prefetch it as soon as possible (e.g. as
+     soon as the <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute is
+     set).</dd>
+
+
+     <dt>"<code title="">loading</code>"</dt>
+
+     <dd><p>A script file is being downloaded in a user agent that
+     supports prefetching scripts.</dd>
+
+
+     <dt>"<code title="">loaded</code>"</dt>
+
+     <dd><p>Either a script file is loaded and ready to be executed,
+     or the script file is not loaded but the user agent does not
+     intend to prefetch the script file anyway, and will merely fetch
+     it when it is to be executed. If the element started in the <code title="">uninitialized</code>" state and the script has not yet
+     begun to be executed, then a <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> event is
+     fired when the state changes to this value.</dd>
+
+
+     <dt>"<code title="">interactive</code>"</dt>
+
+     <dd><p>The script is running.</dd>
+
+
+     <dt>"<code title="">complete</code>"</dt>
+
+     <dd><p>The script has been executed (or it failed). A <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> event is
+     fired when the state changes to this value, just before the
+     corresponding <code title=event-load>load</code> or <code title=event-error>error</code> event.</dd>
+
+    </dl></dd>
+
   </dl><div class=impl>
 
   <p>The IDL attribute <dfn id=dom-script-text title=dom-script-text><code>text</code></dfn> must return a
@@ -15980,6 +16113,10 @@
   tree order. On setting, it must act the same way as the
   <code><a href=#textcontent>textContent</a></code> IDL attribute.</p>
 
+  <p>The IDL attribute <dfn id=dom-script-readystate title=dom-script-readyState><code>readyState</code></dfn> must
+  return the element's <a href=#concept-script-state title=concept-script-state>current
+  status</a>.</p>
+
   </div>
 
   <p class=note>When inserted using the <code title=dom-document-write><a href=#dom-document-write>document.write()</a></code> method,

Modified: index
===================================================================
--- index	2011-09-06 07:21:39 UTC (rev 6542)
+++ index	2011-09-07 21:54:53 UTC (rev 6543)
@@ -243,7 +243,7 @@
 
   <header class=head id=head><p><a class=logo href=http://www.whatwg.org/><img alt=WHATWG height=101 src=/images/logo width=101></a></p>
    <hgroup><h1 class=allcaps>HTML</h1>
-    <h2 class="no-num no-toc">Living Standard — Last Updated 6 September 2011</h2>
+    <h2 class="no-num no-toc">Living Standard — Last Updated 7 September 2011</h2>
    </hgroup><dl><dt><strong>Web developer edition</strong></dt>
     <dd><strong><a href=http://developers.whatwg.org/>http://developers.whatwg.org/</a></strong></dd>
     <dt>Multiple-page version:</dt>
@@ -15079,6 +15079,8 @@
            attribute DOMString <a href=#dom-script-type title=dom-script-type>type</a>;
            attribute DOMString <a href=#dom-script-charset title=dom-script-charset>charset</a>;
            attribute DOMString <a href=#dom-script-text title=dom-script-text>text</a>;
+
+  readonly attribute DOMString <a href=#dom-script-readystate title=dom-script-readyState>readyState</a>;
 };</pre>
    </dd>
   </dl><p>The <code><a href=#the-script-element>script</a></code> element allows authors to include dynamic
@@ -15203,6 +15205,38 @@
   <a href=#parser-inserted>"parser-inserted"</a>, to let the parser know when to
   execute the script.</p>
 
+  <p>The fifth is the <dfn id=concept-script-state title=concept-script-state>current
+  status</dfn> of the script. This is a string. When the element is
+  created, if the user agent does not intend to prefetch the script
+  (i.e. the script, if any, will only be obtained once the
+  <a href=#prepare-a-script>prepare a script</a> algorithm requires it to be fetched),
+  then the <a href=#concept-script-state title=concept-script-state>current status</a>
+  must be set to "<code title="">loaded</code>". If the user agent
+  <em>does</em> intend to prefetch the script (if any), <a href=#scriptPrefetch>as allowed</a> in the <a href=#prepare-a-script>prepare a
+  script</a> algorithm below, the <a href=#concept-script-state title=concept-script-state>current status</a> must be set to
+  "<code title="">uninitialized</code>" when the element is created.
+  When the user agent begins to prefetch the script, it must set the
+  <a href=#concept-script-state title=concept-script-state>current status</a> to "<code title="">loading</code>". Once the script is fetched, the user agent
+  must <a href=#queue-a-task>queue a task</a> that, if the <a href=#prepare-a-script>prepare a
+  script</a> algorithm has still not started and the fetched script
+  is still the appropriate script, sets the <a href=#concept-script-state title=concept-script-state>current status</a> to "<code title="">loaded</code>" and <a href=#fire-a-simple-event title="fire a simple event">fires
+  a simple event</a> named <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> at the
+  element. If the script to be loaded changes while the script is
+  being prefetched, then the user agent must prefetch the new script
+  (if any), without changing the <a href=#concept-script-state title=concept-script-state>current status</a>. If no script is
+  ever successfully fetched (e.g. because the element is an inline
+  script) then the transition to "<code title="">loaded</code>" is
+  skipped, and so the <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> event does
+  not fire for this transition (it still fires when the <a href=#concept-script-state title=concept-script-state>current status</a> is set to "<code title="">complete</code>" later, however). If the script to be
+  loaded changes after a script has been successfully prefetched, the
+  user agent may prefetch the new script but must not change the <a href=#concept-script-state title=concept-script-state>current status</a> or fire any
+  events as a result. If the user agent changes its mind and decides
+  to not bother prefetching the script after all, the user agent must
+  <a href=#queue-a-task>queue a task</a> that, if the <a href=#prepare-a-script>prepare a
+  script</a> algorithm has still not started, sets the <a href=#concept-script-state title=concept-script-state>current status</a> to "<code title="">loaded</code>" and <a href=#fire-a-simple-event title="fire a simple event">fires
+  a simple event</a> named <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> at the
+  element.</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
@@ -15436,10 +15470,31 @@
     user agent must act as if it had received an empty HTTP 400
     response.</p>
 
-    <p>For performance reasons, user agents may start fetching the
-    script as soon as the attribute is set, instead, in the hope that
-    the element will be inserted into the document. Either way, once
-    the element is <a href=#insert-an-element-into-a-document title="insert an element into a
+    <p>If the <a href=#concept-script-state title=concept-script-state>current status</a>
+    of the element at this stage is still "<code title="">uninitialized</code>" (meaning that the user agent
+    intended to prefetch the script as described in the next
+    paragraph, but the <a href=#prepare-a-script>prepare a script</a> algorithm was
+    started before it had a chance to do so), then, if a
+    <a href=#fetch>fetch</a> attempt was started in this step, the user
+    agent must set the <a href=#concept-script-state title=concept-script-state>current
+    status</a> to "<code title="">loading</code>" <!--and
+    <span>queue a task</span> to <span>fire a simple event</span>
+    named <code title="event-readystatechange">readystatechange</code>
+    at the element-->. <!--(If the fetching is started as part of a
+    prefetch, then no <code
+    title="event-readystatechange">readystatechange</code> is fired
+    when <span title="concept-script-state">current status</span> is
+    set to "<code title="">loading</code>".)--></p> <!-- commented out
+    text is what IE does, but IE actually does stuff even more
+    complicated than that which I haven't tried to match exactly here
+    since it's just arcane -->
+
+    <p id=scriptPrefetch>For performance reasons, user agents may
+    start fetching the script as soon as the attribute is set,
+    instead, in the hope that the element will be inserted into the
+    document (user agents that do this have <a href=#concept-script-state title=concept-script-state>requirements</a> relating to what
+    events are to be fired during the process). Either way, once the
+    element is <a href=#insert-an-element-into-a-document title="insert an element into a
     document">inserted into the document</a>, the load must have
     started. If the UA performs such prefetching, but the element is
     never inserted in the document, or the <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute is dynamically
@@ -15623,6 +15678,18 @@
 
   <ol><li>
 
+    <p>If the <a href=#concept-script-state title=concept-script-state>current status</a>
+    of the element at this stage is "<code title="">loading</code>"
+    (meaning that the user agent intended to <a href=#scriptPrefetch>prefetch the script</a> as allowed by the
+    <a href=#prepare-a-script>prepare a script</a> algorithm, but the fetch was not
+    completed before that algorithm was started), then the user agent
+    must set the <a href=#concept-script-state title=concept-script-state>current
+    status</a> to "<code title="">loaded</code>".</p>
+
+   </li>
+
+   <li>
+
     <p>If the element is flagged as <a href=#parser-inserted>"parser-inserted"</a>,
     but the element's <code><a href=#document>Document</a></code> is not the
     <code><a href=#document>Document</a></code> of the parser that created the element, then
@@ -15637,9 +15704,21 @@
     <dl class=switch><dt>If the load resulted in an error (for example a DNS error, or
      an HTTP 404 error)</dt>
 
-     <dd><p>Executing the script block must just consist of <a href=#fire-a-simple-event title="fire a simple event">firing a simple event</a> named
-     <code title=event-error>error</code> at the element.</dd>
+     <dd>
 
+      <p>Executing the script block must consist of running the following steps:</p>
+
+      <ol><li><p>Set the <a href=#concept-script-state title=concept-script-state>current
+       status</a> to "<code title="">complete</code>".</li>
+
+       <li><p><a href=#fire-a-simple-event>Fire a simple event</a> named <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> at the
+       element.</li>
+
+       <li><p><a href=#fire-a-simple-event>Fire a simple event</a> named <code title=event-error>error</code> at the element.</li>
+
+      </ol></dd>
+
+
      <dt>If the load was successful</dt>
 
      <!-- SCRIPT EXEC -->
@@ -15769,6 +15848,9 @@
 
        </li>
 
+       <li><p>Set the <a href=#concept-script-state title=concept-script-state>current
+       status</a> to "<code title="">interactive</code>".</li>
+
        <li>
 
         <p><a href=#create-a-script-from-a-node title="create a script from a node">Create a
@@ -15789,6 +15871,12 @@
 
        </li>
 
+       <li><p>Set the <a href=#concept-script-state title=concept-script-state>current
+       status</a> to "<code title="">complete</code>".</li>
+
+       <li><p><a href=#fire-a-simple-event>Fire a simple event</a> named <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> at the
+       element.</li>
+
        <li>
 
         <p>If the script is from an external file, <a href=#fire-a-simple-event>fire a simple
@@ -15835,6 +15923,51 @@
 
    </dd>
 
+
+   <dt><var title="">script</var> . <code title=dom-script-readyState><a href=#dom-script-readystate>readyState</a></code></dt>
+
+   <dd>
+
+    <p>Returns the current state of the element. The value is one of
+    the following:</p>
+
+    <dl><dt>"<code title="">uninitialized</code>"</dt>
+
+     <dd><p>The script file, if any, has not yet been loaded, but the
+     user agent will try to prefetch it as soon as possible (e.g. as
+     soon as the <code title=attr-script-src><a href=#attr-script-src>src</a></code> attribute is
+     set).</dd>
+
+
+     <dt>"<code title="">loading</code>"</dt>
+
+     <dd><p>A script file is being downloaded in a user agent that
+     supports prefetching scripts.</dd>
+
+
+     <dt>"<code title="">loaded</code>"</dt>
+
+     <dd><p>Either a script file is loaded and ready to be executed,
+     or the script file is not loaded but the user agent does not
+     intend to prefetch the script file anyway, and will merely fetch
+     it when it is to be executed. If the element started in the <code title="">uninitialized</code>" state and the script has not yet
+     begun to be executed, then a <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> event is
+     fired when the state changes to this value.</dd>
+
+
+     <dt>"<code title="">interactive</code>"</dt>
+
+     <dd><p>The script is running.</dd>
+
+
+     <dt>"<code title="">complete</code>"</dt>
+
+     <dd><p>The script has been executed (or it failed). A <code title=event-readystatechange><a href=#event-readystatechange>readystatechange</a></code> event is
+     fired when the state changes to this value, just before the
+     corresponding <code title=event-load>load</code> or <code title=event-error>error</code> event.</dd>
+
+    </dl></dd>
+
   </dl><div class=impl>
 
   <p>The IDL attribute <dfn id=dom-script-text title=dom-script-text><code>text</code></dfn> must return a
@@ -15844,6 +15977,10 @@
   tree order. On setting, it must act the same way as the
   <code><a href=#textcontent>textContent</a></code> IDL attribute.</p>
 
+  <p>The IDL attribute <dfn id=dom-script-readystate title=dom-script-readyState><code>readyState</code></dfn> must
+  return the element's <a href=#concept-script-state title=concept-script-state>current
+  status</a>.</p>
+
   </div>
 
   <p class=note>When inserted using the <code title=dom-document-write><a href=#dom-document-write>document.write()</a></code> method,

Modified: source
===================================================================
--- source	2011-09-06 07:21:39 UTC (rev 6542)
+++ source	2011-09-07 21:54:53 UTC (rev 6543)
@@ -16114,6 +16114,8 @@
            attribute DOMString <span title="dom-script-type">type</span>;
            attribute DOMString <span title="dom-script-charset">charset</span>;
            attribute DOMString <span title="dom-script-text">text</span>;
+
+  readonly attribute DOMString <span title="dom-script-readyState">readyState</span>;
 };</pre>
    </dd>
   </dl>
@@ -16257,6 +16259,52 @@
   <span>"parser-inserted"</span>, to let the parser know when to
   execute the script.</p>
 
+  <p>The fifth is the <dfn title="concept-script-state">current
+  status</dfn> of the script. This is a string. When the element is
+  created, if the user agent does not intend to prefetch the script
+  (i.e. the script, if any, will only be obtained once the
+  <span>prepare a script</span> algorithm requires it to be fetched),
+  then the <span title="concept-script-state">current status</span>
+  must be set to "<code title="">loaded</code>". If the user agent
+  <em>does</em> intend to prefetch the script (if any), <a
+  href="#scriptPrefetch">as allowed</a> in the <span>prepare a
+  script</span> algorithm below, the <span
+  title="concept-script-state">current status</span> must be set to
+  "<code title="">uninitialized</code>" when the element is created.
+  When the user agent begins to prefetch the script, it must set the
+  <span title="concept-script-state">current status</span> to "<code
+  title="">loading</code>". Once the script is fetched, the user agent
+  must <span>queue a task</span> that, if the <span>prepare a
+  script</span> algorithm has still not started and the fetched script
+  is still the appropriate script, sets the <span
+  title="concept-script-state">current status</span> to "<code
+  title="">loaded</code>" and <span title="fire a simple event">fires
+  a simple event</span> named <code
+  title="event-readystatechange">readystatechange</code> at the
+  element. If the script to be loaded changes while the script is
+  being prefetched, then the user agent must prefetch the new script
+  (if any), without changing the <span
+  title="concept-script-state">current status</span>. If no script is
+  ever successfully fetched (e.g. because the element is an inline
+  script) then the transition to "<code title="">loaded</code>" is
+  skipped, and so the <code
+  title="event-readystatechange">readystatechange</code> event does
+  not fire for this transition (it still fires when the <span
+  title="concept-script-state">current status</span> is set to "<code
+  title="">complete</code>" later, however). If the script to be
+  loaded changes after a script has been successfully prefetched, the
+  user agent may prefetch the new script but must not change the <span
+  title="concept-script-state">current status</span> or fire any
+  events as a result. If the user agent changes its mind and decides
+  to not bother prefetching the script after all, the user agent must
+  <span>queue a task</span> that, if the <span>prepare a
+  script</span> algorithm has still not started, sets the <span
+  title="concept-script-state">current status</span> to "<code
+  title="">loaded</code>" and <span title="fire a simple event">fires
+  a simple event</span> named <code
+  title="event-readystatechange">readystatechange</code> at the
+  element.</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
@@ -16536,10 +16584,33 @@
     user agent must act as if it had received an empty HTTP 400
     response.</p>
 
-    <p>For performance reasons, user agents may start fetching the
-    script as soon as the attribute is set, instead, in the hope that
-    the element will be inserted into the document. Either way, once
-    the element is <span title="insert an element into a
+    <p>If the <span title="concept-script-state">current status</span>
+    of the element at this stage is still "<code
+    title="">uninitialized</code>" (meaning that the user agent
+    intended to prefetch the script as described in the next
+    paragraph, but the <span>prepare a script</span> algorithm was
+    started before it had a chance to do so), then, if a
+    <span>fetch</span> attempt was started in this step, the user
+    agent must set the <span title="concept-script-state">current
+    status</span> to "<code title="">loading</code>" <!--and
+    <span>queue a task</span> to <span>fire a simple event</span>
+    named <code title="event-readystatechange">readystatechange</code>
+    at the element-->. <!--(If the fetching is started as part of a
+    prefetch, then no <code
+    title="event-readystatechange">readystatechange</code> is fired
+    when <span title="concept-script-state">current status</span> is
+    set to "<code title="">loading</code>".)--></p> <!-- commented out
+    text is what IE does, but IE actually does stuff even more
+    complicated than that which I haven't tried to match exactly here
+    since it's just arcane -->
+
+    <p id="scriptPrefetch">For performance reasons, user agents may
+    start fetching the script as soon as the attribute is set,
+    instead, in the hope that the element will be inserted into the
+    document (user agents that do this have <span
+    title="concept-script-state">requirements</span> relating to what
+    events are to be fired during the process). Either way, once the
+    element is <span title="insert an element into a
     document">inserted into the document</span>, the load must have
     started. If the UA performs such prefetching, but the element is
     never inserted in the document, or the <code
@@ -16743,6 +16814,19 @@
 
    <li>
 
+    <p>If the <span title="concept-script-state">current status</span>
+    of the element at this stage is "<code title="">loading</code>"
+    (meaning that the user agent intended to <a
+    href="#scriptPrefetch">prefetch the script</a> as allowed by the
+    <span>prepare a script</span> algorithm, but the fetch was not
+    completed before that algorithm was started), then the user agent
+    must set the <span title="concept-script-state">current
+    status</span> to "<code title="">loaded</code>".</p>
+
+   </li>
+
+   <li>
+
     <p>If the element is flagged as <span>"parser-inserted"</span>,
     but the element's <code>Document</code> is not the
     <code>Document</code> of the parser that created the element, then
@@ -16759,10 +16843,27 @@
      <dt>If the load resulted in an error (for example a DNS error, or
      an HTTP 404 error)</dt>
 
-     <dd><p>Executing the script block must just consist of <span
-     title="fire a simple event">firing a simple event</span> named
-     <code title="event-error">error</code> at the element.</p></dd>
+     <dd>
 
+      <p>Executing the script block must consist of running the following steps:</p>
+
+      <ol>
+
+       <li><p>Set the <span title="concept-script-state">current
+       status</span> to "<code title="">complete</code>".</p></li>
+
+       <li><p><span>Fire a simple event</span> named <code
+       title="event-readystatechange">readystatechange</code> at the
+       element.</p></li>
+
+       <li><p><span>Fire a simple event</span> named <code
+       title="event-error">error</code> at the element.</p></li>
+
+      </ol>
+
+     </dd>
+
+
      <dt>If the load was successful</dt>
 
      <!-- SCRIPT EXEC -->
@@ -16916,6 +17017,9 @@
 
        </li>
 
+       <li><p>Set the <span title="concept-script-state">current
+       status</span> to "<code title="">interactive</code>".</p></li>
+
        <li>
 
         <p><span title="create a script from a node">Create a
@@ -16936,6 +17040,13 @@
 
        </li>
 
+       <li><p>Set the <span title="concept-script-state">current
+       status</span> to "<code title="">complete</code>".</p></li>
+
+       <li><p><span>Fire a simple event</span> named <code
+       title="event-readystatechange">readystatechange</code> at the
+       element.</p></li>
+
        <li>
 
         <p>If the script is from an external file, <span>fire a simple
@@ -16995,6 +17106,59 @@
 
    </dd>
 
+
+   <dt><var title="">script</var> . <code title="dom-script-readyState">readyState</code></dt>
+
+   <dd>
+
+    <p>Returns the current state of the element. The value is one of
+    the following:</p>
+
+    <dl>
+
+     <dt>"<code title="">uninitialized</code>"</dt>
+
+     <dd><p>The script file, if any, has not yet been loaded, but the
+     user agent will try to prefetch it as soon as possible (e.g. as
+     soon as the <code title="attr-script-src">src</code> attribute is
+     set).</dd>
+
+
+     <dt>"<code title="">loading</code>"</dt>
+
+     <dd><p>A script file is being downloaded in a user agent that
+     supports prefetching scripts.</dd>
+
+
+     <dt>"<code title="">loaded</code>"</dt>
+
+     <dd><p>Either a script file is loaded and ready to be executed,
+     or the script file is not loaded but the user agent does not
+     intend to prefetch the script file anyway, and will merely fetch
+     it when it is to be executed. If the element started in the <code
+     title="">uninitialized</code>" state and the script has not yet
+     begun to be executed, then a <code
+     title="event-readystatechange">readystatechange</code> event is
+     fired when the state changes to this value.</dd>
+
+
+     <dt>"<code title="">interactive</code>"</dt>
+
+     <dd><p>The script is running.</dd>
+
+
+     <dt>"<code title="">complete</code>"</dt>
+
+     <dd><p>The script has been executed (or it failed). A <code
+     title="event-readystatechange">readystatechange</code> event is
+     fired when the state changes to this value, just before the
+     corresponding <code title="event-load">load</code> or <code
+     title="event-error">error</code> event.</dd>
+
+    </dl>
+
+   </dd>
+
   </dl>
 
   <div class="impl">
@@ -17007,6 +17171,11 @@
   tree order. On setting, it must act the same way as the
   <code>textContent</code> IDL attribute.</p>
 
+  <p>The IDL attribute <dfn
+  title="dom-script-readyState"><code>readyState</code></dfn> must
+  return the element's <span title="concept-script-state">current
+  status</span>.</p>
+
   </div>
 
   <p class="note">When inserted using the <code




More information about the Commit-Watchers mailing list