Permalink
Browse files

[e] (0) Clean up the event loop algorithm

Fixing https://www.w3.org/Bugs/Public/show_bug.cgi?id=24390
Affected topics: DOM APIs, Workers

git-svn-id: http://svn.whatwg.org/webapps@8424 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information...
1 parent c6cbc53 commit 0bd41c9d45e0e0fc63549778163cb85903a10f87 @Hixie Hixie committed Jan 27, 2014
Showing with 79 additions and 46 deletions.
  1. +26 −16 complete.html
  2. +26 −16 index
  3. +27 −14 source
View
@@ -1174,7 +1174,7 @@ <h2 class="no-num no-toc">Living Standard &mdash; Last Updated 27 January 2014</
<li><a href=#the-workerglobalscope-common-interface><span class=secno>10.2.1.1 </span>The <code>WorkerGlobalScope</code> common interface</a></li>
<li><a href=#dedicated-workers-and-the-dedicatedworkerglobalscope-interface><span class=secno>10.2.1.2 </span>Dedicated workers and the <code>DedicatedWorkerGlobalScope</code> interface</a></li>
<li><a href=#shared-workers-and-the-sharedworkerglobalscope-interface><span class=secno>10.2.1.3 </span>Shared workers and the <code>SharedWorkerGlobalScope</code> interface</a></ol></li>
- <li><a href=#the-event-loop><span class=secno>10.2.2 </span>The event loop</a></li>
+ <li><a href=#worker-event-loop><span class=secno>10.2.2 </span>The event loop</a></li>
<li><a href="#the-worker's-lifetime"><span class=secno>10.2.3 </span>The worker's lifetime</a></li>
<li><a href=#processing-model-7><span class=secno>10.2.4 </span>Processing model</a></li>
<li><a href=#runtime-script-errors-0><span class=secno>10.2.5 </span>Runtime script errors</a></li>
@@ -71351,24 +71351,31 @@ <h4 id=event-loops><span class=secno>7.1.4 </span>Event loops</h4>
<h5 id=definitions-1><span class=secno>7.1.4.1 </span>Definitions</h5>
+<!--CLEANUP-->
<p>To coordinate events, user interaction, scripts, rendering, networking, and so forth, user
- agents must use <dfn id=event-loop title="event loop">event loops</dfn> as described in this section.</p>
+ agents must use <dfn id=event-loop title="event loop">event loops</dfn> as described in this section. There are
+ two kinds of event loops: those for <a href=#browsing-context title="browsing context">browsing contexts</a>, and those for <a href=#workers>workers</a>.</p>
- <p>There must be at least one <a href=#event-loop>event loop</a> per user agent, and at most one <a href=#event-loop>event
- loop</a> per <a href=#unit-of-related-similar-origin-browsing-contexts>unit of related similar-origin browsing contexts</a>.</p>
+ <p>There must be at least one <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a> per user
+ agent, and at most one per <a href=#unit-of-related-similar-origin-browsing-contexts>unit of related similar-origin browsing contexts</a>.</p>
<p class=note>When there is more than one <a href=#event-loop>event loop</a> for a <a href=#unit-of-related-browsing-contexts>unit of related
browsing contexts</a>, complications arise when a <a href=#browsing-context>browsing context</a> in that group
is <a href=#navigate title=navigate>navigated</a> such that it switches from one <a href=#unit-of-related-similar-origin-browsing-contexts>unit of related
similar-origin browsing contexts</a> to another. This specification does not currently describe
how to handle these complications.</p>
- <p>An <a href=#event-loop>event loop</a> always has at least one <a href=#browsing-context>browsing context</a>. If an
+<!--CLEANUP-->
+ <p>A <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a> always has at least one <a href=#browsing-context>browsing context</a>. If such an
<a href=#event-loop>event loop</a>'s <a href=#browsing-context title="browsing context">browsing contexts</a> all go away,
then the <a href=#event-loop>event loop</a> goes away as well. A <a href=#browsing-context>browsing context</a> always has an
<a href=#event-loop>event loop</a> coordinating its activities.</p>
- <p>An <a href=#event-loop>event loop</a> has one or more <dfn id=task-queue title="task queue">task queues</dfn>. A
+ <p><a href=#worker-event-loop>Worker event loops</a> are simpler: each worker has one
+ <a href=#event-loop>event loop</a>, and the <a href=#run-a-worker title="run a worker">worker processing model</a>
+ manages the <a href=#event-loop>event loop</a>'s lifetime.</p>
+
+ <hr><p>An <a href=#event-loop>event loop</a> has one or more <dfn id=task-queue title="task queue">task queues</dfn>. A
<a href=#task-queue>task queue</a> is an ordered list of <dfn id=concept-task title=concept-task>tasks</dfn>, which are
algorithms that are responsible for such work as:</p>
@@ -71408,15 +71415,17 @@ <h5 id=definitions-1><span class=secno>7.1.4.1 </span>Definitions</h5>
<dd><p>Some elements have tasks that trigger in response to DOM manipulation, e.g. when that
element is <a href=#insert-an-element-into-a-document title="insert an element into a document">inserted into the document</a>.</p>
- </dl><p>Each <a href=#concept-task title=concept-task>task</a> is associated with a <code><a href=#document>Document</a></code>; if the
+ </dl><!--CLEANUP--><p>Each <a href=#concept-task title=concept-task>task</a> in a <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a> is associated with a <code><a href=#document>Document</a></code>; if the
task was queued in the context of an element, then it is the element's <code><a href=#document>Document</a></code>; if
the task was queued in the context of a <a href=#browsing-context>browsing context</a>, then it is the
<a href=#browsing-context>browsing context</a>'s <a href=#active-document>active document</a> at the time the task was queued; if
the task was queued by or for a <a href=#concept-script title=concept-script>script</a> then the document is
the <a href=#responsible-document>responsible document</a> specified by the script's <a href=#settings-object>settings object</a>.</p>
+<!--CLEANUP-->
<p>A <a href=#concept-task title=concept-task>task</a> is intended for a specific <a href=#event-loop>event loop</a>:
- the <a href=#event-loop>event loop</a> that is handling <a href=#concept-task title=concept-task>tasks</a> for the <a href=#concept-task title=concept-task>task</a>'s associated <code><a href=#document>Document</a></code>.</p>
+ the <a href=#event-loop>event loop</a> that is handling <a href=#concept-task title=concept-task>tasks</a> for the
+ <a href=#concept-task title=concept-task>task</a>'s associated <code><a href=#document>Document</a></code> or <a href=#workers>worker</a>.</p>
<p>When a user agent is to <dfn id=queue-a-task>queue a task</dfn>, it must add the given task to one of the <a href=#task-queue title="task queue">task queues</a> of the relevant <a href=#event-loop>event loop</a>.</p>
@@ -71462,8 +71471,8 @@ <h5 id=processing-model-4><span class=secno>7.1.4.2 </span>Processing model</h5>
exists:</p>
<ol><!-- if you add a step here, make sure to go through the spec updating references to the "first
- step" or "step 1" of the event loop --><li><p>Run the oldest <a href=#concept-task title=concept-task>task</a> on one of the <a href=#event-loop>event
- loop</a>'s <a href=#task-queue title="task queue">task queues</a>, if any, ignoring tasks whose
+ step" or "step 1" of the event loop --><!--CLEANUP--><li><p>Run the oldest <a href=#concept-task title=concept-task>task</a> on one of the <a href=#event-loop>event
+ loop</a>'s <a href=#task-queue title="task queue">task queues</a>, if any, ignoring, in the case of a <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a>, tasks whose
associated <code><a href=#document>Document</a></code>s are not <a href=#fully-active>fully active</a>. The user agent may pick any
<a href=#task-queue>task queue</a>.</li>
@@ -71478,8 +71487,8 @@ <h5 id=processing-model-4><span class=secno>7.1.4.2 </span>Processing model</h5>
<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>
+ <p>If this <a href=#event-loop>event loop</a> is a <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a>
+ (as opposed to a <a href=#workers>worker</a> <a href=#event-loop>event loop</a>), run these substeps:</p>
<ol><li><p><a href=#perform-a-microtask-checkpoint>Perform a microtask checkpoint</a>.</li>
@@ -71490,9 +71499,10 @@ <h5 id=processing-model-4><span class=secno>7.1.4.2 </span>Processing model</h5>
</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>
+<!--CLEANUP-->
+ <li><p>Otherwise, if this is a <a href=#workers>worker</a> <a href=#event-loop>event loop</a> (i.e. one running for a
+ <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>), but there are no <a href=#concept-task title=concept-task>tasks</a> 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, resuming the <a href=#run-a-worker>run a worker</a> steps described in the Web Workers section below.</li>
<li><p>Return to the first step of the <a href=#event-loop>event loop</a>.</li>
@@ -82699,7 +82709,7 @@ <h5 id=shared-workers-and-the-sharedworkerglobalscope-interface><span class=secn
- <h4 id=the-event-loop><span class=secno>10.2.2 </span>The event loop</h4>
+ <h4 id=worker-event-loop><span class=secno>10.2.2 </span>The event loop</h4>
<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
View
42 index
@@ -1174,7 +1174,7 @@
<li><a href=#the-workerglobalscope-common-interface><span class=secno>10.2.1.1 </span>The <code>WorkerGlobalScope</code> common interface</a></li>
<li><a href=#dedicated-workers-and-the-dedicatedworkerglobalscope-interface><span class=secno>10.2.1.2 </span>Dedicated workers and the <code>DedicatedWorkerGlobalScope</code> interface</a></li>
<li><a href=#shared-workers-and-the-sharedworkerglobalscope-interface><span class=secno>10.2.1.3 </span>Shared workers and the <code>SharedWorkerGlobalScope</code> interface</a></ol></li>
- <li><a href=#the-event-loop><span class=secno>10.2.2 </span>The event loop</a></li>
+ <li><a href=#worker-event-loop><span class=secno>10.2.2 </span>The event loop</a></li>
<li><a href="#the-worker's-lifetime"><span class=secno>10.2.3 </span>The worker's lifetime</a></li>
<li><a href=#processing-model-7><span class=secno>10.2.4 </span>Processing model</a></li>
<li><a href=#runtime-script-errors-0><span class=secno>10.2.5 </span>Runtime script errors</a></li>
@@ -71351,24 +71351,31 @@ dictionary <dfn id=erroreventinit>ErrorEventInit</dfn> : <a href=#eventinit>Even
<h5 id=definitions-1><span class=secno>7.1.4.1 </span>Definitions</h5>
+<!--CLEANUP-->
<p>To coordinate events, user interaction, scripts, rendering, networking, and so forth, user
- agents must use <dfn id=event-loop title="event loop">event loops</dfn> as described in this section.</p>
+ agents must use <dfn id=event-loop title="event loop">event loops</dfn> as described in this section. There are
+ two kinds of event loops: those for <a href=#browsing-context title="browsing context">browsing contexts</a>, and those for <a href=#workers>workers</a>.</p>
- <p>There must be at least one <a href=#event-loop>event loop</a> per user agent, and at most one <a href=#event-loop>event
- loop</a> per <a href=#unit-of-related-similar-origin-browsing-contexts>unit of related similar-origin browsing contexts</a>.</p>
+ <p>There must be at least one <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a> per user
+ agent, and at most one per <a href=#unit-of-related-similar-origin-browsing-contexts>unit of related similar-origin browsing contexts</a>.</p>
<p class=note>When there is more than one <a href=#event-loop>event loop</a> for a <a href=#unit-of-related-browsing-contexts>unit of related
browsing contexts</a>, complications arise when a <a href=#browsing-context>browsing context</a> in that group
is <a href=#navigate title=navigate>navigated</a> such that it switches from one <a href=#unit-of-related-similar-origin-browsing-contexts>unit of related
similar-origin browsing contexts</a> to another. This specification does not currently describe
how to handle these complications.</p>
- <p>An <a href=#event-loop>event loop</a> always has at least one <a href=#browsing-context>browsing context</a>. If an
+<!--CLEANUP-->
+ <p>A <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a> always has at least one <a href=#browsing-context>browsing context</a>. If such an
<a href=#event-loop>event loop</a>'s <a href=#browsing-context title="browsing context">browsing contexts</a> all go away,
then the <a href=#event-loop>event loop</a> goes away as well. A <a href=#browsing-context>browsing context</a> always has an
<a href=#event-loop>event loop</a> coordinating its activities.</p>
- <p>An <a href=#event-loop>event loop</a> has one or more <dfn id=task-queue title="task queue">task queues</dfn>. A
+ <p><a href=#worker-event-loop>Worker event loops</a> are simpler: each worker has one
+ <a href=#event-loop>event loop</a>, and the <a href=#run-a-worker title="run a worker">worker processing model</a>
+ manages the <a href=#event-loop>event loop</a>'s lifetime.</p>
+
+ <hr><p>An <a href=#event-loop>event loop</a> has one or more <dfn id=task-queue title="task queue">task queues</dfn>. A
<a href=#task-queue>task queue</a> is an ordered list of <dfn id=concept-task title=concept-task>tasks</dfn>, which are
algorithms that are responsible for such work as:</p>
@@ -71408,15 +71415,17 @@ dictionary <dfn id=erroreventinit>ErrorEventInit</dfn> : <a href=#eventinit>Even
<dd><p>Some elements have tasks that trigger in response to DOM manipulation, e.g. when that
element is <a href=#insert-an-element-into-a-document title="insert an element into a document">inserted into the document</a>.</p>
- </dl><p>Each <a href=#concept-task title=concept-task>task</a> is associated with a <code><a href=#document>Document</a></code>; if the
+ </dl><!--CLEANUP--><p>Each <a href=#concept-task title=concept-task>task</a> in a <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a> is associated with a <code><a href=#document>Document</a></code>; if the
task was queued in the context of an element, then it is the element's <code><a href=#document>Document</a></code>; if
the task was queued in the context of a <a href=#browsing-context>browsing context</a>, then it is the
<a href=#browsing-context>browsing context</a>'s <a href=#active-document>active document</a> at the time the task was queued; if
the task was queued by or for a <a href=#concept-script title=concept-script>script</a> then the document is
the <a href=#responsible-document>responsible document</a> specified by the script's <a href=#settings-object>settings object</a>.</p>
+<!--CLEANUP-->
<p>A <a href=#concept-task title=concept-task>task</a> is intended for a specific <a href=#event-loop>event loop</a>:
- the <a href=#event-loop>event loop</a> that is handling <a href=#concept-task title=concept-task>tasks</a> for the <a href=#concept-task title=concept-task>task</a>'s associated <code><a href=#document>Document</a></code>.</p>
+ the <a href=#event-loop>event loop</a> that is handling <a href=#concept-task title=concept-task>tasks</a> for the
+ <a href=#concept-task title=concept-task>task</a>'s associated <code><a href=#document>Document</a></code> or <a href=#workers>worker</a>.</p>
<p>When a user agent is to <dfn id=queue-a-task>queue a task</dfn>, it must add the given task to one of the <a href=#task-queue title="task queue">task queues</a> of the relevant <a href=#event-loop>event loop</a>.</p>
@@ -71462,8 +71471,8 @@ dictionary <dfn id=erroreventinit>ErrorEventInit</dfn> : <a href=#eventinit>Even
exists:</p>
<ol><!-- if you add a step here, make sure to go through the spec updating references to the "first
- step" or "step 1" of the event loop --><li><p>Run the oldest <a href=#concept-task title=concept-task>task</a> on one of the <a href=#event-loop>event
- loop</a>'s <a href=#task-queue title="task queue">task queues</a>, if any, ignoring tasks whose
+ step" or "step 1" of the event loop --><!--CLEANUP--><li><p>Run the oldest <a href=#concept-task title=concept-task>task</a> on one of the <a href=#event-loop>event
+ loop</a>'s <a href=#task-queue title="task queue">task queues</a>, if any, ignoring, in the case of a <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a>, tasks whose
associated <code><a href=#document>Document</a></code>s are not <a href=#fully-active>fully active</a>. The user agent may pick any
<a href=#task-queue>task queue</a>.</li>
@@ -71478,8 +71487,8 @@ dictionary <dfn id=erroreventinit>ErrorEventInit</dfn> : <a href=#eventinit>Even
<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>
+ <p>If this <a href=#event-loop>event loop</a> is a <a href=#browsing-context>browsing context</a> <a href=#event-loop>event loop</a>
+ (as opposed to a <a href=#workers>worker</a> <a href=#event-loop>event loop</a>), run these substeps:</p>
<ol><li><p><a href=#perform-a-microtask-checkpoint>Perform a microtask checkpoint</a>.</li>
@@ -71490,9 +71499,10 @@ dictionary <dfn id=erroreventinit>ErrorEventInit</dfn> : <a href=#eventinit>Even
</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>
+<!--CLEANUP-->
+ <li><p>Otherwise, if this is a <a href=#workers>worker</a> <a href=#event-loop>event loop</a> (i.e. one running for a
+ <code><a href=#workerglobalscope>WorkerGlobalScope</a></code>), but there are no <a href=#concept-task title=concept-task>tasks</a> 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, resuming the <a href=#run-a-worker>run a worker</a> steps described in the Web Workers section below.</li>
<li><p>Return to the first step of the <a href=#event-loop>event loop</a>.</li>
@@ -82699,7 +82709,7 @@ worker.port.postMessage({ foo: 'structured', bar: ['data', 'also', 'possible']})
- <h4 id=the-event-loop><span class=secno>10.2.2 </span>The event loop</h4>
+ <h4 id=worker-event-loop><span class=secno>10.2.2 </span>The event loop</h4>
<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
Oops, something went wrong.

0 comments on commit 0bd41c9

Please sign in to comment.