@@ -812,7 +812,7 @@ dictionary WebSocketOpenInfo {
812
812
};
813
813
814
814
dictionary WebSocketCloseInfo {
815
- [Clamp] unsigned short code ;
815
+ [Clamp] unsigned short closeCode ;
816
816
USVString reason = "";
817
817
};
818
818
@@ -897,7 +897,7 @@ initially unset.
897
897
898
898
The stream can also be closed by calling {{WritableStream/abort()}}
899
899
{{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
901
901
[=the WebSocket connection close reason=] as with {{ReadableStream/cancel()}} above.
902
902
903
903
: {{WebSocketOpenInfo/extensions}}
@@ -908,19 +908,66 @@ initially unset.
908
908
909
909
: <code> |socket| . {{WebSocketStream/closed}} </code>
910
910
:: 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.
915
915
916
916
: <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
918
918
{{WebSocketCloseInfo/reason}} properties to indicate [=the WebSocket connection close code=] and
919
919
[=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
921
921
{{WebSocketCloseInfo/reason}} will be ignored.
922
922
</dl>
923
923
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
+
924
971
<h2 id="acks" class="no-num">Acknowledgments</h2>
925
972
926
973
Until the creation of this standard in 2021, the text here was maintained in the <a
0 commit comments