HTML Standard Tracker

Diff (omit for latest revision)
Filter

Short URL: http://html5.org/r/2085

File a bug

SVNBugCommentTime (UTC)
2085Further work on the event loop front. (WebSockets, postMessage, MessagePorts, setTimeout)2008-08-19 09:30
Index: source
===================================================================
--- source	(revision 2084)
+++ source	(revision 2085)
@@ -28063,10 +28063,10 @@
   <h4>Processing model</h4>
   <!-- ua side -->
 
-  <p>The <span>event source</span> for all <span
+  <p>The <span>task source</span> for all <span
   title="concept-task">tasks</span> <span title="queue a
   task">queued</span> by algorithms in this section and its
-  subsections is the <dfn>template event source</dfn>.</p>
+  subsections is the <dfn>template task source</dfn>.</p>
 
 
   <h5>The <code title="dom-originalContent">originalContent</code> DOM
@@ -40144,8 +40144,16 @@
   null, and the <code title="dom-MessageEvent-messagePort">messagePort</code>
   attribute must be null.</p>
 
+  <hr>
 
+  <p><span title="concept-task">Tasks</span> in <span>server-sent
+  events</span> and <span>Web Sockets</span> use their own <span
+  title="task source">task sources</span>, but the <span>task
+  source</span> for the <span title="concept-task">tasks</span> in
+  <span>cross-document messaging</span> and <span>channel
+  messaging</span> is the <dfn>posted message task source</dfn>.</p>
 
+
   <h3 id="server-sent-events"><dfn>Server-sent events</dfn></h3>
   <!-- eventsource -->
 
@@ -40214,7 +40222,7 @@
 
     <p>As data is received, the <span
     title="concept-task">tasks</span> queued by the <span>networking
-    event source</span> to handle the data must consist of following
+    task source</span> to handle the data must consist of following
     the rules given in the following sections.</p>
 
    </li>
@@ -40802,15 +40810,6 @@
   <p>The <code title="event-message">message</code> event is fired
   when when data is received for a connection.</p>
 
-  <p>Events that would be fired during script execution (e.g. between
-  the <code>WebSocket</code> object being created &mdash; and thus the
-  connection being established &mdash; and the current script
-  completing; or, during the execution of a <code
-  title="event-message">message</code> event handler) must be
-  buffered, and those events queued up and each one individually fired
-  after the script has completed.</p> <!-- XXX make this more generic
-  -->
-
   <hr>
 
   <p>The following are the <span>event handler DOM attributes</span>
@@ -40842,6 +40841,11 @@
 
   <h4>The Web Socket protocol</h4>
 
+  <p>The <span>task source</span> for all <span
+  title="concept-task">tasks</span> <span title="queue a
+  task">queued</span> by algorithms in this section and its
+  subsections is the <dfn>Web Socket task source</dfn>.</p>
+
   <h5>Client-side requirements</h5>
 
   <p><em>This section only applies to user agents.</em></p>
@@ -41276,8 +41280,8 @@
 
    <li>
 
-    <p><span>Fire a simple event</span> named <code
-    title="event-WebSocket-open">open</code> at the
+    <p><span>Queue a task</span> to <span>fire a simple event</span>
+    named <code title="event-WebSocket-open">open</code> at the
     <code>WebSocket</code> object.</p>
 
    </li>
@@ -41393,9 +41397,9 @@
        the event name <code title="event-message">message</code>,
        which does not bubble, is cancelable, has no default action,
        and whose <code title="dom-MessageEvent-data">data</code>
-       attribute is set to <var title="">data</var>, and dispatch it
-       at the <code>WebSocket</code> object. Otherwise, discard the
-       data.</p></li>
+       attribute is set to <var title="">data</var>, and <span>queue a
+       task</span> to dispatch it at the <code>WebSocket</code>
+       object. Otherwise, discard the data.</p></li>
 
       </ol>
 
@@ -41634,8 +41638,9 @@
   closed</span>, the <code
   title="dom-WebSocket-readyState">readyState</code> attribute's value
   must be changed to <code title="dom-WebSocket-CLOSED">CLOSED</code>
-  (2), and the user agent must <span>fire a simple event</span> named
-  <code title="event-WebSocket-close">close</code> at the
+  (2), and the user agent must <span>queue a task</span> to <span>fire
+  a simple event</span> named <code
+  title="event-WebSocket-close">close</code> at the
   <code>WebSocket</code> object.</p>
 
 
@@ -41762,16 +41767,6 @@
 
    <li>
 
-    <p>Wait for all scripts in the <span>unit of related browsing
-    contexts</span> to which the <code>Window</code> object on
-    which the method was invoked belongs to have finished executing
-    any pending scripts.</p> <!-- XXX define this in terms of the
-    event queue -->
-
-   </li>
-
-   <li>
-
     <p>If the <var title="">targetOrigin</var> argument has a value
     other than a single literal U+002A ASTERISK character ("*"), and
     the <span>active document</span> of the <span>browsing
