-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[wasm][debugger] Remove JToken properties that are for internal use only
#75958
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
Changes from 5 commits
93911d9
5765bed
00ff482
14a2be2
c1396f7
c49e7ea
8c77f58
ea381f8
0effee7
bf636fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,17 +63,17 @@ private static async Task<JObject> ReadFieldValue( | |
| // for backing fields, we are getting it from the properties | ||
| typePropertiesBrowsableInfo.TryGetValue(field.Name, out state); | ||
| } | ||
| fieldValue["__state"] = state?.ToString(); | ||
| fieldValue["__section"] = field.Attributes.HasFlag(FieldAttributes.Private) | ||
| fieldValue[ProxyInternalUseProperty.State.ToUnderscoredString()] = state?.ToString(); | ||
| fieldValue[ProxyInternalUseProperty.Section.ToUnderscoredString()] = field.Attributes.HasFlag(FieldAttributes.Private) | ||
| ? "private" : "result"; | ||
|
|
||
| if (field.IsBackingField) | ||
| { | ||
| fieldValue["__isBackingField"] = true; | ||
| fieldValue["__parentTypeId"] = parentTypeId; | ||
| fieldValue[ProxyInternalUseProperty.IsBackingField.ToUnderscoredString()] = true; | ||
| fieldValue[ProxyInternalUseProperty.ParentTypeId.ToUnderscoredString()] = parentTypeId; | ||
| } | ||
| if (field.Attributes.HasFlag(FieldAttributes.Static)) | ||
| fieldValue["__isStatic"] = true; | ||
| fieldValue[ProxyInternalUseProperty.IsStatic.ToUnderscoredString()] = true; | ||
|
|
||
| if (getObjectOptions.HasFlag(GetObjectCommandOptions.WithSetter)) | ||
| { | ||
|
|
@@ -125,6 +125,8 @@ private static async Task<JArray> GetRootHiddenChildren( | |
| if (rootValue?["type"]?.Value<string>() != "object") | ||
| return new JArray(); | ||
|
|
||
| int? maxSize = null; | ||
|
|
||
| // unpack object/valuetype | ||
| if (rootObjectId.Scheme is "object" or "valuetype") | ||
| { | ||
|
|
@@ -150,8 +152,9 @@ private static async Task<JArray> GetRootHiddenChildren( | |
| { | ||
| // a collection - expose elements to be of array scheme | ||
| var memberNamedItems = members | ||
| .Where(m => m["name"]?.Value<string>() == "Items" || m["name"]?.Value<string>() == "_items") | ||
| .FirstOrDefault(); | ||
| .FirstOrDefault(m => m["name"]?.Value<string>() == "Items" || m["name"]?.Value<string>() == "_items"); | ||
| // sometimes items have dummy empty elements added after real items | ||
| maxSize = members.FirstOrDefault(m => m["name"]?.Value<string>() == "_size")?["value"]?["value"]?.Value<int>(); | ||
|
||
| if (memberNamedItems is not null && | ||
| (DotnetObjectId.TryParse(memberNamedItems["value"]?["objectId"]?.Value<string>(), out DotnetObjectId itemsObjectId)) && | ||
| itemsObjectId.Scheme == "array") | ||
|
|
@@ -164,6 +167,8 @@ private static async Task<JArray> GetRootHiddenChildren( | |
| if (rootObjectId.Scheme == "array") | ||
| { | ||
| JArray resultValue = await sdbHelper.GetArrayValues(rootObjectId.Value, token); | ||
| if (maxSize is not null) | ||
| resultValue = new JArray(resultValue.Take(maxSize.Value)); | ||
|
|
||
| // root hidden item name has to be unique, so we concatenate the root's name to it | ||
| foreach (var item in resultValue) | ||
|
|
@@ -282,6 +287,8 @@ public static async Task<JArray> GetExpandedMemberValues( | |
| { | ||
| if (state is DebuggerBrowsableState.RootHidden) | ||
| { | ||
| if (namePrefix == "valueTypeEnumRootHidden") | ||
| Console.WriteLine($"namePrefix = {namePrefix}; typeName = {typeName}"); | ||
ilonatommy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (MonoSDBHelper.IsPrimitiveType(typeName)) | ||
| return GetHiddenElement(); | ||
|
|
||
|
|
@@ -361,14 +368,14 @@ public static async Task<Dictionary<string, JObject>> ExpandPropertyValues( | |
| continue; | ||
| } | ||
|
|
||
| bool isExistingMemberABackingField = existingMember["__isBackingField"]?.Value<bool>() == true; | ||
| bool isExistingMemberABackingField = existingMember[ProxyInternalUseProperty.IsBackingField.ToUnderscoredString()]?.Value<bool>() == true; | ||
| if (isOwn && !isExistingMemberABackingField) | ||
| { | ||
| // repeated propname on the same type! cannot happen | ||
| throw new Exception($"Internal Error: should not happen. propName: {propName}. Existing all members: {string.Join(",", allMembers.Keys)}"); | ||
| } | ||
|
|
||
| bool isExistingMemberABackingFieldOwnedByThisType = isExistingMemberABackingField && existingMember["__owner"]?.Value<string>() == typeName; | ||
| bool isExistingMemberABackingFieldOwnedByThisType = isExistingMemberABackingField && existingMember[ProxyInternalUseProperty.Owner.ToUnderscoredString()]?.Value<string>() == typeName; | ||
| if (isExistingMemberABackingField && (isOwn || isExistingMemberABackingFieldOwnedByThisType)) | ||
| { | ||
| // this is the property corresponding to the backing field in *this* type | ||
|
|
@@ -382,8 +389,8 @@ public static async Task<Dictionary<string, JObject>> ExpandPropertyValues( | |
| { | ||
| // this has `new` keyword if it is newSlot but direct child was not a newSlot: | ||
| var child = allMembers.FirstOrDefault( | ||
| kvp => (kvp.Key == propName || kvp.Key.StartsWith($"{propName} (")) && kvp.Value["__parentTypeId"]?.Value<int>() == typeId).Value; | ||
| bool wasOverriddenByDerivedType = child != null && child["__isNewSlot"]?.Value<bool>() != true; | ||
| kvp => (kvp.Key == propName || kvp.Key.StartsWith($"{propName} (")) && kvp.Value[ProxyInternalUseProperty.ParentTypeId.ToUnderscoredString()]?.Value<int>() == typeId).Value; | ||
| bool wasOverriddenByDerivedType = child != null && child[ProxyInternalUseProperty.IsNewSlot.ToUnderscoredString()]?.Value<bool>() != true; | ||
| if (wasOverriddenByDerivedType) | ||
| { | ||
| /* | ||
|
|
@@ -409,7 +416,7 @@ public static async Task<Dictionary<string, JObject>> ExpandPropertyValues( | |
| */ | ||
|
|
||
| JObject backingFieldForHiddenProp = allMembers.GetValueOrDefault(overriddenOrHiddenPropName); | ||
| if (backingFieldForHiddenProp is null || backingFieldForHiddenProp["__isBackingField"]?.Value<bool>() != true) | ||
| if (backingFieldForHiddenProp is null || backingFieldForHiddenProp[ProxyInternalUseProperty.IsBackingField.ToUnderscoredString()]?.Value<bool>() != true) | ||
| { | ||
| // hiding with a non-auto property, so nothing to adjust | ||
| // add the new property | ||
|
|
@@ -424,12 +431,12 @@ public static async Task<Dictionary<string, JObject>> ExpandPropertyValues( | |
|
|
||
| async Task UpdateBackingFieldWithPropertyAttributes(JObject backingField, string autoPropName, MethodAttributes getterMemberAccessAttrs, DebuggerBrowsableState? state) | ||
| { | ||
| backingField["__section"] = getterMemberAccessAttrs switch | ||
| backingField[ProxyInternalUseProperty.Section.ToUnderscoredString()] = getterMemberAccessAttrs switch | ||
| { | ||
| MethodAttributes.Private => "private", | ||
| _ => "result" | ||
| }; | ||
| backingField["__state"] = state?.ToString(); | ||
| backingField[ProxyInternalUseProperty.State.ToUnderscoredString()] = state?.ToString(); | ||
|
|
||
| if (state is null) | ||
| return; | ||
|
|
@@ -472,16 +479,16 @@ async Task AddProperty( | |
| } | ||
|
|
||
| propRet["isOwn"] = isOwn; | ||
| propRet["__section"] = getterAttrs switch | ||
| propRet[ProxyInternalUseProperty.Section.ToUnderscoredString()] = getterAttrs switch | ||
| { | ||
| MethodAttributes.Private => "private", | ||
| _ => "result" | ||
| }; | ||
| propRet["__state"] = state?.ToString(); | ||
| propRet[ProxyInternalUseProperty.State.ToUnderscoredString()] = state?.ToString(); | ||
| if (parentTypeId != -1) | ||
| { | ||
| propRet["__parentTypeId"] = parentTypeId; | ||
| propRet["__isNewSlot"] = isNewSlot; | ||
| propRet[ProxyInternalUseProperty.ParentTypeId.ToUnderscoredString()] = parentTypeId; | ||
| propRet[ProxyInternalUseProperty.IsNewSlot.ToUnderscoredString()] = isNewSlot; | ||
| } | ||
|
|
||
| string namePrefix = GetNamePrefixForValues(propNameWithSufix, typeName, isOwn, state); | ||
|
|
@@ -586,7 +593,7 @@ public static async Task<GetMembersResult> GetObjectMemberValues( | |
| if (getCommandType.HasFlag(GetObjectCommandOptions.AccessorPropertiesOnly)) | ||
| { | ||
| foreach (var f in allFields) | ||
| f["__hidden"] = true; | ||
| f[ProxyInternalUseProperty.Hidden.ToUnderscoredString()] = true; | ||
| } | ||
| AddOnlyNewFieldValuesByNameTo(allFields, allMembers, typeName, isOwn); | ||
| } | ||
|
|
@@ -632,8 +639,8 @@ static void AddOnlyNewFieldValuesByNameTo(JArray namedValues, IDictionary<string | |
| if (valuesDict.TryAdd(name, item as JObject)) | ||
| { | ||
| // new member | ||
| if (item["__isBackingField"]?.Value<bool>() == true) | ||
| item["__owner"] = typeName; | ||
| if (item[ProxyInternalUseProperty.IsBackingField.ToUnderscoredString()]?.Value<bool>() == true) | ||
| item[ProxyInternalUseProperty.Owner.ToUnderscoredString()] = typeName; | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -650,6 +657,18 @@ static void AddOnlyNewFieldValuesByNameTo(JArray namedValues, IDictionary<string | |
|
|
||
| } | ||
|
|
||
| public enum ProxyInternalUseProperty | ||
| { | ||
| Hidden, | ||
| State, | ||
| Section, | ||
| Owner, | ||
| IsStatic, | ||
| IsNewSlot, | ||
| IsBackingField, | ||
| ParentTypeId | ||
| } | ||
|
|
||
| internal sealed class GetMembersResult | ||
| { | ||
| // public / protected / internal: | ||
|
|
@@ -676,6 +695,23 @@ public GetMembersResult(JArray value, bool sortByAccessLevel) | |
| PrivateMembers = t.PrivateMembers; | ||
| } | ||
|
|
||
| public void CleanUp() | ||
| { | ||
| CleanUpJArray(Result); | ||
| CleanUpJArray(PrivateMembers); | ||
| static void CleanUpJArray(JArray arr) | ||
| { | ||
| foreach(var item in arr) | ||
| { | ||
| item.Children().Where(x => | ||
| x is JProperty p && | ||
| p.Name.TryConvertToProxyInternalUseProperty()) | ||
| .ToList() | ||
ilonatommy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .ForEach(x => x.Remove()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static GetMembersResult FromValues(IEnumerable<JToken> values, bool splitMembersByAccessLevel = false) => | ||
| FromValues(new JArray(values), splitMembersByAccessLevel); | ||
|
|
||
|
|
@@ -694,10 +730,10 @@ public static GetMembersResult FromValues(JArray values, bool splitMembersByAcce | |
|
|
||
| private void Split(JToken member) | ||
| { | ||
| if (member["__hidden"]?.Value<bool>() == true) | ||
| if (member[ProxyInternalUseProperty.Hidden.ToUnderscoredString()]?.Value<bool>() == true) | ||
| return; | ||
|
|
||
| if (member["__section"]?.Value<string>() is not string section) | ||
| if (member[ProxyInternalUseProperty.Section.ToUnderscoredString()]?.Value<string>() is not string section) | ||
| { | ||
| Result.Add(member); | ||
| return; | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.