Skip to content

Commit 5952bf2

Browse files
authored
Fix WASM debugger breakpoints not hitting after Terser 5.39+. (#123353)
Terser 5.39 introduced an optimization that removes console.assert(true, ...) as "unnecessary" https://github.com/terser/terser/blob/master/CHANGELOG.md#v5390. In runtime we are counting on the assert to keep `base64String`: https://github.com/dotnet/runtime/blob/1af7e1a9b7d659fdb9e2bc7aa52197fd5d272ec6/src/mono/browser/runtime/debug.ts#L37 The assert removal caused the `base64String` to be optimized away, breaking the `BrowserDebugProxy's `, breaking the ability to read them from the paused scope. <img width="2725" height="204" alt="image" src="https://github.com/user-attachments/assets/a55233c9-fe3e-4c5e-99fb-36a5f02b7dba" /> This affects net11 debugging, net10 works correctly. This PR replaces `true` with `!!Date.now()` which Terser cannot statically evaluate.
1 parent d5df04f commit 5952bf2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/mono/browser/runtime/debug.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ export function mono_wasm_runtime_ready (): void {
3434
}
3535

3636
export function mono_wasm_fire_debugger_agent_message_with_data_to_pause (base64String: string): void {
37-
//keep this console.assert, otherwise optimization will remove the assignments
37+
// Terser 5.39+ removes console.assert(true, ...) as "unnecessary".
38+
// !!Date.now() is always true at runtime, but Terser can't evaluate it statically.
3839
// eslint-disable-next-line no-console
39-
console.assert(true, `mono_wasm_fire_debugger_agent_message_with_data ${base64String}`);
40+
console.assert(!!Date.now(), `mono_wasm_fire_debugger_agent_message_with_data ${base64String}`);
4041
// eslint-disable-next-line no-debugger
4142
debugger;
4243
}
@@ -163,9 +164,10 @@ export function mono_wasm_set_entrypoint_breakpoint (entrypoint_method_token: nu
163164
//keep these assignments, these values are used by BrowserDebugProxy
164165
_assembly_name_str = loaderHelpers.config.mainAssemblyName + ".dll";
165166
_entrypoint_method_token = entrypoint_method_token;
166-
//keep this console.assert, otherwise optimization will remove the assignments
167+
// Terser 5.39+ removes console.assert(true, ...) as "unnecessary".
168+
// !!Date.now() is always true at runtime, but Terser can't evaluate it statically.
167169
// eslint-disable-next-line no-console
168-
console.assert(true, `Adding an entrypoint breakpoint ${_assembly_name_str} at method token ${_entrypoint_method_token}`);
170+
console.assert(!!Date.now(), `Adding an entrypoint breakpoint ${_assembly_name_str} at method token ${_entrypoint_method_token}`);
169171
// eslint-disable-next-line no-debugger
170172
debugger;
171173

0 commit comments

Comments
 (0)