[html5] r2023 - [] (0) Simplify message ports: use queueing instead of transient 'active' functi [...]

whatwg at whatwg.org whatwg at whatwg.org
Wed Aug 6 00:24:39 PDT 2008


Author: ianh
Date: 2008-08-06 00:24:38 -0700 (Wed, 06 Aug 2008)
New Revision: 2023

Modified:
   index
   source
Log:
[] (0) Simplify message ports: use queueing instead of transient 'active' functionality. Also, make localStorage use the same mechanism for obtaining origin as openDatabase().

Modified: index
===================================================================
--- index	2008-08-06 00:51:45 UTC (rev 2022)
+++ index	2008-08-06 07:24:38 UTC (rev 2023)
@@ -31664,15 +31664,6 @@
    <a href="#list-of2">list of added properties</a> must be empty when the
    <code>Document</code> object is created.
 
-  <p>Each <code>Document</code> in a <a href="#browsing1">browsing
-   context</a> also has an associated <dfn id=list-of3>list of message
-   ports</dfn>, which must be initially empty. The list is used during <a
-   href="#traverse" title="traverse the history">history traversal</a> in
-   much the same way as the <a href="#list-of2">list of added properties</a>,
-   to keep track of message ports that need to be reactivated if the
-   <code>Document</code> is made the <a href="#active">active document</a>
-   again.
-
   <h4 id=security3><span class=secno>5.2.1 </span>Security</h4>
 
   <p>User agents must raise a <a href="#security10">security exception</a>
@@ -36384,15 +36375,6 @@
      <li class=big-issue>freeze any timers, intervals, XMLHttpRequests,
       database transactions, etc
 
-     <li id=port-traversal-deactivation>If there are any <code><a
-      href="#messageport0">MessagePort</a></code> objects whose owner is the
-      browsing context's default view's <code><a
-      href="#window">Window</a></code> object and that are entangled with
-      another port, the user agent must <a href="#deactivate"
-      title="deactivate a port">deactivate</a> all such ports and let the
-      <code>Document</code>'s <a href="#list-of3">list of message ports</a>
-      be a list of those ports.
-
      <li>The user agent must move any properties that have been added to the
       browsing context's default view's <code><a
       href="#window">Window</a></code> object to the <a href="#active">active
@@ -36444,12 +36426,6 @@
       href="#list-of2">list of added properties</a> to browsing context's
       default view's <code><a href="#window">Window</a></code> object.
 
-     <li id=port-traversal-reactivation>If the <a href="#active">active
-      document</a>'s <a href="#list-of3">list of message ports</a> is not
-      empty, then the user agent must <a href="#reactivate" title="reactivate
-      a port">reactivate</a> all the ports in that list. Empty that <a
-      href="#list-of3">list of message ports</a>.
-
      <li class=big-issue>unfreeze any timers, intervals, XMLHttpRequests,
       database transactions, etc
     </ol>
@@ -36503,13 +36479,8 @@
 
   <p class=big-issue>When a user agent is to <dfn id=discard>discard a
    <code>Document</code></dfn>, any frozen timers, intervals,
-   XMLHttpRequests, database transactions, etc, must be killed, and any ports
-   owned by the Window object that aren't in a <a href="#list-of3">list of
-   message ports</a>, if the document is the <a href="#active">active
-   document</a>, or otherwise any ports in that document's <a
-   href="#list-of3">list of message ports</a>, if the document is not the <a
-   href="#active">active document</a>, must be <span>deactivated</span> and
-   unentangled.
+   XMLHttpRequests, database transactions, etc, must be killed, and any
+   MessagePorts owned by the Window object must be unentangled.
 
   <p class=big-issue>Also, <code title=event-unload>unload</code> events
    should fire.
@@ -36826,8 +36797,11 @@
   <p>When the <code title=dom-localStorage><a
    href="#localstorage">localStorage</a></code> attribute is accessed, the
    user agent must check to see if it has allocated local storage area for
-   the <a href="#origin0">origin</a> of the script. If it has not, a new
-   storage area for that <a href="#origin0">origin</a> must be created.
+   the for the <a href="#origin0">origin</a> of the <a href="#active">active
+   document</a> of the <a href="#browsing1">browsing context</a> of the
+   <code><a href="#window">Window</a></code> object on which the method was
+   invoked. If it has not, a new storage area for that <a
+   href="#origin0">origin</a> must be created.
 
   <p>The user agent must then create a <code><a
    href="#storage0">Storage</a></code> object associated with that origin's
@@ -42208,7 +42182,7 @@
    href="#resolve" title="resolve a url">resolve</a> the <a
    href="#url">URL</a> specified in <var title="">src</var>, and if that
    succeeds, add the resulting <a href="#absolute">absolute URL</a> to the <a
-   href="#list-of4" title=concept-eventsource-list>list of event sources</a>
+   href="#list-of3" title=concept-eventsource-list>list of event sources</a>
    for that object. The same URL can be registered multiple times. If the URL
    fails to resolve, then the user agent must raise a <code>SYNTAX_ERR</code>
    exception.
@@ -42219,7 +42193,7 @@
    href="#resolve" title="resolve a url">resolve</a> the <a
    href="#url">URL</a> specified in <var title="">src</var>, and if that
    succeeds, remove the resulting <a href="#absolute">absolute URL</a> from
-   the <a href="#list-of4" title=concept-eventsource-list>list of event
+   the <a href="#list-of3" title=concept-eventsource-list>list of event
    sources</a> for that object. If the same URI has been registered multiple
    times, removing it must remove only one instance of that URI for each
    invocation of the <code title=removeEventSource>removeEventSource()</code>
