Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Addressing @radical comments.
  • Loading branch information
thaystg committed Aug 12, 2021
commit 427b1f23b6c1e2ad22c659e016a02cd00e5bb882
16 changes: 5 additions & 11 deletions src/mono/wasm/debugger/BrowserDebugProxy/EvaluateExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private object ConvertJSToCSharpType(JToken variable)
case "boolean":
return value?.Value<bool>();
case "object":
return null;
return variable;
Copy link
Member

Choose a reason for hiding this comment

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

Tests needed for this

case "void":
return null;
}
Expand Down Expand Up @@ -396,19 +396,13 @@ private static object ConvertCSharpToJSType(object v, ITypeSymbol type)
{
if (v == null)
return new { type = "object", subtype = "null", className = type.ToString(), description = type.ToString() };

if (v is string s)
{
return new { type = "string", value = s, description = s };
}
else if (NumericTypes.Contains(v.GetType()))
{
if (NumericTypes.Contains(v.GetType()))
return new { type = "number", value = v, description = v.ToString() };
}
else
{
return new { type = "object", value = v, description = v.ToString(), className = type.ToString() };
}
if (v is JObject)
return v;
return new { type = "object", value = v, description = v.ToString(), className = type.ToString() };
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task<JObject> TryToRunOnLoadedClasses(string varName, CancellationT
classNameToFind += part.Trim();
if (typeId != -1)
{
var fields = await proxy.SdbHelper.GetTypeFields(sessionId, typeId, false, token);
var fields = await proxy.SdbHelper.GetTypeFields(sessionId, typeId, onlyPublic: false, token);
foreach (var field in fields)
{
if (field.Name == part.Trim())
Expand Down Expand Up @@ -204,6 +204,7 @@ public async Task<JObject> Resolve(string varName, CancellationToken token)
public async Task<JObject> Resolve(InvocationExpressionSyntax method, Dictionary<string, JObject> memberAccessValues, CancellationToken token)
{
var methodName = "";
int isTryingLinq = 0;
try
{
JObject rootObject = null;
Expand All @@ -223,18 +224,42 @@ public async Task<JObject> Resolve(InvocationExpressionSyntax method, Dictionary
if (rootObject != null)
{
DotnetObjectId.TryParse(rootObject?["objectId"]?.Value<string>(), out DotnetObjectId objectId);
var typeId = await proxy.SdbHelper.GetTypeIdFromObject(sessionId, int.Parse(objectId.Value), true, token);
int methodId = await proxy.SdbHelper.GetMethodIdByName(sessionId, typeId[0], methodName, token);
var typeIds = await proxy.SdbHelper.GetTypeIdFromObject(sessionId, int.Parse(objectId.Value), true, token);
int methodId = await proxy.SdbHelper.GetMethodIdByName(sessionId, typeIds[0], methodName, token);
var className = await proxy.SdbHelper.GetTypeNameOriginal(sessionId, typeIds[0], token);
if (methodId == 0) //try to search on System.Linq.Enumerable
{
var linqTypeId = await proxy.SdbHelper.GetTypeByName(sessionId, "System.Linq.Enumerable", token);
Copy link
Member

Choose a reason for hiding this comment

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

This is a static class, so can we cache it?

var linqInitialize = await proxy.SdbHelper.TypeInitialize(sessionId, linqTypeId, token);
Console.WriteLine($"linqInitialize - {linqInitialize}");
Copy link
Member

Choose a reason for hiding this comment

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

can be dropped

methodId = await proxy.SdbHelper.GetMethodIdByName(sessionId, linqTypeId, methodName, token);
if (methodId != 0)
{
foreach (var typeId in typeIds)
{
var genericTypes = await proxy.SdbHelper.GetGenericTypesFromType(sessionId, typeId, token);
Copy link
Member

Choose a reason for hiding this comment

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

And rename to genericTypeArgs?

if (genericTypes.Count > 0)
{
isTryingLinq = 1;
methodId = await proxy.SdbHelper.MakeGenericMethod(sessionId, methodId, genericTypes, token);
break;
}
}
}
}
if (methodId == 0) {
var typeName = await proxy.SdbHelper.GetTypeName(sessionId, typeId[0], token);
var typeName = await proxy.SdbHelper.GetTypeName(sessionId, typeIds[0], token);
throw new Exception($"Method '{methodName}' not found in type '{typeName}'");
}
var commandParamsObj = new MemoryStream();
var commandParamsObjWriter = new MonoBinaryWriter(commandParamsObj);
commandParamsObjWriter.WriteObj(objectId, proxy.SdbHelper);
if (isTryingLinq == 0)
Copy link
Member

Choose a reason for hiding this comment

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

What is this writing?

commandParamsObjWriter.WriteObj(objectId, proxy.SdbHelper);
if (method.ArgumentList != null)
{
commandParamsObjWriter.Write((int)method.ArgumentList.Arguments.Count);
commandParamsObjWriter.Write((int)method.ArgumentList.Arguments.Count + isTryingLinq);
if (isTryingLinq == 1)
commandParamsObjWriter.WriteObj(objectId, proxy.SdbHelper);
foreach (var arg in method.ArgumentList.Arguments)
{
if (arg.Expression is LiteralExpressionSyntax)
Expand Down
Loading