From a97c2a1f074209584e7a6a4923d2ca029411f718 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Wed, 29 May 2024 15:43:31 -0700 Subject: [PATCH] Implement the VM service `getFlagList` API (#2438) --- dwds/CHANGELOG.md | 1 + .../src/services/chrome_proxy_service.dart | 41 ++++++++++++------- dwds/test/chrome_proxy_service_test.dart | 32 +++++++++++++++ 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 7dee0ec8a..9f835dfac 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -3,6 +3,7 @@ - Fix bug where debugging clients are not aware of service extensions when connecting to a new web app. - [#2388](https://github.com/dart-lang/webdev/pull/2388) - Respect the value of `pause_isolates_on_start` during page-refreshes. - [#2431](https://github.com/dart-lang/webdev/pull/2431) - Fix issue where DAP clients wouldn't resume after a restart. - [#2441](https://github.com/dart-lang/webdev/pull/2441) +- Add implementation for the VM Service's `getFlagList` API. - [#2438](https://github.com/dart-lang/webdev/pull/2438) ## 24.0.0 diff --git a/dwds/lib/src/services/chrome_proxy_service.dart b/dwds/lib/src/services/chrome_proxy_service.dart index 887e5e46b..cbf71ab6d 100644 --- a/dwds/lib/src/services/chrome_proxy_service.dart +++ b/dwds/lib/src/services/chrome_proxy_service.dart @@ -92,12 +92,17 @@ class ChromeProxyService implements VmServiceInterface { StreamSubscription? _consoleSubscription; - bool _pauseIsolatesOnStart = false; + /// The flags that can be set at runtime via [setFlag] and their respective + /// values. + final Map _currentVmServiceFlags = { + _pauseIsolatesOnStartFlag: false, + }; /// The value of the [_pauseIsolatesOnStartFlag]. /// /// This value can be updated at runtime via [setFlag]. - bool get pauseIsolatesOnStart => _pauseIsolatesOnStart; + bool get pauseIsolatesOnStart => + _currentVmServiceFlags[_pauseIsolatesOnStartFlag] ?? false; /// Whether or not the connected app has a pending restart. bool get hasPendingRestart => _resumeAfterRestartEventsController.hasListener; @@ -775,9 +780,22 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer. } @override - Future getFlagList() async { - // VM flags do not apply to web apps. - return FlagList(flags: []); + Future getFlagList() { + return wrapInErrorHandlerAsync( + 'getFlagList', + _getFlagList, + ); + } + + Future _getFlagList() { + final flags = _currentVmServiceFlags.entries.map( + (entry) => Flag( + name: entry.key, + valueAsString: '${entry.value}', + ), + ); + + return Future.value(FlagList(flags: flags.toList())); } @override @@ -1231,14 +1249,12 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer. ); Future _setFlag(String name, String value) async { - if (!_supportedVmServiceFlags.contains(name)) { + if (!_currentVmServiceFlags.containsKey(name)) { return _rpcNotSupportedFuture('setFlag'); } - if (name == _pauseIsolatesOnStartFlag) { - assert(value == 'true' || value == 'false'); - _pauseIsolatesOnStart = value == 'true'; - } + assert(value == 'true' || value == 'false'); + _currentVmServiceFlags[name] = value == 'true'; return Success(); } @@ -1716,8 +1732,3 @@ const _stderrTypes = ['error']; 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 44c3fd52c..678c6d98d 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -2097,6 +2097,38 @@ void main() { }); }); + group('getFlagList', () { + List stringifyFlags(FlagList flagList) { + return flagList.flags + ?.map((flag) => '${flag.name} -> ${flag.valueAsString}') + .toList() ?? + []; + } + + test('returns expected default values', () async { + final service = context.service; + final flagList = await service.getFlagList(); + expect( + stringifyFlags(flagList), + containsAll([ + 'pause_isolates_on_start -> false', + ]), + ); + }); + + test('returns any modified flag values', () async { + final service = context.service; + await service.setFlag('pause_isolates_on_start', 'true'); + final flagList = await service.getFlagList(); + expect( + stringifyFlags(flagList), + containsAll([ + 'pause_isolates_on_start -> true', + ]), + ); + }); + }); + group('streamListen/onEvent', () { late ChromeProxyService service;