@@ -42230,7 +42204,7 @@
 
   <p>Each object implementing the <code>EventTarget</code> and <code><a
    href="#remoteeventtarget">RemoteEventTarget</a></code> interfaces has a
-   <dfn id=list-of4 title=concept-eventsource-list>list of event
+   <dfn id=list-of3 title=concept-eventsource-list>list of event
    sources</dfn> that are registered for that object.
 
   <p>When a new URI is added to this list, the user agent should, as soon as
@@ -43815,10 +43789,6 @@
      <var title="">port2</var> objects.
 
    <li>
-    <p>Set the <code title=dom-MessagePort-active><a
-     href="#active0">active</a></code> attribute of the two ports to true.
-
-   <li>
     <p>Instantiate a new <code><a
      href="#messagechannel">MessageChannel</a></code> object, and let <var
      title="">channel</var> be that object.
@@ -43851,6 +43821,7 @@
   readonly attribute boolean <a href="#active0" title=dom-MessagePort-active>active</a>;
   boolean <a href="#postmessage1" title=dom-MessagePort-postMessage>postMessage</a>(in DOMString message);
   boolean <a href="#postmessage1" title=dom-MessagePort-postMessage>postMessage</a>(in DOMString message, in <a href="#messageport0">MessagePort</a> messagePort);
+  void <span title=dom-MessagePort-start>start</span>();
   void <a href="#close3" title=dom-MessagePort-close>close</a>();
 
   // event handler attributes
@@ -43860,25 +43831,19 @@
            attribute <span>EventListener</span> <a href="#onunload0" title=handler-MessagePort-onunload>onunload</a>;
 };</pre>
 
+  <p>Each <code><a href="#messageport0">MessagePort</a></code> object can be
+   entangled with another (a symmetric relationship). Each <code><a
+   href="#messageport0">MessagePort</a></code> object also has a <dfn
+   id=port-message>port message queue</dfn>, initial empty. A <a
+   href="#port-message">port message queue</a> can be open or closed, and is
+   initially closed.
+
   <p>When the user agent is to <dfn id=create>create a new
    <code>MessagePort</code> object</dfn> owned by a <a href="#script2">script
-   execution context</a> object <var title="">owner</var>, it must run the
-   following steps:
+   execution context</a> object <var title="">owner</var>, it must
+   instantiate a new <code><a href="#messageport0">MessagePort</a></code>
+   object, and let its owner be <var title="">owner</var>.
 
-  <ol>
-   <li>
-    <p>Instantiate a new <code><a href="#messageport0">MessagePort</a></code>
-     object, and let <var title="">port</var> be that object.
-
-   <li>
-    <p>Let <var title="">port</var>'s owner be <var title="">owner</var>.
-
-   <li>
-    <p>Set the <code title=dom-MessagePort-active><a
-     href="#active0">active</a></code> attribute of <var title="">port</var>
-     be false.
-  </ol>
-
   <hr>
 
   <p>When the user agent is to <dfn id=entangle>entangle</dfn> two <code><a
@@ -43887,35 +43852,15 @@
 
   <ol>
    <li>
-    <p>If either port is already entangled, then let <var
-     title="">port1</var> be that port, and run these substeps:</p>
+    <p>If one of the ports is already entangled, then unentangle it and the
+     port that it was entangled with.</p>
 
-    <ol>
-     <li>
-      <p>Let <var title="">old port</var> be the port that <var
-       title="">port1</var> is entangled with.
+    <p class=note>If those two previously entangled ports were the two ports
+     of a <code><a href="#messagechannel">MessageChannel</a></code> object,
+     then that <code><a href="#messagechannel">MessageChannel</a></code>
+     object no longer represents an actual channel: the two ports in that
+     object are no longer entangled.</p>
 
