Skip to content
Permalink
Browse files

[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

git-svn-id: http://svn.whatwg.org/webapps@6543 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Sep 7, 2011
1 parent e7859b7 commit 444fc2b4c0ba3fdf4603f7a5303867207dd98444
Showing with 464 additions and 21 deletions.
  1. +144 −7 complete.html
  2. +144 −7 index
  3. +176 −7 source

<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 &mdash; Last Updated 6 September 2011</h2>
<h2 class="no-num no-toc">Living Standard &mdash; 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>
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
<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
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

<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
<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>


</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

</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

</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
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,

0 comments on commit 444fc2b

Please sign in to comment.
You can’t perform that action at this time.