blob: 077b7df48d7b7f90c0e787c9a8e5eab1ef1eab6f [file] [edit]
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Verifies that rewinding to a frame paused at a call of a closure is refused,
// as the call cannot be executed again.
import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart';
import 'common/service_test_common.dart';
import 'common/test_helper.dart';
import 'rewind_closure_call_lib.dart' as testee_lib;
IsolateTest expectGlobal(String expected) =>
(VmService service, IsolateRef isolateRef) async {
final isolateId = isolateRef.id!;
final isolate = await service.getIsolate(isolateId);
final rootLibId = isolate.libraries!
.firstWhere((l) => l.uri!.contains('rewind_closure_call_lib'))
.id!;
final result =
await service.evaluate(isolateId, rootLibId, 'global') as InstanceRef;
expect(result.valueAsString, expected);
};
Future<void> rewindToCaller(VmService service, IsolateRef isolateRef) async {
final isolateId = isolateRef.id!;
final stack = await service.getStack(isolateId);
expect(stack.frames![1].function!.name, 'caller');
try {
await service.resume(isolateId, step: StepOption.kRewind, frameIndex: 1);
fail('Unreachable');
} on RPCError catch (e) {
expect(e.code, RPCErrorKind.kIsolateCannotBeResumed.code);
expect(
e.details,
startsWith(
'Cannot rewind to frame 1 as the frame is not paused at a call that '
'can be executed again. Next valid rewind frame is 2.',
),
);
}
}
void main([args = const <String>[]]) => IsolateTestHarness(
'rewind_closure_call_lib.dart',
args,
)
.hasStoppedAtBreakpoint()
.stoppedAtLine('LINE_A')
.addCustomTest(rewindToCaller)
.resumeIsolate()
.hasStoppedAtBreakpoint()
.stoppedAtLine('LINE_C')
.addCustomTest(expectGlobal('1'))
.resumeIsolate()
.run(
testeeMain: testee_lib.main,
extraArgs: ['--trace-rewind', ...extraDebuggingArgs],
);