-     <li>
-      <p>Unentangle <var title="">old port</var>, so that it is no longer
-       entangled with any ports.
-
-     <li>
-      <p>Set the <code title=dom-MessagePort-active><a
-       href="#active0">active</a></code> attribute of <var title="">old
-       port</var> to false.
-
-     <li>
-      <p>Unentangle <var title="">port1</var>, so that it is no longer
-       entangled with any ports.
-    </ol>
-
-    <p>If <var title="">port1</var> and <var title="">old port</var> were the
-     two ports of a <code><a href="#messagechannel">MessageChannel</a></code>
-     object, then that <code><a
-     href="#messagechannel">MessageChannel</a></code> object no longer
-     represents an actual channel: the two ports in that object are no longer
-     entangled.</p>
-
    <li>
     <p>Associate the two ports to be entangled, so that they form the two
      parts of a new channel. (There is no <code><a
@@ -43942,35 +43887,24 @@
      <var title="">original port</var> is entangled.
 
    <li>
-    <p>Let <var title="">original status</var> be the value of the <code
-     title=dom-MessagePort-active><a href="#active0">active</a></code>
-     attribute of the <var title="">original port</var>.
-
-   <li>
     <p><a href="#create">Create a new <code>MessagePort</code> object</a>
      owned by <var title="">owner</var>, and let <var title="">new port</var>
      be that object.
 
    <li>
+    <p><span>Move all the events in the <a href="#port-message">port message
+     queue</a> of <var title="">original port</var> to the <a
+     href="#port-message">port message queue</a> of <var title="">new
+     port</var>, if any, leaving the <var title="">new port</var>'s <a
+     href="#port-message">port message queue</a> in its initial closed
+     state.</span>
+
+   <li>
     <p><a href="#entangle">Entangle</a> the <var title="">remote port</var>
      and <var title="">new port</var> objects. The <var title="">original
-     port</var> object will have its <code title=dom-MessagePort-active><a
-     href="#active0">active</a></code> attribute permanently set to false by
-     this process.
+     port</var> object will be unentangled by this process.
 
    <li>
-    <p>Let the <code title=dom-MessagePort-active><a
-     href="#active0">active</a></code> attribute of the <var title="">new
-     port</var> object have the same value as <var title="">original
-     status</var>.
-   </li>
-   <!-- we
-   don't throw if it's false, because it might become true again,
-   e.g. if you're sending a port that is entangled with a port that's
-   associated with a document that's currently not the active document
-   of its iframe, but which hasn't been discarded yet -->
-
-   <li>
     <p>Return <var title="">new port</var>. It is the clone.
   </ol>
 
@@ -43978,8 +43912,7 @@
 
   <p>The <dfn id=active0
    title=dom-MessagePort-active><code>active</code></dfn> attribute must
-   return the last value that it was set to according to the rules of this
-   specification.
+   return true if the port is entangled, and false otherwise.
 
   <hr>
 
@@ -43997,14 +43930,12 @@
      any.
 
    <li>
-    <p>If the <var title="">source port</var>'s <code
-     title=dom-MessagePort-active><a href="#active0">active</a></code>
-     attribute is false, then return false and abort these steps.
+    <p>If the <var title="">source port</var> is not entangled with another
+     port, then return false and abort these steps.
    </li>
-   <!-- we don't
-   raise an exception because this attribute can become false at a
-   moment's notice, but we return false so that the caller can check
-   whether the port was active at time of calling without a race
+   <!-- we don't raise an exception because this can happen moment's
+   notice, but we return false so that the caller can check whether
+   the port was active at time of calling without a race
    condition. -->
 
    <li>
@@ -44050,17 +43981,8 @@
     <p>Return true from the method, but continue with these steps.
 
    <li>
-    <p>Wait for all scripts in the conceptual thread that the <a
-     href="#script2">script execution context</a> that owns the <var
-     title="">target port</var> belongs to have executed to completion. If
-     this never happens (e.g. the relevant <a href="#browsing1">browsing
-     context</a> is closed by the user before the event can be dispatched),
-     then discard the event.
-   </li>
-   <!-- XXX queue -->
-
-   <li>
-    <p>Dispatch the event at the <var title="">target port</var> object.
+    <p>Add the event to the <a href="#port-message">port message queue</a> of
+     <var title="">target port</var>.
   </ol>
 
   <p class=big-issue>People often request the ability to send name/value
@@ -44068,6 +43990,20 @@
 
   <hr>
 
+  <p>The <dfn id=start6
+   title=dom-MessagePort-close><code>start()</code></dfn> method must open
+   its port's <a href="#port-message">port message queue</a>, if it is not
+   already open.
+
+  <p>When a port's <a href="#port-message">port message queue</a> 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><a
+   href="#messageport0">MessagePort</a></code> object, and remove the event
+   from the queue.
+
+  <hr>
+
   <p>The <dfn id=close3
    title=dom-MessagePort-close><code>close()</code></dfn> method, when called
    on a port <var title="">local port</var> that is entangled with another
@@ -44078,10 +44014,6 @@
     <p>Unentangle the two ports.
 
    <li>
-    <p>Set both ports' <code title=dom-messageport-active><a
-     href="#active0">active</a></code> attribute to false.
-
-   <li>
     <p>At the next available opportunity, after any scripts have finished
      executing<!-- XXX queue -->, <a href="#firing2">fire a simple event</a>
      called <code title=event-unload>unload</code> at each of the message
@@ -44107,8 +44039,13 @@
     <p>Must be invoked whenever a <code
      title=event-MessagePort-message>message</code> event is targeted at or
      bubbles through the <code><a href="#messageport0">MessagePort</a></code>
-     object.
+     object.</p>
 
+    <p>The first time a <code><a href="#messageport0">MessagePort</a></code>
+     object's onmessage attribute is set, the port's <a
+     href="#port-message">port message queue</a> must be opened, as if the
+     <code title=dom-MessagePort-start>start()</code> method had been called.</p>
+
    <dt><dfn id=onload0
     title=handler-MessagePort-onload><code>onload</code></dfn>
 
@@ -44143,46 +44080,19 @@
 
   <h5 id=ports><span class=secno>7.5.3.1. </span>Ports and browsing contexts</h5>
 
-  <p>During <a href="#traverse" title="traverse the history">session history
-   traversal</a> (e.g. when a user <a href="#navigate"
-   title=navigate>navigates</a> a <a href="#browsing1">browsing context</a>
-   to another page, or goes back to a previous page), the user agent will
-   have to <a href="#port-traversal-deactivation">deactivate</a> and/or <a
-   href="#port-traversal-reactivation">reactivate</a> some ports.
+  <p>Ports are unentangled when the <code>Document</code> that was the <a
+   href="#active">active document</a> of the <a href="#browsing1">browsing
+   context</a> corresponding to the <code><a href="#window">Window</a></code>
+   object that owns them is <a href="#discard" title="discard a
+   document">discarded</a>.
 
-  <p>Ports are deactivated and unentangled when the <code>Document</code>
-   that was the <a href="#active">active document</a> of the <a
-   href="#browsing1">browsing context</a> corresponding to the <code><a
-   href="#window">Window</a></code> object that owns them is <a
-   href="#discard" title="discard a document">discarded</a>.
-
-  <p>To <dfn id=deactivate>deactivate a port</dfn> <var title="">local
-   port</var> that is entangled with a second port <var title="">remote
-   port</var>, the user agent must set the <code
-   title=dom-MessagePort-active><a href="#active0">active</a></code>
-   attribute of the <var title="">remote port</var> to false.
-
-  <p>To <dfn id=reactivate>reactivate a port</dfn> <var title="">local
-   port</var> that is entangled with a second port <var title="">remote
-   port</var>, the user agent must set the <code
-   title=dom-MessagePort-active><a href="#active0">active</a></code>
-   attribute of the <var title="">remote port</var> to true.
-
-  <p class=note>It's important to note that activating or deactivating a port
-   actually changes the <code title=dom-MessagePort-active><a
-   href="#active0">active</a></code> attribute of the port's entangled port,
-   not its own attribute.
-
   <h5 id=ports0><span class=secno>7.5.3.2. </span>Ports and garbage
    collection</h5>
 
   <p>User agents must act as if <code><a
    href="#messageport0">MessagePort</a></code> objects have a strong
    reference to their entangled <code><a
-   href="#messageport0">MessagePort</a></code> object so long as that other
-   <code><a href="#messageport0">MessagePort</a></code> object has any <code
-   title=event-message><a href="#message2">message</a></code> or <code
-   title=event-unload>unload</code> event listeners registered.
+   href="#messageport0">MessagePort</a></code> object.
 
   <div class=note>
    <p>Thus, a message port can be received, given an event listener, and then
@@ -44195,10 +44105,10 @@
   </div>
 
   <p>When an entangled message port is about to be garbage collected, it must
-   be <span>deactivated</span> and unentangled, so that the two ports are no
-   longer related and so that the other port's <code
-   title=dom-MessagePort-active><a href="#active0">active</a></code>
-   attribute is set to false.
+   be unentangled. Because of the aforementioned strong reference, this can
+   only happen if either both ports are about to be garbage collected as a
+   pair, or if the entire <a href="#script2">script execution context</a> of
+   the port is being discarded.
 
   <h2 id=syntax><span class=secno>8. </span>The HTML syntax</h2>
 
@@ -44371,7 +44281,7 @@
 
   <p><dfn id=tags title=syntax-tags>Tags</dfn> are used to delimit the start
    and end of elements in the markup. CDATA, RCDATA, and normal elements have
-   a <a href="#start6" title=syntax-start-tags>start tag</a> to indicate
+   a <a href="#start7" title=syntax-start-tags>start tag</a> to indicate
    where they begin, and an <a href="#end-tags0" title=syntax-end-tags>end
    tag</a> to indicate where they end. The start and end tags of certain
    normal elements can be <a href="#omitted"
@@ -44444,7 +44354,7 @@
 
   <h5 id=start><span class=secno>8.1.2.1. </span>Start tags</h5>
 
-  <p><dfn id=start6 title=syntax-start-tags>Start tags</dfn> must have the
+  <p><dfn id=start7 title=syntax-start-tags>Start tags</dfn> must have the
    following format:
 
   <ol>
@@ -46079,7 +45989,7 @@
 
    <dd>
     <p>The following HTML elements are those that end up in the <a
-     href="#list-of5">list of active formatting elements</a>: <code><a
+     href="#list-of4">list of active formatting elements</a>: <code><a
      href="#a">a</a></code>, <code><a href="#b">b</a></code>,
      <code>big</code>, <code><a href="#em">em</a></code>, <code>font</code>,
      <code><a href="#i">i</a></code>, <code>nobr</code>, <code>s</code>,
@@ -46194,7 +46104,7 @@
   <h5 id=the-list><span class=secno>8.2.3.3. </span>The list of active
    formatting elements</h5>
 
-  <p>Initially the <dfn id=list-of5>list of active formatting elements</dfn>
+  <p>Initially the <dfn id=list-of4>list of active formatting elements</dfn>
    is empty. It is used to handle mis-nested <a href="#formatting"
    title=formatting>formatting element tags</a>.
 
@@ -46211,32 +46121,32 @@
    steps:
 
   <ol>
-   <li>If there are no entries in the <a href="#list-of5">list of active
+   <li>If there are no entries in the <a href="#list-of4">list of active
     formatting elements</a>, then there is nothing to reconstruct; stop this
     algorithm.
 
    <li>If the last (most recently added) entry in the <a
-    href="#list-of5">list of active formatting elements</a> is a marker, or
+    href="#list-of4">list of active formatting elements</a> is a marker, or
     if it is an element that is in the <a href="#stack">stack of open
     elements</a>, then there is nothing to reconstruct; stop this algorithm.
 
    <li>Let <var title="">entry</var> be the last (most recently added)
-    element in the <a href="#list-of5">list of active formatting
+    element in the <a href="#list-of4">list of active formatting
     elements</a>.
 
    <li>If there are no entries before <var title="">entry</var> in the <a
-    href="#list-of5">list of active formatting elements</a>, then jump to
+    href="#list-of4">list of active formatting elements</a>, then jump to
     step 8.
 
    <li>Let <var title="">entry</var> be the entry one earlier than <var
-    title="">entry</var> in the <a href="#list-of5">list of active formatting
+    title="">entry</var> in the <a href="#list-of4">list of active formatting
     elements</a>.
 
    <li>If <var title="">entry</var> is neither a marker nor an element that
     is also in the <a href="#stack">stack of open elements</a>, go to step 4.
 
    <li>Let <var title="">entry</var> be the element one later than <var
-    title="">entry</var> in the <a href="#list-of5">list of active formatting
+    title="">entry</var> in the <a href="#list-of4">list of active formatting
     elements</a>.
 
    <li>Perform a shallow clone of the element <var title="">entry</var> to
@@ -46250,7 +46160,7 @@
     entry for <var title="">clone</var>.
 
    <li>If the entry for <var title="">clone</var> in the <a
-    href="#list-of5">list of active formatting elements</a> is not the last
+    href="#list-of4">list of active formatting elements</a> is not the last
     entry in the list, return to step 7.
   </ol>
 
@@ -46259,7 +46169,7 @@
    haven't been explicitly closed.
 
   <p class=note>The way this specification is written, the <a
-   href="#list-of5">list of active formatting elements</a> always consists of
+   href="#list-of4">list of active formatting elements</a> always consists of
    elements in chronological order with the least recently added element
    first and the most recently added element last (except for while steps 8
    to 11 of the above algorithm are being executed, of course).
@@ -46270,9 +46180,9 @@
 
   <ol>
    <li>Let <var title="">entry</var> be the last (most recently added) entry
-    in the <a href="#list-of5">list of active formatting elements</a>.
+    in the <a href="#list-of4">list of active formatting elements</a>.
 
-   <li>Remove <var title="">entry</var> from the <a href="#list-of5">list of
+   <li>Remove <var title="">entry</var> from the <a href="#list-of4">list of
     active formatting elements</a>.
 
    <li>If <var title="">entry</var> was a marker, then stop the algorithm at
@@ -49806,12 +49716,12 @@
    <dt>A start tag whose tag name is "a"
 
    <dd>
-    <p>If the <a href="#list-of5">list of active formatting elements</a>
+    <p>If the <a href="#list-of4">list of active formatting elements</a>
      contains an element whose tag name is "a" between the end of the list
      and the last marker on the list (or the start of the list if there is no
      marker on the list), then this is a <a href="#parse2">parse error</a>;
      act as if an end tag with the tag name "a" had been seen, then remove
-     that element from the <a href="#list-of5">list of active formatting
+     that element from the <a href="#list-of4">list of active formatting
      elements</a> and the <a href="#stack">stack of open elements</a> if the
      end tag didn't already remove it (it might not have if the element is
      not <a href="#have-an0" title="has an element in table scope">in table
@@ -49830,7 +49740,7 @@
      if any.</p>
 
     <p><a href="#insert0">Insert an HTML element</a> for the token. Add that
-     element to the <a href="#list-of5">list of active formatting
+     element to the <a href="#list-of4">list of active formatting
      elements</a>.</p>
 
    <dt>A start tag whose tag name is one of: "b", "big", "em", "font", "i",
@@ -49841,7 +49751,7 @@
      if any.</p>
 
     <p><a href="#insert0">Insert an HTML element</a> for the token. Add that
-     element to the <a href="#list-of5">list of active formatting
+     element to the <a href="#list-of4">list of active formatting
      elements</a>.</p>
 
    <dt>A start tag whose tag name is "nobr"
@@ -49858,7 +49768,7 @@
      any.</p>
 
     <p><a href="#insert0">Insert an HTML element</a> for the token. Add that
-     element to the <a href="#list-of5">list of active formatting
+     element to the <a href="#list-of4">list of active formatting
      elements</a>.</p>
 
    <dt id=adoptionAgency>An end tag whose tag name is one of: "a", "b",
@@ -49871,7 +49781,7 @@
     <ol>
      <li>
       <p>Let the <var title="">formatting element</var> be the last element
-       in the <a href="#list-of5">list of active formatting elements</a>
+       in the <a href="#list-of4">list of active formatting elements</a>
        that:</p>
 
       <ul>
@@ -49912,7 +49822,7 @@
        bottom of the <a href="#stack">stack of open elements</a>, from the <a
        href="#current5">current node</a> up to and including the <var
        title="">formatting element</var>, and remove the <var
-       title="">formatting element</var> from the <a href="#list-of5">list of
+       title="">formatting element</var> from the <a href="#list-of4">list of
        active formatting elements</a>.
 
      <li>
@@ -49926,7 +49836,7 @@
 
      <li>
       <p>Let a bookmark note the position of the <var title="">formatting
-       element</var> in the <a href="#list-of5">list of active formatting
+       element</var> in the <a href="#list-of4">list of active formatting
        elements</a> relative to the elements on either side of it in the
        list.
 
@@ -49939,7 +49849,7 @@
         title="">node</var> in the <a href="#stack">stack of open
         elements</a>.
 
-       <li>If <var title="">node</var> is not in the <a href="#list-of5">list
+       <li>If <var title="">node</var> is not in the <a href="#list-of4">list
         of active formatting elements</a>, then remove <var
         title="">node</var> from the <a href="#stack">stack of open
         elements</a> and then go back to step 1.
@@ -49951,11 +49861,11 @@
        <li>Otherwise, if <var title="">last node</var> is the <var
         title="">furthest block</var>, then move the aforementioned bookmark
         to be immediately after the <var title="">node</var> in the <a
-        href="#list-of5">list of active formatting elements</a>.
+        href="#list-of4">list of active formatting elements</a>.
 
        <li>If <var title="">node</var> has any children, perform a shallow
         clone of <var title="">node</var>, replace the entry for <var
-        title="">node</var> in the <a href="#list-of5">list of active
+        title="">node</var> in the <a href="#list-of4">list of active
         formatting elements</a> with an entry for the clone, replace the
         entry for <var title="">node</var> in the <a href="#stack">stack of
         open elements</a> with an entry for the clone, and let <var
@@ -49996,8 +49906,8 @@
 
      <li>
       <p>Remove the <var title="">formatting element</var> from the <a
-       href="#list-of5">list of active formatting elements</a>, and insert
-       the clone into the <a href="#list-of5">list of active formatting
+       href="#list-of4">list of active formatting elements</a>, and insert
+       the clone into the <a href="#list-of4">list of active formatting
        elements</a> at the position of the aforementioned bookmark.
 
      <li>
@@ -50047,7 +49957,7 @@
      pointed to by the <a href="#form-element"><code title="">form</code>
      element pointer</a>.</p>
 
-    <p>Insert a marker at the end of the <a href="#list-of5">list of active
+    <p>Insert a marker at the end of the <a href="#list-of4">list of active
      formatting elements</a>.</p>
 
    <dt>A start tag token whose tag name is one of: "applet", "marquee",
@@ -50059,7 +49969,7 @@
 
     <p><a href="#insert0">Insert an HTML element</a> for the token.</p>
 
-    <p>Insert a marker at the end of the <a href="#list-of5">list of active
+    <p>Insert a marker at the end of the <a href="#list-of4">list of active
      formatting elements</a>.</p>
 
    <dt>An end tag token whose tag name is one of: "applet", "button",
@@ -50532,7 +50442,7 @@
     <p><a href="#clear2">Clear the stack back to a table context</a>. (See
      below.)</p>
 
-    <p>Insert a marker at the end of the <a href="#list-of5">list of active
+    <p>Insert a marker at the end of the <a href="#list-of4">list of active
      formatting elements</a>.</p>
 
     <p><a href="#insert0">Insert an HTML element</a> for the token, then
@@ -50934,7 +50844,7 @@
      switch the <span>insertion mode</span> to "<a href="#in-cell"
      title="insertion mode: in cell">in cell</a>".</p>
 
-    <p>Insert a marker at the end of the <a href="#list-of5">list of active
+    <p>Insert a marker at the end of the <a href="#list-of4">list of active
      formatting elements</a>.</p>
 
    <dt>An end tag whose tag name is "tr"

Modified: source
===================================================================
--- source	2008-08-06 00:51:45 UTC (rev 2022)
+++ source	2008-08-06 07:24:38 UTC (rev 2023)
@@ -28854,16 +28854,8 @@
   <span>list of added properties</span> must be empty when the
   <code>Document</code> object is created.</p>
 
-  <p>Each <code>Document</code> in a <span>browsing context</span>
-  also has an associated <dfn>list of message ports</dfn>, which must
-  be initially empty. The list is used during <span title="traverse
-  the history">history traversal</span> in much the same way as the
-  <span>list of added properties</span>, to keep track of message
-  ports that need to be reactivated if the <code>Document</code> is
-  made the <span>active document</span> again.</p>
 
 
-
   <h4>Security</h4>
 
   <p>User agents must raise a <span>security exception</span> whenever
@@ -33732,14 +33724,6 @@
      <li class="big-issue">freeze any timers, intervals,
      XMLHttpRequests, database transactions, etc</li>
 
-     <li id="port-traversal-deactivation">If there are any
-     <code>MessagePort</code> objects whose owner is the browsing
-     context's default view's <code>Window</code> object and that are
-     entangled with another port, the user agent must <span
-     title="deactivate a port">deactivate</span> all such ports and
-     let the <code>Document</code>'s <span>list of message
-     ports</span> be a list of those ports.</li>
-
      <li>The user agent must move any properties that have been added
      to the browsing context's default view's <code>Window</code>
      object to the <span>active document</span>'s
@@ -33801,12 +33785,6 @@
      <span>list of added properties</span> to browsing context's
      default view's <code>Window</code> object.</li>
 
-     <li id="port-traversal-reactivation">If the <span>active
-     document</span>'s <span>list of message ports</span> is not
-     empty, then the user agent must <span title="reactivate a
-     port">reactivate</span> all the ports in that list. Empty that
-     <span>list of message ports</span>.</li>
-
      <li class="big-issue">unfreeze any timers, intervals,
      XMLHttpRequests, database transactions, etc</li>
 
@@ -33863,11 +33841,7 @@
   <p class="big-issue">When a user agent is to <dfn>discard a
   <code>Document</code></dfn>, any frozen timers, intervals,
   XMLHttpRequests, database transactions, etc, must be killed, and any
-  ports owned by the Window object that aren't in a <span>list of
-  message ports</span>, if the document is the <span>active
-  document</span>, or otherwise any ports in that document's
-  <span>list of message ports</span>, if the document is not the
-  <span>active document</span>, must be <span>deactivated</span> and
+  MessagePorts owned by the Window object must be
   unentangled.</p>
 
   <p class="big-issue">Also, <code title="event-unload">unload</code>
@@ -34176,8 +34150,10 @@
 
   <p>When the <code title="dom-localStorage">localStorage</code>
   attribute is accessed, the user agent must check to see if it has
-  allocated local storage area for the <span>origin</span> of the
-  script. If it has not, a new storage area for that
+  allocated local storage area for the for the <span>origin</span> of
+  the <span>active document</span> of the <span>browsing
+  context</span> of the <code>Window</code> object on which the method
+  was invoked. If it has not, a new storage area for that
   <span>origin</span> must be created.</p>
 
   <p>The user agent must then create a <code>Storage</code> object
@@ -41224,9 +41200,6 @@
    <li><p><span>Entangle</span> the <var title="">port1</var> and <var
    title="">port2</var> objects.</p></li>
 
-   <li><p>Set the <code title="dom-MessagePort-active">active</code>
-   attribute of the two ports to true.</p></li>
-
    <li><p>Instantiate a new <code>MessageChannel</code> object, and
    let <var title="">channel</var> be that object.</p></li>
 
@@ -41257,6 +41230,7 @@
   readonly attribute boolean <span title="dom-MessagePort-active">active</span>;
   boolean <span title="dom-MessagePort-postMessage">postMessage</span>(in DOMString message);
   boolean <span title="dom-MessagePort-postMessage">postMessage</span>(in DOMString message, in <span>MessagePort</span> messagePort);
+  void <span title="dom-MessagePort-start">start</span>();
   void <span title="dom-MessagePort-close">close</span>();
 
   // event handler attributes
@@ -41266,24 +41240,18 @@
            attribute <span>EventListener</span> <span title="handler-MessagePort-onunload">onunload</span>;
 };</pre>
 
