[html5] r6154 - [giow] (0) WebSocket: Add support for close codes and reasons

whatwg at whatwg.org whatwg at whatwg.org
Fri May 27 14:38:56 PDT 2011


Author: ianh
Date: 2011-05-27 14:38:55 -0700 (Fri, 27 May 2011)
New Revision: 6154

Modified:
   complete.html
   index
   source
Log:
[giow] (0) WebSocket: Add support for close codes and reasons

Modified: complete.html
===================================================================
--- complete.html	2011-05-27 00:31:28 UTC (rev 6153)
+++ complete.html	2011-05-27 21:38:55 UTC (rev 6154)
@@ -60437,7 +60437,7 @@
   <code><a href=#about:blank>about:blank</a></code> <code><a href=#document>Document</a></code> to another, with
   <a href=#replacement-enabled>replacement enabled</a>. Second, a <code><a href=#document>Document</a></code>
   can end up being reused for several <code><a href=#window>Window</a></code> objects when
-  the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> methos is
+  the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> method is
   used, such that the mapping is then 1-to-many.</p>
 
   <p class=note>A <code><a href=#document>Document</a></code> does not necessarily have a
@@ -64367,12 +64367,15 @@
   </ol><p>This specification defines the following <dfn id=unloading-document-cleanup-steps>unloading document
   cleanup steps</dfn>. Other specifications can define more.</p>
 
-  <ol><li><p><span>Close the WebSocket connection</span> of any
+  <ol><li><p><span>Start the WebSocket closing handshake</span> of any
    <code><a href=#websocket>WebSocket</a></code> objects that were created by the <code title=dom-WebSocket><a href=#dom-websocket>WebSocket()</a></code> constructor visible on the
-   <code><a href=#document>Document</a></code>'s <code><a href=#window>Window</a></code> object. If this
-   affected any <code><a href=#websocket>WebSocket</a></code> objects, the set
-   <code><a href=#document>Document</a></code>'s <var title=concept-document-salvageable>salvageable</var> state to
-   false.
+   <code><a href=#document>Document</a></code>'s <code><a href=#window>Window</a></code> object, with the status
+   code<!--CLOSE CODE--> set to 1001. If this affected any
+   <code><a href=#websocket>WebSocket</a></code> objects, the set <code><a href=#document>Document</a></code>'s
+   <var title=concept-document-salvageable>salvageable</var> state
+   to false.
+
+
    </li>
 
    <li><p>If the <code><a href=#document>Document</a></code>'s <var title=concept-document-salvageable>salvageable</var> state is
@@ -78836,7 +78839,7 @@
            attribute <a href=#function>Function</a> <a href=#handler-websocket-onerror title=handler-WebSocket-onerror>onerror</a>;
            attribute <a href=#function>Function</a> <a href=#handler-websocket-onclose title=handler-WebSocket-onclose>onclose</a>;
   readonly attribute DOMString <a href=#dom-websocket-protocol title=dom-WebSocket-protocol>protocol</a>;
-  void <a href=#dom-websocket-close title=dom-WebSocket-close>close</a>();
+  void <a href=#dom-websocket-close title=dom-WebSocket-close>close</a>(in optional unsigned short code, in optional DOMString reason);
 
   // messaging
            attribute <a href=#function>Function</a> <a href=#handler-websocket-onmessage title=handler-WebSocket-onmessage>onmessage</a>;
@@ -78982,74 +78985,91 @@
   to perform subprotocol negotiation.</p>
 
   <p>The <dfn id=dom-websocket-close title=dom-WebSocket-close><code>close()</code></dfn>
-  method must run the first matching steps from the following list:</p>
+  method must run the following steps:</p>
 
-  <dl class=switch><dt>If the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code>
-   attribute is in the <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2) or <code title=dom-WebSocket-CLOSED><a href=#dom-websocket-closed>CLOSED</a></code> (3) state</dt>
+  <ol><li><p>If the method's first argument is present but is not an
+   integer equal to 1000 or in the range 3000 to 4999, throw an
+   <code><a href=#invalid_access_err>INVALID_ACCESS_ERR</a></code> exception and abort these
+   steps.</li>
 
-   <dd>
+   <li><p>Run the first matching steps from the following list:</p>
 
-    <p>Do nothing.</p>
+    <dl class=switch><dt>If the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code>
+     attribute is in the <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2) or <code title=dom-WebSocket-CLOSED><a href=#dom-websocket-closed>CLOSED</a></code> (3) state</dt>
 
