Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Savara <pavel.savara@gmail.com>2022-07-08 20:50:49 +0300
committerGitHub <noreply@github.com>2022-07-08 20:50:49 +0300
commit76bd0ca4faad7883d32530596f89888d86f7281c (patch)
tree6e5e485570376d6a0922d87987dec0c6da4d1829 /src/mono/wasm/runtime
parente79526a4a251a657b2ea811ee4240e8b139c3fa2 (diff)
[wasm] fix V8 events (#71834)
Diffstat (limited to 'src/mono/wasm/runtime')
-rw-r--r--src/mono/wasm/runtime/pthreads/worker/events.ts34
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);
+ });