+  <p>Each <code>MessagePort</code> object can be entangled with
+  another (a symmetric relationship). Each <code>MessagePort</code>
+  object also has a <dfn>port message queue</dfn>, initial empty. A
+  <span>port message queue</span> can be open or closed, and is
+  initially closed.</p>
+
   <p>When the user agent is to <dfn>create a new
   <code>MessagePort</code> object</dfn> owned by a <span>script
   execution context</span> object <var title="">owner</var>, it must
-  run the following steps:</p>
+  instantiate a new <code>MessagePort</code> object, and let its owner
+  be <var title="">owner</var>.</p>
 
-  <ol>
-
-   <li><p>Instantiate a new <code>MessagePort</code> object, and let
-   <var title="">port</var> be that object.</p></li>
-
-   <li><p>Let <var title="">port</var>'s owner be <var
-   title="">owner</var>.</p></li>
-
-   <li><p>Set the <code title="dom-MessagePort-active">active</code>
-   attribute of <var title="">port</var> be false.</p></li>
-
-  </ol>
-
   <hr>
 
   <p>When the user agent is to <dfn>entangle</dfn> two
@@ -41292,31 +41260,16 @@
 
   <ol>
 
-   <li><p>If either port is already entangled, then let <var
-   title="">port1</var> be that port, and run these substeps:</p>
+   <li>
 
