mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(ext/websocket): don't throw exception when sending to closed socket (#26932)
[The WebSocket specification for the `send` function](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send) says: > The browser will throw an exception if you call `send()` when the connection is in the `CONNECTING` state. If you call `send()` when the connection is in the `CLOSING` or `CLOSED` states, the browser will silently discard the data. and: > ### Exceptions > > `InvalidStateError` [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException) > > Thrown if [`WebSocket.readyState`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState) is `CONNECTING`. This pull request fixes the current behavior to match the specification. Also, I believe it fixes #17586.
This commit is contained in:
parent
a19b3f44d4
commit
8f7787f81b
3 changed files with 22 additions and 3 deletions
|
@ -330,10 +330,14 @@ class WebSocket extends EventTarget {
|
|||
webidl.requiredArguments(arguments.length, 1, prefix);
|
||||
data = webidl.converters.WebSocketSend(data, prefix, "Argument 1");
|
||||
|
||||
if (this[_readyState] !== OPEN) {
|
||||
if (this[_readyState] === CONNECTING) {
|
||||
throw new DOMException("'readyState' not OPEN", "InvalidStateError");
|
||||
}
|
||||
|
||||
if (this[_readyState] !== OPEN) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this[_sendQueue].length === 0) {
|
||||
// Fast path if the send queue is empty, for example when only synchronous
|
||||
// data is being sent.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue