HTML Standard Tracker

Filter

File a bug

SVNBugCommentTime (UTC)
842424390Clean up the event loop algorithm2014-01-27 20:20
@@ -79681,37 +79681,46 @@ dictionary <dfn>ErrorEventInit</dfn> : <span>EventInit</span> {
   the case of an uncaught DOM exception).</p>
 
 
 
   <div class="impl">
 
   <h4>Event loops</h4>
 
   <h5>Definitions</h5>
 
+<!--CLEANUP-->
   <p>To coordinate events, user interaction, scripts, rendering, networking, and so forth, user
-  agents must use <dfn data-x="event loop">event loops</dfn> as described in this section.</p>
+  agents must use <dfn data-x="event loop">event loops</dfn> as described in this section. There are
+  two kinds of event loops: those for <span data-x="browsing context">browsing contexts</span>, and those for <a href="#workers">workers</a>.</p>
 
-  <p>There must be at least one <span>event loop</span> per user agent, and at most one <span>event
-  loop</span> per <span>unit of related similar-origin browsing contexts</span>.</p>
+  <p>There must be at least one <span>browsing context</span> <span>event loop</span> per user
+  agent, and at most one per <span>unit of related similar-origin browsing contexts</span>.</p>
 
   <p class="note">When there is more than one <span>event loop</span> for a <span>unit of related
   browsing contexts</span>, complications arise when a <span>browsing context</span> in that group
   is <span data-x="navigate">navigated</span> such that it switches from one <span>unit of related
   similar-origin browsing contexts</span> to another. This specification does not currently describe
   how to handle these complications.</p>
 
-  <p>An <span>event loop</span> always has at least one <span>browsing context</span>. If an
+<!--CLEANUP-->
+  <p>A <span>browsing context</span> <span>event loop</span> always has at least one <span>browsing context</span>. If such an
   <span>event loop</span>'s <span data-x="browsing context">browsing contexts</span> all go away,
   then the <span>event loop</span> goes away as well. A <span>browsing context</span> always has an
   <span>event loop</span> coordinating its activities.</p>
 
+  <p><a href="#worker-event-loop">Worker event loops</a> are simpler: each worker has one
+  <span>event loop</span>, and the <span data-x="run a worker">worker processing model</span>
+  manages the <span>event loop</span>'s lifetime.</p>
+
+  <hr>
+
   <p>An <span>event loop</span> has one or more <dfn data-x="task queue">task queues</dfn>. A
   <span>task queue</span> is an ordered list of <dfn data-x="concept-task">tasks</dfn>, which are
   algorithms that are responsible for such work as:</p>
 
   <dl>
 
    <dt>Events</dt>
 
    <dd>
 