-    <ol>
+    <p>If one of the ports is already entangled, then unentangle it
+    and the port that it was entangled with.</p>
 
-     <li><p>Let <var title="">old port</var> be the port that <var
-     title="">port1</var> is entangled with.</p></li>
+    <p class="note">If those two previously entangled ports were the
+    two ports of a <code>MessageChannel</code> object, then that
+    <code>MessageChannel</code> object no longer represents an actual
+    channel: the two ports in that object are no longer entangled.</p>
 
-     <li><p>Unentangle <var title="">old port</var>, so that it is no
-     longer entangled with any ports.</p></li>
-
-     <li><p>Set the <code title="dom-MessagePort-active">active</code>
-     attribute of <var title="">old port</var> to false.</p></li>
-
-     <li><p>Unentangle <var title="">port1</var>, so that it is no
-     longer entangled with any ports.</p></li>
-
-    </ol>
-
-    <p>If <var title="">port1</var> and <var title="">old port</var>
-    were the two ports of a <code>MessageChannel</code> object, then
-    that <code>MessageChannel</code> object no longer represents an
-    actual channel: the two ports in that object are no longer
-    entangled.</p>
-
    </li>
 
    <li><p>Associate the two ports to be entangled, so that they form
@@ -41343,28 +41296,21 @@
    <li><p>Let the <var title="">remote port</var> be the port with
    which the <var title="">original port</var> is entangled.</p></li>
 
