diff --git a/Plugins/PackageToJS/Templates/runtime.d.ts b/Plugins/PackageToJS/Templates/runtime.d.ts index 98e1f1cc..9613004c 100644 --- a/Plugins/PackageToJS/Templates/runtime.d.ts +++ b/Plugins/PackageToJS/Templates/runtime.d.ts @@ -1,3 +1,6 @@ +type ref = number; +type pointer = number; + declare class Memory { readonly rawMemory: WebAssembly.Memory; private readonly heap; @@ -18,9 +21,6 @@ declare class Memory { writeFloat64: (ptr: pointer, value: number) => void; } -type ref = number; -type pointer = number; - /** * A thread channel is a set of functions that are used to communicate between * the main thread and the worker thread. The main thread and the worker thread @@ -189,6 +189,7 @@ declare class SwiftRuntime { private textEncoder; /** The thread ID of the current thread. */ private tid; + UnsafeEventLoopYield: typeof UnsafeEventLoopYield; constructor(options?: SwiftRuntimeOptions); setInstance(instance: WebAssembly.Instance): void; main(): void; @@ -209,6 +210,8 @@ declare class SwiftRuntime { private postMessageToMainThread; private postMessageToWorkerThread; } +declare class UnsafeEventLoopYield extends Error { +} export { SwiftRuntime }; export type { SwiftRuntimeOptions, SwiftRuntimeThreadChannel }; diff --git a/Plugins/PackageToJS/Templates/runtime.js b/Plugins/PackageToJS/Templates/runtime.js index 1e45e9b0..da27a152 100644 --- a/Plugins/PackageToJS/Templates/runtime.js +++ b/Plugins/PackageToJS/Templates/runtime.js @@ -312,6 +312,7 @@ this.version = 708; this.textDecoder = new TextDecoder("utf-8"); this.textEncoder = new TextEncoder(); // Only support utf-8 + this.UnsafeEventLoopYield = UnsafeEventLoopYield; /** @deprecated Use `wasmImports` instead */ this.importObjects = () => this.wasmImports; this._instance = null; diff --git a/Plugins/PackageToJS/Templates/runtime.mjs b/Plugins/PackageToJS/Templates/runtime.mjs index ef1f57e7..71f7f9a3 100644 --- a/Plugins/PackageToJS/Templates/runtime.mjs +++ b/Plugins/PackageToJS/Templates/runtime.mjs @@ -306,6 +306,7 @@ class SwiftRuntime { this.version = 708; this.textDecoder = new TextDecoder("utf-8"); this.textEncoder = new TextEncoder(); // Only support utf-8 + this.UnsafeEventLoopYield = UnsafeEventLoopYield; /** @deprecated Use `wasmImports` instead */ this.importObjects = () => this.wasmImports; this._instance = null; diff --git a/Runtime/src/index.ts b/Runtime/src/index.ts index b70bed3a..05c2964f 100644 --- a/Runtime/src/index.ts +++ b/Runtime/src/index.ts @@ -38,6 +38,8 @@ export class SwiftRuntime { /** The thread ID of the current thread. */ private tid: number | null; + UnsafeEventLoopYield = UnsafeEventLoopYield; + constructor(options?: SwiftRuntimeOptions) { this._instance = null; this._memory = null; @@ -749,4 +751,4 @@ export class SwiftRuntime { /// This error is thrown to unwind the call stack of the Swift program and return the control to /// the JavaScript side. Otherwise, the `swift_task_asyncMainDrainQueue` ends up with `abort()` /// because the event loop expects `exit()` call before the end of the event loop. -export class UnsafeEventLoopYield extends Error {} +class UnsafeEventLoopYield extends Error {}