[wasm][debugger] Default null columnNumber to 0 (#81336)
authorLarry Ewing <lewing@microsoft.com>
Mon, 30 Jan 2023 18:11:10 +0000 (12:11 -0600)
committerGitHub <noreply@github.com>
Mon, 30 Jan 2023 18:11:10 +0000 (12:11 -0600)
* Default null columnNumber to 0

* Fix compilation

* adding test case

---------

Co-authored-by: Thays Grazia <thaystg@gmail.com>
src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs

index d5d5b5a..02c6a66 100644 (file)
@@ -116,15 +116,15 @@ namespace Microsoft.WebAssembly.Diagnostics
                 return false;
 
             int? line = request?["lineNumber"]?.Value<int>();
-            int? column = request?["columnNumber"]?.Value<int>();
+            int column = request?["columnNumber"]?.Value<int>() ?? 0;
 
-            if (line == null || column == null)
+            if (line == null)
                 return false;
 
             Assembly = sourceFile.AssemblyName;
             File = sourceFile.FilePath;
             Line = line.Value;
-            Column = column.Value;
+            Column = column;
             return true;
         }
 
index 69a99a3..13abc58 100644 (file)
@@ -171,6 +171,18 @@ namespace DebuggerTests
             );
         }
 
+        [ConditionalFact(nameof(RunningOnChrome))]
+        public async Task CreateGoodBreakpointWithoutColumnAndHit()
+        {
+            var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, -1);
+
+            await EvaluateAndCheck(
+                "window.setTimeout(function() { invoke_add(); }, 1);",
+                "dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
+                "Math.IntAdd"
+            );
+        }
+
         public static TheoryData<string, string, string, bool> FalseConditions = new TheoryData<string, string, string, bool>
         {
             { "invoke_add()", "IntAdd", "0.0", false },
index 673217c..55d59bd 100644 (file)
@@ -1155,9 +1155,19 @@ namespace DebuggerTests
 
         internal virtual async Task<Result> SetBreakpoint(string url_key, int line, int column, bool expect_ok = true, bool use_regex = false, string condition = "")
         {
-            var bp1_req = !use_regex ?
+            JObject bp1_req;
+            if (column != -1)
+            {
+                bp1_req = !use_regex ?
                 JObject.FromObject(new { lineNumber = line, columnNumber = column, url = dicFileToUrl[url_key], condition }) :
                 JObject.FromObject(new { lineNumber = line, columnNumber = column, urlRegex = url_key, condition });
+            }
+            else
+            {
+                bp1_req = !use_regex ?
+                JObject.FromObject(new { lineNumber = line, url = dicFileToUrl[url_key], condition }) :
+                JObject.FromObject(new { lineNumber = line, urlRegex = url_key, condition });
+            }
 
             var bp1_res = await cli.SendCommand("Debugger.setBreakpointByUrl", bp1_req, token);
             Assert.True(expect_ok ? bp1_res.IsOk : !bp1_res.IsOk);