Skip to content

Commit 69bae4f

Browse files
committed
Add IDL for WebSocketError
1 parent 96baeed commit 69bae4f

File tree

1 file changed

+55
-8
lines changed

1 file changed

+55
-8
lines changed

index.bs

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ dictionary WebSocketOpenInfo {
812812
};
813813

814814
dictionary WebSocketCloseInfo {
815-
[Clamp] unsigned short code;
815+
[Clamp] unsigned short closeCode;
816816
USVString reason = "";
817817
};
818818

@@ -897,7 +897,7 @@ initially unset.
897897

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

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

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

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

924+
925+
926+
# The {{WebSocketError}} interface # {#the-websocketevent-interface}
927+
928+
<dfn interface>WebSocketError</dfn> is a subclass of {{DOMException}}
929+
that represents the information associated with closing a WebSocket.
930+
931+
<xmp class="idl">
932+
[
933+
Exposed=(Window,Worker),
934+
] interface WebSocketError : DOMException {
935+
constructor(optional DOMString message = "",
936+
optional WebSocketCloseInfo init = {});
937+
938+
readonly attribute unsigned short? closeCode;
939+
readonly attribute USVString reason;
940+
};
941+
</xmp>
942+
943+
A {{WebSocketError}} object has an associated <dfn>closeCode</dfn>.
944+
945+
A {{WebSocketError}} object has an associated <dfn>reason</dfn>.
946+
947+
<dl class="domintro non-normative">
948+
: <code>|error| = new {{WebSocketError/constructor(message, init)|WebSocketError}}([|message| [,
949+
|init| ] ]</code>
950+
:: Creates a new {{WebSocketError}} object.
951+
952+
|message| is a string which will be used to initialize the {{DOMException/message}} attribute of
953+
the base class.
954+
955+
The |init| argument is an object whose properties can be set as follows:
956+
957+
: {{WebSocketCloseInfo/closeCode}}
958+
:: A number, either 1000 or any integer in the range 3000 to 4999, inclusive. Any other number
959+
will result in an "{{InvalidAccessError}}" {{DOMException}}.
960+
: {{WebSocketCloseInfo/reason}}
961+
:: A string. Must be 123 bytes or less when converted to [=UTF-8=]. A longer string will result in
962+
a "{{SyntaxError}}" {{DOMException}} being thrown.
963+
964+
: <code>|error| . {{WebSocketError/closeCode}}</code>
965+
:: Returns the [=the WebSocket connection close code=].
966+
967+
: <code>|error| . {{WebSocketError/reason}}</code>
968+
:: Returns the [=the WebSocket connection close reason=].
969+
</dl>
970+
924971
<h2 id="acks" class="no-num">Acknowledgments</h2>
925972

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

0 commit comments

Comments
 (0)