@@ -41807,9 +41802,11 @@
 
    <li>
 
-    <p>Dispatch the event created in the previous step at the
-    <code>Window</code> object on which the method was invoked.</p>
-    <!-- XXX define this in terms of the event queue -->
+    <p><span>Queue a task</span> to dispatch the event created in the
+    previous step at the <code>Window</code> object on which the
+    method was invoked. The <span>task source</span> for this <span
+    title="concept-task">task</span> is the <span>posted message task
+    source</span>.</p>
     <!-- XXX apply any body/window dispatch decisions here -->
 
    </li>
@@ -41872,16 +41869,6 @@
 
    <li>
 
-    <p>Wait for all scripts in the <span>unit of related browsing
-    contexts</span> to which the <code>Window</code> object on
-    which the method was invoked belongs to have finished executing
-    any pending scripts.</p> <!-- XXX define this in terms of the
-    event queue -->
-
-   </li>
-
-   <li>
-
     <p>If the <var title="">targetOrigin</var> argument has a value
     other than a single literal U+002A ASTERISK character ("*"), and
     the <span>active document</span> of the <span>browsing
@@ -41925,9 +41912,11 @@
 
    <li>
 
-    <p>Dispatch the event created in the previous step at the
-    <code>Window</code> object on which the method was invoked.</p>
-    <!-- XXX define this in terms of the event queue -->
+    <p><span>Queue a task</span> to dispatch the event created in the
+    previous step at the <code>Window</code> object on which the
+    method was invoked. The <span>task source</span> for this <span
+    title="concept-task">task</span> is the <span>posted message task
+    source</span>.</p>
     <!-- XXX apply any body/window dispatch decisions here -->
 
    </li>
@@ -42248,23 +42237,32 @@
   method must open its port's <span>port message queue</span>, if it
   is not already open.</p>
 
-  <p>When a port's <span>port message queue</span> is open and
-  contains an event, the user agent must, at the earliest opportunity,
-  after any scripts have finished executing<!-- XXX queue -->,
-  dispatch the first event in the queue on the
-  <code>MessagePort</code> object, and remove the event from the
-  queue.</p>
+  <p>When a port's <span>port message queue</span> is open, contains
+  an event, and its owner is <span title="port owner
+  available">available</span>, the user agent must <span>queue a
+  task</span> in the <span>event loop</span> to dispatch the first
+  event in the queue on the <code>MessagePort</code> object, and
+  remove the event from the queue.  The <span>task source</span> for
+  this <span title="concept-task">task</span> is the <span>posted
+  message task source</span>.</p>
 
-  <p>If the <code>MessagePort</code> is owned by a <code>Window</code>
-  object and the <code>Document</code> that was the <span>active
-  document</span> in that <span>browsing context</span> when the
-  <code>MessagePort</code> was created is not <span>fully
-  active</span>, then an opportunity doesn't exist &mdash; events in
-  such cases must only be dispatched once the <code>Document</code> in
-  question becomes <span>fully active</span>. If that doesn't happen
-  before that <code>Document</code> is discarded, then the events are
-  lost.</p>
+  <p>A <code>MessagePort</code>'s owner is <dfn title="port owner
+  available">available</dfn> if the <code>MessagePort</code> is owned
+  by an object other than a <code>Window</code> object, or if it is
+  owned by a <code>Window</code> object and the <code>Document</code>
+  that was the <span>active document</span> in that <span>browsing
+  context</span> when the <code>MessagePort</code> was created is
+  <span>fully active</span>. If that <code>Document</code> is
+  discarded before the port's owner becomes available, then the events
+  are lost.</p>
 