-    <p class=note>The connection is already closing or is already
-    closed. If it has not already, a <code title=event-close>close</code> event will eventually fire <a href=#closeWebSocket>as described below</a>.</p>
+     <dd>
 
-   </dd>
+      <p>Do nothing.</p>
 
+      <p class=note>The connection is already closing or is already
+      closed. If it has not already, a <code title=event-close>close</code> event will eventually fire <a href=#closeWebSocket>as described below</a>.</p>
 
-   <dt>If the WebSocket connection is not yet <span title="WebSocket
-   connection is established">established</span> <a href=#refsWSP>[WSP]</a></dt>
+     </dd>
 
-   <dd>
 
-    <p><span>Fail the WebSocket connection</span> and set the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's
-    value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2).
-    <a href=#refsWSP>[WSP]</a></p>
+     <dt>If the WebSocket connection is not yet <span title="WebSocket
+     connection is established">established</span> <a href=#refsWSP>[WSP]</a></dt>
 
-    <p class=note>The "<span>fail the WebSocket connection</span>"
-    algorithm invokes the "<span>close the WebSocket
-    connection</span>" algorithm, which then establishes that the
-    "<span>WebSocket connection is closed</span>", which fires the
-    <code title=event-close>close</code> event <a href=#closeWebSocket>as described below</a>.</p>
+     <dd>
 
-   </dd>
+      <p><span>Fail the WebSocket connection</span> and set the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's
+      value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2).
+      <a href=#refsWSP>[WSP]</a></p>
 
+      <p class=note>The "<span>fail the WebSocket connection</span>"
+      algorithm invokes the "<span>close the WebSocket
+      connection</span>" algorithm, which then establishes that the
+      "<span>WebSocket connection is closed</span>", which fires the
+      <code title=event-close>close</code> event <a href=#closeWebSocket>as described below</a>.</p>
 
-   <dt>If the WebSocket closing handshake has not yet been <span title="the WebSocket closing handshake has
-   started">started</span> <a href=#refsWSP>[WSP]</a></dt>
+     </dd>
 
-   <dd>
 
-    <p><span>Start the WebSocket closing handshake</span> and set the
-    <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code>
-    attribute's value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2). <a href=#refsWSP>[WSP]</a></p>
+     <dt>If the WebSocket closing handshake has not yet been <span title="the WebSocket closing handshake has
+     started">started</span> <a href=#refsWSP>[WSP]</a></dt>
 
-    <p class=note>The "<span>start the WebSocket closing
-    handshake</span>" algorithm eventually invokes the "<span>close
-    the WebSocket connection</span>" algorithm, which then establishes
-    that the "<span>WebSocket connection is closed</span>", which
-    fires the <code title=event-close>close</code> event <a href=#closeWebSocket>as described below</a>.</p>
+     <dd>
 
-   </dd>
+      <p><span>Start the WebSocket closing handshake</span> and set the
+      <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code>
+      attribute's value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2). <a href=#refsWSP>[WSP]</a></p>
 
+      <p>If the first argument is present, then the status
+      code<!--CLOSE CODE--> to use in the WebSocket Close message must
+      be the integer given by the first argument. <a href=#refsWSP>[WSP]</a></p>
 
-   <dt>Otherwise</dt>
+      <p>If the second argument is also present, then it must be
+      encoded as UTF-8 and provided in the Close message after the
+      status code<!--CLOSE CODE-->. <a href=#refsWSP>[WSP]</a></p>
 
-   <dd>
+      <p class=note>The "<span>start the WebSocket closing
+      handshake</span>" algorithm eventually invokes the "<span>close
+      the WebSocket connection</span>" algorithm, which then establishes
+      that the "<span>WebSocket connection is closed</span>", which
+      fires the <code title=event-close>close</code> event <a href=#closeWebSocket>as described below</a>.</p>
 
-    <p>Set the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's
-    value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code>
-    (2).</p>
+     </dd>
 
-    <p class=note><span>The WebSocket closing handshake has
-    started</span>, and will eventually invokethe "<span>close the
-    WebSocket connection</span>" algorithm, which will establish that
-    the "<span>WebSocket connection is closed</span>", and thus the
-    <code title=event-close>close</code> event will fire, <a href=#closeWebSocket>as described below</a>.</p>
 
-   </dd>
+     <dt>Otherwise</dt>
 
