Skip to content

Commit

Permalink
Add IDL for WebSocketError
Browse files Browse the repository at this point in the history
  • Loading branch information
ricea committed Jan 28, 2024
1 parent 811add2 commit d47f9ea
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ dictionary WebSocketOpenInfo {
};

dictionary WebSocketCloseInfo {
[Clamp] unsigned short code;
[Clamp] unsigned short closeCode;
USVString reason = "";
};

Expand Down Expand Up @@ -897,7 +897,7 @@ initially unset.

The stream can also be closed by calling {{WritableStream/abort()}}
{{WebSocketOpenInfo/writable}}. If the reason passed to {{WritableStream/abort()}} is a
{{WebSocketError]}}, then it will be used to set [=the WebSocket connection close code=] and
{{WebSocketError}}, then it will be used to set [=the WebSocket connection close code=] and
[=the WebSocket connection close reason=] as with {{ReadableStream/cancel()}} above.

: {{WebSocketOpenInfo/extensions}}
Expand All @@ -908,19 +908,66 @@ initially unset.

: <code>|socket| . {{WebSocketStream/closed}}</code>
:: A {{promise}} which resolves when the connection is closed. If the connection did not close
[=cleanly=] then the promise is rejected. When the connection closes [=cleanly=] the promise is
resolved with an object with properties {{WebSocketCloseInfo/code}} and
{{WebSocketCloseInfo/reason}}, giving [=the WebSocket connection close code=] and [=the WebSocket
connection close reason=] that were supplied by the server.
[=cleanly=] then the promise is rejected with a {{WebSocketError}}. When the connection closes
[=cleanly=] the promise is resolved with an object with properties {{WebSocketCloseInfo/closeCode}}
and {{WebSocketCloseInfo/reason}}, giving [=the WebSocket connection close code=] and [=the
WebSocket connection close reason=] that were supplied by the server.

: <code>|socket| . {{WebSocketStream/close()}}</code>
:: Close the connection, optionally supplying an object with {{WebSocketCloseInfo/code}} and
:: Close the connection, optionally supplying an object with {{WebSocketCloseInfo/closeCode}} and
{{WebSocketCloseInfo/reason}} properties to indicate [=the WebSocket connection close code=] and
[=the WebSocket connection close reason=] that will be sent to the remote server. If the handshake
is still in progress then it will be aborted and {{WebSocketCloseInfo/code}} and
is still in progress then it will be aborted and {{WebSocketCloseInfo/closeCode}} and
{{WebSocketCloseInfo/reason}} will be ignored.
</dl>



# The {{WebSocketError}} interface # {#the-websocketevent-interface}

<dfn interface>WebSocketError</dfn> is a subclass of {{DOMException}}
that represents the information associated with closing a WebSocket.

<xmp class="idl">
[
Exposed=(Window,Worker),
] interface WebSocketError : DOMException {
constructor(optional DOMString message = "",
optional WebSocketCloseInfo init = {});

readonly attribute unsigned short? closeCode;
readonly attribute USVString reason;
};
</xmp>

A {{WebSocketError}} object has an associated <dfn>closeCode</dfn>.

A {{WebSocketError}} object has an associated <dfn>reason</dfn>.

<dl class="domintro non-normative">
: <code>|error| = new {{WebSocketError/constructor(message, init)|WebSocketError}}([|message| [,
|init| ] ]</code>
:: Creates a new {{WebSocketError}} object.

|message| is a string which will be used to initialize the {{DOMException/message}} attribute of
the base class.

The |init| argument is an object whose properties can be set as follows:

: {{WebSocketCloseInfo/closeCode}}
:: A number, either 1000 or any integer in the range 3000 to 4999, inclusive. Any other number
will result in an "{{InvalidAccessError}}" {{DOMException}}.
: {{WebSocketCloseInfo/reason}}
:: A string. Must be 123 bytes or less when converted to [=UTF-8=]. A longer string will result in
a "{{SyntaxError}}" {{DOMException}} being thrown.

: <code>|error| . {{WebSocketError/closeCode}}</code>
:: Returns the [=the WebSocket connection close code=].

: <code>|error| . {{WebSocketError/reason}}</code>
:: Returns the [=the WebSocket connection close reason=].
</dl>

<h2 id="acks" class="no-num">Acknowledgments</h2>

Until the creation of this standard in 2021, the text here was maintained in the <a
Expand Down

0 comments on commit d47f9ea

Please sign in to comment.