-   <li><p>Let <var title="">original status</var> be the value of the
-   <code title="dom-MessagePort-active">active</code> attribute of the
-   <var title="">original port</var>.</p></li>
-
    <li><p><span>Create a new <code>MessagePort</code> object</span>
    owned by <var title="">owner</var>, and let <var title="">new
    port</var> be that object.</p></li>
 
+   <li><p><span>Move all the events in the <span>port message
+   queue</span> of <var title="">original port</var> to the <span>port
+   message queue</span> of <var title="">new port</var>, if any,
+   leaving the <var title="">new port</var>'s <span>port message
+   queue</span> in its initial closed state.</p></li>
+
    <li><p><span>Entangle</span> the <var title="">remote port</var>
    and <var title="">new port</var> objects. The <var
-   title="">original port</var> object will have its <code
-   title="dom-MessagePort-active">active</code> attribute permanently
-   set to false by this process.</p></li>
+   title="">original port</var> object will be unentangled by this
+   process.</p></li>
 
-   <li><p>Let the <code title="dom-MessagePort-active">active</code>
-   attribute of the <var title="">new port</var> object have the same
-   value as <var title="">original status</var>.</p></li> <!-- we
-   don't throw if it's false, because it might become true again,
-   e.g. if you're sending a port that is entangled with a port that's
-   associated with a document that's currently not the active document
-   of its iframe, but which hasn't been discarded yet -->
-
    <li><p>Return <var title="">new port</var>. It is the
    clone.</p></li>
 
