Skip to content

Commit

Permalink
[browser] unhandled JS exceptions (#100855)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Apr 10, 2024
1 parent e33b832 commit b229723
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/mono/browser/runtime/invoke-js.ts
Expand Up @@ -59,8 +59,8 @@ export function mono_wasm_invoke_jsimport_MT (signature: JSFunctionSignature, ar
}
}
return;
} catch (ex2: any) {
runtimeHelpers.nativeAbort(ex2);
} catch (ex: any) {
loaderHelpers.mono_exit(1, ex);
return;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/mono/browser/runtime/pthreads/shared.ts
Expand Up @@ -77,7 +77,11 @@ export function exec_synchronization_context_pump (): void {
return;
}
forceThreadMemoryViewRefresh();
tcwraps.mono_wasm_synchronization_context_pump();
try {
tcwraps.mono_wasm_synchronization_context_pump();
} catch (ex) {
loaderHelpers.mono_exit(1, ex);
}
}

export function mono_wasm_schedule_synchronization_context (): void {
Expand Down
31 changes: 22 additions & 9 deletions src/mono/browser/runtime/scheduling.ts
Expand Up @@ -35,20 +35,28 @@ function prevent_timer_throttling_tick () {
if (!loaderHelpers.is_runtime_running()) {
return;
}
cwraps.mono_wasm_execute_timer();
pump_count++;
try {
cwraps.mono_wasm_execute_timer();
pump_count++;
} catch (ex) {
loaderHelpers.mono_exit(1, ex);
}
mono_background_exec_until_done();
}

function mono_background_exec_until_done () {
if (WasmEnableThreads) return;
Module.maybeExit();
if (!loaderHelpers.is_runtime_running()) {
return;
}
while (pump_count > 0) {
--pump_count;
cwraps.mono_background_exec();
try {
while (pump_count > 0) {
--pump_count;
if (!loaderHelpers.is_runtime_running()) {
return;
}
cwraps.mono_background_exec();
}
} catch (ex) {
loaderHelpers.mono_exit(1, ex);
}
}

Expand Down Expand Up @@ -78,5 +86,10 @@ function mono_wasm_schedule_timer_tick () {
return;
}
lastScheduledTimeoutId = undefined;
cwraps.mono_wasm_execute_timer();
try {
cwraps.mono_wasm_execute_timer();
pump_count++;
} catch (ex) {
loaderHelpers.mono_exit(1, ex);
}
}

0 comments on commit b229723

Please sign in to comment.