MCPcopy Create free account
hub / github.com/nodejs/node / close

Method close

deps/undici/src/lib/web/websocket/websocket.js:202–223  ·  view source on GitHub ↗

* @see https://websockets.spec.whatwg.org/#dom-websocket-close * @param {number|undefined} code * @param {string|undefined} reason

(code = undefined, reason = undefined)

Source from the content-addressed store, hash-verified

200 * @param {string|undefined} reason
201 */
202 close (code = undefined, reason = undefined) {
203 webidl.brandCheck(this, WebSocket)
204
205 const prefix = 'WebSocket.close'
206
207 if (code !== undefined) {
208 code = webidl.converters['unsigned short'](code, prefix, 'code', webidl.attributes.Clamp)
209 }
210
211 if (reason !== undefined) {
212 reason = webidl.converters.USVString(reason)
213 }
214
215 // 1. If code is the special value "missing", then set code to null.
216 code ??= null
217
218 // 2. If reason is the special value "missing", then set reason to the empty string.
219 reason ??= ''
220
221 // 3. Close the WebSocket with this, code, and reason.
222 closeWebSocketConnection(this.#handler, code, reason, true)
223 }
224
225 /**
226 * @see https://websockets.spec.whatwg.org/#dom-websocket-send

Callers

nothing calls this directly

Calls 3

brandCheckMethod · 0.80
USVStringMethod · 0.80
closeWebSocketConnectionFunction · 0.70

Tested by

no test coverage detected