diff --git a/cli/js/lib.deno.shared_globals.d.ts b/cli/js/lib.deno.shared_globals.d.ts index a1e834cc42..f7f9b346ba 100644 --- a/cli/js/lib.deno.shared_globals.d.ts +++ b/cli/js/lib.deno.shared_globals.d.ts @@ -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; } diff --git a/cli/js/lib.deno.worker.d.ts b/cli/js/lib.deno.worker.d.ts index ca3670c774..e1db7e691e 100644 --- a/cli/js/lib.deno.worker.d.ts +++ b/cli/js/lib.deno.worker.d.ts @@ -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; diff --git a/cli/js/web/workers.ts b/cli/js/web/workers.ts index 054c26193b..421b82fbcd 100644 --- a/cli/js/web/workers.ts +++ b/cli/js/web/workers.ts @@ -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 {