@@ -41373,8 +41319,8 @@
   <hr>
 
   <p>The <dfn title="dom-MessagePort-active"><code>active</code></dfn>
-  attribute must return the last value that it was set to according to
-  the rules of this specification.</p>
+  attribute must return true if the port is entangled, and false
+  otherwise.</p>
 
   <hr>
 
@@ -41391,12 +41337,11 @@
    <li><p>Let <var title="">data port</var> be the method's second
    argument, if any.</p></li>
 
-   <li><p>If the <var title="">source port</var>'s <code
-   title="dom-MessagePort-active">active</code> attribute is false,
-   then return false and abort these steps.</p></li> <!-- we don't
-   raise an exception because this attribute can become false at a
-   moment's notice, but we return false so that the caller can check
-   whether the port was active at time of calling without a race
+   <li><p>If the <var title="">source port</var> is not entangled with
+   another port, then return false and abort these steps.</p></li>
+   <!-- we don't raise an exception because this can happen moment's
+   notice, but we return false so that the caller can check whether
+   the port was active at time of calling without a race
    condition. -->
 
    <li><p>Let <var title="">target port</var> be the port with which
@@ -41439,16 +41384,9 @@
    <li><p>Return true from the method, but continue with these
    steps.</p></li>
 
-   <li><p>Wait for all scripts in the conceptual thread that the
-   <span>script execution context</span> that owns the <var
-   title="">target port</var> belongs to have executed to
-   completion. If this never happens (e.g. the relevant <span>browsing
-   context</span> is closed by the user before the event can be
-   dispatched), then discard the event.</p></li><!-- XXX queue -->
+   <li><p>Add the event to the <span>port message queue</span> of <var
+   title="">target port</var>.</p></li>
 
