mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
workers: update postMessage and location types (#4734)
This commit is contained in:
parent
a5f7ff7200
commit
5105c68399
3 changed files with 15 additions and 3 deletions
7
cli/js/lib.deno.shared_globals.d.ts
vendored
7
cli/js/lib.deno.shared_globals.d.ts
vendored
|
@ -1037,6 +1037,10 @@ declare const URL: {
|
||||||
revokeObjectURL(url: string): void;
|
revokeObjectURL(url: string): void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface PostMessageOptions {
|
||||||
|
transfer?: any[];
|
||||||
|
}
|
||||||
|
|
||||||
declare class Worker {
|
declare class Worker {
|
||||||
onerror?: (e: Event) => void;
|
onerror?: (e: Event) => void;
|
||||||
onmessage?: (data: any) => void;
|
onmessage?: (data: any) => void;
|
||||||
|
@ -1048,7 +1052,8 @@ declare class Worker {
|
||||||
name?: string;
|
name?: string;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
postMessage(data: any): void;
|
postMessage(message: any, transfer: ArrayBuffer[]): void;
|
||||||
|
postMessage(message: any, options?: PostMessageOptions): void;
|
||||||
terminate(): void;
|
terminate(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
cli/js/lib.deno.worker.d.ts
vendored
1
cli/js/lib.deno.worker.d.ts
vendored
|
@ -9,6 +9,7 @@
|
||||||
declare interface DedicatedWorkerGlobalScope {
|
declare interface DedicatedWorkerGlobalScope {
|
||||||
self: DedicatedWorkerGlobalScope & typeof globalThis;
|
self: DedicatedWorkerGlobalScope & typeof globalThis;
|
||||||
onmessage: (e: { data: any }) => void;
|
onmessage: (e: { data: any }) => void;
|
||||||
|
location: Location;
|
||||||
onerror: undefined | typeof onerror;
|
onerror: undefined | typeof onerror;
|
||||||
name: typeof __workerMain.name;
|
name: typeof __workerMain.name;
|
||||||
close: typeof __workerMain.close;
|
close: typeof __workerMain.close;
|
||||||
|
|
|
@ -160,12 +160,18 @@ export class WorkerImpl extends EventTarget implements Worker {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
postMessage(data: any): void {
|
postMessage(message: any, transferOrOptions?: any): void {
|
||||||
|
if (transferOrOptions) {
|
||||||
|
throw new Error(
|
||||||
|
"Not yet implemented: `transfer` and `options` are not supported."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.#terminated) {
|
if (this.#terminated) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hostPostMessage(this.#id, encodeMessage(data));
|
hostPostMessage(this.#id, encodeMessage(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
terminate(): void {
|
terminate(): void {
|
||||||
|
|
Loading…
Reference in a new issue