Skip to content

Commit 2e6e1b6

Browse files
author
Anna Gringauze
authored
Fix getObject failure on record class. (#2063)
1 parent b139649 commit 2e6e1b6

File tree

4 files changed

+303
-75
lines changed

4 files changed

+303
-75
lines changed

dwds/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 19.0.0-dev
2+
23
- Allow clients to specify the connected app's entrypoint file. - [#2047](https://github.com/dart-lang/webdev/pull/2047)
4+
- Fix `getObject` failure on record class - [2063](https://github.com/dart-lang/webdev/pull/2063)
35

46
## 18.0.2
57

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ const _dartCoreLibrary = 'dart:core';
1313
const _dartInterceptorsLibrary = 'dart:_interceptors';
1414

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

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

21+
/// A hard-coded ClassRef for the Record class.
22+
final classRefForRecord = classRefFor(_dartCoreLibrary, InstanceKind.kRecord);
23+
2124
/// A hard-coded ClassRef for a (non-existent) class called Unknown.
2225
final classRefForUnknown = classRefFor(_dartCoreLibrary, 'Unknown');
2326

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

6366
/// Returns a [ClassRef] for the provided library ID and class name.
6467
ClassRef classRefFor(String libraryId, String? name) => ClassRef(
65-
id: 'classes|$libraryId|$name',
68+
id: classIdFor(libraryId, name),
6669
name: name,
6770
library: libraryRefFor(libraryId),
6871
);
6972

73+
String classIdFor(String libraryId, String? name) => 'classes|$libraryId|$name';
74+
7075
/// Meta data for a remote Dart class in Chrome.
7176
class ClassMetaData {
7277
static final _logger = Logger('ClassMetadata');
7378

79+
/// Class id.
80+
///
81+
/// Takes the form of 'libraryId:name'.
82+
final String id;
83+
7484
/// The name of the JS constructor for the object.
7585
///
7686
/// This may be a constructor for a Dart, but it's still a JS name. For
@@ -85,8 +95,8 @@ class ClassMetaData {
8595
/// For example, 'int', 'List<String>', 'Null'
8696
final String? dartName;
8797

88-
/// The library identifier, which is the URI of the library.
89-
final String libraryId;
98+
/// Class ref for the class metadata.
99+
final ClassRef classRef;
90100

91101
factory ClassMetaData({
92102
Object? jsName,
@@ -97,10 +107,18 @@ class ClassMetaData {
97107
bool isRecord = false,
98108
bool isNativeError = false,
99109
}) {
110+
final jName = jsName as String?;
111+
final dName = dartName as String?;
112+
final library = libraryId as String? ?? _dartCoreLibrary;
113+
final id = '$library:$jName';
114+
115+
final classRef = isRecord ? classRefForRecord : classRefFor(library, dName);
116+
100117
return ClassMetaData._(
101-
jsName as String?,
102-
libraryId as String? ?? _dartCoreLibrary,
103-
dartName as String?,
118+
id,
119+
classRef,
120+
jName,
121+
dName,
104122
int.tryParse('$length'),
105123
isFunction,
106124
isRecord,
@@ -109,20 +127,16 @@ class ClassMetaData {
109127
}
110128

111129
ClassMetaData._(
130+
this.id,
131+
this.classRef,
112132
this.jsName,
113-
this.libraryId,
114133
this.dartName,
115134
this.length,
116135
this.isFunction,
117136
this.isRecord,
118137
this.isNativeError,
119138
);
120139

121-
/// Returns the ID of the class.
122-
///
123-
/// Takes the form of 'libraryId:name'.
124-
String get id => '$libraryId:$jsName';
125-
126140
/// Returns the [ClassMetaData] for the Chrome [remoteObject].
127141
///
128142
/// Returns null if the [remoteObject] is not a Dart class.
@@ -189,9 +203,6 @@ class ClassMetaData {
189203
}
190204
}
191205

192-
/// Return a [ClassRef] appropriate to this metadata.
193-
ClassRef get classRef => classRefFor(libraryId, dartName);
194-
195206
/// True if this class refers to system maps, which are treated specially.
196207
///
197208
/// Classes that implement Map or inherit from MapBase are still treated as

dwds/test/instances/instance_inspection_common.dart

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@TestOn('vm')
66
@Timeout(Duration(minutes: 2))
77

8+
import 'package:dwds/src/debugging/metadata/class.dart';
89
import 'package:test/test.dart';
910
import 'package:vm_service/vm_service.dart';
1011

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

186-
Matcher matchRecordInstance({required int length, required String type}) =>
187-
isA<Instance>()
188-
.having((e) => e.kind, 'kind', InstanceKind.kRecord)
189-
.having((e) => e.length, 'length', length)
190-
.having((e) => e.classRef!, 'classRef', matchRecordType(type));
191-
192-
/// Currently some dart versions allow for the record type
193-
/// to show as `RecordType(type1, type2...)`, and some as `(type1, type2...)`.
194-
/// Match both versions.
195-
///
196-
/// TODO(annagrin): Replace by matching `(type1, type2...)` after dart 3.0
197-
/// is stable.
198-
Matcher matchRecordType(String type) => isA<ClassRef>().having(
199-
(e) => e.name,
200-
'type name',
201-
anyOf([type.replaceAll('RecordType', ''), type]),
202-
);
187+
Matcher matchRecordInstance({required int length}) => isA<Instance>()
188+
.having((e) => e.kind, 'kind', InstanceKind.kRecord)
189+
.having((e) => e.length, 'length', length)
190+
.having((e) => e.classRef!, 'classRef', matchRecordType);
191+
192+
Matcher matchRecordClass = matchClass(libraryId: 'dart:core', type: 'Record');
193+
194+
Matcher matchTypeClass = matchClass(libraryId: 'dart:_runtime', type: '_Type');
195+
196+
Matcher matchClass({required String libraryId, required String type}) =>
197+
isA<Class>()
198+
.having((e) => e.name, 'name', type)
199+
.having((e) => e.id, 'id', classIdFor(libraryId, type));
200+
201+
Matcher matchRecordType = matchType('Record');
202+
203+
Matcher matchType(String type) =>
204+
isA<ClassRef>().having((e) => e.name, 'type name', type);
203205

204206
Object? _getValue(InstanceRef instanceRef) {
205207
switch (instanceRef.kind) {

0 commit comments

Comments
 (0)