-   <li><p>Dispatch the event at the <var title="">target port</var>
-   object.</p></li>
-
   </ol>
 
   <p class="big-issue">People often request the ability to send
@@ -41457,6 +41395,19 @@
 
   <hr>
 
+  <p>The <dfn title="dom-MessagePort-close"><code>start()</code></dfn>
+  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>
+
+  <hr>
+
   <p>The <dfn title="dom-MessagePort-close"><code>close()</code></dfn>
   method, when called on a port <var title="">local port</var> that is
   entangled with another port, must cause the user agents to run the
@@ -41466,10 +41417,6 @@
 
    <li><p>Unentangle the two ports.</p></li>
 
-   <li><p>Set both ports' <code
-   title="dom-messageport-active">active</code> attribute to
-   false.</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
@@ -41492,10 +41439,21 @@
 
    <dt><dfn title="handler-MessagePort-onmessage"><code>onmessage</code></dfn></dt>
 
-   <dd><p>Must be invoked whenever a <code
-   title="event-MessagePort-message">message</code> event is targeted
-   at or bubbles through the <code>MessagePort</code> object.</p></dd>
+   <dd>
 
+    <p>Must be invoked whenever a <code
+    title="event-MessagePort-message">message</code> event is targeted
+    at or bubbles through the <code>MessagePort</code> object.</p>
+
+    <p>The first time a <code>MessagePort</code> object's
+    <codetitle="handler-MessagePort-onmessage">onmessage</code>
+    attribute is set, the port's <span>port message queue</span> must
+    be opened, as if the <code
+    title="dom-MessagePort-start">start()</code> method had been
+    called.</p>
+
+   </dd>
+
    <dt><dfn title="handler-MessagePort-onload"><code>onload</code></dfn></dt>
 
    <dd><p>Must be invoked whenever a <code
@@ -41528,46 +41486,18 @@
 
   <h5>Ports and browsing contexts</h5>
 
-  <p>During <span title="traverse the history">session history
-  traversal</span> (e.g. when a user <span
-  title="navigate">navigates</span> a <span>browsing context</span> to
-  another page, or goes back to a previous page), the user agent will
-  have to <a href="#port-traversal-deactivation">deactivate</a> and/or
-  <a href="#port-traversal-reactivation">reactivate</a> some
-  ports.</p>
+  <p>Ports are unentangled when the <code>Document</code> that was the
+  <span>active document</span> of the <span>browsing context</span>
+  corresponding to the <code>Window</code> object that owns them is
+  <span title="discard a document">discarded</span>.</p>
 
-  <p>Ports are deactivated and unentangled when the
-  <code>Document</code> that was the <span>active document</span> of
-  the <span>browsing context</span> corresponding to the
-  <code>Window</code> object that owns them is <span title="discard a
-  document">discarded</span>.</p>
 
-  <p>To <dfn>deactivate a port</dfn> <var title="">local port</var>
-  that is entangled with a second port <var title="">remote
-  port</var>, the user agent must set the <code
-  title="dom-MessagePort-active">active</code> attribute of the <var
-  title="">remote port</var> to false.</p>
 
-  <p>To <dfn>reactivate a port</dfn> <var title="">local port</var>
-  that is entangled with a second port <var title="">remote
-  port</var>, the user agent must set the <code
-  title="dom-MessagePort-active">active</code> attribute of the <var
-  title="">remote port</var> to true.</p>
-
-  <p class="note">It's important to note that activating or
-  deactivating a port actually changes the <code
-  title="dom-MessagePort-active">active</code> attribute of the port's
-  entangled port, not its own attribute.</p>
-
-
-
   <h5>Ports and garbage collection</h5>
 
   <p>User agents must act as if <code>MessagePort</code> objects have
   a strong reference to their entangled <code>MessagePort</code>
-  object so long as that other <code>MessagePort</code> object has any
-  <code title="event-message">message</code> or <code
-  title="event-unload">unload</code> event listeners registered.</p>
+  object.</p>
 
   <div class="note">
 
@@ -41583,10 +41513,10 @@
   </div>
 
   <p>When an entangled message port is about to be garbage collected,
-  it must be <span>deactivated</span> and unentangled, so that the two
-  ports are no longer related and so that the other port's <code
-  title="dom-MessagePort-active">active</code> attribute is set to
-  false.</p>
+  it must be unentangled. Because of the aforementioned strong
+  reference, this can only happen if either both ports are about to be
+  garbage collected as a pair, or if the entire <span>script execution
+  context</span> of the port is being discarded.</p>
 
 
 




More information about the Commit-Watchers mailing list