Skip to content
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

[release/7.0-rc2] [wasm][debugger] Removed internalProperties group. #75906

Merged
merged 1 commit into from
Sep 20, 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
33 changes: 6 additions & 27 deletions src/mono/wasm/debugger/BrowserDebugProxy/MemberObjectsExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ private static async Task<JObject> ReadFieldValue(
fieldValue["__section"] = field.Attributes switch
{
FieldAttributes.Private => "private",
FieldAttributes.Public => "result",
_ => "internal"
_ => "result"
};

if (field.IsBackingField)
Expand Down Expand Up @@ -432,8 +431,7 @@ async Task UpdateBackingFieldWithPropertyAttributes(JObject backingField, string
backingField["__section"] = getterMemberAccessAttrs switch
{
MethodAttributes.Private => "private",
MethodAttributes.Public => "result",
_ => "internal"
_ => "result"
};
backingField["__state"] = state?.ToString();

Expand Down Expand Up @@ -481,8 +479,7 @@ async Task AddProperty(
propRet["__section"] = getterAttrs switch
{
MethodAttributes.Private => "private",
MethodAttributes.Public => "result",
_ => "internal"
_ => "result"
};
propRet["__state"] = state?.ToString();
if (parentTypeId != -1)
Expand Down Expand Up @@ -659,33 +656,28 @@ static void AddOnlyNewFieldValuesByNameTo(JArray namedValues, IDictionary<string

internal sealed class GetMembersResult
{
// public:
// public / protected / internal:
public JArray Result { get; set; }
// private:
public JArray PrivateMembers { get; set; }
// protected / internal:
public JArray OtherMembers { get; set; }

public JObject JObject => JObject.FromObject(new
{
result = Result,
privateProperties = PrivateMembers,
internalProperties = OtherMembers
privateProperties = PrivateMembers
});

public GetMembersResult()
{
Result = new JArray();
PrivateMembers = new JArray();
OtherMembers = new JArray();
}

public GetMembersResult(JArray value, bool sortByAccessLevel)
{
var t = FromValues(value, sortByAccessLevel);
Result = t.Result;
PrivateMembers = t.PrivateMembers;
OtherMembers = t.OtherMembers;
}

public static GetMembersResult FromValues(IEnumerable<JToken> values, bool splitMembersByAccessLevel = false) =>
Expand Down Expand Up @@ -720,9 +712,6 @@ private void Split(JToken member)
case "private":
PrivateMembers.Add(member);
return;
case "internal":
OtherMembers.Add(member);
return;
default:
Result.Add(member);
return;
Expand All @@ -733,7 +722,6 @@ private void Split(JToken member)
{
Result = (JArray)Result.DeepClone(),
PrivateMembers = (JArray)PrivateMembers.DeepClone(),
OtherMembers = (JArray)OtherMembers.DeepClone()
};

public IEnumerable<JToken> Where(Func<JToken, bool> predicate)
Expand All @@ -752,26 +740,17 @@ public IEnumerable<JToken> Where(Func<JToken, bool> predicate)
yield return item;
}
}
foreach (var item in OtherMembers)
{
if (predicate(item))
{
yield return item;
}
}
}

internal JToken FirstOrDefault(Func<JToken, bool> p)
=> Result.FirstOrDefault(p)
?? PrivateMembers.FirstOrDefault(p)
?? OtherMembers.FirstOrDefault(p);
?? PrivateMembers.FirstOrDefault(p);

internal JArray Flatten()
{
var result = new JArray();
result.AddRange(Result);
result.AddRange(PrivateMembers);
result.AddRange(OtherMembers);
return result;
}
public override string ToString() => $"{JObject}\n";
Expand Down
5 changes: 1 addition & 4 deletions src/mono/wasm/debugger/BrowserDebugProxy/ValueTypeClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ JObject GetFieldWithMetadata(FieldTypeClass field, JObject fieldValue, bool isSt
if (isStatic)
fieldValue["name"] = field.Name;
FieldAttributes attr = field.Attributes & FieldAttributes.FieldAccessMask;
fieldValue["__section"] = attr == FieldAttributes.Public
? "public" :
attr == FieldAttributes.Private ? "private" : "internal";
fieldValue["__section"] = attr == FieldAttributes.Private ? "private" : "result";

if (field.IsBackingField)
{
Expand Down Expand Up @@ -218,7 +216,6 @@ public async Task<GetMembersResult> GetMemberValues(
result = _combinedResult.Clone();
RemovePropertiesFrom(result.Result);
RemovePropertiesFrom(result.PrivateMembers);
RemovePropertiesFrom(result.OtherMembers);
}

if (result == null)
Expand Down
9 changes: 4 additions & 5 deletions src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ internal virtual async Task<JToken> GetProperties(string id, JToken fn_args = nu
return locals;
}

internal async Task<(JToken, JToken, JToken)> GetPropertiesSortedByProtectionLevels(string id, JToken fn_args = null, bool? own_properties = null, bool? accessors_only = null, bool expect_ok = true)
internal async Task<(JToken, JToken)> GetPropertiesSortedByProtectionLevels(string id, JToken fn_args = null, bool? own_properties = null, bool? accessors_only = null, bool expect_ok = true)
{
if (UseCallFunctionOnBeforeGetProperties && !id.StartsWith("dotnet:scope:"))
{
Expand All @@ -1004,7 +1004,7 @@ internal virtual async Task<JToken> GetProperties(string id, JToken fn_args = nu
var result = await cli.SendCommand("Runtime.callFunctionOn", cfo_args, token);
AssertEqual(expect_ok, result.IsOk, $"Runtime.getProperties returned {result.IsOk} instead of {expect_ok}, for {cfo_args.ToString()}, with Result: {result}");
if (!result.IsOk)
return (null, null, null);
return (null, null);
id = result.Value["result"]?["objectId"]?.Value<string>();
}

Expand All @@ -1024,10 +1024,9 @@ internal virtual async Task<JToken> GetProperties(string id, JToken fn_args = nu
var frame_props = await cli.SendCommand("Runtime.getProperties", get_prop_req, token);
AssertEqual(expect_ok, frame_props.IsOk, $"Runtime.getProperties returned {frame_props.IsOk} instead of {expect_ok}, for {get_prop_req}, with Result: {frame_props}");
if (!frame_props.IsOk)
return (null, null, null);;
return (null, null);;

var locals = frame_props.Value["result"];
var locals_internal = frame_props.Value["internalProperties"];
var locals_private = frame_props.Value["privateProperties"];

// FIXME: Should be done when generating the list in dotnet.es6.lib.js, but not sure yet
Expand All @@ -1044,7 +1043,7 @@ internal virtual async Task<JToken> GetProperties(string id, JToken fn_args = nu
}
}

return (locals, locals_internal, locals_private);
return (locals, locals_private);
}

internal virtual async Task<(JToken, Result)> EvaluateOnCallFrame(string id, string expression, bool expect_ok = true)
Expand Down
30 changes: 13 additions & 17 deletions src/mono/wasm/debugger/DebuggerTestSuite/GetPropertiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,13 @@ private void AssertHasOnlyExpectedProperties(string[] expected_names, IEnumerabl
throw new XunitException($"missing or unexpected members found");
}

public static TheoryData<Dictionary<string, JObject>, Dictionary<string, JObject>, Dictionary<string, JObject>, string> GetDataForProtectionLevels()
public static TheoryData<Dictionary<string, JObject>, Dictionary<string, JObject>, string> GetDataForProtectionLevels()
{
var data = new TheoryData<Dictionary<string, JObject>, Dictionary<string, JObject>, Dictionary<string, JObject>, string>();
var data = new TheoryData<Dictionary<string, JObject>, Dictionary<string, JObject>, string>();

var public_props = new Dictionary<string, JObject>()
{
// --------- public ------------:
// own:
{"BaseBase_PropertyForHidingWithField", TNumber(210)},
{"Base_PropertyForOverridingWithProperty", TGetter("Base_PropertyForOverridingWithProperty", TDateTime(new DateTime(2020, 7, 6, 5, 4, 3)))},
Expand Down Expand Up @@ -487,10 +488,8 @@ public static TheoryData<Dictionary<string, JObject>, Dictionary<string, JObject
{"BaseBase_AutoPropertyForHidingWithAutoProperty (BaseBaseClass2)", TString("BaseBase#BaseBase_AutoPropertyForHidingWithAutoProperty")},
{"BaseBase_PropertyForVHO (BaseBaseClass2)", TGetter("BaseBase_PropertyForVHO (BaseBaseClass2)", TString("BaseBase#BaseBase_PropertyForVHO"))},
{"BaseBase_AutoPropertyForVHO (BaseBaseClass2)", TString("BaseBase#BaseBase_AutoPropertyForVHO")},
};

var internal_protected_props = new Dictionary<string, JObject>(){

// ---- internal / protected ----:
// own:
{"BaseBase_AutoPropertyForHidingWithProperty", TGetter("BaseBase_AutoPropertyForHidingWithProperty", TString("Derived#BaseBase_AutoPropertyForHidingWithProperty"))},
{"Base_PropertyForOverridingWithAutoProperty", TDateTime(new DateTime(2022, 7, 6, 5, 4, 3))},
Expand All @@ -510,20 +509,19 @@ public static TheoryData<Dictionary<string, JObject>, Dictionary<string, JObject
{"BaseBase_AutoPropertyForHidingWithProperty (BaseClass2)", TGetter("BaseBase_AutoPropertyForHidingWithProperty (BaseClass2)", TString("Base#BaseBase_AutoPropertyForHidingWithProperty"))},
{"BaseBase_PropertyForHidingWithAutoProperty", TString("Base#BaseBase_PropertyForHidingWithAutoProperty")},
};
data.Add(public_props, internal_protected_props, private_props, "DerivedClass2");
data.Add(public_props, private_props, "DerivedClass2");

// structure CloneableStruct:
public_props = new Dictionary<string, JObject>()
{
// own
// public
{"a", TNumber(4)},
{"DateTime", TGetter("DateTime")},
{"AutoStringProperty", TString("CloneableStruct#AutoStringProperty")},
{"FirstName", TGetter("FirstName")},
{"LastName", TGetter("LastName")}
};
internal_protected_props = new Dictionary<string, JObject>()
{
{"LastName", TGetter("LastName")},

// internal
{"b", TBool(true)}
};
Expand All @@ -533,29 +531,27 @@ public static TheoryData<Dictionary<string, JObject>, Dictionary<string, JObject
{"_dateTime", TDateTime(new DateTime(2020, 7, 6, 5, 4, 3 + 3))},
{"_DTProp", TGetter("_DTProp")}
};
data.Add(public_props, internal_protected_props, private_props, "CloneableStruct");
data.Add(public_props, private_props, "CloneableStruct");
return data;
}

[ConditionalTheory(nameof(RunningOnChrome))]
[MemberData(nameof(GetDataForProtectionLevels))]
public async Task PropertiesSortedByProtectionLevel(
Dictionary<string, JObject> expectedPublic, Dictionary<string, JObject> expectedProtInter, Dictionary<string, JObject> expectedPriv, string entryMethod) =>
Dictionary<string, JObject> expectedPublicInternalAndProtected, Dictionary<string, JObject> expectedPriv, string entryMethod) =>
await CheckInspectLocalsAtBreakpointSite(
$"DebuggerTests.GetPropertiesTests.{entryMethod}", "InstanceMethod", 1, $"DebuggerTests.GetPropertiesTests.{entryMethod}.InstanceMethod",
$"window.setTimeout(function() {{ invoke_static_method ('[debugger-test] DebuggerTests.GetPropertiesTests.{entryMethod}:run'); }})",
wait_for_event_fn: async (pause_location) =>
{
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();
var (obj, _) = await EvaluateOnCallFrame(id, "this");
var (pub, internalAndProtected, priv) = await GetPropertiesSortedByProtectionLevels(obj["objectId"]?.Value<string>());
var (pubInternalAndProtected, priv) = await GetPropertiesSortedByProtectionLevels(obj["objectId"]?.Value<string>());

AssertHasOnlyExpectedProperties(expectedPublic.Keys.ToArray(), pub.Values<JObject>());
AssertHasOnlyExpectedProperties(expectedProtInter.Keys.ToArray(), internalAndProtected.Values<JObject>());
AssertHasOnlyExpectedProperties(expectedPublicInternalAndProtected.Keys.ToArray(), pubInternalAndProtected.Values<JObject>());
AssertHasOnlyExpectedProperties(expectedPriv.Keys.ToArray(), priv.Values<JObject>());

await CheckProps(pub, expectedPublic, "public");
await CheckProps(internalAndProtected, expectedProtInter, "internalAndProtected");
await CheckProps(pubInternalAndProtected, expectedPublicInternalAndProtected, "result");
await CheckProps(priv, expectedPriv, "private");
});
}
Expand Down