Skip to content

[release/7.0][wasm][debugger] Indexing with expression #75559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System.IO;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Collections.Generic;
using System.Net.WebSockets;
Expand Down Expand Up @@ -409,7 +411,16 @@ public async Task<JObject> Resolve(ElementAccessExpressionSyntax elementAccess,
}
elementIdxStr += indexObject["value"].ToString();
}
// FixMe: indexing with expressions, e.g. x[a + 1]
// indexing with expressions, e.g. x[a + 1]
else
{
string expression = arg.ToString();
indexObject = await ExpressionEvaluator.EvaluateSimpleExpression(this, expression, expression, variableDefinitions, logger, token);
string type = indexObject["type"].Value<string>();
if (type != "number")
throw new InvalidOperationException($"Cannot index with an object of type '{type}'");
elementIdxStr += indexObject["value"].ToString();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,48 @@ await EvaluateOnCallFrameAndCheck(id,

});

[Fact]
public async Task EvaluateIndexingByExpression() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.EvaluateLocalsWithIndexingTests", "EvaluateLocals", 5, "DebuggerTests.EvaluateLocalsWithIndexingTests.EvaluateLocals",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateLocalsWithIndexingTests:EvaluateLocals'); })",
wait_for_event_fn: async (pause_location) =>
{
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
await EvaluateOnCallFrameAndCheck(id,
("f.numList[i + 1]", TNumber(2)),
("f.textList[(2 * j) - 1]", TString("2")),
("f.textList[j - 1]", TString("1")),
("f.numArray[f.numList[j - 1]]", TNumber(2))
);
});

[Fact]
public async Task EvaluateIndexingByExpressionMultidimensional() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.EvaluateLocalsWithMultidimensionalIndexingTests", "EvaluateLocals", 5, "DebuggerTests.EvaluateLocalsWithMultidimensionalIndexingTests.EvaluateLocals",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateLocalsWithMultidimensionalIndexingTests:EvaluateLocals'); })",
wait_for_event_fn: async (pause_location) =>
{
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
await EvaluateOnCallFrameAndCheck(id,
("f.numArray2D[0, j - 1]", TNumber(1)), // 0, 0
("f.numArray2D[f.idx1, i + j]", TNumber(4)), // 1, 1
("f.numArray2D[(f.idx1 - j) * 5, i + j]", TNumber(2)), // 0, 1
("f.numArray2D[i + j, f.idx1 - 1]", TNumber(3)) // 1, 0
);
});

[ConditionalFact(nameof(RunningOnChrome))]
public async Task EvaluateIndexingByExpressionNegative() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.EvaluateLocalsWithIndexingTests", "EvaluateLocals", 5, "DebuggerTests.EvaluateLocalsWithIndexingTests.EvaluateLocals",
$"window.setTimeout(function() {{ invoke_static_method ('[debugger-test] DebuggerTests.EvaluateLocalsWithIndexingTests:EvaluateLocals'); 1 }})",
wait_for_event_fn: async (pause_location) =>
{
// indexing with expression of a wrong type
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
var (_, res) = await EvaluateOnCallFrame(id, "f.numList[\"a\" + 1]", expect_ok: false );
Assert.Equal("Unable to evaluate element access 'f.numList[\"a\" + 1]': Cannot index with an object of type 'string'", res.Error["message"]?.Value<string>());
});

[Fact]
public async Task EvaluateIndexingByMemberVariables() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.EvaluateLocalsWithIndexingTests", "EvaluateLocals", 5, "DebuggerTests.EvaluateLocalsWithIndexingTests.EvaluateLocals",
Expand Down