1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-27 16:10:57 -05:00

fix(ext/websocket): initialize error attribute of WebSocket ErrorEvent (#26796)

Fixes https://github.com/denoland/deno/issues/26216

Not required by the spec but Discord.js depends on it, see
https://github.com/denoland/deno/issues/26216#issuecomment-2466060306
This commit is contained in:
Divy Srivastava 2024-11-12 17:10:07 +05:30 committed by GitHub
parent c3c2b37966
commit 3b99f6833c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -28,6 +28,7 @@ const {
ArrayPrototypePush, ArrayPrototypePush,
ArrayPrototypeShift, ArrayPrototypeShift,
ArrayPrototypeSome, ArrayPrototypeSome,
Error,
ErrorPrototypeToString, ErrorPrototypeToString,
ObjectDefineProperties, ObjectDefineProperties,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
@ -488,8 +489,11 @@ class WebSocket extends EventTarget {
/* error */ /* error */
this[_readyState] = CLOSED; this[_readyState] = CLOSED;
const message = op_ws_get_error(rid);
const error = new Error(message);
const errorEv = new ErrorEvent("error", { const errorEv = new ErrorEvent("error", {
message: op_ws_get_error(rid), error,
message,
}); });
this.dispatchEvent(errorEv); this.dispatchEvent(errorEv);

View file

@ -453,7 +453,8 @@ Deno.test("invalid server", async () => {
const { promise, resolve } = Promise.withResolvers<void>(); const { promise, resolve } = Promise.withResolvers<void>();
const ws = new WebSocket("ws://localhost:2121"); const ws = new WebSocket("ws://localhost:2121");
let err = false; let err = false;
ws.onerror = () => { ws.onerror = (e) => {
assert("error" in e);
err = true; err = true;
}; };
ws.onclose = () => { ws.onclose = () => {