From 51b5484348b4a8ede351e8dff0428b083495ba78 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:08:04 -0800 Subject: [PATCH] Implement `setFlag` for 'pause_isolates_on_start' (#2373) --- dwds/CHANGELOG.md | 4 +-- dwds/lib/dart_web_debug_service.dart | 9 ++++- .../src/services/chrome_proxy_service.dart | 33 +++++++++++++++++-- dwds/test/chrome_proxy_service_test.dart | 28 ++++++++++++++++ dwds/test/fixtures/context.dart | 3 ++ 5 files changed, 72 insertions(+), 5 deletions(-) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 79f58ba1e..596a25b57 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,7 +1,7 @@ ## 23.4.0-wip -- Adding tests for constants in DDC after a hot restart - [#2349](https://github.com/dart-lang/webdev/pull/2349) -- Renaming `dart_library.js` to `ddc_module_loader.js` to match SDK naming changes - [#2360](https://github.com/dart-lang/webdev/pull/2360) +- Rename `dart_library.js` to `ddc_module_loader.js` to match SDK naming changes. - [#2360](https://github.com/dart-lang/webdev/pull/2360) +- Implement `setFlag` when it is called with `pause_isolates_on_start`. - [#2373](https://github.com/dart-lang/webdev/pull/2373) ## 23.3.0 diff --git a/dwds/lib/dart_web_debug_service.dart b/dwds/lib/dart_web_debug_service.dart index 467e568d1..65c1c3078 100644 --- a/dwds/lib/dart_web_debug_service.dart +++ b/dwds/lib/dart_web_debug_service.dart @@ -47,6 +47,9 @@ class Dwds { StreamController get extensionDebugConnections => _devHandler.extensionDebugConnections; + bool get shouldPauseIsolatesOnStart => _shouldPauseIsolatesOnStart; + bool _shouldPauseIsolatesOnStart = false; + Future stop() async { await _devTools?.close(); await _devHandler.close(); @@ -56,7 +59,11 @@ class Dwds { Future debugConnection(AppConnection appConnection) async { if (!_enableDebugging) throw StateError('Debugging is not enabled.'); final appDebugServices = await _devHandler.loadAppServices(appConnection); - await appDebugServices.chromeProxyService.isInitialized; + final chromeProxyService = appDebugServices.chromeProxyService; + await chromeProxyService.isInitialized; + chromeProxyService.pauseIsolatesOnStartStream.listen((value) { + _shouldPauseIsolatesOnStart = value; + }); return DebugConnection(appDebugServices); } diff --git a/dwds/lib/src/services/chrome_proxy_service.dart b/dwds/lib/src/services/chrome_proxy_service.dart index 33b12ea11..94d690c8c 100644 --- a/dwds/lib/src/services/chrome_proxy_service.dart +++ b/dwds/lib/src/services/chrome_proxy_service.dart @@ -91,6 +91,14 @@ class ChromeProxyService implements VmServiceInterface { StreamSubscription? _consoleSubscription; + final _pauseIsolatesOnStartController = StreamController.broadcast(); + + /// A global stream of the value of the [_pauseIsolatesOnStartFlag]. + /// + /// The flag's value can be updated during runtime. + Stream get pauseIsolatesOnStartStream => + _pauseIsolatesOnStartController.stream; + final _disabledBreakpoints = {}; final _previousBreakpoints = {}; @@ -1195,8 +1203,22 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer. } @override - Future setFlag(String name, String value) { - return _rpcNotSupportedFuture('setFlag'); + Future setFlag(String name, String value) => wrapInErrorHandlerAsync( + 'setFlag', + () => _setFlag(name, value), + ); + + Future _setFlag(String name, String value) async { + if (!_supportedVmServiceFlags.contains(name)) { + return _rpcNotSupportedFuture('setFlag'); + } + + if (name == _pauseIsolatesOnStartFlag) { + assert(value == 'true' || value == 'false'); + _pauseIsolatesOnStartController.sink.add(value == 'true'); + } + + return Success(); } @override @@ -1657,3 +1679,10 @@ const _stderrTypes = ['error']; /// The `type`s of [ConsoleAPIEvent]s that are treated as `stdout` logs. const _stdoutTypes = ['log', 'info', 'warning']; + +const _pauseIsolatesOnStartFlag = 'pause_isolates_on_start'; + +/// The flags that can be set at runtime via [setFlag]. +const _supportedVmServiceFlags = { + _pauseIsolatesOnStartFlag, +}; diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index c2d757868..22ad31f69 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -2063,6 +2063,34 @@ void main() { await expectLater(service.streamCancel(''), throwsRPCError); }); + group('setFlag', () { + test('pause_isolates_on_start set to true', () { + final service = context.service; + expect( + service.setFlag('pause_isolates_on_start', 'true'), + completion(_isSuccess), + ); + expect(context.dwds!.shouldPauseIsolatesOnStart, equals(true)); + }); + + test('pause_isolates_on_start set to false', () { + final service = context.service; + expect( + service.setFlag('pause_isolates_on_start', 'false'), + completion(_isSuccess), + ); + expect(context.dwds!.shouldPauseIsolatesOnStart, equals(false)); + }); + + test('pause_isolates_on_start set to invalid value', () { + final service = context.service; + expect( + service.setFlag('pause_isolates_on_start', 'pizza'), + throwsRPCError, + ); + }); + }); + group('streamListen/onEvent', () { late ChromeProxyService service; diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 25a19ddf2..7780ed271 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -10,6 +10,7 @@ import 'package:build_daemon/client.dart'; import 'package:build_daemon/data/build_status.dart'; import 'package:build_daemon/data/build_target.dart'; import 'package:dwds/asset_reader.dart'; +import 'package:dwds/dart_web_debug_service.dart'; import 'package:dwds/src/connections/app_connection.dart'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/webkit_debugger.dart'; @@ -75,6 +76,8 @@ class TestContext { TestServer get testServer => _testServer!; TestServer? _testServer; + Dwds? get dwds => _testServer?.dwds; + BuildDaemonClient get daemonClient => _daemonClient!; BuildDaemonClient? _daemonClient;