Skip to content
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 @@
- Fix failure to map JS exceptions to dart. - [#2004](https://github.com/dart-lang/webdev/pull/2004)
- Fix for listening to custom streams. - [#2011](https://github.com/dart-lang/webdev/pull/2011)
- Handle unexpected extension debugger disconnect events without crashing the app - [#2021](https://github.com/dart-lang/webdev/pull/2021)
- Support `Set` inspection. - [#2024](https://github.com/dart-lang/webdev/pull/2024)

## 18.0.0

Expand Down
65 changes: 63 additions & 2 deletions dwds/lib/src/debugging/instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ class InstanceHelper extends Domain {
} else if (metaData.isRecord) {
return await _recordInstanceFor(classRef, remoteObject,
offset: offset, count: count, length: metaData.length);
} else if (metaData.isSet) {
return await _setInstanceFor(
classRef,
remoteObject,
offset: offset,
count: count,
length: metaData.length,
);
} else if (metaData.isNativeError) {
return await _plainInstanceFor(classRefForNativeJsError, remoteObject,
offset: offset, count: count, length: metaData.length);
Expand Down Expand Up @@ -376,7 +384,7 @@ class InstanceHelper extends Domain {
///
/// If [offset] is `null`, assumes 0 offset.
/// If [count] is `null`, return all fields starting from the offset.
Future<List<BoundField>> _recordFields(RemoteObject map,
Future<List<BoundField>> _recordFields(RemoteObject record,
{int? offset, int? count}) async {
// We do this in in awkward way because we want the keys and values, but we
// can't return things by value or some Dart objects will come back as
Expand All @@ -398,7 +406,7 @@ class InstanceHelper extends Domain {
};
}
''';
final result = await inspector.jsCallFunctionOn(map, expression, []);
final result = await inspector.jsCallFunctionOn(record, expression, []);
final positionalCountObject =
await inspector.loadField(result, 'positionalCount');
if (positionalCountObject == null || positionalCountObject.value is! int) {
Expand Down Expand Up @@ -494,6 +502,51 @@ class InstanceHelper extends Domain {
..fields = fields;
}

Future<Instance?> _setInstanceFor(
ClassRef classRef,
RemoteObject remoteObject, {
int? offset,
int? count,
int? length,
}) async {
final objectId = remoteObject.objectId;
if (objectId == null) return null;

final expression = '''
function() {
const sdkUtils = ${globalLoadStrategy.loadModuleSnippet}('dart_sdk').dart;
const jsSet = sdkUtils.dloadRepl(this, "_map");
const entries = [...jsSet.values()];
return {
entries: entries
};
}
''';

final result =
await inspector.jsCallFunctionOn(remoteObject, expression, []);
final entriesObject = await inspector.loadField(result, 'entries');
final entriesInstance =
await instanceFor(entriesObject, offset: offset, count: count);
final elements = entriesInstance?.elements ?? [];

final setInstance = Instance(
identityHashCode: remoteObject.objectId.hashCode,
kind: InstanceKind.kSet,
id: objectId,
classRef: classRef)
..length = length
..elements = elements;
if (offset != null && offset > 0) {
setInstance.offset = offset;
}
if (length != null && elements.length < length) {
setInstance.count = elements.length;
}

return setInstance;
}

/// Return the available count of elements in the requested range.
/// Return `null` if the range includes the whole object.
/// [count] is the range length requested by the `getObject` call.
Expand Down Expand Up @@ -633,6 +686,14 @@ class InstanceHelper extends Domain {
classRef: metaData.classRef)
..length = metaData.length;
}
if (metaData.isSet) {
return InstanceRef(
kind: InstanceKind.kSet,
id: objectId,
identityHashCode: remoteObject.objectId.hashCode,
classRef: metaData.classRef)
..length = metaData.length;
}
if (metaData.isNativeError) {
return InstanceRef(
kind: InstanceKind.kPlainInstance,
Expand Down
2 changes: 2 additions & 0 deletions dwds/lib/src/debugging/metadata/class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ class ClassMetaData {
/// True if this class refers to system Lists, which are treated specially.
bool get isSystemList => jsName == 'JSArray';

bool get isSet => jsName == '_HashSet';

/// True if this class refers to a function type.
bool isFunction;

Expand Down
Loading