-  </dl><hr><p>The <dfn id=dom-websocket-bufferedamount title=dom-WebSocket-bufferedAmount><code>bufferedAmount</code></dfn>
+     <dd>
+
+      <p>Set the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's
+      value to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code>
+      (2).</p>
+
+      <p class=note><span>The WebSocket closing handshake has
+      started</span>, and will eventually invokethe "<span>close the
+      WebSocket connection</span>" algorithm, which will establish that
+      the "<span>WebSocket connection is closed</span>", and thus the
+      <code title=event-close>close</code> event will fire, <a href=#closeWebSocket>as described below</a>.</p>
+
+     </dd>
+
+    </dl></li>
+
+  </ol><hr><p>The <dfn id=dom-websocket-bufferedamount title=dom-WebSocket-bufferedAmount><code>bufferedAmount</code></dfn>
   attribute must return the number of bytes of UTF-8 text that have
   been queued using <code title=dom-WebSocket-send><a href=#dom-websocket-send>send()</a></code> but
   that, as of the last time the <a href=#event-loop>event loop</a> started
@@ -79360,8 +79380,9 @@
   collected. <a href=#refsWSP>[WSP]</a></p>
 
   <p>If a <code><a href=#websocket>WebSocket</a></code> object is garbage collected while its
-  connection is still open, the user agent must <span>close the
-  WebSocket connection</span>. <a href=#refsWSP>[WSP]</a></p>
+  connection is still open, the user agent must <span>start the
+  WebSocket closing handshake</span>, with no status code<!--CLOSE
+  CODE--> for the Close message. <a href=#refsWSP>[WSP]</a></p>
 
 
 

Modified: index
===================================================================
--- index	2011-05-27 00:31:28 UTC (rev 6153)
+++ index	2011-05-27 21:38:55 UTC (rev 6154)
@@ -60457,7 +60457,7 @@
   <code><a href=#about:blank>about:blank</a></code> <code><a href=#document>Document</a></code> to another, with
   <a href=#replacement-enabled>replacement enabled</a>. Second, a <code><a href=#document>Document</a></code>
   can end up being reused for several <code><a href=#window>Window</a></code> objects when
-  the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> methos is
+  the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> method is
   used, such that the mapping is then 1-to-many.</p>
 
   <p class=note>A <code><a href=#document>Document</a></code> does not necessarily have a
@@ -64387,15 +64387,18 @@
   </ol><p>This specification defines the following <dfn id=unloading-document-cleanup-steps>unloading document
   cleanup steps</dfn>. Other specifications can define more.</p>
 
-  <ol><li><p><span>Close the WebSocket connection</span> of any
+  <ol><li><p><span>Start the WebSocket closing handshake</span> of any
    <code>WebSocket</code> objects that were created by the <code title=dom-WebSocket>WebSocket()</code> constructor visible on the
-   <code><a href=#document>Document</a></code>'s <code><a href=#window>Window</a></code> object. If this
-   affected any <code>WebSocket</code> objects, the set
-   <code><a href=#document>Document</a></code>'s <var title=concept-document-salvageable>salvageable</var> state to
-   false.
-   
+   <code><a href=#document>Document</a></code>'s <code><a href=#window>Window</a></code> object, with the status
+   code<!--CLOSE CODE--> set to 1001. If this affected any
+   <code>WebSocket</code> objects, the set <code><a href=#document>Document</a></code>'s
+   <var title=concept-document-salvageable>salvageable</var> state
+   to false.
+
+
    <a href=#refsWEBSOCKET>[WEBSOCKET]</a>
-   
+
+
    </li>
 
    <li><p>If the <code><a href=#document>Document</a></code>'s <var title=concept-document-salvageable>salvageable</var> state is

Modified: source
===================================================================
--- source	2011-05-27 00:31:28 UTC (rev 6153)
+++ source	2011-05-27 21:38:55 UTC (rev 6154)
@@ -68876,7 +68876,7 @@
   <code>about:blank</code> <code>Document</code> to another, with
   <span>replacement enabled</span>. Second, a <code>Document</code>
   can end up being reused for several <code>Window</code> objects when
-  the <code title="dom-document-open">document.open()</code> methos is
+  the <code title="dom-document-open">document.open()</code> method is
   used, such that the mapping is then 1-to-many.</p>
 
   <p class="note">A <code>Document</code> does not necessarily have a
@@ -73370,17 +73370,19 @@
 
   <ol>
 
-   <li><p><span>Close the WebSocket connection</span> of any
+   <li><p><span>Start the WebSocket closing handshake</span> of any
    <code>WebSocket</code> objects that were created by the <code
    title="dom-WebSocket">WebSocket()</code> constructor visible on the
