Skip to content

Remove obfuscation from late fields, update example to not crash #1355

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
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
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Return empty library from `ChromeProxyService.getObject` for
libraries present in medatata but not lodaded at runtime.
- Log failures to load kernel during expression evaluation.
- Show lowered final fields using their original dart names.

## 11.1.1

Expand Down
12 changes: 9 additions & 3 deletions dwds/lib/src/debugging/instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,17 @@ class InstanceHelper extends Domain {
return fields.join(',');
}
const privateFields = sdk_utils.getOwnPropertySymbols(fields);
const nonSymbolNames = privateFields.map(sym => sym.description);
const nonSymbolNames = privateFields
.map(sym => sym.description
.split('#').slice(-1)[0]);
const publicFieldNames = sdk_utils.getOwnPropertyNames(fields);
const symbolNames = Object.getOwnPropertySymbols(this)
.map(sym => sym.description.split('.').slice(-1)[0]);
return nonSymbolNames.concat(publicFieldNames).concat(symbolNames).join(',');
.map(sym => sym.description
.split('#').slice(-1)[0]
.split('.').slice(-1)[0]);
return nonSymbolNames
.concat(publicFieldNames)
.concat(symbolNames).join(',');
}
''';
var allNames = (await inspector
Expand Down
5 changes: 5 additions & 0 deletions dwds/lib/src/utilities/objects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class Property {
var nonSymbol = (rawName.startsWith(prefix))
? rawName.substring(prefix.length, rawName.length - 1)
: rawName;
// Adjust names for late fields:
// '_#MyTestClass#myselfField' -> 'myselfField'
// TODO(annagrin): Use debug symbols to map from dart to JS symbols.
// https://github.com/dart-lang/sdk/issues/40273
nonSymbol = nonSymbol.split('#').last;
return nonSymbol.split('.').last;
}

Expand Down
8 changes: 4 additions & 4 deletions example/web/scopes_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ Function? someFunction() => null;
// ignore: unused_element
int _libraryPrivateFunction(int a, int b) => a + b;

class NotReallyAList extends ListBase<Object> {
final List<Object> _internal;
class NotReallyAList extends ListBase<Object?> {
final List<Object?> _internal;

NotReallyAList() : _internal = [];

@override
Object operator [](x) => _internal[x];
Object? operator [](x) => _internal[x];

@override
operator []=(int x, Object y) => _internal[x] = y;
operator []=(int x, Object? y) => _internal[x] = y;

@override
int get length => _internal.length;
Expand Down