1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00
denoland-deno/ext/web/04_global_interfaces.js

84 lines
1.7 KiB
JavaScript
Raw Normal View History

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// @ts-check
/// <reference path="../../core/internal.d.ts" />
import { EventTarget } from "internal:deno_web/02_event.js";
const primordials = globalThis.__bootstrap.primordials;
const {
Symbol,
SymbolToStringTag,
TypeError,
} = primordials;
const illegalConstructorKey = Symbol("illegalConstructorKey");
class Window extends EventTarget {
constructor(key = null) {
if (key !== illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}
super();
}
get [SymbolToStringTag]() {
return "Window";
}
}
class WorkerGlobalScope extends EventTarget {
constructor(key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}
super();
}
get [SymbolToStringTag]() {
return "WorkerGlobalScope";
}
}
class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
constructor(key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
}
super();
}
get [SymbolToStringTag]() {
return "DedicatedWorkerGlobalScope";
}
}
const dedicatedWorkerGlobalScopeConstructorDescriptor = {
configurable: true,
enumerable: false,
value: DedicatedWorkerGlobalScope,
writable: true,
};
const windowConstructorDescriptor = {
configurable: true,
enumerable: false,
value: Window,
writable: true,
};
const workerGlobalScopeConstructorDescriptor = {
configurable: true,
enumerable: false,
value: WorkerGlobalScope,
writable: true,
};
export {
DedicatedWorkerGlobalScope,
dedicatedWorkerGlobalScopeConstructorDescriptor,
Window,
windowConstructorDescriptor,
WorkerGlobalScope,
workerGlobalScopeConstructorDescriptor,
};