fix: Expose ErrorEvent globally (#5222)

This commit is contained in:
Kitson Kelly 2020-05-11 22:28:13 +10:00 committed by GitHub
parent 32aeec9630
commit d16c7394cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 31 deletions

View file

@ -11,6 +11,7 @@ import { TextDecoder, TextEncoder } from "./text_encoding.ts";
/*
import { blobURLMap } from "./web/url.ts";
*/
import { ErrorEventImpl as ErrorEvent } from "./error_event.ts";
import { EventImpl as Event } from "./event.ts";
import { EventTargetImpl as EventTarget } from "./event_target.ts";
@ -41,36 +42,6 @@ export class MessageEvent extends Event {
}
}
export interface ErrorEventInit extends EventInit {
message?: string;
filename?: string;
lineno?: number;
colno?: number;
error?: any;
}
export class ErrorEvent extends Event {
readonly message: string;
readonly filename: string;
readonly lineno: number;
readonly colno: number;
readonly error: any;
constructor(type: string, eventInitDict?: ErrorEventInit) {
super(type, {
bubbles: eventInitDict?.bubbles ?? false,
cancelable: eventInitDict?.cancelable ?? false,
composed: eventInitDict?.composed ?? false,
});
this.message = eventInitDict?.message ?? "";
this.filename = eventInitDict?.filename ?? "";
this.lineno = eventInitDict?.lineno ?? 0;
this.colno = eventInitDict?.colno ?? 0;
this.error = eventInitDict?.error ?? null;
}
}
function encodeMessage(data: any): Uint8Array {
const dataJson = JSON.stringify(data);
return encoder.encode(dataJson);