Skip to content

Commit 51b5484

Browse files
authored
Implement setFlag for 'pause_isolates_on_start' (#2373)
1 parent 629c632 commit 51b5484

File tree

5 files changed

+72
-5
lines changed

5 files changed

+72
-5
lines changed

dwds/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## 23.4.0-wip
22

3-
- Adding tests for constants in DDC after a hot restart - [#2349](https://github.com/dart-lang/webdev/pull/2349)
4-
- Renaming `dart_library.js` to `ddc_module_loader.js` to match SDK naming changes - [#2360](https://github.com/dart-lang/webdev/pull/2360)
3+
- Rename `dart_library.js` to `ddc_module_loader.js` to match SDK naming changes. - [#2360](https://github.com/dart-lang/webdev/pull/2360)
4+
- Implement `setFlag` when it is called with `pause_isolates_on_start`. - [#2373](https://github.com/dart-lang/webdev/pull/2373)
55

66
## 23.3.0
77

dwds/lib/dart_web_debug_service.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class Dwds {
4747
StreamController<DebugConnection> get extensionDebugConnections =>
4848
_devHandler.extensionDebugConnections;
4949

50+
bool get shouldPauseIsolatesOnStart => _shouldPauseIsolatesOnStart;
51+
bool _shouldPauseIsolatesOnStart = false;
52+
5053
Future<void> stop() async {
5154
await _devTools?.close();
5255
await _devHandler.close();
@@ -56,7 +59,11 @@ class Dwds {
5659
Future<DebugConnection> debugConnection(AppConnection appConnection) async {
5760
if (!_enableDebugging) throw StateError('Debugging is not enabled.');
5861
final appDebugServices = await _devHandler.loadAppServices(appConnection);
59-
await appDebugServices.chromeProxyService.isInitialized;
62+
final chromeProxyService = appDebugServices.chromeProxyService;
63+
await chromeProxyService.isInitialized;
64+
chromeProxyService.pauseIsolatesOnStartStream.listen((value) {
65+
_shouldPauseIsolatesOnStart = value;
66+
});
6067
return DebugConnection(appDebugServices);
6168
}
6269

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ class ChromeProxyService implements VmServiceInterface {
9191

9292
StreamSubscription<ConsoleAPIEvent>? _consoleSubscription;
9393

94+
final _pauseIsolatesOnStartController = StreamController<bool>.broadcast();
95+
96+
/// A global stream of the value of the [_pauseIsolatesOnStartFlag].
97+
///
98+
/// The flag's value can be updated during runtime.
99+
Stream<bool> get pauseIsolatesOnStartStream =>
100+
_pauseIsolatesOnStartController.stream;
101+
94102
final _disabledBreakpoints = <Breakpoint>{};
95103
final _previousBreakpoints = <Breakpoint>{};
96104

@@ -1195,8 +1203,22 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
11951203
}
11961204

11971205
@override
1198-
Future<Success> setFlag(String name, String value) {
1199-
return _rpcNotSupportedFuture('setFlag');
1206+
Future<Success> setFlag(String name, String value) => wrapInErrorHandlerAsync(
1207+
'setFlag',
1208+
() => _setFlag(name, value),
1209+
);
1210+
1211+
Future<Success> _setFlag(String name, String value) async {
1212+
if (!_supportedVmServiceFlags.contains(name)) {
1213+
return _rpcNotSupportedFuture('setFlag');
1214+
}
1215+
1216+
if (name == _pauseIsolatesOnStartFlag) {
1217+
assert(value == 'true' || value == 'false');
1218+
_pauseIsolatesOnStartController.sink.add(value == 'true');
1219+
}
1220+
1221+
return Success();
12001222
}
12011223

12021224
@override
@@ -1657,3 +1679,10 @@ const _stderrTypes = ['error'];
16571679

16581680
/// The `type`s of [ConsoleAPIEvent]s that are treated as `stdout` logs.
16591681
const _stdoutTypes = ['log', 'info', 'warning'];
1682+
1683+
const _pauseIsolatesOnStartFlag = 'pause_isolates_on_start';
1684+
1685+
/// The flags that can be set at runtime via [setFlag].
1686+
const _supportedVmServiceFlags = {
1687+
_pauseIsolatesOnStartFlag,
1688+
};

dwds/test/chrome_proxy_service_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,34 @@ void main() {
20632063
await expectLater(service.streamCancel(''), throwsRPCError);
20642064
});
20652065

2066+
group('setFlag', () {
2067+
test('pause_isolates_on_start set to true', () {
2068+
final service = context.service;
2069+
expect(
2070+
service.setFlag('pause_isolates_on_start', 'true'),
2071+
completion(_isSuccess),
2072+
);
2073+
expect(context.dwds!.shouldPauseIsolatesOnStart, equals(true));
2074+
});
2075+
2076+
test('pause_isolates_on_start set to false', () {
2077+
final service = context.service;
2078+
expect(
2079+
service.setFlag('pause_isolates_on_start', 'false'),
2080+
completion(_isSuccess),
2081+
);
2082+
expect(context.dwds!.shouldPauseIsolatesOnStart, equals(false));
2083+
});
2084+
2085+
test('pause_isolates_on_start set to invalid value', () {
2086+
final service = context.service;
2087+
expect(
2088+
service.setFlag('pause_isolates_on_start', 'pizza'),
2089+
throwsRPCError,
2090+
);
2091+
});
2092+
});
2093+
20662094
group('streamListen/onEvent', () {
20672095
late ChromeProxyService service;
20682096

dwds/test/fixtures/context.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:build_daemon/client.dart';
1010
import 'package:build_daemon/data/build_status.dart';
1111
import 'package:build_daemon/data/build_target.dart';
1212
import 'package:dwds/asset_reader.dart';
13+
import 'package:dwds/dart_web_debug_service.dart';
1314
import 'package:dwds/src/connections/app_connection.dart';
1415
import 'package:dwds/src/connections/debug_connection.dart';
1516
import 'package:dwds/src/debugging/webkit_debugger.dart';
@@ -75,6 +76,8 @@ class TestContext {
7576
TestServer get testServer => _testServer!;
7677
TestServer? _testServer;
7778

79+
Dwds? get dwds => _testServer?.dwds;
80+
7881
BuildDaemonClient get daemonClient => _daemonClient!;
7982
BuildDaemonClient? _daemonClient;
8083

0 commit comments

Comments
 (0)