Skip to content

Commit b229723

Browse files
authored
[browser] unhandled JS exceptions (#100855)
1 parent e33b832 commit b229723

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

src/mono/browser/runtime/invoke-js.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export function mono_wasm_invoke_jsimport_MT (signature: JSFunctionSignature, ar
5959
}
6060
}
6161
return;
62-
} catch (ex2: any) {
63-
runtimeHelpers.nativeAbort(ex2);
62+
} catch (ex: any) {
63+
loaderHelpers.mono_exit(1, ex);
6464
return;
6565
}
6666
}

src/mono/browser/runtime/pthreads/shared.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ export function exec_synchronization_context_pump (): void {
7777
return;
7878
}
7979
forceThreadMemoryViewRefresh();
80-
tcwraps.mono_wasm_synchronization_context_pump();
80+
try {
81+
tcwraps.mono_wasm_synchronization_context_pump();
82+
} catch (ex) {
83+
loaderHelpers.mono_exit(1, ex);
84+
}
8185
}
8286

8387
export function mono_wasm_schedule_synchronization_context (): void {

src/mono/browser/runtime/scheduling.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,28 @@ function prevent_timer_throttling_tick () {
3535
if (!loaderHelpers.is_runtime_running()) {
3636
return;
3737
}
38-
cwraps.mono_wasm_execute_timer();
39-
pump_count++;
38+
try {
39+
cwraps.mono_wasm_execute_timer();
40+
pump_count++;
41+
} catch (ex) {
42+
loaderHelpers.mono_exit(1, ex);
43+
}
4044
mono_background_exec_until_done();
4145
}
4246

4347
function mono_background_exec_until_done () {
4448
if (WasmEnableThreads) return;
4549
Module.maybeExit();
46-
if (!loaderHelpers.is_runtime_running()) {
47-
return;
48-
}
49-
while (pump_count > 0) {
50-
--pump_count;
51-
cwraps.mono_background_exec();
50+
try {
51+
while (pump_count > 0) {
52+
--pump_count;
53+
if (!loaderHelpers.is_runtime_running()) {
54+
return;
55+
}
56+
cwraps.mono_background_exec();
57+
}
58+
} catch (ex) {
59+
loaderHelpers.mono_exit(1, ex);
5260
}
5361
}
5462

@@ -78,5 +86,10 @@ function mono_wasm_schedule_timer_tick () {
7886
return;
7987
}
8088
lastScheduledTimeoutId = undefined;
81-
cwraps.mono_wasm_execute_timer();
89+
try {
90+
cwraps.mono_wasm_execute_timer();
91+
pump_count++;
92+
} catch (ex) {
93+
loaderHelpers.mono_exit(1, ex);
94+
}
8295
}

0 commit comments

Comments
 (0)