mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -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;
|
||||
};
|
||||
|
||||
interface PostMessageOptions {
|
||||
transfer?: any[];
|
||||
}
|
||||
|
||||
declare class Worker {
|
||||
onerror?: (e: Event) => void;
|
||||
onmessage?: (data: any) => void;
|
||||
|
@ -1048,7 +1052,8 @@ declare class Worker {
|
|||
name?: string;
|
||||
}
|
||||
);
|
||||
postMessage(data: any): void;
|
||||
postMessage(message: any, transfer: ArrayBuffer[]): void;
|
||||
postMessage(message: any, options?: PostMessageOptions): 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 {
|
||||
self: DedicatedWorkerGlobalScope & typeof globalThis;
|
||||
onmessage: (e: { data: any }) => void;
|
||||
location: Location;
|
||||
onerror: undefined | typeof onerror;
|
||||
name: typeof __workerMain.name;
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
hostPostMessage(this.#id, encodeMessage(data));
|
||||
hostPostMessage(this.#id, encodeMessage(message));
|
||||
}
|
||||
|
||||
terminate(): void {
|
||||
|
|
Loading…
Reference in a new issue