mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 15:19:40 -05:00
fix: Expose ErrorEvent globally (#5222)
This commit is contained in:
parent
32aeec9630
commit
d16c7394cb
4 changed files with 73 additions and 31 deletions
|
@ -11,6 +11,7 @@ import * as promiseTypes from "./web/promise.ts";
|
|||
import * as customEvent from "./web/custom_event.ts";
|
||||
import * as domException from "./web/dom_exception.ts";
|
||||
import * as domFile from "./web/dom_file.ts";
|
||||
import * as errorEvent from "./web/error_event.ts";
|
||||
import * as event from "./web/event.ts";
|
||||
import * as eventTarget from "./web/event_target.ts";
|
||||
import * as formData from "./web/form_data.ts";
|
||||
|
@ -227,6 +228,7 @@ export const windowOrWorkerGlobalScopeProperties = {
|
|||
File: nonEnumerable(domFile.DomFileImpl),
|
||||
CustomEvent: nonEnumerable(customEvent.CustomEventImpl),
|
||||
DOMException: nonEnumerable(domException.DOMExceptionImpl),
|
||||
ErrorEvent: nonEnumerable(errorEvent.ErrorEventImpl),
|
||||
Event: nonEnumerable(event.EventImpl),
|
||||
EventTarget: nonEnumerable(eventTarget.EventTargetImpl),
|
||||
URL: nonEnumerable(url.URLImpl),
|
||||
|
|
|
@ -22,7 +22,8 @@ import * as denoNs from "./deno.ts";
|
|||
import * as denoUnstableNs from "./deno_unstable.ts";
|
||||
import * as webWorkerOps from "./ops/web_worker.ts";
|
||||
import { log, assert, immutableDefine } from "./util.ts";
|
||||
import { MessageEvent, ErrorEvent } from "./web/workers.ts";
|
||||
import { ErrorEventImpl as ErrorEvent } from "./web/error_event.ts";
|
||||
import { MessageEvent } from "./web/workers.ts";
|
||||
import { TextEncoder } from "./web/text_encoding.ts";
|
||||
import * as runtime from "./runtime.ts";
|
||||
import { internalObject, internalSymbol } from "./internals.ts";
|
||||
|
|
68
cli/js/web/error_event.ts
Normal file
68
cli/js/web/error_event.ts
Normal file
|
@ -0,0 +1,68 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { EventImpl as Event } from "./event.ts";
|
||||
import { defineEnumerableProps } from "./util.ts";
|
||||
|
||||
export class ErrorEventImpl extends Event implements ErrorEvent {
|
||||
#message: string;
|
||||
#filename: string;
|
||||
#lineno: number;
|
||||
#colno: number;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
#error: any;
|
||||
|
||||
get message(): string {
|
||||
return this.#message;
|
||||
}
|
||||
get filename(): string {
|
||||
return this.#filename;
|
||||
}
|
||||
get lineno(): number {
|
||||
return this.#lineno;
|
||||
}
|
||||
get colno(): number {
|
||||
return this.#colno;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
get error(): any {
|
||||
return this.#error;
|
||||
}
|
||||
|
||||
constructor(
|
||||
type: string,
|
||||
{
|
||||
bubbles,
|
||||
cancelable,
|
||||
composed,
|
||||
message = "",
|
||||
filename = "",
|
||||
lineno = 0,
|
||||
colno = 0,
|
||||
error = null,
|
||||
}: ErrorEventInit = {}
|
||||
) {
|
||||
super(type, {
|
||||
bubbles: bubbles,
|
||||
cancelable: cancelable,
|
||||
composed: composed,
|
||||
});
|
||||
|
||||
this.#message = message;
|
||||
this.#filename = filename;
|
||||
this.#lineno = lineno;
|
||||
this.#colno = colno;
|
||||
this.#error = error;
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag](): string {
|
||||
return "ErrorEvent";
|
||||
}
|
||||
}
|
||||
|
||||
defineEnumerableProps(ErrorEventImpl, [
|
||||
"message",
|
||||
"filename",
|
||||
"lineno",
|
||||
"colno",
|
||||
"error",
|
||||
]);
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue