diff --git a/src/mono/browser/runtime/exports-binding.ts b/src/mono/browser/runtime/exports-binding.ts index bcecfec8b10ea4..7bcbe4c43359a2 100644 --- a/src/mono/browser/runtime/exports-binding.ts +++ b/src/mono/browser/runtime/exports-binding.ts @@ -32,6 +32,7 @@ import { mono_wasm_pthread_on_pthread_registered, mono_wasm_pthread_set_name, mono_wasm_install_js_worker_interop, mono_wasm_uninstall_js_worker_interop, mono_wasm_start_io_thread_async } from "./pthreads"; import { mono_wasm_dump_threads } from "./pthreads/ui-thread"; +import { loaderHelpers } from "./globals"; import { mono_wasm_schedule_synchronization_context } from "./pthreads/shared"; @@ -147,7 +148,23 @@ export function replace_linker_placeholders (imports: WebAssembly.Imports) { } } - for (const [idx, realFn] of wasmImports.entries()) { + for (const [idx, rfn] of wasmImports.entries()) { + let realFn = rfn; + if (WasmEnableThreads) { + realFn = function catch_and_log_exceptions (...args: any[]) { + try { + return rfn(...args); + } catch (ex: any) { + if (ex == "unwind") { + throw ex; + } + if (ex && !ex.silent) { + loaderHelpers.mono_exit(1, ex); + } + } + }; + } + const shortName = indexToNameMap[idx]; // if it's not found it means the emcc linker didn't include it, which is fine if (shortName !== undefined) { diff --git a/src/mono/browser/runtime/managed-exports.ts b/src/mono/browser/runtime/managed-exports.ts index f90fbb049d1504..b202c56e2fa7b4 100644 --- a/src/mono/browser/runtime/managed-exports.ts +++ b/src/mono/browser/runtime/managed-exports.ts @@ -14,7 +14,7 @@ import { assert_c_interop, assert_js_interop } from "./invoke-js"; import { monoThreadInfo, mono_wasm_main_thread_ptr } from "./pthreads"; import { _zero_region, copyBytes } from "./memory"; import { stringToUTF8Ptr } from "./strings"; -import { mono_log_debug } from "./logging"; +import { mono_log_error } from "./logging"; const managedExports: ManagedExports = {} as any; @@ -254,7 +254,7 @@ export function install_main_synchronization_context (jsThreadBlockingMode: numb } return get_arg_gc_handle(res) as any; } catch (e) { - mono_log_debug("install_main_synchronization_context failed", e); + mono_log_error("install_main_synchronization_context failed", e); throw e; } }