From 7aba07cc7711adfa774afd8e77695f386127c4bc Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 20 Oct 2020 05:05:42 +0100 Subject: fix(cli/worker): Print error stacks from the origin Worker (#7987) Fixes #4728 --- op_crates/web/03_global_interfaces.js | 66 +++++++++++++++++++++++++++++++++++ op_crates/web/lib.rs | 4 +++ 2 files changed, 70 insertions(+) create mode 100644 op_crates/web/03_global_interfaces.js (limited to 'op_crates/web') diff --git a/op_crates/web/03_global_interfaces.js b/op_crates/web/03_global_interfaces.js new file mode 100644 index 000000000..f900e7160 --- /dev/null +++ b/op_crates/web/03_global_interfaces.js @@ -0,0 +1,66 @@ +((window) => { + const { EventTarget } = window; + + const illegalConstructorKey = Symbol("illegalConstuctorKey"); + + class Window extends EventTarget { + constructor(key) { + if (key !== illegalConstructorKey) { + throw new TypeError("Illegal constructor."); + } + } + + get [Symbol.toStringTag]() { + return "Window"; + } + } + + class WorkerGlobalScope extends EventTarget { + constructor(key) { + if (key != illegalConstructorKey) { + throw new TypeError("Illegal constructor."); + } + } + + get [Symbol.toStringTag]() { + return "WorkerGlobalScope"; + } + } + + class DedicatedWorkerGlobalScope extends WorkerGlobalScope { + constructor(key) { + if (key != illegalConstructorKey) { + throw new TypeError("Illegal constructor."); + } + } + + get [Symbol.toStringTag]() { + return "DedicatedWorkerGlobalScope"; + } + } + + window.__bootstrap = (window.__bootstrap || {}); + window.__bootstrap.globalInterfaces = { + DedicatedWorkerGlobalScope, + Window, + WorkerGlobalScope, + dedicatedWorkerGlobalScopeConstructorDescriptor: { + configurable: true, + enumerable: false, + value: DedicatedWorkerGlobalScope, + writable: true, + }, + windowConstructorDescriptor: { + configurable: true, + enumerable: false, + value: Window, + writable: true, + }, + workerGlobalScopeConstructorDescriptor: { + configurable: true, + enumerable: false, + value: WorkerGlobalScope, + writable: true, + }, + }; +})(this); diff --git a/op_crates/web/lib.rs b/op_crates/web/lib.rs index eaf7e9f14..958d11177 100644 --- a/op_crates/web/lib.rs +++ b/op_crates/web/lib.rs @@ -52,6 +52,10 @@ pub fn init(isolate: &mut JsRuntime) { "deno:op_crates/web/02_abort_signal.js", include_str!("02_abort_signal.js"), ), + ( + "deno:op_crates/web/03_global_interfaces.js", + include_str!("03_global_interfaces.js"), + ), ( "deno:op_crates/web/08_text_encoding.js", include_str!("08_text_encoding.js"), -- cgit v1.2.3