Skip to content

Migrate away from deprecated js_util in web_benchmarks #5574

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

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 4 additions & 0 deletions packages/web_benchmarks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Migrates benchmark recorder away from deprecated `js_util` APIs.

## 0.1.0+9

* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
Expand Down
21 changes: 11 additions & 10 deletions packages/web_benchmarks/lib/src/recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

import 'dart:async';
import 'dart:html' as html;
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we try to drop dart:html, too?

CC @yjbanov

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed flutter/flutter#139577 to track this work separately.

import 'dart:js';
import 'dart:js_util' as js_util;
import 'dart:math' as math;
import 'dart:ui';
import 'dart:ui_web' as ui_web;

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
Expand Down Expand Up @@ -1211,19 +1210,21 @@ final Map<String, EngineBenchmarkValueListener> _engineBenchmarkListeners =
///
/// If another listener is already registered, overrides it.
void registerEngineBenchmarkValueListener(
String name, EngineBenchmarkValueListener listener) {
String name,
EngineBenchmarkValueListener listener,
) {
if (_engineBenchmarkListeners.containsKey(name)) {
throw StateError('A listener for "$name" is already registered.\n'
'Call `stopListeningToEngineBenchmarkValues` to unregister the previous '
'listener before registering a new one.');
throw StateError(
'A listener for "$name" is already registered.\n'
'Call `stopListeningToEngineBenchmarkValues` to unregister the previous '
'listener before registering a new one.',
);
}

if (_engineBenchmarkListeners.isEmpty) {
// The first listener is being registered. Register the global listener.
js_util.setProperty(html.window, '_flutter_internal_on_benchmark',
allowInterop(_dispatchEngineBenchmarkValue));
ui_web.benchmarkValueCallback = _dispatchEngineBenchmarkValue;
}

_engineBenchmarkListeners[name] = listener;
}

Expand All @@ -1232,7 +1233,7 @@ void stopListeningToEngineBenchmarkValues(String name) {
_engineBenchmarkListeners.remove(name);
if (_engineBenchmarkListeners.isEmpty) {
// The last listener unregistered. Remove the global listener.
js_util.setProperty(html.window, '_flutter_internal_on_benchmark', null);
ui_web.benchmarkValueCallback = null;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/web_benchmarks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+
version: 0.1.0+9

environment:
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.10.0"
sdk: ">=3.2.0 <4.0.0"
flutter: ">=3.16.0"

dependencies:
flutter:
Expand Down