Skip to content

Commit 7ad5248

Browse files
authored
Fixes trying to evaluate a debugger helper function in a non-wasm page. (#74434)
1 parent 96a32c6 commit 7ad5248

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,9 @@ protected async Task<DebugStore> RuntimeReady(SessionId sessionId, CancellationT
15391539
ExecutionContext context = GetContext(sessionId);
15401540
if (Interlocked.CompareExchange(ref context.ready, new TaskCompletionSource<DebugStore>(), null) != null)
15411541
return await context.ready.Task;
1542-
1543-
await context.SdbAgent.SendDebuggerAgentCommand(CmdEventRequest.ClearAllBreakpoints, null, token);
1542+
var res = await context.SdbAgent.SendDebuggerAgentCommand(CmdEventRequest.ClearAllBreakpoints, null, token, false);
1543+
if (res.HasError) //it's not a wasm page then the command returns an error
1544+
return null;
15441545

15451546
if (context.PauseOnExceptions != PauseOnExceptionsKind.None && context.PauseOnExceptions != PauseOnExceptionsKind.Unset)
15461547
await context.SdbAgent.EnableExceptions(context.PauseOnExceptions, token);

src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,10 @@ await SendCommandAndCheck(null, "Debugger.resume",
470470
});
471471
}
472472

473-
[ConditionalFact(nameof(RunningOnChrome))]
474-
public async Task CreateGoodBreakpointAndHitGoToNonWasmPageComeBackAndHitAgain()
473+
[ConditionalTheory(nameof(RunningOnChrome))]
474+
[InlineData("load_non_wasm_page")]
475+
[InlineData("load_non_wasm_page_forcing_runtime_ready")] //to simulate the same behavior that has when debugging from VS and OnDefaultContextCreated is called
476+
public async Task CreateGoodBreakpointAndHitGoToNonWasmPageComeBackAndHitAgain(string func_name)
475477
{
476478
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
477479
var pause_location = await EvaluateAndCheck(
@@ -500,7 +502,7 @@ public async Task CreateGoodBreakpointAndHitGoToNonWasmPageComeBackAndHitAgain()
500502

501503
var run_method = JObject.FromObject(new
502504
{
503-
expression = "window.setTimeout(function() { load_non_wasm_page(); }, 1);"
505+
expression = "window.setTimeout(function() { " + func_name + "(); }, 1);"
504506
});
505507
await cli.SendCommand("Runtime.evaluate", run_method, token);
506508
await Task.Delay(1000, token);

src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
console.log("load_wasm_page_without_assets")
9393
window.location.replace("http://localhost:9400/wasm-page-without-assets.html");
9494
}
95+
function load_non_wasm_page_forcing_runtime_ready () {
96+
console.log("load_non_wasm_page_forcing_runtime_ready")
97+
window.location.replace("http://localhost:9400/non-wasm-page-forcing-runtime-ready.html");
98+
}
9599
</script>
96100

97101
<script type="text/javascript" src="other.js"></script>

src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<ItemGroup>
1414
<WasmExtraFilesToDeploy Include="debugger-driver.html" />
1515
<WasmExtraFilesToDeploy Include="non-wasm-page.html" />
16+
<WasmExtraFilesToDeploy Include="non-wasm-page-forcing-runtime-ready.html" />
1617
<WasmExtraFilesToDeploy Include="wasm-page-without-assets.html" />
1718
<WasmExtraFilesToDeploy Include="other.js" />
1819
<WasmExtraFilesToDeploy Include="weather.json" />
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en-us">
3+
<head>
4+
</head>
5+
<body>
6+
<script type='text/javascript'>
7+
console.debug ("#debugger-app-ready#");
8+
console.debug("mono_wasm_runtime_ready", "fe00e07a-5519-4dfe-b35a-f867dbaf2e28");
9+
function reload_wasm_page () {
10+
window.location.replace("http://localhost:9400/debugger-driver.html");
11+
}
12+
</script>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)