diff options
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/globals.ts | 2 | ||||
-rw-r--r-- | cli/js/runtime_worker.ts | 3 | ||||
-rw-r--r-- | cli/js/web/error_event.ts | 68 | ||||
-rw-r--r-- | cli/js/web/workers.ts | 31 |
4 files changed, 73 insertions, 31 deletions
diff --git a/cli/js/globals.ts b/cli/js/globals.ts index be327722c..28910d76b 100644 --- a/cli/js/globals.ts +++ b/cli/js/globals.ts @@ -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), diff --git a/cli/js/runtime_worker.ts b/cli/js/runtime_worker.ts index 18f8841f9..ed735fd52 100644 --- a/cli/js/runtime_worker.ts +++ b/cli/js/runtime_worker.ts @@ -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"; diff --git a/cli/js/web/error_event.ts b/cli/js/web/error_event.ts new file mode 100644 index 000000000..fbdd19fb5 --- /dev/null +++ b/cli/js/web/error_event.ts @@ -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", +]); diff --git a/cli/js/web/workers.ts b/cli/js/web/workers.ts index 6fcab3fe3..1e0762932 100644 --- a/cli/js/web/workers.ts +++ b/cli/js/web/workers.ts @@ -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); |