diff options
Diffstat (limited to 'op_crates')
-rw-r--r-- | op_crates/web/03_global_interfaces.js | 66 | ||||
-rw-r--r-- | op_crates/web/lib.rs | 4 |
2 files changed, 70 insertions, 0 deletions
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 @@ -53,6 +53,10 @@ pub fn init(isolate: &mut JsRuntime) { 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"), ), |