This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 12912 - Close status code is an unsigned short
Summary: Close status code is an unsigned short
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebSocket API (editor: Ian Hickson) (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-08 17:17 UTC by Adrian Bateman [MSFT]
Modified: 2011-06-22 01:30 UTC (History)
5 users (show)

See Also:


Attachments

Description Adrian Bateman [MSFT] 2011-06-08 17:17:20 UTC
The code argument to the close() method [1] should be an unsigned short to match the protocol spec [2]. This should also be reflected in the CloseEvent [3].

The protocol document says:

      If there is a body, the first two bytes of the body
      MUST be a 2-byte integer (in network byte order)
      representing a status code defined in Section 7.4.


[1] http://dev.w3.org/html5/websockets/#the-websocket-interface
[2] http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07#section-4.5.1
[3] http://dev.w3.org/html5/websockets/#closeevent
Comment 1 Ian 'Hixie' Hickson 2011-06-21 22:40:35 UTC
Why should 65535 throw INVALID_ACCESS_ERR but 66535 send the code 1000? I guess one could ask the same of why 4294967295 should throw INVALID_ACCESS_ERR when 4294968295 sends the code 1000... Maybe the solution is to add [Clamp] to the interface.

I've changed it to 'unsigned short' with [Clamp].

cc'ing heycam for sanity check.

(Note that this makes the CloseEvent interface less useful, since anyone reusing it now is limited to 2**16 codes instead of 2**32, but I guess that's not a big deal.)
Comment 2 contributor 2011-06-21 22:42:11 UTC
Checked in as WHATWG revision r6268.
Check-in comment: WebSocket close code can fit in an unsigned short, so use that instead.
http://html5.org/tools/web-apps-tracker?from=6267&to=6268
Comment 3 Cameron McCormack 2011-06-21 23:53:41 UTC
(Not being overly familiar with the Web Sockets protocol: is the 2-byte integer closing code meant to be signed or unsigned?  All other instances of the word "integer" in the Internet-Draft are prefaced with "unsigned", so does that mean the bare "integer" for the code means it is signed?)

I introduced [Clamp] in Web IDL to resolve the situation where for compatibility reasons, the way that JS Number values are converted into octets on CanvasPixelArray needed to be different from the default.  I don't see why close() needs different conversion behaviour from the default that Web IDL uses.
Comment 4 Ian Fette [Google] 2011-06-22 01:30:22 UTC
Bug in the protocol. It should say "unsigned" in the protocol. I will fix that.