1
0
Fork 0
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:
Bartek Iwańczuk 2020-04-13 16:48:12 +02:00 committed by GitHub
parent a5f7ff7200
commit 5105c68399
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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 {