From b88e27ab19d184c7093a5811cdb0bd33934c8e2d Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Tue, 13 Feb 2024 16:24:48 -0800 Subject: [PATCH 1/3] Implement setFlag for 'pause_isolates_on_start' --- 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 ++ 4 files changed, 70 insertions(+), 3 deletions(-) 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..6e35cb365 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' ? true : false); + } + + 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; From dae718617ee9072bcc70a92c488bea2ec2a743b4 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Tue, 13 Feb 2024 16:26:32 -0800 Subject: [PATCH 2/3] Simplify logic --- dwds/lib/src/services/chrome_proxy_service.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwds/lib/src/services/chrome_proxy_service.dart b/dwds/lib/src/services/chrome_proxy_service.dart index 6e35cb365..94d690c8c 100644 --- a/dwds/lib/src/services/chrome_proxy_service.dart +++ b/dwds/lib/src/services/chrome_proxy_service.dart @@ -1215,7 +1215,7 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer. if (name == _pauseIsolatesOnStartFlag) { assert(value == 'true' || value == 'false'); - _pauseIsolatesOnStartController.sink.add(value == 'true' ? true : false); + _pauseIsolatesOnStartController.sink.add(value == 'true'); } return Success(); From 77e8ba6198034f23491e5281bd8adae50a9e638b Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Tue, 13 Feb 2024 16:28:33 -0800 Subject: [PATCH 3/3] Update CHANGELOG --- dwds/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 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