Skip to content
Permalink
Browse files

[e] (0) Integrate the 'event loop' mechanism of workers and windows t…

…ogether, and try to specify which is meant when it might be ambiguous.

Fixing https://www.w3.org/Bugs/Public/show_bug.cgi?id=20041

git-svn-id: http://svn.whatwg.org/webapps@7696 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information...
Hixie committed Feb 6, 2013
1 parent e942ce1 commit 39db003fdb582aa1de60a1420b782f17849f8f35
Showing with 119 additions and 158 deletions.
  1. +37 −52 complete.html
  2. +37 −52 index
  3. +45 −54 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 class=allcaps>HTML</h1>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 5 February 2013</h2>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 6 February 2013</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>
<li><p>If a task was run in the first step above, remove that task from its <a href=#task-queue>task
queue</a>.</li>

<li><p><a href=#perform-a-microtask-checkpoint>Perform a microtask checkpoint</a>.</li>
<li>

<li><p><a href=#provide-a-stable-state>Provide a stable state</a>.</li>
<p>If this <a href=#event-loop>event loop</a> is not a worker's <a href=#event-loop>event loop</a>, run these
substeps:</p>

<li><p>If necessary, update the rendering or user interface of any <code><a href=#document>Document</a></code> or
<a href=#browsing-context>browsing context</a> to reflect the current state.</li>
<ol><li><p><a href=#perform-a-microtask-checkpoint>Perform a microtask checkpoint</a>.</li>

<li><p><a href=#provide-a-stable-state>Provide a stable state</a>.</li>

<li><p>If necessary, update the rendering or user interface of any <code><a href=#document>Document</a></code> or
<a href=#browsing-context>browsing context</a> to reflect the current state.</li>

</ol></li>

<li><p>Otherwise, if this <a href=#event-loop>event loop</a> is running for a
<code><a href=#workerglobalscope>WorkerGlobalScope</a></code>, but there are no events in the <a href=#event-loop>event loop</a>'s <a href=#task-queue title="task queue">task queues</a> and the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is true, then destroy the <a href=#event-loop>event
loop</a>, aborting these steps.</li>

<li><p>Return to the first step of the <a href=#event-loop>event loop</a>.</li>

(atomically):</p>

<ol><li><p>Discard any <a href=#concept-task title=concept-task>tasks</a> that have been added to the
<a href=#event-loop>event loop</a>'s <a href=#task-queue title="task queue">task queues</a>.</p>
<code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's <a href=#event-loop>event loop</a>'s <a href=#task-queue title="task queue">task
queues</a>.</p>

<!-- v2-onclose
<!-- v2-onclose (remember to specify the task source, too)
<li><p><span>Queue a task</span> to <span>fire a simple event</span> named <code
title="event-worker-close">close</code> at the <code>WorkerGlobalScope</code> object.</p></li>
-->

<h4 id=the-event-loop><span class=secno>9.2.2 </span>The event loop</h4>

<p>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object has an <a href=#event-loop>event loop</a> distinct from those
defined for <a href=#unit-of-related-similar-origin-browsing-contexts title="unit of related similar-origin browsing contexts">units of related
<p>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object has a distinct <a href=#event-loop>event loop</a>, separate
from those used by <a href=#unit-of-related-similar-origin-browsing-contexts title="unit of related similar-origin browsing contexts">units of related
similar-origin browsing contexts</a>. This <a href=#event-loop>event loop</a> has no associated
<a href=#browsing-context>browsing context</a>, and its <a href=#task-queue title="task queue">task queues</a> only have
events, callbacks, and networking activity as <a href=#concept-task title=concept-task>tasks</a>. The
processing model of these <a href=#event-loop title="event loop">event loops</a> is defined below in the
<a href=#run-a-worker>run a worker</a> algorithm.</p>
events, callbacks, and networking activity as <a href=#concept-task title=concept-task>tasks</a>. These <a href=#event-loop title="event loop">event loops</a> are created by the <a href=#run-a-worker>run a worker</a> algorithm.</p>

