1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-20 22:34:46 -05:00
denoland-deno/ext/web/04_global_interfaces.js
Ian Bull b78c851a94
refactor(ext/web): align error messages (#25871)
Aligns the error messages in the ext/web folder to be in-line with the
Deno style guide.
2024-12-03 03:30:39 +00:00

83 lines
1.7 KiB
JavaScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// @ts-check
/// <reference path="../../core/internal.d.ts" />
import { primordials } from "ext:core/mod.js";
const {
Symbol,
SymbolToStringTag,
TypeError,
} = primordials;
import { EventTarget } from "./02_event.js";
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,
};