1
0
Fork 0
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:
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; 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;
} }

View file

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

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) { if (this.#terminated) {
return; return;
} }
hostPostMessage(this.#id, encodeMessage(data)); hostPostMessage(this.#id, encodeMessage(message));
} }
terminate(): void { terminate(): void {