-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement WebSocketStream (#3560)
* start fixup fixup fixup * fixup * fixup * fixup * run wpts * fix 49 errors * fix 49 errors * fix 7 errors * fix 12 failures * fix 10 failures * fixup * fix 9 failures * fix 3 failures * fix 3 failures * fix rest of failures * fixup * mark timing test as flaky * spell * fixup * fixup * run the CI again! woo!
- Loading branch information
Showing
9 changed files
with
819 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use strict' | ||
|
||
const { webidl } = require('../../fetch/webidl') | ||
const { validateCloseCodeAndReason } = require('../util') | ||
const { kConstruct } = require('../../../core/symbols') | ||
const { kEnumerableProperty } = require('../../../core/util') | ||
|
||
class WebSocketError extends DOMException { | ||
#closeCode | ||
#reason | ||
|
||
constructor (message = '', init = undefined) { | ||
message = webidl.converters.DOMString(message, 'WebSocketError', 'message') | ||
|
||
// 1. Set this 's name to " WebSocketError ". | ||
// 2. Set this 's message to message . | ||
super(message, 'WebSocketError') | ||
|
||
if (init === kConstruct) { | ||
return | ||
} else if (init !== null) { | ||
init = webidl.converters.WebSocketCloseInfo(init) | ||
} | ||
|
||
// 3. Let code be init [" closeCode "] if it exists , or null otherwise. | ||
let code = init.closeCode ?? null | ||
|
||
// 4. Let reason be init [" reason "] if it exists , or the empty string otherwise. | ||
const reason = init.reason ?? '' | ||
|
||
// 5. Validate close code and reason with code and reason . | ||
validateCloseCodeAndReason(code, reason) | ||
|
||
// 6. If reason is non-empty, but code is not set, then set code to 1000 ("Normal Closure"). | ||
if (reason.length !== 0 && code === null) { | ||
code = 1000 | ||
} | ||
|
||
// 7. Set this 's closeCode to code . | ||
this.#closeCode = code | ||
|
||
// 8. Set this 's reason to reason . | ||
this.#reason = reason | ||
} | ||
|
||
get closeCode () { | ||
return this.#closeCode | ||
} | ||
|
||
get reason () { | ||
return this.#reason | ||
} | ||
|
||
/** | ||
* @param {string} message | ||
* @param {number|null} code | ||
* @param {string} reason | ||
*/ | ||
static createUnvalidatedWebSocketError (message, code, reason) { | ||
const error = new WebSocketError(message, kConstruct) | ||
error.#closeCode = code | ||
error.#reason = reason | ||
return error | ||
} | ||
} | ||
|
||
const { createUnvalidatedWebSocketError } = WebSocketError | ||
delete WebSocketError.createUnvalidatedWebSocketError | ||
|
||
Object.defineProperties(WebSocketError.prototype, { | ||
closeCode: kEnumerableProperty, | ||
reason: kEnumerableProperty, | ||
[Symbol.toStringTag]: { | ||
value: 'WebSocketError', | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
} | ||
}) | ||
|
||
module.exports = { WebSocketError, createUnvalidatedWebSocketError } |
Oops, something went wrong.