Skip to content

Commit

Permalink
[giow] (0) First attempt at speccing the generic microtask queue idea.
Browse files Browse the repository at this point in the history
Fixing https://www.w3.org/Bugs/Public/show_bug.cgi?id=22296
Affected topics: DOM APIs

git-svn-id: http://svn.whatwg.org/webapps@8463 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Feb 5, 2014
1 parent e5e0c93 commit 9e4e534
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 56 deletions.
74 changes: 57 additions & 17 deletions complete.html
Expand Up @@ -298,7 +298,7 @@

<header class=head id=head><p><a href=http://www.whatwg.org/ class=logo><img width=101 src=/images/logo alt=WHATWG height=101></a></p>
<hgroup><h1 class=allcaps>HTML</h1>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 4 February 2014</h2>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 5 February 2014</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>
Expand Down Expand Up @@ -71921,21 +71921,60 @@ <h5 id=processing-model-4><span class=secno>7.1.4.2 </span>Processing model</h5>

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

</ol><hr><p>When a user agent is to <dfn id=perform-a-microtask-checkpoint>perform a microtask checkpoint</dfn>, if the <a href=#performing-a-microtask-checkpoint>performing a
</ol><hr><p>Each <a href=#event-loop>event loop</a> has a <dfn id=microtask-queue>microtask queue</dfn>. A <dfn id=microtask>microtask</dfn> is a
<a href=#concept-task title=concept-task>task</a> that is originally to be queued on the <a href=#microtask-queue>microtask
queue</a> rather than a <a href=#task-queue>task queue</a>. When an algorithm requires a
<a href=#microtask>microtask</a> to be <dfn id=queue-a-microtask title="queue a microtask">queued</dfn>, it must be appended
to the relevant <a href=#event-loop>event loop</a>'s <a href=#microtask-queue>microtask queue</a>; the <a href=#task-source>task
source</a> of such a <a href=#microtask>microtask</a> is the <dfn id=microtask-task-source>microtask task source</dfn>.</p>

<p class=note>It is possible for a <a href=#microtask>microtask</a> to be moved to a regular <a href=#task-queue>task
queue</a>, if, during its initial execution, it <a href=#spin-the-event-loop title="spin the event loop">spins the
event loop</a>. In that case, the <a href=#microtask-task-source>microtask task source</a> is the <a href=#task-source>task
source</a> used. Normally, the <a href=#task-source>task source</a> of a <a href=#microtask>microtask</a> is
irrelevant.</p>

<p>When a user agent is to <dfn id=perform-a-microtask-checkpoint>perform a microtask checkpoint</dfn>, if the <a href=#performing-a-microtask-checkpoint>performing a
microtask checkpoint</a> flag is false, then the user agent must run the following steps:</p>

<ol><li><p>Let the <a href=#performing-a-microtask-checkpoint>performing a microtask checkpoint</a> flag be true.</li>

<li><p><dfn id=perform-a-custom-elements-checkpoint>Perform a custom elements checkpoint</dfn>. <a href=#refsCUSTOM>[CUSTOM]</a></li>
<li>

<p><dfn id=perform-a-custom-elements-checkpoint>Perform a custom elements checkpoint</dfn>. <a href=#refsCUSTOM>[CUSTOM]</a></p>

<p class=critical>This will be removed once custom elements have been updated to use the
<a href=#microtask-queue>microtask queue</a>.</p>

</li>

<li>

<p><a href=#sort-the-tables-with-pending-sorts>Sort the tables with pending sorts</a>.</p>

<li><p><a href=#sort-the-tables-with-pending-sorts>Sort the tables with pending sorts</a>.</li>
<p class=critical>This will be removed once sortable tables have been updated to use the
<a href=#microtask-queue>microtask queue</a>.</p>

</li>

<li>

<p><a href=#concept-mo-invoke title=concept-mo-invoke>Invoke <code>MutationObserver</code> objects</a> for the
<a href=#unit-of-related-similar-origin-browsing-contexts>unit of related similar-origin browsing contexts</a> to which the <a href=#responsible-browsing-context>responsible
browsing context</a> specified by the script's <a href=#settings-object>settings object</a> belongs, using
the <a href=#task-wrapper-algorithm>task wrapper algorithm</a> as the steps to invoke each callback.</p>
browsing context</a> specified by the script's <a href=#settings-object>settings object</a> belongs.</p>

<p class=critical>This will be removed once mutation observers have been updated to use the
<a href=#microtask-queue>microtask queue</a>.</p>

</li>

<li><p><i>Microtask queue handling</i>: If the <a href=#event-loop>event loop</a>'s <a href=#microtask-queue>microtask
queue</a> is empty, jump to the <i>done</i> step below.</li>

<li>

<p>Run the oldest <a href=#microtask>microtask</a> on the <a href=#event-loop>event loop</a>'s <a href=#microtask-queue>microtask
queue</a>.</p>

<p class=note>This will typically invoke scripted callbacks, which eventually calls the
<a href=#clean-up-after-running-a-callback>clean up after running a callback</a> steps, which call this <a href=#perform-a-microtask-checkpoint>perform a microtask
Expand All @@ -71944,7 +71983,14 @@ <h5 id=processing-model-4><span class=secno>7.1.4.2 </span>Processing model</h5>

</li>

<li><p>Let the <a href=#performing-a-microtask-checkpoint>performing a microtask checkpoint</a> flag be false.</li>
<li><p>If the <a href=#storage-mutex>storage mutex</a> is now owned by the <a href=#event-loop>event loop</a>, release it
so that it is once again free.</li>

<li><p>Remove the <a href=#microtask>microtask</a> run in the step above from the <a href=#microtask-queue>microtask
queue</a>, and return to the <i>microtask queue handling</i> step.</li>

<li><p><i>Done</i>: Let the <a href=#performing-a-microtask-checkpoint>performing a microtask checkpoint</a> flag be
false.</li>

</ol><hr><p>When the user agent is to <dfn id=provide-a-stable-state>provide a stable state</dfn>, if any asynchronously-running
algorithms are <dfn id=await-a-stable-state title="await a stable state">awaiting a stable state</dfn>, then the user
Expand All @@ -71958,14 +72004,6 @@ <h5 id=processing-model-4><span class=secno>7.1.4.2 </span>Processing model</h5>
<p class=note>Steps in <a href=#synchronous-section title="synchronous section">synchronous sections</a> are marked
with &#x231b;.</p>

<hr><p>The <dfn id=task-wrapper-algorithm>task wrapper algorithm</dfn>, which is implicitly invoked in the context of an
<a href=#event-loop>event loop</a> and is used to invoke a given <var title="">callback</var> in a specific
way, is as follows:</p>

<ol><li><p>Invoke <var title="">callback</var> as specified.</li>

</ol><p class=critical>The above will change in due course; see <a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=20821">bug 20821</a>.</p>

<hr><p>When an algorithm says to <dfn id=spin-the-event-loop>spin the event loop</dfn> until a condition <var title="">goal</var> is met, the user agent must run the following steps:</p>

<ol><li><p>Let <var title="">task source</var> be the <a href=#task-source>task source</a> of the currently
Expand All @@ -71985,8 +72023,10 @@ <h5 id=processing-model-4><span class=secno>7.1.4.2 </span>Processing model</h5>
<p>Stop the currently running <a href=#concept-task title=concept-task>task</a>, allowing the <a href=#event-loop>event
loop</a> to resume, but continue these steps asynchronously.</p>

<p class=note>This causes the <a href=#event-loop>event loop</a> to move on to the second step of its
processing model (defined above).</p>
<p class=note>This either causes the <a href=#event-loop>event loop</a> to move on to the second step of
its processing model, or causes the <a href=#perform-a-microtask-checkpoint>perform a microtask checkpoint</a> algorithm to
move on to its next step, depending on how the <span class=concept-task>task</span> came to be
run.</p>

