Skip to content

Fix getObject failure on record class. #2063

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 4 commits into from
Apr 3, 2023
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
2 changes: 2 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 19.0.0-dev

- Allow clients to specify the connected app's entrypoint file. - [#2047](https://github.com/dart-lang/webdev/pull/2047)
- Fix `getObject` failure on record class - [2063](https://github.com/dart-lang/webdev/pull/2063)

## 18.0.2

Expand Down
43 changes: 27 additions & 16 deletions dwds/lib/src/debugging/metadata/class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ const _dartCoreLibrary = 'dart:core';
const _dartInterceptorsLibrary = 'dart:_interceptors';

/// A hard-coded ClassRef for the Closure class.
final classRefForClosure = classRefFor(_dartCoreLibrary, 'Closure');
final classRefForClosure = classRefFor(_dartCoreLibrary, InstanceKind.kClosure);

/// A hard-coded ClassRef for the String class.
final classRefForString = classRefFor(_dartCoreLibrary, InstanceKind.kString);

/// A hard-coded ClassRef for the Record class.
final classRefForRecord = classRefFor(_dartCoreLibrary, InstanceKind.kRecord);

/// A hard-coded ClassRef for a (non-existent) class called Unknown.
final classRefForUnknown = classRefFor(_dartCoreLibrary, 'Unknown');

Expand Down Expand Up @@ -62,15 +65,22 @@ LibraryRef libraryRefFor(String libraryId) => LibraryRef(

/// Returns a [ClassRef] for the provided library ID and class name.
ClassRef classRefFor(String libraryId, String? name) => ClassRef(
id: 'classes|$libraryId|$name',
id: classIdFor(libraryId, name),
name: name,
library: libraryRefFor(libraryId),
);

String classIdFor(String libraryId, String? name) => 'classes|$libraryId|$name';

/// Meta data for a remote Dart class in Chrome.
class ClassMetaData {
static final _logger = Logger('ClassMetadata');

/// Class id.
///
/// Takes the form of 'libraryId:name'.
final String id;

/// The name of the JS constructor for the object.
///
/// This may be a constructor for a Dart, but it's still a JS name. For
Expand All @@ -85,8 +95,8 @@ class ClassMetaData {
/// For example, 'int', 'List<String>', 'Null'
final String? dartName;

/// The library identifier, which is the URI of the library.
final String libraryId;
/// Class ref for the class metadata.
final ClassRef classRef;

factory ClassMetaData({
Object? jsName,
Expand All @@ -97,10 +107,18 @@ class ClassMetaData {
bool isRecord = false,
bool isNativeError = false,
}) {
final jName = jsName as String?;
final dName = dartName as String?;
final library = libraryId as String? ?? _dartCoreLibrary;
final id = '$library:$jName';

final classRef = isRecord ? classRefForRecord : classRefFor(library, dName);

return ClassMetaData._(
jsName as String?,
libraryId as String? ?? _dartCoreLibrary,
dartName as String?,
id,
classRef,
jName,
dName,
int.tryParse('$length'),
isFunction,
isRecord,
Expand All @@ -109,20 +127,16 @@ class ClassMetaData {
}

ClassMetaData._(
this.id,
this.classRef,
this.jsName,
this.libraryId,
this.dartName,
this.length,
this.isFunction,
this.isRecord,
this.isNativeError,
);

/// Returns the ID of the class.
///
/// Takes the form of 'libraryId:name'.
String get id => '$libraryId:$jsName';

/// Returns the [ClassMetaData] for the Chrome [remoteObject].
///
/// Returns null if the [remoteObject] is not a Dart class.
Expand Down Expand Up @@ -189,9 +203,6 @@ class ClassMetaData {
}
}

/// Return a [ClassRef] appropriate to this metadata.
ClassRef get classRef => classRefFor(libraryId, dartName);

/// True if this class refers to system maps, which are treated specially.
///
/// Classes that implement Map or inherit from MapBase are still treated as
Expand Down
36 changes: 19 additions & 17 deletions dwds/test/instances/instance_inspection_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@TestOn('vm')
@Timeout(Duration(minutes: 2))

import 'package:dwds/src/debugging/metadata/class.dart';
import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart';

Expand Down Expand Up @@ -183,23 +184,24 @@ Matcher matchSetInstance({required String type}) => isA<Instance>()
.having((e) => e.kind, 'kind', InstanceKind.kSet)
.having((e) => e.classRef!.name, 'classRef.name', type);

Matcher matchRecordInstance({required int length, required String type}) =>
isA<Instance>()
.having((e) => e.kind, 'kind', InstanceKind.kRecord)
.having((e) => e.length, 'length', length)
.having((e) => e.classRef!, 'classRef', matchRecordType(type));

/// Currently some dart versions allow for the record type
/// to show as `RecordType(type1, type2...)`, and some as `(type1, type2...)`.
/// Match both versions.
///
/// TODO(annagrin): Replace by matching `(type1, type2...)` after dart 3.0
/// is stable.
Matcher matchRecordType(String type) => isA<ClassRef>().having(
(e) => e.name,
'type name',
anyOf([type.replaceAll('RecordType', ''), type]),
);
Matcher matchRecordInstance({required int length}) => isA<Instance>()
.having((e) => e.kind, 'kind', InstanceKind.kRecord)
.having((e) => e.length, 'length', length)
.having((e) => e.classRef!, 'classRef', matchRecordType);

Matcher matchRecordClass = matchClass(libraryId: 'dart:core', type: 'Record');

Matcher matchTypeClass = matchClass(libraryId: 'dart:_runtime', type: '_Type');

Matcher matchClass({required String libraryId, required String type}) =>
isA<Class>()
.having((e) => e.name, 'name', type)
.having((e) => e.id, 'id', classIdFor(libraryId, type));

Matcher matchRecordType = matchType('Record');

Matcher matchType(String type) =>
isA<ClassRef>().having((e) => e.name, 'type name', type);

Object? _getValue(InstanceRef instanceRef) {
switch (instanceRef.kind) {
Expand Down
Loading