Skip to content

Commit 4f18b15

Browse files
committed
websocket: use isClosed and isClosing in websocket.close()
1 parent 5600aa1 commit 4f18b15

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

lib/web/websocket/util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { MessageEvent, ErrorEvent } = require('./events')
88

99
/**
1010
* @param {import('./websocket').WebSocket} ws
11+
* @returns {boolean}
1112
*/
1213
function isEstablished (ws) {
1314
// If the server's response is validated as provided for above, it is
@@ -18,6 +19,7 @@ function isEstablished (ws) {
1819

1920
/**
2021
* @param {import('./websocket').WebSocket} ws
22+
* @returns {boolean}
2123
*/
2224
function isClosing (ws) {
2325
// Upon either sending or receiving a Close control frame, it is said
@@ -28,6 +30,7 @@ function isClosing (ws) {
2830

2931
/**
3032
* @param {import('./websocket').WebSocket} ws
33+
* @returns {boolean}
3134
*/
3235
function isClosed (ws) {
3336
return ws[kReadyState] === states.CLOSED

lib/web/websocket/websocket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const {
1313
kSentClose,
1414
kByteParser
1515
} = require('./symbols')
16-
const { isEstablished, isClosing, isValidSubprotocol, failWebsocketConnection, fireEvent } = require('./util')
16+
const { isEstablished, isClosing, isValidSubprotocol, failWebsocketConnection, fireEvent, isClosed } = require('./util')
1717
const { establishWebSocketConnection } = require('./connection')
1818
const { WebsocketFrameSend } = require('./frame')
1919
const { ByteParser } = require('./receiver')
@@ -184,7 +184,7 @@ class WebSocket extends EventTarget {
184184
}
185185

186186
// 3. Run the first matching steps from the following list:
187-
if (this[kReadyState] === WebSocket.CLOSING || this[kReadyState] === WebSocket.CLOSED) {
187+
if (isClosing(this) || isClosed(this)) {
188188
// If this's ready state is CLOSING (2) or CLOSED (3)
189189
// Do nothing.
190190
} else if (!isEstablished(this)) {

0 commit comments

Comments
 (0)