</li>

Expand Down
74 changes: 57 additions & 17 deletions index
Expand Up @@ -298,7 +298,7 @@

<header class=head id=head><p><a href=http://www.whatwg.org/ class=logo><img width=101 src=/images/logo alt=WHATWG height=101></a></p>
<hgroup><h1 class=allcaps>HTML</h1>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 4 February 2014</h2>
<h2 class="no-num no-toc">Living Standard &mdash; Last Updated 5 February 2014</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>
Expand Down Expand Up @@ -71921,21 +71921,60 @@ dictionary <dfn id=erroreventinit>ErrorEventInit</dfn> : <a href=#eventinit>Even

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

</ol><hr><p>When a user agent is to <dfn id=perform-a-microtask-checkpoint>perform a microtask checkpoint</dfn>, if the <a href=#performing-a-microtask-checkpoint>performing a
</ol><hr><p>Each <a href=#event-loop>event loop</a> has a <dfn id=microtask-queue>microtask queue</dfn>. A <dfn id=microtask>microtask</dfn> is a
<a href=#concept-task title=concept-task>task</a> that is originally to be queued on the <a href=#microtask-queue>microtask
queue</a> rather than a <a href=#task-queue>task queue</a>. When an algorithm requires a
<a href=#microtask>microtask</a> to be <dfn id=queue-a-microtask title="queue a microtask">queued</dfn>, it must be appended
to the relevant <a href=#event-loop>event loop</a>'s <a href=#microtask-queue>microtask queue</a>; the <a href=#task-source>task
source</a> of such a <a href=#microtask>microtask</a> is the <dfn id=microtask-task-source>microtask task source</dfn>.</p>

<p class=note>It is possible for a <a href=#microtask>microtask</a> to be moved to a regular <a href=#task-queue>task
queue</a>, if, during its initial execution, it <a href=#spin-the-event-loop title="spin the event loop">spins the
event loop</a>. In that case, the <a href=#microtask-task-source>microtask task source</a> is the <a href=#task-source>task
source</a> used. Normally, the <a href=#task-source>task source</a> of a <a href=#microtask>microtask</a> is
irrelevant.</p>

<p>When a user agent is to <dfn id=perform-a-microtask-checkpoint>perform a microtask checkpoint</dfn>, if the <a href=#performing-a-microtask-checkpoint>performing a
microtask checkpoint</a> flag is false, then the user agent must run the following steps:</p>

<ol><li><p>Let the <a href=#performing-a-microtask-checkpoint>performing a microtask checkpoint</a> flag be true.</li>

<li><p><dfn id=perform-a-custom-elements-checkpoint>Perform a custom elements checkpoint</dfn>. <a href=#refsCUSTOM>[CUSTOM]</a></li>
<li>

<p><dfn id=perform-a-custom-elements-checkpoint>Perform a custom elements checkpoint</dfn>. <a href=#refsCUSTOM>[CUSTOM]</a></p>

<p class=critical>This will be removed once custom elements have been updated to use the
<a href=#microtask-queue>microtask queue</a>.</p>

</li>

<li>

<p><a href=#sort-the-tables-with-pending-sorts>Sort the tables with pending sorts</a>.</p>

<li><p><a href=#sort-the-tables-with-pending-sorts>Sort the tables with pending sorts</a>.</li>
<p class=critical>This will be removed once sortable tables have been updated to use the
<a href=#microtask-queue>microtask queue</a>.</p>

</li>

<li>

<p><a href=#concept-mo-invoke title=concept-mo-invoke>Invoke <code>MutationObserver</code> objects</a> for the
<a href=#unit-of-related-similar-origin-browsing-contexts>unit of related similar-origin browsing contexts</a> to which the <a href=#responsible-browsing-context>responsible
browsing context</a> specified by the script's <a href=#settings-object>settings object</a> belongs, using
the <a href=#task-wrapper-algorithm>task wrapper algorithm</a> as the steps to invoke each callback.</p>
browsing context</a> specified by the script's <a href=#settings-object>settings object</a> belongs.</p>