<p>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object also has a <dfn id=dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</dfn> flag, which must initially be false, but which
can get set to true by the algorithms in the processing model section below.</p>
<dfn id="the-worker's-ports">the worker's ports</dfn>, which consists of all the <code><a href=#messageport>MessagePort</a></code> objects that are
entangled with another port and that have one (but only one) port owned by <var title="">worker
global scope</var>. This list includes <!--all the <code>MessagePort</code> objects that are in
events pending in the <span>event loop</span>, as well as (commented out because in practice it
makes no difference either way as far as I can tell, and it would be hard to strictly implement
since these ports might not yet be across the thread boundary)--> the implicit
<code><a href=#messageport>MessagePort</a></code> in the case of <a href=#dedicatedworkerglobalscope title=DedicatedWorkerGlobalScope>dedicated
workers</a>.</p>
events pending in the <code>WorkerGlobalScope</code> object's <span>event loop</span>, as well as
(commented out because in practice it makes no difference either way as far as I can tell, and it
would be hard to strictly implement since these ports might not yet be across the thread
boundary)--> the implicit <code><a href=#messageport>MessagePort</a></code> in the case of <a href=#dedicatedworkerglobalscope title=DedicatedWorkerGlobalScope>dedicated workers</a>.</p>

<p>Each <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> also has a list of <dfn id="the-worker's-workers">the worker's workers</dfn>.
Initially this list is empty; it is populated when the worker creates or obtains further
<!-- v2-onclose
<p class="note">If the script gets aborted by the "<span>kill a worker</span>" algorithm, then
that same algorithm will cause there to only be a single <span title="concept-task">task</span>
in the <span>event loop</span> at the next step, namely the task for the <code
title="message-close">close</code> event. The "<span>terminate a worker</span>" algorithm
removes all the events.</p>
in the <code>WorkerGlobalScope</code> object's <span>event loop</span> at the next step, namely
the task for the <code title="message-close">close</code> event. The "<span>terminate a
worker</span>" algorithm removes all the events.</p>
-->

</li>

<li>

<p><i title="">Event loop</i>: Wait until either there is a <a href=#concept-task title=concept-task>task</a> in one of the <a href=#event-loop>event loop</a>'s <a href=#task-queue title="task
queue">task queues</a> or <var title="">worker global scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set to true.</p>

</li>

<li>

<p>Run the oldest task on one of the <a href=#event-loop>event loop</a>'s <a href=#task-queue title="task queue">task
queues</a>, if any. The user agent may pick any <a href=#task-queue>task queue</a>.</p>
<p><i title="">Event loop</i>: Create a new <a href=#event-loop>event loop</a>, and run it until it is
destroyed.</p>

<p class=note>The handling of events or the execution of callbacks might get prematurely
<p class=note>The handling of events or the execution of callbacks by <a href=#concept-task title=concept-task>tasks</a> run by the <a href=#event-loop>event loop</a> might get prematurely
aborted by the "<a href=#kill-a-worker>kill a worker</a>" or "<a href=#terminate-a-worker>terminate a worker</a>" algorithms
defined below.</p>

</li>

<li>

<p>If the <a href=#storage-mutex>storage mutex</a> is now owned by the worker's <a href=#event-loop>event loop</a>,
release it so that it is once again free.</p>

</li>

<li>

<p>Remove the task just run in the earlier step, if any, from its <a href=#task-queue>task queue</a>.</p>

</li>

<li>

<p>If there are any more events in the <a href=#event-loop>event loop</a>'s <a href=#task-queue title="task queue">task
queues</a> or if <var title="">worker global scope</var>'s <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag is set to false, then jump back to the
step above labeled <i><a href=#event-loop>event loop</a></i>.</p>
<p class=note>The worker processing model remains on this step until the event loop is
destroyed, which happens after the <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a>
flag is set to true, as described in the <a href=#event-loop>event loop</a> processing model.</p>

</li>

shutting down unexpectedly.</p></li>
-->

<li><p>If there are any <a href=#concept-task title=concept-task>tasks</a> queued in the <a href=#event-loop>event
<li><p>If there are any <a href=#concept-task title=concept-task>tasks</a> queued in the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's <a href=#event-loop>event <!--CLEANUP-->
loop</a>'s <a href=#task-queue title="task queue">task queues</a><!-- v2-onclose other than the <code
title="event-worker-close">close</code> event that this algorithm just added-->, discard them
without processing them.</li>

<ol><li><p>Set the worker's <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's <a href=#dom-workerglobalscope-closing title=dom-WorkerGlobalScope-closing>closing</a> flag to true.</li>

<li><p>If there are any <a href=#concept-task title=concept-task>tasks</a> queued in the <a href=#event-loop>event
<li><p>If there are any <a href=#concept-task title=concept-task>tasks</a> queued in the <code><a href=#workerglobalscope>WorkerGlobalScope</a></code> object's <a href=#event-loop>event <!--CLEANUP-->
loop</a>'s <a href=#task-queue title="task queue">task queues</a>, discard them without processing
them.</li>

0 comments on commit 39db003

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