-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enumerable implement some more implement close finish open run WPTs update wpts and fix 9/19 failures fix most remaining failures fix remaining test failures fix writing fix: implement writing completely fixup fixup
- Loading branch information
Showing
14 changed files
with
1,189 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
'use strict' | ||
|
||
const { kEnumerableProperty } = require('../../../core/util') | ||
const { webidl } = require('../../fetch/webidl') | ||
const { validateCloseCodeAndReason } = require('../util') | ||
|
||
/** | ||
* @see https://whatpr.org/websockets/48/7b748d3...7b81f79.html#websocketerror | ||
*/ | ||
class WebSocketError extends DOMException { | ||
/** @type {string} */ | ||
#reason | ||
/** @type {number|null} */ | ||
#closeCode = null | ||
|
||
/** | ||
* @param {string} message | ||
* @param {import('./websocketstream').WebSocketCloseInfo} init | ||
*/ | ||
constructor (message = '', init = {}) { | ||
super(message, 'WebSocketError') | ||
|
||
message = webidl.converters.DOMString(message) | ||
init = webidl.converters.WebSocketCloseInfo(init) | ||
|
||
// 1. Set this 's name to " WebSocketError ". | ||
// 2. Set this 's message to message . | ||
|
||
// 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) 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 | ||
} | ||
} | ||
|
||
Object.defineProperties(WebSocketError.prototype, { | ||
closeCode: kEnumerableProperty, | ||
reason: kEnumerableProperty | ||
}) | ||
|
||
webidl.converters.WebSocketCloseInfo = webidl.dictionaryConverter([ | ||
{ | ||
converter: webidl.nullableConverter((V) => webidl.converters['unsigned short'](V, { enforceRange: true })), | ||
key: 'closeCode' | ||
}, | ||
{ | ||
converter: webidl.converters.USVString, | ||
key: 'reason', | ||
defaultValue: '' | ||
} | ||
]) | ||
|
||
module.exports = { | ||
WebSocketError | ||
} |
Oops, something went wrong.