-   <code>Document</code>'s <code>Window</code> object. If this
-   affected any <code>WebSocket</code> objects, the set
-   <code>Document</code>'s <var
-   title="concept-document-salvageable">salvageable</var> state to
-   false.
-   <!--END complete--><!--END epub-->
+   <code>Document</code>'s <code>Window</code> object, with the status
+   code<!--CLOSE CODE--> set to 1001. If this affected any
+   <code>WebSocket</code> objects, the set <code>Document</code>'s
+   <var title="concept-document-salvageable">salvageable</var> state
+   to false.
+
+<!--END complete--><!--END epub-->
    <a href="#refsWEBSOCKET">[WEBSOCKET]</a>
-   <!--START complete--><!--START epub-->
+<!--START complete--><!--START epub-->
+
    </p></li>
 
    <li><p>If the <code>Document</code>'s <var
@@ -89478,7 +89480,7 @@
            attribute <span>Function</span> <span title="handler-WebSocket-onerror">onerror</span>;
            attribute <span>Function</span> <span title="handler-WebSocket-onclose">onclose</span>;
   readonly attribute DOMString <span title="dom-WebSocket-protocol">protocol</span>;
-  void <span title="dom-WebSocket-close">close</span>();
+  void <span title="dom-WebSocket-close">close</span>(in optional unsigned short code, in optional DOMString reason);
 
   // messaging
            attribute <span>Function</span> <span title="handler-WebSocket-onmessage">onmessage</span>;
@@ -89651,90 +89653,112 @@
   to perform subprotocol negotiation.</p>
 
   <p>The <dfn title="dom-WebSocket-close"><code>close()</code></dfn>
-  method must run the first matching steps from the following list:</p>
+  method must run the following steps:</p>
 
-  <dl class="switch">
+  <ol>
 
-   <dt>If the <code title="dom-WebSocket-readyState">readyState</code>
-   attribute is in the <code
-   title="dom-WebSocket-CLOSING">CLOSING</code> (2) or <code
-   title="dom-WebSocket-CLOSED">CLOSED</code> (3) state</dt>
+   <li><p>If the method's first argument is present but is not an
+   integer equal to 1000 or in the range 3000 to 4999, throw an
+   <code>INVALID_ACCESS_ERR</code> exception and abort these
+   steps.</p></li>
 
-   <dd>
+   <li><p>Run the first matching steps from the following list:</p>
 
-    <p>Do nothing.</p>
+    <dl class="switch">
 
-    <p class="note">The connection is already closing or is already
-    closed. If it has not already, a <code
-    title="event-close">close</code> event will eventually fire <a
-    href="#closeWebSocket">as described below</a>.</p>
+     <dt>If the <code title="dom-WebSocket-readyState">readyState</code>
+     attribute is in the <code
+     title="dom-WebSocket-CLOSING">CLOSING</code> (2) or <code
+     title="dom-WebSocket-CLOSED">CLOSED</code> (3) state</dt>
 
-   </dd>
+     <dd>
 
+      <p>Do nothing.</p>
 
-   <dt>If the WebSocket connection is not yet <span title="WebSocket
-   connection is established">established</span> <a
-   href="#refsWSP">[WSP]</a></dt>
+      <p class="note">The connection is already closing or is already
+      closed. If it has not already, a <code
+      title="event-close">close</code> event will eventually fire <a
+      href="#closeWebSocket">as described below</a>.</p>
 
-   <dd>
+     </dd>
 
-    <p><span>Fail the WebSocket connection</span> and set the <code
-    title="dom-WebSocket-readyState">readyState</code> attribute's
-    value to <code title="dom-WebSocket-CLOSING">CLOSING</code> (2).
-    <a href="#refsWSP">[WSP]</a></p>
 
-    <p class="note">The "<span>fail the WebSocket connection</span>"
-    algorithm invokes the "<span>close the WebSocket
-    connection</span>" algorithm, which then establishes that the
-    "<span>WebSocket connection is closed</span>", which fires the
-    <code title="event-close">close</code> event <a
-    href="#closeWebSocket">as described below</a>.</p>
+     <dt>If the WebSocket connection is not yet <span title="WebSocket
+     connection is established">established</span> <a
+     href="#refsWSP">[WSP]</a></dt>
 
-   </dd>
+     <dd>
 
+      <p><span>Fail the WebSocket connection</span> and set the <code
+      title="dom-WebSocket-readyState">readyState</code> attribute's
+      value to <code title="dom-WebSocket-CLOSING">CLOSING</code> (2).
+      <a href="#refsWSP">[WSP]</a></p>
 
