Short URL: http://html5.org/r/6543
Index: source
===================================================================
--- source (revision 6542)
+++ source (revision 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