Skip to content

Commit 9fa1d54

Browse files
author
Anna Gringauze
authored
Do not show native JavaScript fields, include dart:ui library (#1367)
* Do not show native js fields, include dart:ui library Fix bugs discovered in manual testing debugging on flutter apps: Closes: #1366 Closes: #1365 * Make test validate all fields of Type object * Addressed CR comments
1 parent bcc8c93 commit 9fa1d54

File tree

4 files changed

+60
-14
lines changed

4 files changed

+60
-14
lines changed

dwds/lib/src/debugging/debugger.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,10 @@ class Debugger extends Domain {
325325
// JavaScript objects
326326
return boundVariables
327327
.where((bv) =>
328-
bv != null &&
329-
!_isNativeJsObject(bv.value as vm_service.InstanceRef))
328+
bv != null && !isNativeJsObject(bv.value as vm_service.InstanceRef))
330329
.toList();
331330
}
332331

333-
bool _isNativeJsObject(vm_service.InstanceRef instanceRef) =>
334-
// New type representation of JS objects reifies them to JavaScriptObject.
335-
(instanceRef?.classRef?.name == 'JavaScriptObject' &&
336-
instanceRef?.classRef?.library?.uri == 'dart:_interceptors') ||
337-
// Old type representation still needed to support older SDK versions.
338-
instanceRef?.classRef?.name == 'NativeJavaScriptObject';
339-
340332
Future<BoundVariable> _boundVariable(Property property) async {
341333
// We return one level of properties from this object. Sub-properties are
342334
// another round trip.
@@ -511,7 +503,7 @@ class Debugger extends Domain {
511503

512504
// TODO: The exception object generally doesn't get converted to a
513505
// Dart object (and instead has a classRef name of 'NativeJavaScriptObject').
514-
if (_isNativeJsObject(exception)) {
506+
if (isNativeJsObject(exception)) {
515507
if (obj.description != null) {
516508
// Create a string exception object.
517509
exception = await inspector.instanceHelper
@@ -639,6 +631,13 @@ class Debugger extends Domain {
639631
}
640632
}
641633

634+
bool isNativeJsObject(vm_service.InstanceRef instanceRef) =>
635+
// New type representation of JS objects reifies them to JavaScriptObject.
636+
(instanceRef?.classRef?.name == 'JavaScriptObject' &&
637+
instanceRef?.classRef?.library?.uri == 'dart:_interceptors') ||
638+
// Old type representation still needed to support older SDK versions.
639+
instanceRef?.classRef?.name == 'NativeJavaScriptObject';
640+
642641
/// Returns the Dart line number for the provided breakpoint.
643642
int _lineNumberFor(Breakpoint breakpoint) =>
644643
int.parse(breakpoint.id.split('#').last);

dwds/lib/src/debugging/instance.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import '../utilities/domain.dart';
1515
import '../utilities/objects.dart';
1616
import '../utilities/shared.dart';
1717
import 'classes.dart';
18+
import 'debugger.dart';
1819
import 'inspector.dart';
1920
import 'metadata/class.dart';
2021
import 'metadata/function.dart';
@@ -169,16 +170,18 @@ class InstanceHelper extends Domain {
169170
Future<Instance> _plainInstanceFor(ClassRef classRef,
170171
RemoteObject remoteObject, List<Property> properties) async {
171172
var dartProperties = await _dartFieldsFor(properties, remoteObject);
172-
var fields = await Future.wait(
173+
var boundFields = await Future.wait(
173174
dartProperties.map<Future<BoundField>>((p) => _fieldFor(p, classRef)));
174-
fields = fields.toList()
175+
boundFields = boundFields
176+
.where((bv) => bv != null && !isNativeJsObject(bv.value as InstanceRef))
177+
.toList()
175178
..sort((a, b) => a.decl.name.compareTo(b.decl.name));
176179
var result = Instance(
177180
kind: InstanceKind.kPlainInstance,
178181
id: remoteObject.objectId,
179182
identityHashCode: remoteObject.objectId.hashCode,
180183
classRef: classRef)
181-
..fields = fields;
184+
..fields = boundFields;
182185
return result;
183186
}
184187

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class MetadataProvider {
6565
'dart:svg',
6666
'dart:web_audio',
6767
'dart:web_gl',
68-
'dart:web_sql'
68+
'dart:web_sql',
69+
'dart:ui',
6970
];
7071

7172
MetadataProvider(this.entrypoint, this._assetReader)

dwds/test/build_daemon_evaluate_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,49 @@ void main() async {
164164
});
165165
});
166166

167+
test('Type does not show native JavaScript object fields', () async {
168+
await onBreakPoint(isolate.id, mainScript, 'printLocal', () async {
169+
Future<Instance> getInstance(InstanceRef ref) async {
170+
var result = await setup.service.getObject(isolate.id, ref.id);
171+
expect(result, isA<Instance>());
172+
return result as Instance;
173+
}
174+
175+
var event = await stream.firstWhere(
176+
(event) => event.kind == EventKind.kPauseBreakpoint);
177+
178+
var result = await setup.service
179+
.evaluateInFrame(isolate.id, event.topFrame.index, 'Type');
180+
expect(result, isA<InstanceRef>());
181+
var instanceRef = result as InstanceRef;
182+
183+
// Type
184+
var instance = await getInstance(instanceRef);
185+
for (var field in instance.fields) {
186+
var name = field.decl.name;
187+
188+
// Type.<name> (i.e. Type._type)
189+
instance = await getInstance(field.value as InstanceRef);
190+
for (var field in instance.fields) {
191+
var nestedName = field.decl.name;
192+
193+
// Type.<name>.<nestedName> (i.e Type._type._subtypeCache)
194+
instance = await getInstance(field.value as InstanceRef);
195+
196+
expect(
197+
instance,
198+
isA<Instance>().having(
199+
(instance) => instance.classRef.name,
200+
'Type.$name.$nestedName: classRef.name',
201+
isNot(isIn([
202+
'NativeJavaScriptObject',
203+
'JavaScriptObject',
204+
]))));
205+
}
206+
}
207+
});
208+
});
209+
167210
test('field', () async {
168211
await onBreakPoint(
169212
isolate.id, mainScript, 'printFieldFromLibraryClass', () async {

0 commit comments

Comments
 (0)