-   <dt>If the WebSocket closing handshake has not yet been <span
-   title="the WebSocket closing handshake has
-   started">started</span> <a href="#refsWSP">[WSP]</a></dt>
+      <p class="note">The "<span>fail the WebSocket connection</span>"
+      algorithm invokes the "<span>close the WebSocket
+      connection</span>" algorithm, which then establishes that the
+      "<span>WebSocket connection is closed</span>", which fires the
+      <code title="event-close">close</code> event <a
+      href="#closeWebSocket">as described below</a>.</p>
 
-   <dd>
+     </dd>
 
-    <p><span>Start the WebSocket closing handshake</span> and set the
-    <code title="dom-WebSocket-readyState">readyState</code>
-    attribute's value to <code
-    title="dom-WebSocket-CLOSING">CLOSING</code> (2). <a
-    href="#refsWSP">[WSP]</a></p>
 
-    <p class="note">The "<span>start the WebSocket closing
-    handshake</span>" algorithm eventually invokes the "<span>close
-    the WebSocket connection</span>" algorithm, which then establishes
-    that the "<span>WebSocket connection is closed</span>", which
-    fires the <code title="event-close">close</code> event <a
-    href="#closeWebSocket">as described below</a>.</p>
+     <dt>If the WebSocket closing handshake has not yet been <span
+     title="the WebSocket closing handshake has
+     started">started</span> <a href="#refsWSP">[WSP]</a></dt>
 
-   </dd>
+     <dd>
 
+      <p><span>Start the WebSocket closing handshake</span> and set the
+      <code title="dom-WebSocket-readyState">readyState</code>
+      attribute's value to <code
+      title="dom-WebSocket-CLOSING">CLOSING</code> (2). <a
+      href="#refsWSP">[WSP]</a></p>
 
-   <dt>Otherwise</dt>
+      <p>If the first argument is present, then the status
+      code<!--CLOSE CODE--> to use in the WebSocket Close message must
+      be the integer given by the first argument. <a
+      href="#refsWSP">[WSP]</a></p>
 
-   <dd>
+      <p>If the second argument is also present, then it must be
+      encoded as UTF-8 and provided in the Close message after the
+      status code<!--CLOSE CODE-->. <a href="#refsWSP">[WSP]</a></p>
 
-    <p>Set the <code
-    title="dom-WebSocket-readyState">readyState</code> attribute's
-    value to <code title="dom-WebSocket-CLOSING">CLOSING</code>
-    (2).</p>
+      <p class="note">The "<span>start the WebSocket closing
+      handshake</span>" algorithm eventually invokes the "<span>close
+      the WebSocket connection</span>" algorithm, which then establishes
+      that the "<span>WebSocket connection is closed</span>", which
+      fires the <code title="event-close">close</code> event <a
+      href="#closeWebSocket">as described below</a>.</p>
 
-    <p class="note"><span>The WebSocket closing handshake has
-    started</span>, and will eventually invokethe "<span>close the
-    WebSocket connection</span>" algorithm, which will establish that
-    the "<span>WebSocket connection is closed</span>", and thus the
-    <code title="event-close">close</code> event will fire, <a
-    href="#closeWebSocket">as described below</a>.</p>
+     </dd>
 
-   </dd>
 
-  </dl>
+     <dt>Otherwise</dt>
 
+     <dd>
+
+      <p>Set the <code
+      title="dom-WebSocket-readyState">readyState</code> attribute's
+      value to <code title="dom-WebSocket-CLOSING">CLOSING</code>
+      (2).</p>
+
+      <p class="note"><span>The WebSocket closing handshake has
+      started</span>, and will eventually invokethe "<span>close the
+      WebSocket connection</span>" algorithm, which will establish that
+      the "<span>WebSocket connection is closed</span>", and thus the
+      <code title="event-close">close</code> event will fire, <a
+      href="#closeWebSocket">as described below</a>.</p>
+
+     </dd>
+
+    </dl>
+
+   </li>
+
+  </ol>
+
   <hr>
 
   <p>The <dfn
@@ -90121,8 +90145,9 @@
   collected. <a href="#refsWSP">[WSP]</a></p>
 
   <p>If a <code>WebSocket</code> object is garbage collected while its
-  connection is still open, the user agent must <span>close the
-  WebSocket connection</span>. <a href="#refsWSP">[WSP]</a></p>
+  connection is still open, the user agent must <span>start the
+  WebSocket closing handshake</span>, with no status code<!--CLOSE
+  CODE--> for the Close message. <a href="#refsWSP">[WSP]</a></p>
 
 
 <!--END websocket-api-->




More information about the Commit-Watchers mailing list