2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2020-01-29 18:54:23 +01:00
|
|
|
|
|
|
|
/// <reference no-default-lib="true" />
|
2020-04-16 23:40:29 +02:00
|
|
|
/// <reference lib="deno.ns" />
|
2020-02-19 16:34:11 +11:00
|
|
|
/// <reference lib="deno.shared_globals" />
|
2020-01-29 18:54:23 +01:00
|
|
|
/// <reference lib="esnext" />
|
2022-09-28 17:41:12 +05:30
|
|
|
/// <reference lib="deno.cache" />
|
2020-01-29 18:54:23 +01:00
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2021-06-15 11:16:06 +10:00
|
|
|
interface WorkerGlobalScopeEventMap {
|
|
|
|
"error": ErrorEvent;
|
2022-07-21 23:54:53 +02:00
|
|
|
"unhandledrejection": PromiseRejectionEvent;
|
2021-06-15 11:16:06 +10:00
|
|
|
}
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2021-06-15 11:16:06 +10:00
|
|
|
declare class WorkerGlobalScope extends EventTarget {
|
|
|
|
readonly location: WorkerLocation;
|
|
|
|
readonly navigator: WorkerNavigator;
|
|
|
|
onerror: ((this: WorkerGlobalScope, ev: ErrorEvent) => any) | null;
|
2022-07-21 23:54:53 +02:00
|
|
|
onunhandledrejection:
|
|
|
|
| ((this: WorkerGlobalScope, ev: PromiseRejectionEvent) => any)
|
|
|
|
| null;
|
2021-06-15 11:16:06 +10:00
|
|
|
|
|
|
|
readonly self: WorkerGlobalScope & typeof globalThis;
|
|
|
|
|
|
|
|
addEventListener<K extends keyof WorkerGlobalScopeEventMap>(
|
|
|
|
type: K,
|
|
|
|
listener: (
|
|
|
|
this: WorkerGlobalScope,
|
|
|
|
ev: WorkerGlobalScopeEventMap[K],
|
|
|
|
) => any,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
|
|
|
): void;
|
|
|
|
addEventListener(
|
|
|
|
type: string,
|
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
|
|
|
): void;
|
|
|
|
removeEventListener<K extends keyof WorkerGlobalScopeEventMap>(
|
|
|
|
type: K,
|
|
|
|
listener: (
|
|
|
|
this: WorkerGlobalScope,
|
|
|
|
ev: WorkerGlobalScopeEventMap[K],
|
|
|
|
) => any,
|
|
|
|
options?: boolean | EventListenerOptions,
|
|
|
|
): void;
|
|
|
|
removeEventListener(
|
|
|
|
type: string,
|
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | EventListenerOptions,
|
|
|
|
): void;
|
|
|
|
|
2020-04-16 23:40:29 +02:00
|
|
|
Deno: typeof Deno;
|
2022-09-28 17:41:12 +05:30
|
|
|
caches: CacheStorage;
|
2021-03-01 11:31:13 +01:00
|
|
|
}
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web APIs */
|
2021-03-08 12:27:49 +00:00
|
|
|
declare class WorkerNavigator {
|
|
|
|
constructor();
|
2021-07-30 01:15:11 +05:30
|
|
|
readonly hardwareConcurrency: number;
|
2022-05-14 11:00:02 +01:00
|
|
|
readonly userAgent: string;
|
2022-10-18 15:33:35 +02:00
|
|
|
readonly language: string;
|
|
|
|
readonly languages: string[];
|
2020-01-29 18:54:23 +01:00
|
|
|
}
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web APIs */
|
2021-03-08 12:27:49 +00:00
|
|
|
declare var navigator: WorkerNavigator;
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2021-06-15 11:16:06 +10:00
|
|
|
interface DedicatedWorkerGlobalScopeEventMap extends WorkerGlobalScopeEventMap {
|
|
|
|
"message": MessageEvent;
|
|
|
|
"messageerror": MessageEvent;
|
|
|
|
}
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web APIs */
|
2020-10-11 23:04:43 +01:00
|
|
|
declare class DedicatedWorkerGlobalScope extends WorkerGlobalScope {
|
2021-06-15 11:16:06 +10:00
|
|
|
readonly name: string;
|
|
|
|
onmessage:
|
|
|
|
| ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any)
|
|
|
|
| null;
|
|
|
|
onmessageerror:
|
|
|
|
| ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any)
|
|
|
|
| null;
|
|
|
|
close(): void;
|
2021-06-22 16:30:16 +02:00
|
|
|
postMessage(message: any, transfer: Transferable[]): void;
|
2021-08-09 10:39:00 +02:00
|
|
|
postMessage(message: any, options?: StructuredSerializeOptions): void;
|
2021-06-15 11:16:06 +10:00
|
|
|
addEventListener<K extends keyof DedicatedWorkerGlobalScopeEventMap>(
|
|
|
|
type: K,
|
|
|
|
listener: (
|
|
|
|
this: DedicatedWorkerGlobalScope,
|
|
|
|
ev: DedicatedWorkerGlobalScopeEventMap[K],
|
|
|
|
) => any,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
|
|
|
): void;
|
|
|
|
addEventListener(
|
|
|
|
type: string,
|
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
|
|
|
): void;
|
|
|
|
removeEventListener<K extends keyof DedicatedWorkerGlobalScopeEventMap>(
|
|
|
|
type: K,
|
|
|
|
listener: (
|
|
|
|
this: DedicatedWorkerGlobalScope,
|
|
|
|
ev: DedicatedWorkerGlobalScopeEventMap[K],
|
|
|
|
) => any,
|
|
|
|
options?: boolean | EventListenerOptions,
|
|
|
|
): void;
|
|
|
|
removeEventListener(
|
|
|
|
type: string,
|
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | EventListenerOptions,
|
|
|
|
): void;
|
2020-10-11 23:04:43 +01:00
|
|
|
}
|
|
|
|
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2021-06-15 11:16:06 +10:00
|
|
|
declare var name: string;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2020-10-08 20:43:26 +11:00
|
|
|
declare var onmessage:
|
2021-06-15 11:16:06 +10:00
|
|
|
| ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any)
|
2020-10-08 20:43:26 +11:00
|
|
|
| null;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2020-10-08 20:43:26 +11:00
|
|
|
declare var onmessageerror:
|
2021-06-15 11:16:06 +10:00
|
|
|
| ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any)
|
2020-10-08 20:43:26 +11:00
|
|
|
| null;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2021-06-15 11:16:06 +10:00
|
|
|
declare function close(): void;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2021-06-22 16:30:16 +02:00
|
|
|
declare function postMessage(message: any, transfer: Transferable[]): void;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2021-08-09 10:39:00 +02:00
|
|
|
declare function postMessage(
|
|
|
|
message: any,
|
|
|
|
options?: StructuredSerializeOptions,
|
|
|
|
): void;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web APIs */
|
2021-06-15 11:16:06 +10:00
|
|
|
declare var navigator: WorkerNavigator;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web APIs */
|
2020-09-25 22:23:35 +01:00
|
|
|
declare var onerror:
|
2021-06-15 11:16:06 +10:00
|
|
|
| ((this: DedicatedWorkerGlobalScope, ev: ErrorEvent) => any)
|
2020-10-08 20:43:26 +11:00
|
|
|
| null;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Observability */
|
2022-07-21 23:54:53 +02:00
|
|
|
declare var onunhandledrejection:
|
|
|
|
| ((this: DedicatedWorkerGlobalScope, ev: PromiseRejectionEvent) => any)
|
|
|
|
| null;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web Workers */
|
2021-06-15 11:16:06 +10:00
|
|
|
declare var self: WorkerGlobalScope & typeof globalThis;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category DOM Events */
|
2021-06-15 11:16:06 +10:00
|
|
|
declare function addEventListener<
|
|
|
|
K extends keyof DedicatedWorkerGlobalScopeEventMap,
|
|
|
|
>(
|
|
|
|
type: K,
|
|
|
|
listener: (
|
|
|
|
this: DedicatedWorkerGlobalScope,
|
|
|
|
ev: DedicatedWorkerGlobalScopeEventMap[K],
|
|
|
|
) => any,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
|
|
|
): void;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category DOM Events */
|
2021-06-15 11:16:06 +10:00
|
|
|
declare function addEventListener(
|
|
|
|
type: string,
|
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | AddEventListenerOptions,
|
|
|
|
): void;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category DOM Events */
|
2021-06-15 11:16:06 +10:00
|
|
|
declare function removeEventListener<
|
|
|
|
K extends keyof DedicatedWorkerGlobalScopeEventMap,
|
|
|
|
>(
|
|
|
|
type: K,
|
|
|
|
listener: (
|
|
|
|
this: DedicatedWorkerGlobalScope,
|
|
|
|
ev: DedicatedWorkerGlobalScopeEventMap[K],
|
|
|
|
) => any,
|
|
|
|
options?: boolean | EventListenerOptions,
|
|
|
|
): void;
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category DOM Events */
|
2021-06-15 11:16:06 +10:00
|
|
|
declare function removeEventListener(
|
|
|
|
type: string,
|
|
|
|
listener: EventListenerOrEventListenerObject,
|
|
|
|
options?: boolean | EventListenerOptions,
|
|
|
|
): void;
|
2021-01-17 15:28:54 +00:00
|
|
|
|
2021-04-30 12:51:48 -07:00
|
|
|
// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is.
|
2021-01-17 15:28:54 +00:00
|
|
|
// The types there must first be split into window, worker and global types.
|
|
|
|
/** The absolute location of the script executed by the Worker. Such an object
|
|
|
|
* is initialized for each worker and is available via the
|
2022-08-17 13:12:24 +10:00
|
|
|
* WorkerGlobalScope.location property obtained by calling self.location.
|
|
|
|
*
|
|
|
|
* @category Web APIs
|
|
|
|
*/
|
2021-01-17 15:28:54 +00:00
|
|
|
declare class WorkerLocation {
|
|
|
|
constructor();
|
|
|
|
readonly hash: string;
|
|
|
|
readonly host: string;
|
|
|
|
readonly hostname: string;
|
|
|
|
readonly href: string;
|
|
|
|
toString(): string;
|
|
|
|
readonly origin: string;
|
|
|
|
readonly pathname: string;
|
|
|
|
readonly port: string;
|
|
|
|
readonly protocol: string;
|
|
|
|
readonly search: string;
|
|
|
|
}
|
|
|
|
|
2021-04-30 12:51:48 -07:00
|
|
|
// TODO(nayeemrmn): Move this to `extensions/web` where its implementation is.
|
2021-01-17 15:28:54 +00:00
|
|
|
// The types there must first be split into window, worker and global types.
|
2022-08-17 13:12:24 +10:00
|
|
|
/** @category Web APIs */
|
2021-01-17 15:28:54 +00:00
|
|
|
declare var location: WorkerLocation;
|