<p class=critical>This will be removed once mutation observers have been updated to use the
<a href=#microtask-queue>microtask queue</a>.</p>

</li>

<li><p><i>Microtask queue handling</i>: If the <a href=#event-loop>event loop</a>'s <a href=#microtask-queue>microtask
queue</a> is empty, jump to the <i>done</i> step below.</li>

<li>

<p>Run the oldest <a href=#microtask>microtask</a> on the <a href=#event-loop>event loop</a>'s <a href=#microtask-queue>microtask
queue</a>.</p>

<p class=note>This will typically invoke scripted callbacks, which eventually calls the
<a href=#clean-up-after-running-a-callback>clean up after running a callback</a> steps, which call this <a href=#perform-a-microtask-checkpoint>perform a microtask
Expand All @@ -71944,7 +71983,14 @@ dictionary <dfn id=erroreventinit>ErrorEventInit</dfn> : <a href=#eventinit>Even

</li>

<li><p>Let the <a href=#performing-a-microtask-checkpoint>performing a microtask checkpoint</a> flag be false.</li>
<li><p>If the <a href=#storage-mutex>storage mutex</a> is now owned by the <a href=#event-loop>event loop</a>, release it
so that it is once again free.</li>

<li><p>Remove the <a href=#microtask>microtask</a> run in the step above from the <a href=#microtask-queue>microtask
queue</a>, and return to the <i>microtask queue handling</i> step.</li>

<li><p><i>Done</i>: Let the <a href=#performing-a-microtask-checkpoint>performing a microtask checkpoint</a> flag be
false.</li>

</ol><hr><p>When the user agent is to <dfn id=provide-a-stable-state>provide a stable state</dfn>, if any asynchronously-running
algorithms are <dfn id=await-a-stable-state title="await a stable state">awaiting a stable state</dfn>, then the user
Expand All @@ -71958,14 +72004,6 @@ dictionary <dfn id=erroreventinit>ErrorEventInit</dfn> : <a href=#eventinit>Even
<p class=note>Steps in <a href=#synchronous-section title="synchronous section">synchronous sections</a> are marked
with &#x231b;.</p>

<hr><p>The <dfn id=task-wrapper-algorithm>task wrapper algorithm</dfn>, which is implicitly invoked in the context of an
<a href=#event-loop>event loop</a> and is used to invoke a given <var title="">callback</var> in a specific
way, is as follows:</p>

<ol><li><p>Invoke <var title="">callback</var> as specified.</li>

</ol><p class=critical>The above will change in due course; see <a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=20821">bug 20821</a>.</p>

<hr><p>When an algorithm says to <dfn id=spin-the-event-loop>spin the event loop</dfn> until a condition <var title="">goal</var> is met, the user agent must run the following steps:</p>

<ol><li><p>Let <var title="">task source</var> be the <a href=#task-source>task source</a> of the currently
Expand All @@ -71985,8 +72023,10 @@ dictionary <dfn id=erroreventinit>ErrorEventInit</dfn> : <a href=#eventinit>Even
<p>Stop the currently running <a href=#concept-task title=concept-task>task</a>, allowing the <a href=#event-loop>event
loop</a> to resume, but continue these steps asynchronously.</p>

<p class=note>This causes the <a href=#event-loop>event loop</a> to move on to the second step of its
processing model (defined above).</p>
<p class=note>This either causes the <a href=#event-loop>event loop</a> to move on to the second step of
its processing model, or causes the <a href=#perform-a-microtask-checkpoint>perform a microtask checkpoint</a> algorithm to
move on to its next step, depending on how the <span class=concept-task>task</span> came to be
run.</p>

</li>

Expand Down

0 comments on commit 9e4e534

Please sign in to comment.