+  <!-- XXX when we have sorted out the global object mess, if that
+  makes this easier to fix, then fix it better. (e.g. maybe just say
+  that callback tasks aren't processed if they involve firing a
+  callback that wouldn't fire because the code is swapped out? not
+  sure how you'd handle prioritisation, i guess you'd just pretend
+  those events weren't there for the time being) -->
+
   <hr>
 
   <p>The <dfn title="dom-MessagePort-close"><code>close()</code></dfn>
@@ -42276,15 +42274,20 @@
 
    <li><p>Unentangle the two ports.</p></li>
 
-   <li><p>At the next available opportunity, after any scripts have
-   finished executing<!-- XXX queue -->, <span>fire a simple
-   event</span> called <code title="event-unload">unload</code> at
-   each of the message ports. If the two message ports are in the same
-   <span>unit of related browsing contexts</span>, then the port on
-   which the method was called must receive the event first.</p></li>
+   <li><p><span>Queue a task</span> to <span>fire a simple
+   event</span> called <code title="event-unload">unload</code> at the
+   port on which the method was called.</p></li>
 
+   <li><p><span>Queue a task</span> to <span>fire a simple
+   event</span> called <code title="event-unload">unload</code> at the
+   other port.</p></li>
+
   </ol>
 
+  <p>The <span>task source</span> for the two <span
+  title="concept-task">tasks</span> above is the <span>posted message
+  task source</span>.
+
   <p>If the method is called on a port that is not entangled, then the
   method must do nothing.</p>
 
@@ -42348,10 +42351,11 @@
 
    <li><p>Unentangle the two ports.</p></li>
 
-   <li><p>At the next available opportunity, after any scripts have
-   finished executing<!-- XXX queue -->, <span>fire a simple
+   <li><p><span>Queue a task</span> to <span>fire a simple
    event</span> called <code title="event-unload">unload</code> at
-   <var title="">surviving port</var>.</p></li>
+   <var title="">surviving port</var>.  The <span>task source</span>
+   for this <span title="concept-task">task</span> is the <span>posted
+   message task source</span>.</p></li>
 
   </ol>
 
@@ -50397,8 +50401,9 @@
 
   <h3 id="timers">Timers</h3>
 
-  <p class="big-issue">This section is expected to be moved to the
-  Window Object specification in due course.</p>
+  <p class="big-issue">This section is expected to be moved to its own
+  specification in due course. It needs a lot of work to actually make
+  it into a semi-decent spec.</p>
 
   <p>Objects that implement the <code>Window</code> interface must
   also implement the <code>WindowTimers</code> interface:</p>
@@ -50433,22 +50438,23 @@
   to a <code>TimeoutHandler</code> object and a length of time in
   milliseconds. It must return a handle to the timeout created, and
   then asynchronously wait <var title="">timeout</var> milliseconds
-  and then invoke <code>handleEvent()</code> on the <var
-  title="">handler</var> object. If any <var
-  title="">arguments...</var> were provided, they must be passed to
-  the <var title="">handler</var> as arguments to the
-  <code>handleEvent()</code> function.</p>
+  and then <span>queue a task</span> to invoke
+  <code>handleEvent()</code> on the <var title="">handler</var>
+  object. If any <var title="">arguments...</var> were provided, they
+  must be passed to the <var title="">handler</var> as arguments to
+  the <code>handleEvent()</code> function.</p>
 
   <p>Alternatively, <dfn title=""><code>setTimeout(<var
   title="">code</var>, <var title="">timeout</var>[, <var
   title="">language</var>])</code></dfn> may be used. This variant
-  takes a string instead of a <code>TimeoutHandler</code> object. That
-  string must be parsed using the specified <var
-  title="">language</var> (defaulting to ECMAScript if the third
-  argument is omitted) and executed in the scope of the <span>browsing
-  context</span> associated with the <code>Window</code> object on
-  which the <code title="setTimeout">setTimeout()</code> method was
-  invoked.</p>
+  takes a string instead of a <code>TimeoutHandler</code>
+  object. <span title="big-issue">define the actual requirements for
+  this method, as with the previous one.</span> That string must be
+  parsed using the specified <var title="">language</var> (defaulting
+  to ECMAScript if the third argument is omitted) and executed in the
+  scope of the <span>browsing context</span> associated with the
+  <code>Window</code> object on which the <code
+  title="setTimeout">setTimeout()</code> method was invoked.</p>
 
   <p class="big-issue">Need to define <var title="">language</var>
   values.</p>
@@ -50457,8 +50463,9 @@
   title="dom-windowtimers-setInterval"><code>setInterval(...)</code></dfn>
   variants must work in the same way as the <code>setTimeout</code>
   variants except that if <var title="">timeout</var> is a value
-  greater than zero, the <var title="">handler</var> or
-  <code>code</code> must be invoked again every <var
+  greater than zero, the <span title="concept-task">task</span> that
+  invokes the <var title="">handler</var> or <code>code</code> must be
+  <span title="queue a task">queued</span> again every <var
   title="">timeout</var> milliseconds, not just the once.</p> <!-- so
   setInterval(x) and setInterval(x, 0) are equivalent to setTimeout(x)
   and setTimeout(x, 0) respectively -->
@@ -50474,13 +50481,9 @@
   with a value that does not correspond to an active timeout or
   interval, the methods must return without doing anything.</p>
 
-  <p>Timeouts must never fire while another script is executing. (Thus
-  the HTML scripting model is strictly single-threaded and not
-  reentrant.)</p><!-- XXX queue -->
 
 
 
-
   <h2 class="no-num">Index</h2>
 
   <p><em>This section is non-normative.</em></p>

|