Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9d8d713

Browse files
committed
tidy up functions
1 parent e3d8126 commit 9d8d713

7 files changed

Lines changed: 47 additions & 44 deletions

File tree

lib/web_ui/lib/src/engine/dom.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ extension DomWindowExtension on DomWindow {
127127
void postMessage(Object message, String targetOrigin,
128128
[List<DomMessagePort>? messagePorts]) {
129129
if (messagePorts == null) {
130-
_postMessage1(message.toJS, targetOrigin.toJS);
130+
_postMessage1(message.toJSAnyShallow!, targetOrigin.toJS);
131131
} else {
132132
_postMessage2(
133-
message.toJS,
133+
message.toJSAnyShallow!,
134134
targetOrigin.toJS,
135135
// Cast is necessary so we can call `.toJS` on the right extension.
136136
// ignore: unnecessary_cast
@@ -143,7 +143,7 @@ extension DomWindowExtension on DomWindow {
143143
external DomTrustedTypePolicyFactory? get trustedTypes;
144144
}
145145

146-
typedef DomRequestAnimationFrameCallback = void Function(num highResTime);
146+
typedef DomRequestAnimationFrameCallback = void Function(JSNumber highResTime);
147147

148148
@JS()
149149
@staticInterop
@@ -202,7 +202,7 @@ extension DomNavigatorExtension on DomNavigator {
202202
@JS('languages')
203203
external JSArray? get _languages;
204204
List<String>? get languages => _languages?.toDart
205-
.map((JSAny? any) => (any! as JSString).toDart)
205+
.map<String>((JSAny? any) => (any! as JSString).toDart)
206206
.toList();
207207
}
208208

@@ -889,8 +889,8 @@ class DomHTMLScriptElement extends DomHTMLElement {}
889889
extension DomHTMLScriptElementExtension on DomHTMLScriptElement {
890890
@JS('src')
891891
external set _src(JSAny value);
892-
set src(Object /* String|TrustedScriptURL */ value) => _src =
893-
value.toJSAnyShallow!;
892+
set src(Object /* String|TrustedScriptURL */ value) =>
893+
_src = value.toJSAnyShallow!;
894894
}
895895

896896
DomHTMLScriptElement createDomHTMLScriptElement() =>
@@ -1608,7 +1608,7 @@ class HttpFetchPayloadImpl implements HttpFetchPayload {
16081608
/// Returns the data as a [ByteBuffer].
16091609
@override
16101610
Future<ByteBuffer> asByteBuffer() async {
1611-
return (await _domResponse.arrayBuffer()) as ByteBuffer;
1611+
return (await _domResponse.arrayBuffer())! as ByteBuffer;
16121612
}
16131613

16141614
/// Returns the data parsed as JSON.
@@ -1869,8 +1869,8 @@ DomFontFace createDomFontFace(String family, Object source,
18691869
if (descriptors == null) {
18701870
return DomFontFace._args2(family.toJS, source.toJSAnyShallow!);
18711871
} else {
1872-
return DomFontFace._args3(family.toJS, source.toJSAnyShallow!,
1873-
descriptors.toJSAnyShallow!);
1872+
return DomFontFace._args3(
1873+
family.toJS, source.toJSAnyShallow!, descriptors.toJSAnyShallow!);
18741874
}
18751875
}
18761876

@@ -2162,10 +2162,11 @@ class DomBlob {
21622162
external factory DomBlob(JSArray parts);
21632163
}
21642164

2165-
DomBlob createDomBlob(List<Object?> parts) => DomBlob(parts.toJSAnyShallow! as JSArray);
2165+
DomBlob createDomBlob(List<Object?> parts) =>
2166+
DomBlob(parts.toJSAnyShallow! as JSArray);
21662167

21672168
typedef DomMutationCallback = void Function(
2168-
List<dynamic> mutation, DomMutationObserver observer);
2169+
JSArray mutation, DomMutationObserver observer);
21692170

21702171
@JS('MutationObserver')
21712172
@staticInterop
@@ -2885,7 +2886,7 @@ class DomMessagePort extends DomEventTarget {}
28852886
extension DomMessagePortExtension on DomMessagePort {
28862887
@JS('postMessage')
28872888
external JSVoid _postMessage(JSAny? message);
2888-
void postMessage(Object? message) => _postMessage(message?.toJS);
2889+
void postMessage(Object? message) => _postMessage(message.toJSAnyShallow);
28892890

28902891
external JSVoid start();
28912892
}
@@ -3068,7 +3069,7 @@ final DomTrustedTypePolicy _ttPolicy = domWindow.trustedTypes!.createPolicy(
30683069
createScriptURL: (JSString url) {
30693070
final Uri uri = Uri.parse(url.toDart);
30703071
if (_expectedFilesForTT.contains(uri.pathSegments.last)) {
3071-
return uri.toString();
3072+
return uri.toString().toJS;
30723073
}
30733074
domWindow.console
30743075
.error('URL rejected by TrustedTypes policy flutter-engine: $url'

lib/web_ui/lib/src/engine/font_change_util.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'dart:typed_data';
77

88
import 'dom.dart';
99
import 'platform_dispatcher.dart';
10-
import 'safe_browser_api.dart';
1110
import 'services.dart';
1211

1312
final ByteData? _fontChangeMessage =
@@ -23,13 +22,13 @@ FutureOr<void> sendFontChangeMessage() async {
2322
if (!_fontChangeScheduled) {
2423
_fontChangeScheduled = true;
2524
// Batch updates into next animationframe.
26-
domWindow.requestAnimationFrame(allowInterop((num _) {
25+
domWindow.requestAnimationFrame((_) {
2726
_fontChangeScheduled = false;
2827
EnginePlatformDispatcher.instance.invokeOnPlatformMessage(
2928
'flutter/system',
3029
_fontChangeMessage,
3130
(_) {},
3231
);
33-
}));
32+
});
3433
}
3534
}

lib/web_ui/lib/src/engine/initialization.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:async';
66
import 'dart:developer' as developer;
7+
import 'dart:js_interop';
78

89
import 'package:ui/src/engine/assets.dart';
910
import 'package:ui/src/engine/browser_detection.dart';
@@ -174,7 +175,7 @@ Future<void> initializeEngineServices({
174175
// fires.
175176
if (!waitingForAnimation) {
176177
waitingForAnimation = true;
177-
domWindow.requestAnimationFrame(allowInterop((num highResTime) {
178+
domWindow.requestAnimationFrame((JSNumber highResTime) {
178179
frameTimingsOnVsync();
179180

180181
// Reset immediately, because `frameHandler` can schedule more frames.
@@ -185,7 +186,7 @@ Future<void> initializeEngineServices({
185186
// milliseconds as a double value, with sub-millisecond information
186187
// hidden in the fraction. So we first multiply it by 1000 to uncover
187188
// microsecond precision, and only then convert to `int`.
188-
final int highResTimeMicroseconds = (1000 * highResTime).toInt();
189+
final int highResTimeMicroseconds = (1000 * highResTime.toDart).toInt();
189190

190191
// In Flutter terminology "building a frame" consists of "beginning
191192
// frame" and "drawing frame".
@@ -206,7 +207,7 @@ Future<void> initializeEngineServices({
206207
// implement it properly.
207208
EnginePlatformDispatcher.instance.invokeOnDrawFrame();
208209
}
209-
}));
210+
});
210211
}
211212
};
212213

lib/web_ui/lib/src/engine/platform_dispatcher.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:async';
66
import 'dart:convert';
7+
import 'dart:js_interop';
78
import 'dart:typed_data';
89

910
import 'package:ui/src/engine/canvaskit/renderer.dart';
@@ -934,17 +935,17 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
934935
void _addFontSizeObserver() {
935936
const String styleAttribute = 'style';
936937

937-
_fontSizeObserver = createDomMutationObserver(allowInterop(
938-
(List<dynamic> mutations, DomMutationObserver _) {
939-
for (final dynamic mutation in mutations) {
940-
final DomMutationRecord record = mutation as DomMutationRecord;
938+
_fontSizeObserver = createDomMutationObserver(
939+
(JSArray mutations, DomMutationObserver _) {
940+
for (final DomMutationRecord mutation in mutations.toDart.cast<DomMutationRecord>()) {
941+
final DomMutationRecord record = mutation;
941942
if (record.type == 'attributes' &&
942943
record.attributeName == styleAttribute) {
943944
final double newTextScaleFactor = findBrowserTextScaleFactor();
944945
_updateTextScaleFactor(newTextScaleFactor);
945946
}
946947
}
947-
}));
948+
});
948949
_fontSizeObserver!.observe(
949950
domDocument.documentElement!,
950951
attributes: true,

lib/web_ui/test/engine/surface/scene_builder_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@TestOn('chrome || firefox')
66

77
import 'dart:async';
8+
import 'dart:js_interop';
89
import 'dart:js_util' as js_util;
910

1011
import 'package:test/bootstrap/browser.dart';
@@ -500,12 +501,12 @@ void testMain() {
500501

501502
// Watches DOM mutations and counts deletions and additions to the child
502503
// list of the `<flt-scene>` element.
503-
final DomMutationObserver observer = createDomMutationObserver(allowInterop((List<dynamic> mutations, _) {
504-
for (final DomMutationRecord record in mutations.cast<DomMutationRecord>()) {
504+
final DomMutationObserver observer = createDomMutationObserver((JSArray mutations, _) {
505+
for (final DomMutationRecord record in mutations.toDart.cast<DomMutationRecord>()) {
505506
actualDeletions.addAll(record.removedNodes!);
506507
actualAdditions.addAll(record.addedNodes!);
507508
}
508-
}));
509+
});
509510
observer.observe(
510511
SurfaceSceneBuilder.debugLastFrameScene!.rootElement!, childList: true);
511512

lib/web_ui/test/text/font_collection_test.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ void testMain() {
3434
await fontManager.downloadAllFonts();
3535
fontManager.registerDownloadedFonts();
3636
domDocument.fonts!
37-
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
37+
.forEach((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
3838
fontFamilyList.add(f.family!);
39-
}));
39+
});
4040

4141
expect(fontFamilyList.length, equals(1));
4242
expect(fontFamilyList.first, 'Ahem');
@@ -51,9 +51,9 @@ void testMain() {
5151
await fontManager.downloadAllFonts();
5252
fontManager.registerDownloadedFonts();
5353
domDocument.fonts!
54-
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
54+
.forEach((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
5555
fontFamilyList.add(f.family!);
56-
}));
56+
});
5757

5858
expect(fontFamilyList.length, equals(1));
5959
expect(fontFamilyList.first, 'Ahem ahem ahem');
@@ -70,9 +70,9 @@ void testMain() {
7070
await fontManager.downloadAllFonts();
7171
fontManager.registerDownloadedFonts();
7272
domDocument.fonts!
73-
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
73+
.forEach((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
7474
fontFamilyList.add(f.family!);
75-
}));
75+
});
7676

7777
expect(fontFamilyList.length, equals(1));
7878
expect(fontFamilyList.first, 'AhEm');
@@ -89,9 +89,9 @@ void testMain() {
8989
await fontManager.downloadAllFonts();
9090
fontManager.registerDownloadedFonts();
9191
domDocument.fonts!
92-
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
92+
.forEach((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
9393
fontFamilyList.add(f.family!);
94-
}));
94+
});
9595

9696
if (browserEngine != BrowserEngine.firefox) {
9797
expect(fontFamilyList.length, equals(2));
@@ -114,9 +114,9 @@ void testMain() {
114114
await fontManager.downloadAllFonts();
115115
fontManager.registerDownloadedFonts();
116116
domDocument.fonts!
117-
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
117+
.forEach((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
118118
fontFamilyList.add(f.family!);
119-
}));
119+
});
120120

121121
if (browserEngine != BrowserEngine.firefox) {
122122
expect(fontFamilyList.length, equals(2));
@@ -139,9 +139,9 @@ void testMain() {
139139
await fontManager.downloadAllFonts();
140140
fontManager.registerDownloadedFonts();
141141
domDocument.fonts!
142-
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
142+
.forEach((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
143143
fontFamilyList.add(f.family!);
144-
}));
144+
});
145145

146146
if (browserEngine != BrowserEngine.firefox) {
147147
expect(fontFamilyList.length, equals(2));
@@ -165,9 +165,9 @@ void testMain() {
165165
await fontManager.downloadAllFonts();
166166
fontManager.registerDownloadedFonts();
167167
domDocument.fonts!
168-
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
168+
.forEach((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
169169
fontFamilyList.add(f.family!);
170-
}));
170+
});
171171

172172
if (browserEngine != BrowserEngine.firefox) {
173173
expect(fontFamilyList.length, equals(2));

lib/web_ui/test/text/font_loading_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Future<void> testMain() async {
8181
final ByteBuffer response = await httpFetchByteBuffer(testFontUrl);
8282
await ui.loadFontFromList(response.asUint8List(), fontFamily: 'Blehm');
8383
final Completer<void> completer = Completer<void>();
84-
domWindow.requestAnimationFrame(allowInterop((_) { completer.complete();}) );
84+
domWindow.requestAnimationFrame((_) { completer.complete();});
8585
await completer.future;
8686
window.onPlatformMessage = oldHandler;
8787
expect(actualName, 'flutter/system');
@@ -94,11 +94,11 @@ Future<void> testMain() async {
9494

9595
bool _containsFontFamily(String family) {
9696
bool found = false;
97-
domDocument.fonts!.forEach(allowInterop((DomFontFace fontFace,
97+
domDocument.fonts!.forEach((DomFontFace fontFace,
9898
DomFontFace fontFaceAgain, DomFontFaceSet fontFaceSet) {
9999
if (fontFace.family == family) {
100100
found = true;
101101
}
102-
}));
102+
});
103103
return found;
104104
}

0 commit comments

Comments
 (0)