diff options
author | Pavel Savara <pavel.savara@gmail.com> | 2022-07-08 20:50:49 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-08 20:50:49 +0300 |
commit | 76bd0ca4faad7883d32530596f89888d86f7281c (patch) | |
tree | 6e5e485570376d6a0922d87987dec0c6da4d1829 /src/mono/wasm | |
parent | e79526a4a251a657b2ea811ee4240e8b139c3fa2 (diff) |
[wasm] fix V8 events (#71834)
Diffstat (limited to 'src/mono/wasm')
-rw-r--r-- | src/mono/wasm/runtime/pthreads/worker/events.ts | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/mono/wasm/runtime/pthreads/worker/events.ts b/src/mono/wasm/runtime/pthreads/worker/events.ts index 933f72c065b..4544811fd96 100644 --- a/src/mono/wasm/runtime/pthreads/worker/events.ts +++ b/src/mono/wasm/runtime/pthreads/worker/events.ts @@ -19,17 +19,6 @@ export interface WorkerThreadEvent extends Event { readonly portToMain: MessagePort; } -class WorkerThreadEventImpl extends Event implements WorkerThreadEvent { - readonly pthread_ptr: pthread_ptr; - readonly portToMain: MessagePort; - constructor(type: keyof WorkerThreadEventMap, pthread_ptr: pthread_ptr, portToMain: MessagePort) { - super(type); - this.pthread_ptr = pthread_ptr; - this.portToMain = portToMain; - } -} - - export interface WorkerThreadEventTarget extends EventTarget { dispatchEvent(event: WorkerThreadEvent): boolean; @@ -37,11 +26,18 @@ export interface WorkerThreadEventTarget extends EventTarget { addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void; } -export function makeWorkerThreadEvent(type: keyof WorkerThreadEventMap, pthread_ptr: pthread_ptr, port: MessagePort): WorkerThreadEvent { - // this 'if' helps to tree-shake the WorkerThreadEventImpl class if threads are disabled. - if (MonoWasmThreads) { - return new WorkerThreadEventImpl(type, pthread_ptr, port); - } else { - throw new Error("threads support disabled"); - } -} +let WorkerThreadEventClassConstructor: new (type: keyof WorkerThreadEventMap, pthread_ptr: pthread_ptr, port: MessagePort) => WorkerThreadEvent; +export const makeWorkerThreadEvent: (type: keyof WorkerThreadEventMap, pthread_ptr: pthread_ptr, port: MessagePort) => WorkerThreadEvent = !MonoWasmThreads + ? (() => { throw new Error("threads support disabled"); }) + : ((type: keyof WorkerThreadEventMap, pthread_ptr: pthread_ptr, port: MessagePort) => { + if (!WorkerThreadEventClassConstructor) WorkerThreadEventClassConstructor = class WorkerThreadEventImpl extends Event implements WorkerThreadEvent { + readonly pthread_ptr: pthread_ptr; + readonly portToMain: MessagePort; + constructor(type: keyof WorkerThreadEventMap, pthread_ptr: pthread_ptr, portToMain: MessagePort) { + super(type); + this.pthread_ptr = pthread_ptr; + this.portToMain = portToMain; + } + }; + return new WorkerThreadEventClassConstructor(type, pthread_ptr, port); + }); |