Skip to content

Commit c8d4439

Browse files
authored
Support Set inspection in DWDS (#2024)
1 parent 442639d commit c8d4439

File tree

8 files changed

+1229
-468
lines changed

8 files changed

+1229
-468
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Fix failure to map JS exceptions to dart. - [#2004](https://github.com/dart-lang/webdev/pull/2004)
44
- Fix for listening to custom streams. - [#2011](https://github.com/dart-lang/webdev/pull/2011)
55
- Handle unexpected extension debugger disconnect events without crashing the app - [#2021](https://github.com/dart-lang/webdev/pull/2021)
6+
- Support `Set` inspection. - [#2024](https://github.com/dart-lang/webdev/pull/2024)
67

78
## 18.0.0
89

dwds/lib/src/debugging/instance.dart

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ class InstanceHelper extends Domain {
128128
} else if (metaData.isRecord) {
129129
return await _recordInstanceFor(classRef, remoteObject,
130130
offset: offset, count: count, length: metaData.length);
131+
} else if (metaData.isSet) {
132+
return await _setInstanceFor(
133+
classRef,
134+
remoteObject,
135+
offset: offset,
136+
count: count,
137+
length: metaData.length,
138+
);
131139
} else if (metaData.isNativeError) {
132140
return await _plainInstanceFor(classRefForNativeJsError, remoteObject,
133141
offset: offset, count: count, length: metaData.length);
@@ -376,7 +384,7 @@ class InstanceHelper extends Domain {
376384
///
377385
/// If [offset] is `null`, assumes 0 offset.
378386
/// If [count] is `null`, return all fields starting from the offset.
379-
Future<List<BoundField>> _recordFields(RemoteObject map,
387+
Future<List<BoundField>> _recordFields(RemoteObject record,
380388
{int? offset, int? count}) async {
381389
// We do this in in awkward way because we want the keys and values, but we
382390
// can't return things by value or some Dart objects will come back as
@@ -398,7 +406,7 @@ class InstanceHelper extends Domain {
398406
};
399407
}
400408
''';
401-
final result = await inspector.jsCallFunctionOn(map, expression, []);
409+
final result = await inspector.jsCallFunctionOn(record, expression, []);
402410
final positionalCountObject =
403411
await inspector.loadField(result, 'positionalCount');
404412
if (positionalCountObject == null || positionalCountObject.value is! int) {
@@ -494,6 +502,51 @@ class InstanceHelper extends Domain {
494502
..fields = fields;
495503
}
496504

505+
Future<Instance?> _setInstanceFor(
506+
ClassRef classRef,
507+
RemoteObject remoteObject, {
508+
int? offset,
509+
int? count,
510+
int? length,
511+
}) async {
512+
final objectId = remoteObject.objectId;
513+
if (objectId == null) return null;
514+
515+
final expression = '''
516+
function() {
517+
const sdkUtils = ${globalLoadStrategy.loadModuleSnippet}('dart_sdk').dart;
518+
const jsSet = sdkUtils.dloadRepl(this, "_map");
519+
const entries = [...jsSet.values()];
520+
return {
521+
entries: entries
522+
};
523+
}
524+
''';
525+
526+
final result =
527+
await inspector.jsCallFunctionOn(remoteObject, expression, []);
528+
final entriesObject = await inspector.loadField(result, 'entries');
529+
final entriesInstance =
530+
await instanceFor(entriesObject, offset: offset, count: count);
531+
final elements = entriesInstance?.elements ?? [];
532+
533+
final setInstance = Instance(
534+
identityHashCode: remoteObject.objectId.hashCode,
535+
kind: InstanceKind.kSet,
536+
id: objectId,
537+
classRef: classRef)
538+
..length = length
539+
..elements = elements;
540+
if (offset != null && offset > 0) {
541+
setInstance.offset = offset;
542+
}
543+
if (length != null && elements.length < length) {
544+
setInstance.count = elements.length;
545+
}
546+
547+
return setInstance;
548+
}
549+
497550
/// Return the available count of elements in the requested range.
498551
/// Return `null` if the range includes the whole object.
499552
/// [count] is the range length requested by the `getObject` call.
@@ -633,6 +686,14 @@ class InstanceHelper extends Domain {
633686
classRef: metaData.classRef)
634687
..length = metaData.length;
635688
}
689+
if (metaData.isSet) {
690+
return InstanceRef(
691+
kind: InstanceKind.kSet,
692+
id: objectId,
693+
identityHashCode: remoteObject.objectId.hashCode,
694+
classRef: metaData.classRef)
695+
..length = metaData.length;
696+
}
636697
if (metaData.isNativeError) {
637698
return InstanceRef(
638699
kind: InstanceKind.kPlainInstance,

dwds/lib/src/debugging/metadata/class.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ class ClassMetaData {
196196
/// True if this class refers to system Lists, which are treated specially.
197197
bool get isSystemList => jsName == 'JSArray';
198198

199+
bool get isSet => jsName == '_HashSet';
200+
199201
/// True if this class refers to a function type.
200202
bool isFunction;
201203

0 commit comments

Comments
 (0)