Skip to content

Fix expression evaluation failures on empty scopes #1998

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
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 @@ -12,6 +12,7 @@
- Remove test-only code from `sdk_configuration.dart`.
- Move shared test-only code to a new `test_common` package.
- Convert unnecessary async code to sync.
- Allow empty scopes in expression evaluation in a frame.

**Breaking changes**

Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/services/expression_evaluator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ExpressionEvaluator {
/// [expression] dart expression to evaluate.
Future<RemoteObject> evaluateExpressionInFrame(String isolateId,
int frameIndex, String expression, Map<String, String>? scope) async {
if (scope != null) {
if (scope != null && scope.isNotEmpty) {
// TODO(annagrin): Implement scope support.
// Issue: https://github.com/dart-lang/webdev/issues/1344
return createError(
Expand Down
36 changes: 36 additions & 0 deletions dwds/test/expression_evaluator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:dwds/src/services/expression_evaluator.dart';
import 'package:test/test.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

import 'fixtures/context.dart';
import 'fixtures/fakes.dart';

late ExpressionEvaluator? _evaluator;
Expand Down Expand Up @@ -94,6 +95,41 @@ void main() async {
.having((o) => o.value, 'value', 'true'));
});

test('can evaluate expression in frame with null scope', () async {
// Verify that we don't get the internal error.
// More extensive testing of 'evaluateExpressionInFrame' is done in
// evaluation tests for frontend server and build daemon.
await expectLater(
evaluator.evaluateExpressionInFrame('1', 0, 'true', null),
throwsRPCErrorWithMessage(
'Cannot evaluate on a call frame when the program is not paused'));
});

test('can evaluate expression in frame with empty scope', () async {
// Verify that we don't get the internal error.
// More extensive testing of 'evaluateExpressionInFrame' is done in
// evaluation tests for frontend server and build daemon.
await expectLater(
evaluator.evaluateExpressionInFrame('1', 0, 'true', {}),
throwsRPCErrorWithMessage(
'Cannot evaluate on a call frame when the program is not paused'));
});

test('cannot evaluate expression in frame with non-empty scope',
() async {
final result = await evaluator
.evaluateExpressionInFrame('1', 0, 'true', {'a': '1'});
expect(
result,
const TypeMatcher<RemoteObject>()
.having((o) => o.type, 'type', 'InternalError')
.having(
(o) => o.value,
'value',
contains(
'Using scope for expression evaluation in frame is not supported')));
});

test('returns error if closed', () async {
evaluator.close();
final result =
Expand Down
5 changes: 5 additions & 0 deletions dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const isSentinelException = TypeMatcher<SentinelException>();
final Matcher throwsRPCError = throwsA(isRPCError);
final Matcher throwsSentinelException = throwsA(isSentinelException);

Matcher isRPCErrorWithMessage(String message) =>
isA<RPCError>().having((e) => e.message, 'message', contains(message));
Matcher throwsRPCErrorWithMessage(String message) =>
throwsA(isRPCErrorWithMessage(message));

enum CompilationMode { buildDaemon, frontendServer }

class TestContext {
Expand Down