Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the VM service getFlagList API #2438

Merged
merged 6 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
41 changes: 26 additions & 15 deletions dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,17 @@ class ChromeProxyService implements VmServiceInterface {

StreamSubscription<ConsoleAPIEvent>? _consoleSubscription;

bool _pauseIsolatesOnStart = false;
/// The flags that can be set at runtime via [setFlag] and their respective
/// values.
final Map<String, bool> _currentVmServiceFlags = {
_pauseIsolatesOnStartFlag: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is pause-on-exit not supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pause-on-exit is not supported - because the web doesn't have "real" isolates we mimic the pause-on-start behavior by waiting to run the app's main method until we get a resume event. However, I can't think of a way we could mimic pause-on-exit.

};

/// 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;
Expand Down Expand Up @@ -775,9 +780,22 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
}

@override
Future<FlagList> getFlagList() async {
// VM flags do not apply to web apps.
return FlagList(flags: []);
Future<FlagList> getFlagList() {
return wrapInErrorHandlerAsync(
'getFlagList',
_getFlagList,
);
}

Future<FlagList> _getFlagList() {
final flags = _currentVmServiceFlags.entries.map<Flag>(
(entry) => Flag(
name: entry.key,
valueAsString: '${entry.value}',
),
);

return Future.value(FlagList(flags: flags.toList()));
}

@override
Expand Down Expand Up @@ -1231,14 +1249,12 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
);

Future<Success> _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();
}
Expand Down Expand Up @@ -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,
};
32 changes: 32 additions & 0 deletions dwds/test/chrome_proxy_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,38 @@ void main() {
});
});

group('getFlagList', () {
List<String> 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;

Expand Down
Loading