Skip to content
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

Fix failures on displaying getters #2343

Merged
merged 10 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -2,6 +2,7 @@

- Send untruncated `dart:developer` logs to debugging clients. - [#2333](https://github.com/dart-lang/webdev/pull/2333)
- Enabling tests that run with the DDC module system and exposing `utilities/ddc_names.dart` - [#2295](https://github.com/dart-lang/webdev/pull/2295)
- Fix errors on displaying getters. - [#2343](https://github.com/dart-lang/webdev/pull/2343)
annagrin marked this conversation as resolved.
Show resolved Hide resolved

## 23.1.1

Expand Down
41 changes: 39 additions & 2 deletions dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,35 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
await isCompilerInitialized;
_checkIsolate('evaluate', isolateId);

final library = await inspector.getLibrary(targetId);
late Obj object;
try {
object = await inspector.getObject(targetId);
} catch (_) {
return ErrorRef(
kind: 'error',
message: 'Evaluate is called on an unsupported target:'
'$targetId',
id: createId(),
);
}

final library =
object is Library ? object : inspector.isolate.rootLib;

if (object is Instance) {
// Evaluate is called on a target - convert this to a dart
// expression and scope by adding a target variable to the
// expression and the scope, for example:
//
// Library: 'package:hello_world/main.dart'
// Expression: 'hashCode' => 'x.hashCode'
// Scope: {} => { 'x' : targetId }

final target = _newVariableForScope(scope);
expression = '$target.$expression';
scope = (scope ?? {})..addAll({target: targetId});
}

return await _getEvaluationResult(
isolateId,
() => evaluator.evaluateExpression(
Expand All @@ -631,7 +659,7 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
);
}
throw RPCError(
'evaluateInFrame',
'evaluate',
RPCErrorKind.kInvalidRequest.code,
'Expression evaluation is not supported for this configuration.',
);
Expand All @@ -640,6 +668,15 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
);
}

String _newVariableForScope(Map<String, String>? scope) {
// Find a new variable not in scope.
var candidate = 'x';
while (scope?.containsKey(candidate) ?? false) {
candidate += '\$1';
}
return candidate;
}

@override
Future<Response> evaluateInFrame(
String isolateId,
Expand Down
50 changes: 35 additions & 15 deletions dwds/test/evaluate_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -668,24 +668,24 @@ void testAll({
tearDown(() async {});

evaluate(
libraryId,
targetId,
expr, {
scope,
}) async =>
await context.service.evaluate(
isolateId,
libraryId,
targetId,
expr,
scope: scope,
);

getInstanceRef(
libraryId,
targetId,
expr, {
scope,
}) async {
final result = await evaluate(
libraryId,
targetId,
expr,
scope: scope,
);
Expand All @@ -699,6 +699,28 @@ void testAll({
return isolate.rootLib!.id!;
}

test(
'RecordType getters',
() async {
final libraryId = getRootLibraryId();

final type = await getInstanceRef(libraryId, '(0,1).runtimeType');
final result = await getInstanceRef(type.id, 'hashCode');

expect(result, matchInstanceRefKind('Double'));
},
skip: 'https://github.com/dart-lang/sdk/issues/54609',
annagrin marked this conversation as resolved.
Show resolved Hide resolved
);

test('Object getters', () async {
final libraryId = getRootLibraryId();

final type = await getInstanceRef(libraryId, 'Object()');
final result = await getInstanceRef(type.id, 'hashCode');

expect(result, matchInstanceRefKind('Double'));
});

test('with scope', () async {
final libraryId = getRootLibraryId();

Expand Down Expand Up @@ -762,15 +784,13 @@ void testAll({
final evaluation2 = evaluate(libraryId, 'MainClass(1,1).toString()');

final results = await Future.wait([evaluation1, evaluation2]);

expect(
results[0],
matchErrorRef(contains('No batch result object ID')),
);
expect(
results[1],
matchErrorRef(contains('No batch result object ID')),
matchErrorRef(
contains('Evaluate is called on an unsupported target'),
),
);
expect(results[1], matchInstanceRef('1, 1'));
});

test('with scope override', () async {
Expand Down Expand Up @@ -902,11 +922,11 @@ Future<String> _setBreakpointInInjectedClient(WipDebugger debugger) async {
return result.json['result']['breakpointId'];
}

Matcher matchInstanceRef(dynamic value) => isA<InstanceRef>().having(
(instance) => instance.valueAsString,
'valueAsString',
value,
);
Matcher matchInstanceRefKind(String kind) =>
isA<InstanceRef>().having((instance) => instance.kind, 'kind', kind);

Matcher matchInstanceRef(dynamic value) => isA<InstanceRef>()
.having((instance) => instance.valueAsString, 'valueAsString', value);

Matcher matchInstance(dynamic className) => isA<Instance>().having(
(instance) => instance.classRef!.name,
Expand Down
Loading