@@ -79742,30 +79751,32 @@ dictionary <dfn>ErrorEventInit</dfn> : <span>EventInit</span> {
    is performed by a task.</p></dd>
 
 
    <dt>Reacting to DOM manipulation</dt>
 
    <dd><p>Some elements have tasks that trigger in response to DOM manipulation, e.g. when that
    element is <span data-x="insert an element into a document">inserted into the document</span>.</p>
 
   </dl>
 
-  <p>Each <span data-x="concept-task">task</span> is associated with a <code>Document</code>; if the
+<!--CLEANUP-->
+  <p>Each <span data-x="concept-task">task</span> in a <span>browsing context</span> <span>event loop</span> is associated with a <code>Document</code>; if the
   task was queued in the context of an element, then it is the element's <code>Document</code>; if
   the task was queued in the context of a <span>browsing context</span>, then it is the
   <span>browsing context</span>'s <span>active document</span> at the time the task was queued; if
   the task was queued by or for a <span data-x="concept-script">script</span> then the document is
   the <span>responsible document</span> specified by the script's <span>settings object</span>.</p>
 
+<!--CLEANUP-->
   <p>A <span data-x="concept-task">task</span> is intended for a specific <span>event loop</span>:
-  the <span>event loop</span> that is handling <span data-x="concept-task">tasks</span> for the <span
-  data-x="concept-task">task</span>'s associated <code>Document</code>.</p>
+  the <span>event loop</span> that is handling <span data-x="concept-task">tasks</span> for the
+  <span data-x="concept-task">task</span>'s associated <code>Document</code> or <a href="#workers">worker</a>.</p>
 
   <p>When a user agent is to <dfn>queue a task</dfn>, it must add the given task to one of the <span
   data-x="task queue">task queues</span> of the relevant <span>event loop</span>.</p>
 
   <p>Each <span data-x="concept-task">task</span> is defined as coming from a specific <dfn>task
   source</dfn>. All the tasks from one particular <span>task source</span> and destined to a
   particular <span>event loop</span> (e.g. the callbacks generated by timers of a
   <code>Document</code>, the events fired for mouse movements over that <code>Document</code>, the
   tasks queued for the parser of that <code>Document</code>) must always be added to the same
   <span>task queue</span>, but <span data-x="concept-task">tasks</span> from different <span
@@ -79806,57 +79817,59 @@ dictionary <dfn>ErrorEventInit</dfn> : <span>EventInit</span> {
   <h5>Processing model</h5>
 
   <p>An <span>event loop</span> must continually run through the following steps for as long as it
   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 -->
 
+<!--CLEANUP-->
    <li><p>Run the oldest <span data-x="concept-task">task</span> on one of the <span>event
-   loop</span>'s <span data-x="task queue">task queues</span>, if any, ignoring tasks whose
+   loop</span>'s <span data-x="task queue">task queues</span>, if any, ignoring, in the case of a <span>browsing context</span> <span>event loop</span>, tasks whose
    associated <code>Document</code>s are not <span>fully active</span>. The user agent may pick any
    <span>task queue</span>.</p></li>
 
    <!-- warning! if you renumber these steps, make sure to update the "spin the event loop"
    algorithm below! -->
 
    <li><p>If the <span>storage mutex</span> is now owned by the <span>event loop</span>, release it
    so that it is once again free.</p></li>
 
    <li><p>If a task was run in the first step above, remove that task from its <span>task
    queue</span>.</p></li>
 
    <li>
 
-    <p>If this <span>event loop</span> is not a worker's <span>event loop</span>, run these
-    substeps:</p>
+    <p>If this <span>event loop</span> is a <span>browsing context</span> <span>event loop</span>
+    (as opposed to a <a href="#workers">worker</a> <span>event loop</span>), run these substeps:</p>
 
     <ol>
 
      <li><p><span>Perform a microtask checkpoint</span>.</p></li>
 
      <li><p><span>Provide a stable state</span>.</p></li>
 
      <li><p>If necessary, update the rendering or user interface of any <code>Document</code> or
      <span>browsing context</span> to reflect the current state.</p></li>
 
     </ol>
 
    </li>
 
-   <li><p>Otherwise, if this <span>event loop</span> is running for a
-   <code>WorkerGlobalScope</code>, but there are no events in the <span>event loop</span>'s <span
+<!--CLEANUP-->
+   <li><p>Otherwise, if this is a <a href="#workers">worker</a> <span>event loop</span> (i.e. one running for a
+   <code>WorkerGlobalScope</code>), but there are no <span data-x="concept-task">tasks</span> in the <span>event loop</span>'s <span
    data-x="task queue">task queues</span> and the <code>WorkerGlobalScope</code> object's <span
    data-x="dom-WorkerGlobalScope-closing">closing</span> flag is true, then destroy the <span>event
-   loop</span>, aborting these steps.</p></li>
+   loop</span>, aborting these steps, resuming the <span>run a worker</span> steps described in the Web Workers section below.</p></li>
 
    <li><p>Return to the first step of the <span>event loop</span>.</p></li>
 
   </ol>
 
   <hr>
 
   <p>When a user agent is to <dfn>perform a microtask checkpoint</dfn>, if the <span>performing a
   microtask checkpoint</span> flag is false, then the user agent must run the following steps:</p>
 
@@ -92050,21 +92063,21 @@ worker.port.postMessage({ foo: 'structured', bar: ['data', 'also', 'possible']})
   own <span>cache host</span>. The <span>run a worker</span> algorithm takes care of associating the
   worker with an <span>application cache</span>.</p>
 
   <p class="note">The <code
   data-x="dom-SharedWorkerGlobalScope-applicationCache">applicationCache</code> attribute returns the
   <code>ApplicationCache</code> object for the worker.</p><!-- normative conf criteria is in the
   appcache section -->
 
 
 
-  <h4>The event loop</h4>
+  <h4 id="worker-event-loop">The event loop</h4>
 
   <p>Each <code>WorkerGlobalScope</code> object has a distinct <span>event loop</span>, separate
   from those used by <span data-x="unit of related similar-origin browsing contexts">units of related
   similar-origin browsing contexts</span>. This <span>event loop</span> has no associated
   <span>browsing context</span>, and its <span data-x="task queue">task queues</span> only have
   events, callbacks, and networking activity as <span data-x="concept-task">tasks</span>. These <span
   data-x="event loop">event loops</span> are created by the <span>run a worker</span> algorithm.</p>
 
   <p>Each <code>WorkerGlobalScope</code> object also has a <dfn
   data-x="dom-WorkerGlobalScope-closing">closing</dfn> flag, which must initially be false, but which

|