using System; using System.Linq; using System.Threading.Tasks; using Newtonsoft.Json.Linq; using Xunit; using WebAssembly.Net.Debugging; namespace DebuggerTests { public class EvaluateOnCallFrameTests : DebuggerTestBase { [Fact] public async Task EvaluateThisProperties () => await CheckInspectLocalsAtBreakpointSite ( "dotnet://debugger-test.dll/debugger-evaluate-test.cs", 20, 16, "run", "window.setTimeout(function() { invoke_static_method_async ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocals'); })", wait_for_event_fn: async (pause_location) => { var locals = await GetProperties (pause_location ["callFrames"][0] ["callFrameId"].Value ()); var evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "a"); CheckContentValue (evaluate, "1"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "b"); CheckContentValue (evaluate, "2"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "c"); CheckContentValue (evaluate, "3"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "dt"); await CheckDateTimeValue (evaluate, new DateTime (2000, 5, 4, 3, 2, 1)); }); [Theory] [InlineData (58, 3, "EvaluateTestsStructInstanceMethod")] [InlineData (74, 3, "GenericInstanceMethodOnStruct")] [InlineData (97, 3, "EvaluateTestsGenericStructInstanceMethod")] public async Task EvaluateThisPropertiesOnStruct (int line, int col, string method_name) => await CheckInspectLocalsAtBreakpointSite ( "dotnet://debugger-test.dll/debugger-evaluate-test.cs", line, col, method_name, "window.setTimeout(function() { invoke_static_method_async ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocals'); })", wait_for_event_fn: async (pause_location) => { var evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "a"); CheckContentValue (evaluate, "1"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "b"); CheckContentValue (evaluate, "2"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "c"); CheckContentValue (evaluate, "3"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "dateTime"); await CheckDateTimeValue (evaluate, new DateTime (2020, 1, 2, 3, 4, 5)); }); [Fact] public async Task EvaluateParameters () => await CheckInspectLocalsAtBreakpointSite ( "dotnet://debugger-test.dll/debugger-evaluate-test.cs", 20, 16, "run", "window.setTimeout(function() { invoke_static_method_async ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocals'); })", wait_for_event_fn: async (pause_location) => { var locals = await GetProperties (pause_location ["callFrames"][0] ["callFrameId"].Value ()); var evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "g"); CheckContentValue (evaluate, "100"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "h"); CheckContentValue (evaluate, "200"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "valString"); CheckContentValue (evaluate, "test"); }); [Fact] public async Task EvaluateLocals () => await CheckInspectLocalsAtBreakpointSite ( "dotnet://debugger-test.dll/debugger-evaluate-test.cs", 20, 16, "run", "window.setTimeout(function() { invoke_static_method_async ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocals'); })", wait_for_event_fn: async (pause_location) => { var locals = await GetProperties (pause_location ["callFrames"][0] ["callFrameId"].Value ()); var evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "d"); CheckContentValue (evaluate, "101"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "e"); CheckContentValue (evaluate, "102"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "f"); CheckContentValue (evaluate, "103"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "local_dt"); await CheckDateTimeValue (evaluate, new DateTime (2010, 9, 8, 7, 6, 5)); }); [Fact] public async Task EvaluateLocalsAsync () { var bp_loc = "dotnet://debugger-test.dll/debugger-array-test.cs"; int line = 227; int col = 3; var function_name = "MoveNext"; await CheckInspectLocalsAtBreakpointSite ( bp_loc, line, col, function_name, "window.setTimeout(function() { invoke_static_method_async ('[debugger-test] DebuggerTests.ArrayTestsClass:EntryPointForStructMethod', true); })", wait_for_event_fn: async (pause_location) => { var locals = await GetProperties (pause_location ["callFrames"][0] ["callFrameId"].Value ()); // sc_arg { var sc_arg = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "sc_arg"); await CheckValue (sc_arg, TObject ("DebuggerTests.SimpleClass"), "sc_arg#1"); var sc_arg_props = await GetProperties (sc_arg ["objectId"]?.Value ()); await CheckProps (sc_arg_props, new { X = TNumber (10), Y = TNumber (45), Id = TString ("sc#Id"), Color = TEnum ("DebuggerTests.RGB", "Blue"), PointWithCustomGetter = TGetter ("PointWithCustomGetter") }, "sc_arg_props#1"); } // local_gs { var local_gs = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "local_gs"); await CheckValue (local_gs, TValueType ("DebuggerTests.SimpleGenericStruct"), "local_gs#1"); var local_gs_props = await GetProperties (local_gs ["objectId"]?.Value ()); await CheckProps (local_gs_props, new { Id = TObject ("string", is_null: true), Color = TEnum ("DebuggerTests.RGB", "Red"), Value = TNumber (0) }, "local_gs_props#1"); } // step, check local_gs pause_location = await StepAndCheck (StepKind.Over, bp_loc, line + 1, col, function_name); { var local_gs = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "local_gs"); await CheckValue (local_gs, TValueType ("DebuggerTests.SimpleGenericStruct"), "local_gs#2"); var local_gs_props = await GetProperties (local_gs ["objectId"]?.Value ()); await CheckProps (local_gs_props, new { Id = TString ("local_gs#Id"), Color = TEnum ("DebuggerTests.RGB", "Green"), Value = TNumber (4) }, "local_gs_props#2"); } // step check sc_arg.Id pause_location = await StepAndCheck (StepKind.Over, bp_loc, line + 2, col, function_name); { var sc_arg = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "sc_arg"); await CheckValue (sc_arg, TObject ("DebuggerTests.SimpleClass"), "sc_arg#2"); var sc_arg_props = await GetProperties (sc_arg ["objectId"]?.Value ()); await CheckProps (sc_arg_props, new { X = TNumber (10), Y = TNumber (45), Id = TString ("sc_arg#Id"), // <------- This changed Color = TEnum ("DebuggerTests.RGB", "Blue"), PointWithCustomGetter = TGetter ("PointWithCustomGetter") }, "sc_arg_props#2"); } }); } [Fact] public async Task EvaluateExpressions () => await CheckInspectLocalsAtBreakpointSite ( "dotnet://debugger-test.dll/debugger-evaluate-test.cs", 20, 16, "run", "window.setTimeout(function() { invoke_static_method_async ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocals'); })", wait_for_event_fn: async (pause_location) => { var locals = await GetProperties (pause_location ["callFrames"][0] ["callFrameId"].Value ()); var evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "d + e"); CheckContentValue (evaluate, "203"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "e + 10"); CheckContentValue (evaluate, "112"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "a + a"); CheckContentValue (evaluate, "2"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "this.a + this.b"); CheckContentValue (evaluate, "3"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "\"test\" + \"test\""); CheckContentValue (evaluate, "testtest"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "5 + 5"); CheckContentValue (evaluate, "10"); }); [Fact] public async Task EvaluateThisExpressions () => await CheckInspectLocalsAtBreakpointSite ( "dotnet://debugger-test.dll/debugger-evaluate-test.cs", 20, 16, "run", "window.setTimeout(function() { invoke_static_method_async ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocals'); })", wait_for_event_fn: async (pause_location) => { var locals = await GetProperties (pause_location ["callFrames"][0] ["callFrameId"].Value ()); var evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "this.a"); CheckContentValue (evaluate, "1"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "this.b"); CheckContentValue (evaluate, "2"); evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "this.c"); CheckContentValue (evaluate, "3"); // FIXME: not supported yet // evaluate = await EvaluateOnCallFrame (pause_location ["callFrames"][0] ["callFrameId"].Value (), "this.dt"); // await CheckDateTimeValue (evaluate, new DateTime (2000, 5, 4, 3, 2, 1)); }); } }