Skip to content
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 @@ -86,7 +86,8 @@ public static bool TryParse(string id, out DotnetObjectId objectId)
case "methodId":
{
parts = id.Split(":");
objectId.SubValue = int.Parse(parts[3]);
if (parts.Length > 3)
objectId.SubValue = int.Parse(parts[3]);
break;
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,9 @@ public async Task<JObject> InvokeMethod(ArraySegment<byte> valueTypeBuffer, int

public async Task<JObject> InvokeMethodInObject(int objectId, int methodId, string varName, CancellationToken token)
{
valueTypes.TryGetValue(objectId, out var valueType);
if (valueType != null)
Comment on lines +1545 to +1546
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (valueTypes.TryGetValue(objectId, out var valueType))
    return await InvokeMethod(valueType.valueTypeBuffer, methodId, varName, token);

Try* pattern returns true when the call succeeds, and the out param has a valid value.

return await InvokeMethod(valueType.valueTypeBuffer, methodId, varName, token);
using var commandParamsObjWriter = new MonoBinaryWriter();
commandParamsObjWriter.Write(ElementType.Class, objectId);
return await InvokeMethod(commandParamsObjWriter.GetParameterBuffer(), methodId, varName, token);
Expand Down Expand Up @@ -1569,7 +1572,7 @@ public async Task<int> GetPropertyMethodIdByName(int typeId, string propertyName
return -1;
}

public async Task<JArray> CreateJArrayForProperties(int typeId, ArraySegment<byte> object_buffer, JArray attributes, bool isAutoExpandable, string objectIdStr, bool isOwn, CancellationToken token)
public async Task<JArray> CreateJArrayForProperties(int typeId, ElementType elementType, ArraySegment<byte> object_buffer, JArray attributes, bool isAutoExpandable, string objectIdStr, bool isOwn, CancellationToken token)
{
JArray ret = new JArray();
using var retDebuggerCmdReader = await GetTypePropertiesReader(typeId, token);
Expand Down Expand Up @@ -1606,7 +1609,7 @@ public async Task<JArray> CreateJArrayForProperties(int typeId, ArraySegment<byt
get = new
{
type = "function",
objectId = $"dotnet:methodId:{objectId.Value}:{getMethodId}",
objectId = $"dotnet:methodId:{objectId.Value}:{getMethodId}:{elementType}",
className = "Function",
description = "get " + propertyNameStr + " ()",
methodId = getMethodId,
Expand Down Expand Up @@ -1650,7 +1653,7 @@ public async Task<JArray> GetPropertiesValuesOfValueType(int valueTypeId, Cancel
}
for (int i = 0 ; i < typesToGetProperties.Count; i++)
{
var properties = await CreateJArrayForProperties(typesToGetProperties[i], valueType.valueTypeBuffer, valueType.valueTypeJson, valueType.valueTypeAutoExpand, $"dotnet:valuetype:{valueType.Id}", i == 0, token);
var properties = await CreateJArrayForProperties(typesToGetProperties[i], ElementType.ValueType, valueType.valueTypeBuffer, valueType.valueTypeJson, valueType.valueTypeAutoExpand, $"dotnet:valuetype:{valueType.Id}", i == 0, token);
ret = new JArray(ret.Union(properties));
}

Expand Down Expand Up @@ -2375,6 +2378,7 @@ public async Task<JArray> GetObjectValues(int objectId, GetObjectCommandOptions
commandParamsObjWriter.WriteObj(new DotnetObjectId("object", objectId), this);
var props = await CreateJArrayForProperties(
typeId,
ElementType.Class,
commandParamsObjWriter.GetParameterBuffer(),
new JArray(objects.Values),
getCommandType.HasFlag(GetObjectCommandOptions.ForDebuggerProxyAttribute),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,28 @@ public async Task EvaluateProtectionLevels() => await CheckInspectLocalsAtBreak
Assert.Equal(internalAndProtected[1]["value"]["value"], "protected");
Assert.Equal(priv[0]["value"]["value"], "private");
});

[Fact]
public async Task StructureGetters() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.StructureGetters", "Evaluate", 2, "Evaluate",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.StructureGetters:Evaluate'); })",
wait_for_event_fn: async (pause_location) =>
{
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
var (obj, _) = await EvaluateOnCallFrame(id, "s");
var props = await GetProperties(obj["objectId"]?.Value<string>());

await CheckProps(props, new
{
Id = TGetter("Id", TNumber(123))
}, "s#1");

var getter = props.FirstOrDefault(p => p["name"]?.Value<string>() == "Id");
Assert.NotNull(getter);
var getterId = getter["get"]["objectId"]?.Value<string>();
var getterProps = await GetProperties(getterId);
Assert.Equal(getterProps[0]?["value"]?["value"]?.Value<int>(), 123);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,19 @@ public static void Evaluate()
var testClass = new TestClass();
}
}

public static class StructureGetters
{
public struct Point
{
public int Id { get { return 123; } }
}

public static void Evaluate()
{
var s = new Point();
}
}
}

namespace DebuggerTestsV2
Expand Down