From 2e89a0784acfdd8af49c05eac62254a8b9d8cf2f Mon Sep 17 00:00:00 2001 From: Yegor Date: Wed, 4 Aug 2021 17:23:21 -0700 Subject: [PATCH] [web] remove implicit casts and implicit dynamic (flutter/engine#27882) --- .../flutter/lib/web_ui/analysis_options.yaml | 5 - .../lib/web_ui/lib/src/engine/assets.dart | 2 +- .../src/engine/canvaskit/font_fallbacks.dart | 8 +- .../lib/src/engine/canvaskit/fonts.dart | 15 ++- .../src/engine/canvaskit/initialization.dart | 2 +- .../lib/src/engine/canvaskit/layer.dart | 2 +- .../web_ui/lib/src/engine/canvaskit/text.dart | 2 +- .../lib/web_ui/lib/src/engine/clipboard.dart | 2 +- .../web_ui/lib/src/engine/dom_renderer.dart | 11 ++- .../lib/src/engine/html/offscreen_canvas.dart | 7 +- .../engine/html/shaders/webgl_context.dart | 29 ++++-- .../lib/src/engine/html_image_codec.dart | 13 ++- .../lib/web_ui/lib/src/engine/keyboard.dart | 2 +- .../lib/src/engine/keyboard_binding.dart | 3 +- .../lib/src/engine/platform_dispatcher.dart | 12 +-- .../platform_views/content_manager.dart | 2 +- .../platform_views/message_handler.dart | 9 +- .../lib/src/engine/pointer_binding.dart | 2 +- .../lib/web_ui/lib/src/engine/profiler.dart | 2 +- .../src/engine/semantics/accessibility.dart | 7 +- .../src/engine/services/message_codecs.dart | 9 +- .../lib/src/engine/text/font_collection.dart | 11 +-- .../web_ui/lib/src/engine/text/paragraph.dart | 6 +- .../src/engine/text_editing/text_editing.dart | 93 +++++++++++-------- .../lib/web_ui/lib/src/engine/util.dart | 82 +++++++++++++++- .../web_ui/lib/src/engine/vector_math.dart | 16 ---- .../lib/web_ui/lib/src/engine/window.dart | 11 ++- .../lib/web_ui/test/clipboard_test.dart | 4 +- .../test/engine/pointer_binding_test.dart | 14 ++- .../lib/web_ui/test/engine/profiler_test.dart | 11 ++- .../engine/surface/scene_builder_test.dart | 2 +- .../html/canvas_clip_path_golden_test.dart | 2 +- .../compositing/canvas_blend_golden_test.dart | 2 +- .../compositing/color_filter_golden_test.dart | 2 +- .../canvas_draw_image_golden_test.dart | 2 +- .../drawing/draw_vertices_golden_test.dart | 2 +- .../shaders/image_shader_golden_test.dart | 2 +- .../lib/web_ui/test/keyboard_test.dart | 24 ++--- .../src/flutter/lib/web_ui/test/matchers.dart | 3 + .../web_ui/test/text/font_loading_test.dart | 6 +- .../lib/web_ui/test/text_editing_test.dart | 6 +- .../lib/web_ui/tool/unicode_sync_script.dart | 6 +- 42 files changed, 283 insertions(+), 170 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/analysis_options.yaml b/engine/src/flutter/lib/web_ui/analysis_options.yaml index 9e6bab0f4a..60918b30bb 100644 --- a/engine/src/flutter/lib/web_ui/analysis_options.yaml +++ b/engine/src/flutter/lib/web_ui/analysis_options.yaml @@ -6,11 +6,6 @@ include: ../../analysis_options.yaml -analyzer: - strong-mode: - implicit-casts: true - implicit-dynamic: true - linter: rules: public_member_api_docs: false \ No newline at end of file diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/assets.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/assets.dart index 350e4daa87..a1bbfcc5eb 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/assets.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/assets.dart @@ -61,7 +61,7 @@ class AssetManager { final html.HttpRequest request = await html.HttpRequest.request(url, responseType: 'arraybuffer'); - final ByteBuffer response = request.response; + final ByteBuffer response = request.response as ByteBuffer; return response.asByteData(); } on html.ProgressEvent catch (e) { final html.EventTarget? target = e.target; diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart index 15db754fe5..85dc7938e9 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/font_fallbacks.dart @@ -969,8 +969,8 @@ class NotoDownloader { if (assertionsEnabled) { _debugActiveDownloadCount += 1; } - final Future result = html.window.fetch(url).then( - (dynamic fetchResult) => fetchResult + final Future result = httpFetch(url).then( + (html.Body fetchResult) => fetchResult .arrayBuffer() .then((dynamic x) => x as ByteBuffer)); if (assertionsEnabled) { @@ -988,8 +988,8 @@ class NotoDownloader { if (assertionsEnabled) { _debugActiveDownloadCount += 1; } - final Future result = html.window.fetch(url).then( - (dynamic response) => + final Future result = httpFetch(url).then( + (html.Body response) => response.text().then((dynamic x) => x as String)); if (assertionsEnabled) { result.whenComplete(() { diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/fonts.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/fonts.dart index 07805d0004..3bd5eae920 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/fonts.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/fonts.dart @@ -109,7 +109,7 @@ class SkiaFontCollection { } final List? fontManifest = - json.decode(utf8.decode(byteData.buffer.asUint8List())); + json.decode(utf8.decode(byteData.buffer.asUint8List())) as List?; if (fontManifest == null) { throw AssertionError( 'There was a problem trying to load FontManifest.json'); @@ -119,16 +119,16 @@ class SkiaFontCollection { for (final Map fontFamily in fontManifest.cast>()) { - final String family = fontFamily['family']!; - final List fontAssets = fontFamily['fonts']; + final String family = fontFamily.readString('family'); + final List fontAssets = fontFamily.readList('fonts'); if (family == 'Roboto') { registeredRoboto = true; } for (final dynamic fontAssetItem in fontAssets) { - final Map fontAsset = fontAssetItem; - final String asset = fontAsset['asset']; + final Map fontAsset = fontAssetItem as Map; + final String asset = fontAsset.readString('asset'); _unloadedFonts .add(_registerFont(assetManager.getAssetUrl(asset), family)); } @@ -151,7 +151,7 @@ class SkiaFontCollection { Future _registerFont(String url, String family) async { ByteBuffer buffer; try { - buffer = await html.window.fetch(url).then(_getArrayBuffer); + buffer = await httpFetch(url).then(_getArrayBuffer); } catch (e) { printWarning('Failed to load font $family at $url'); printWarning(e.toString()); @@ -178,8 +178,7 @@ class SkiaFontCollection { return actualFamily; } - Future _getArrayBuffer(dynamic fetchResult) { - // TODO(yjbanov): fetchResult.arrayBuffer is a dynamic invocation. Clean it up. + Future _getArrayBuffer(html.Body fetchResult) { return fetchResult .arrayBuffer() .then((dynamic x) => x as ByteBuffer); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/initialization.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/initialization.dart index ef8c905a25..39744ca334 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/initialization.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/initialization.dart @@ -179,7 +179,7 @@ void _startDownloadingCanvasKit(String? canvasKitBase) { // First check if `exports` and `module` are already defined. If so, then // CommonJS is being used, and we shouldn't have any problems. - final js.JsFunction objectConstructor = js.context['Object']; + final js.JsFunction objectConstructor = js.context['Object'] as js.JsFunction; if (js.context['exports'] == null) { final js.JsObject exportsAccessor = js.JsObject.jsify({ 'get': js.allowInterop(() { diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/layer.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/layer.dart index 8b9e22e887..d061e4ab88 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/layer.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/layer.dart @@ -361,7 +361,7 @@ class TransformEngineLayer extends ContainerLayer @override void preroll(PrerollContext prerollContext, Matrix4 matrix) { - final Matrix4 childMatrix = matrix * _transform; + final Matrix4 childMatrix = matrix.multiplied(_transform); prerollContext.mutatorsStack.pushTransform(_transform); final ui.Rect childPaintBounds = prerollChildren(prerollContext, childMatrix); paintBounds = transformRect(_transform, childPaintBounds); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart index 97453df880..afa865166d 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/text.dart @@ -725,7 +725,7 @@ class CkParagraph extends SkiaObject implements ui.Paragraph { final List result = []; for (int i = 0; i < skRects.length; i++) { - final List rect = skRects[i]; + final List rect = skRects[i] as List; result.add(ui.TextBox.fromLTRBD( rect[0], rect[1], diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/clipboard.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/clipboard.dart index 3cd1d4ef33..4bc1e8da24 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/clipboard.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/clipboard.dart @@ -25,7 +25,7 @@ class ClipboardMessageHandler { const MethodCodec codec = JSONMethodCodec(); bool errorEnvelopeEncoded = false; _copyToClipboardStrategy - .setData(methodCall.arguments['text']) + .setData(methodCall.arguments['text'] as String?) .then((bool success) { if (success) { callback!(codec.encodeSuccessEnvelope(true)); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/dom_renderer.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/dom_renderer.dart index d584e12316..694d4f89f8 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/dom_renderer.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/dom_renderer.dart @@ -115,12 +115,12 @@ class DomRenderer { /// See for more details: /// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus bool get windowHasFocus => - js_util.callMethod(html.document, 'hasFocus', []) ?? false; + js_util.callMethod(html.document, 'hasFocus', []) as bool; void _setupHotRestart() { // This persists across hot restarts to clear stale DOM. _staleHotRestartState = - js_util.getProperty(html.window, _staleHotRestartStore); + js_util.getProperty(html.window, _staleHotRestartStore) as List?; if (_staleHotRestartState == null) { _staleHotRestartState = []; js_util.setProperty( @@ -238,7 +238,10 @@ class DomRenderer { static void setElementTransform(html.Element element, String transformValue) { js_util.setProperty( - js_util.getProperty(element, 'style'), 'transform', transformValue); + js_util.getProperty(element, 'style') as Object, + 'transform', + transformValue, + ); } void setText(html.Element element, String text) { @@ -571,7 +574,7 @@ class DomRenderer { return Future.value(true); } else { final String? lockType = - _deviceOrientationToLockType(orientations.first); + _deviceOrientationToLockType(orientations.first as String?); if (lockType != null) { final Completer completer = Completer(); try { diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/html/offscreen_canvas.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/html/offscreen_canvas.dart index 88e027c890..3fae5d1096 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/html/offscreen_canvas.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/html/offscreen_canvas.dart @@ -69,15 +69,16 @@ class OffScreenCanvas { 0, 0, width, height]); } - /// Converts canvas contents to an image and returns as data url. + /// Converts canvas contents to an image and returns as data URL. Future toDataUrl() { final Completer completer = Completer(); if (offScreenCanvas != null) { offScreenCanvas!.convertToBlob().then((html.Blob value) { final html.FileReader fileReader = html.FileReader(); fileReader.onLoad.listen((html.ProgressEvent event) { - completer.complete(js_util.getProperty( - js_util.getProperty(event, 'target')!, 'result')!); + completer.complete( + js_util.getProperty(js_util.getProperty(event, 'target') as Object, 'result') as String, + ); }); fileReader.readAsDataUrl(value); }); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/html/shaders/webgl_context.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/html/shaders/webgl_context.dart index bd4b4b03e6..1343647ec6 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/html/shaders/webgl_context.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/html/shaders/webgl_context.dart @@ -113,8 +113,11 @@ class GlContext { } js_util.callMethod(glContext, 'shaderSource', [shader, source]); js_util.callMethod(glContext, 'compileShader', [shader]); - final bool shaderStatus = js_util - .callMethod(glContext, 'getShaderParameter', [shader, compileStatus]); + final bool shaderStatus = js_util.callMethod( + glContext, + 'getShaderParameter', + [shader, compileStatus], + ) as bool; if (!shaderStatus) { throw Exception('Shader compilation failed: ${getShaderInfoLog(shader)}'); } @@ -122,7 +125,7 @@ class GlContext { } Object createProgram() => - js_util.callMethod(glContext, 'createProgram', const [])!; + js_util.callMethod(glContext, 'createProgram', const []) as Object; void attachShader(Object? program, Object shader) { js_util.callMethod(glContext, 'attachShader', [program, shader]); @@ -130,8 +133,12 @@ class GlContext { void linkProgram(Object program) { js_util.callMethod(glContext, 'linkProgram', [program]); - if (!js_util - .callMethod(glContext, 'getProgramParameter', [program, kLinkStatus])) { + final bool programStatus = js_util.callMethod( + glContext, + 'getProgramParameter', + [program, kLinkStatus], + ) as bool; + if (!programStatus) { throw Exception(getProgramInfoLog(program)); } } @@ -219,7 +226,11 @@ class GlContext { /// Destroys gl context. void dispose() { - js_util.callMethod(_getExtension('WEBGL_lose_context'), 'loseContext', const []); + js_util.callMethod( + _getExtension('WEBGL_lose_context') as Object, + 'loseContext', + const [], + ); } void deleteProgram(Object program) { @@ -393,13 +404,13 @@ class GlContext { /// Errors that occurred during failed linking or validation of program /// objects. Typically called after [linkProgram]. String? getProgramInfoLog(Object glProgram) { - return js_util.callMethod(glContext, 'getProgramInfoLog', [glProgram]); + return js_util.callMethod(glContext, 'getProgramInfoLog', [glProgram]) as String?; } int? get drawingBufferWidth => - js_util.getProperty(glContext, 'drawingBufferWidth'); + js_util.getProperty(glContext, 'drawingBufferWidth') as int?; int? get drawingBufferHeight => - js_util.getProperty(glContext, 'drawingBufferWidth'); + js_util.getProperty(glContext, 'drawingBufferWidth') as int?; /// Reads gl contents as image data. /// diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/html_image_codec.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/html_image_codec.dart index ee68d6db88..01c394354d 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/html_image_codec.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/html_image_codec.dart @@ -12,11 +12,14 @@ import 'package:ui/ui.dart' as ui; import 'browser_detection.dart'; import 'util.dart'; -final bool _supportsDecode = js_util.getProperty( - js_util.getProperty( - js_util.getProperty(html.window, 'Image'), 'prototype'), - 'decode') != - null; +Object? get _jsImageDecodeFunction => js_util.getProperty( + js_util.getProperty( + js_util.getProperty(html.window, 'Image') as Object, + 'prototype', + ) as Object, + 'decode', +); +final bool _supportsDecode = _jsImageDecodeFunction != null; typedef WebOnlyImageCodecChunkCallback = void Function( int cumulativeBytesLoaded, int expectedTotalBytes); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/keyboard.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/keyboard.dart index 74779355e0..6153455cdd 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/keyboard.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/keyboard.dart @@ -136,7 +136,7 @@ class Keyboard { if (data == null) { return; } - final Map jsonResponse = _messageCodec.decodeMessage(data); + final Map jsonResponse = _messageCodec.decodeMessage(data) as Map; if (jsonResponse['handled'] as bool) { // If the framework handled it, then don't propagate it any further. event.preventDefault(); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/keyboard_binding.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/keyboard_binding.dart index 086743a868..6895cb1888 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/keyboard_binding.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/keyboard_binding.dart @@ -124,8 +124,9 @@ class KeyboardBinding { print(event.type); } if (EngineSemanticsOwner.instance.receiveGlobalEvent(event)) { - return handler(event); + return handler(event) as html.EventListener?; } + return null; } assert(!_listeners.containsKey(eventName)); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 1b7ae1537c..6957a192e6 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -416,12 +416,12 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { }); return; case 'HapticFeedback.vibrate': - final String? type = decoded.arguments; + final String? type = decoded.arguments as String?; domRenderer.vibrate(_getHapticFeedbackDuration(type)); replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true)); return; case 'SystemChrome.setApplicationSwitcherDescription': - final Map arguments = decoded.arguments; + final Map arguments = decoded.arguments as Map; // TODO(ferhat): Find more appropriate defaults? Or noop when values are null? final String label = arguments['label'] as String? ?? ''; final int primaryColor = arguments['primaryColor'] as int? ?? 0xFF000000; @@ -430,7 +430,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true)); return; case 'SystemChrome.setPreferredOrientations': - final List arguments = decoded.arguments; + final List arguments = decoded.arguments as List; domRenderer.setPreferredOrientation(arguments).then((bool success) { replyToPlatformMessage( callback, codec.encodeSuccessEnvelope(success)); @@ -461,10 +461,10 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { case 'flutter/mousecursor': const MethodCodec codec = StandardMethodCodec(); final MethodCall decoded = codec.decodeMethodCall(data); - final Map arguments = decoded.arguments; + final Map arguments = decoded.arguments as Map; switch (decoded.method) { case 'activateSystemCursor': - MouseCursor.instance!.activateSystemCursor(arguments['kind']); + MouseCursor.instance!.activateSystemCursor(arguments.tryString('kind')); } return; @@ -1001,7 +1001,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { bool _handleWebTestEnd2EndMessage(MethodCodec codec, ByteData? data) { final MethodCall decoded = codec.decodeMethodCall(data); - final double ratio = double.parse(decoded.arguments); + final double ratio = double.parse(decoded.arguments as String); switch (decoded.method) { case 'setDevicePixelRatio': window.debugOverrideDevicePixelRatio(ratio); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_views/content_manager.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_views/content_manager.dart index 38c52ebdd8..064bed679a 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_views/content_manager.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_views/content_manager.dart @@ -117,7 +117,7 @@ class PlatformViewManager { if (factoryFunction is ParameterizedPlatformViewFactory) { content = factoryFunction(viewId, params: params); } else { - content = factoryFunction(viewId); + content = (factoryFunction as PlatformViewFactory).call(viewId); } _ensureContentCorrectlySized(content, viewType); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_views/message_handler.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_views/message_handler.dart index d823e58302..a46fff244a 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_views/message_handler.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_views/message_handler.dart @@ -6,6 +6,7 @@ import 'dart:html' as html; import 'dart:typed_data'; import '../services.dart'; +import '../util.dart'; import 'content_manager.dart'; /// The signature for a callback for a Platform Message. From the `ui` package. @@ -65,9 +66,9 @@ class PlatformViewMessageHandler { MethodCall methodCall, _PlatformMessageResponseCallback callback, ) { - final Map args = methodCall.arguments; - final int viewId = args['id']; - final String viewType = args['viewType']; + final Map args = methodCall.arguments as Map; + final int viewId = args.readInt('id'); + final String viewType = args.readString('viewType'); if (!_contentManager.knowsViewType(viewType)) { callback(_codec.encodeErrorEnvelope( @@ -116,7 +117,7 @@ class PlatformViewMessageHandler { MethodCall methodCall, _PlatformMessageResponseCallback callback, ) { - final int viewId = methodCall.arguments; + final int viewId = methodCall.arguments as int; // The contentManager removes the slot and the contents from its internal // cache, and the DOM. diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/pointer_binding.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/pointer_binding.dart index 9f1d57694d..faa6e87e4a 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/pointer_binding.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/pointer_binding.dart @@ -293,7 +293,7 @@ mixin _WheelEventListenerMixin on _BaseAdapter { } void _addWheelEventListener(html.EventListener handler) { - final dynamic eventOptions = js_util.newObject(); + final Object eventOptions = js_util.newObject() as Object; final html.EventListener jsHandler = js.allowInterop((html.Event event) => handler(event)); _BaseAdapter._nativeListeners['wheel'] = jsHandler; js_util.setProperty(eventOptions, 'passive', false); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/profiler.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/profiler.dart index 9458de8ce8..b5f14383d3 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/profiler.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/profiler.dart @@ -106,7 +106,7 @@ class Profiler { _checkBenchmarkMode(); final OnBenchmark? onBenchmark = - js_util.getProperty(html.window, '_flutter_internal_on_benchmark'); + js_util.getProperty(html.window, '_flutter_internal_on_benchmark') as OnBenchmark?; if (onBenchmark != null) { onBenchmark(name, value); } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/accessibility.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/accessibility.dart index f81bc94f43..2a63357d53 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/accessibility.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/accessibility.dart @@ -8,6 +8,7 @@ import 'dart:typed_data'; import '../../engine.dart' show registerHotRestartListener; import '../services.dart'; +import '../util.dart'; /// Singleton for accessing accessibility announcements from the platform. final AccessibilityAnnouncements accessibilityAnnouncements = @@ -58,9 +59,9 @@ class AccessibilityAnnouncements { /// Decodes the message coming from the 'flutter/accessibility' channel. void handleMessage(StandardMessageCodec codec, ByteData? data) { final Map inputMap = - codec.decodeMessage(data); - final Map dataMap = inputMap['data']; - final String? message = dataMap['message']; + codec.decodeMessage(data) as Map; + final Map dataMap = inputMap.readDynamicJson('data'); + final String? message = dataMap.tryString('message'); if (message != null && message.isNotEmpty) { _initLiveRegion(message); _removeElementTimer = Timer(durationA11yMessageIsOnDom, () { diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/services/message_codecs.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/services/message_codecs.dart index 777386978c..3f7257989f 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/services/message_codecs.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/services/message_codecs.dart @@ -144,8 +144,8 @@ class JSONMethodCodec implements MethodCodec { decoded[0] is String && (decoded[1] == null || decoded[1] is String)) { throw PlatformException( - code: decoded[0], - message: decoded[1], + code: decoded[0] as String, + message: decoded[1] as String?, details: decoded[2], ); } @@ -559,7 +559,10 @@ class StandardMethodCodec implements MethodCodec { (errorMessage == null || errorMessage is String) && !buffer.hasRemaining) throw PlatformException( - code: errorCode, message: errorMessage, details: errorDetails); + code: errorCode, + message: errorMessage as String?, + details: errorDetails, + ); else throw const FormatException('Invalid envelope'); } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text/font_collection.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text/font_collection.dart index 8a93fd1824..4538545ed3 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/text/font_collection.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text/font_collection.dart @@ -46,7 +46,7 @@ class FontCollection { } final List? fontManifest = - json.decode(utf8.decode(byteData.buffer.asUint8List())); + json.decode(utf8.decode(byteData.buffer.asUint8List())) as List?; if (fontManifest == null) { throw AssertionError( 'There was a problem trying to load FontManifest.json'); @@ -60,12 +60,11 @@ class FontCollection { for (final Map fontFamily in fontManifest.cast>()) { - final String? family = fontFamily['family']; - final List fontAssets = fontFamily['fonts']; + final String? family = fontFamily.tryString('family'); + final List> fontAssets = fontFamily.castList>('fonts'); - for (final dynamic fontAssetItem in fontAssets) { - final Map fontAsset = fontAssetItem; - final String asset = fontAsset['asset']; + for (final Map fontAsset in fontAssets) { + final String asset = fontAsset.readString('asset'); final Map descriptors = {}; for (final String descriptor in fontAsset.keys) { if (descriptor != 'asset') { diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart index fb1447bb0d..8a942ac0c6 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text/paragraph.dart @@ -1372,7 +1372,7 @@ class DomParagraphBuilder implements ui.ParagraphBuilder { // entirely. Occasionally there will be one [pushStyle], which causes this // loop to run once then move on to aggregating text. while (i < _ops.length && _ops[i] is EngineTextStyle) { - final EngineTextStyle style = _ops[i]; + final EngineTextStyle style = _ops[i] as EngineTextStyle; if (style.color != null) { color = style.color!; } @@ -1554,8 +1554,8 @@ class DomParagraphBuilder implements ui.ParagraphBuilder { /// Builds a [Paragraph] as rich text. EngineParagraph _buildRichText() { - final List elementStack = []; - dynamic currentElement() => + final List elementStack = []; + html.Element currentElement() => elementStack.isNotEmpty ? elementStack.last : _paragraphElement; for (int i = 0; i < _ops.length; i++) { diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart index ae5971218c..99860c3a02 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart @@ -191,17 +191,20 @@ class EngineAutofillForm { if (fields != null) { for (final Map field in fields.cast>()) { - final Map autofillInfo = field['autofill']; + final Map autofillInfo = field.readJson('autofill'); final AutofillInfo autofill = AutofillInfo.fromFrameworkMessage( - autofillInfo, - textCapitalization: TextCapitalizationConfig.fromInputConfiguration( - field['textCapitalization'])); + autofillInfo, + textCapitalization: TextCapitalizationConfig.fromInputConfiguration( + field.readString('textCapitalization'), + ), + ); ids.add(autofill.uniqueIdentifier); if (autofill.uniqueIdentifier != focusedElement.uniqueIdentifier) { - final EngineInputType engineInputType = - EngineInputType.fromName(field['inputType']['name']); + final EngineInputType engineInputType = EngineInputType.fromName( + field.readJson('inputType').readString('name'), + ); final html.HtmlElement htmlElement = engineInputType.createDomElement(); autofill.editingState.applyToDomElement(htmlElement); @@ -367,15 +370,16 @@ class AutofillInfo { {TextCapitalizationConfig textCapitalization = const TextCapitalizationConfig.defaultCapitalization()}) { assert(autofill != null); // ignore: unnecessary_null_comparison - final String uniqueIdentifier = autofill['uniqueIdentifier']!; - final List hintsList = autofill['hints']; + final String uniqueIdentifier = autofill.readString('uniqueIdentifier'); + final List hintsList = autofill.readList('hints'); final EditingState editingState = - EditingState.fromFrameworkMessage(autofill['editingValue']); + EditingState.fromFrameworkMessage(autofill.readJson('editingValue')); return AutofillInfo( - uniqueIdentifier: uniqueIdentifier, - hint: BrowserAutofillHints.instance.flutterToEngine(hintsList[0]), - editingState: editingState, - textCapitalization: textCapitalization); + uniqueIdentifier: uniqueIdentifier, + hint: BrowserAutofillHints.instance.flutterToEngine(hintsList[0] as String), + editingState: editingState, + textCapitalization: textCapitalization, + ); } void applyToDomElement(html.HtmlElement domElement, @@ -429,9 +433,9 @@ class EditingState { /// valid selection range for input DOM elements. factory EditingState.fromFrameworkMessage( Map flutterEditingState) { - final int selectionBase = flutterEditingState['selectionBase']; - final int selectionExtent = flutterEditingState['selectionExtent']; - final String? text = flutterEditingState['text']; + final int selectionBase = flutterEditingState.readInt('selectionBase'); + final int selectionExtent = flutterEditingState.readInt('selectionExtent'); + final String? text = flutterEditingState.tryString('text'); return EditingState( text: text, @@ -576,24 +580,25 @@ class InputConfiguration { InputConfiguration.fromFrameworkMessage( Map flutterInputConfiguration) : inputType = EngineInputType.fromName( - flutterInputConfiguration['inputType']['name'], - isDecimal: flutterInputConfiguration['inputType']['decimal'] ?? false, + flutterInputConfiguration.readJson('inputType').readString('name'), + isDecimal: flutterInputConfiguration.readJson('inputType').tryBool('decimal') ?? false, ), inputAction = - flutterInputConfiguration['inputAction'] ?? 'TextInputAction.done', - obscureText = flutterInputConfiguration['obscureText'] ?? false, - readOnly = flutterInputConfiguration['readOnly'] ?? false, - autocorrect = flutterInputConfiguration['autocorrect'] ?? true, + flutterInputConfiguration.tryString('inputAction') ?? 'TextInputAction.done', + obscureText = flutterInputConfiguration.tryBool('obscureText') ?? false, + readOnly = flutterInputConfiguration.tryBool('readOnly') ?? false, + autocorrect = flutterInputConfiguration.tryBool('autocorrect') ?? true, textCapitalization = TextCapitalizationConfig.fromInputConfiguration( - flutterInputConfiguration['textCapitalization'], + flutterInputConfiguration.readString('textCapitalization'), ), autofill = flutterInputConfiguration.containsKey('autofill') ? AutofillInfo.fromFrameworkMessage( - flutterInputConfiguration['autofill']) + flutterInputConfiguration.readJson('autofill')) : null, autofillGroup = EngineAutofillForm.fromFrameworkMessage( - flutterInputConfiguration['autofill'], - flutterInputConfiguration['fields']); + flutterInputConfiguration.tryJson('autofill'), + flutterInputConfiguration.tryList('fields'), + ); /// The type of information being edited in the input control. final EngineInputType inputType; @@ -1597,8 +1602,8 @@ class TextEditingChannel { switch (call.method) { case 'TextInput.setClient': command = TextInputSetClient( - clientId: call.arguments[0], - configuration: InputConfiguration.fromFrameworkMessage(call.arguments[1]), + clientId: call.arguments[0] as int, + configuration: InputConfiguration.fromFrameworkMessage(call.arguments[1] as Map), ); break; @@ -1606,13 +1611,17 @@ class TextEditingChannel { // Set configuration eagerly because it contains data about the text // field used to flush the command queue. However, delaye applying the // configuration because the strategy may not be available yet. - implementation.configuration = InputConfiguration.fromFrameworkMessage(call.arguments); + implementation.configuration = InputConfiguration.fromFrameworkMessage( + call.arguments as Map + ); command = const TextInputUpdateConfig(); break; case 'TextInput.setEditingState': command = TextInputSetEditingState( - state: EditingState.fromFrameworkMessage(call.arguments), + state: EditingState.fromFrameworkMessage( + call.arguments as Map + ), ); break; @@ -1622,13 +1631,17 @@ class TextEditingChannel { case 'TextInput.setEditableSizeAndTransform': command = TextInputSetEditableSizeAndTransform( - geometry: EditableTextGeometry.fromFrameworkMessage(call.arguments), + geometry: EditableTextGeometry.fromFrameworkMessage( + call.arguments as Map + ), ); break; case 'TextInput.setStyle': command = TextInputSetStyle( - style: EditableTextStyle.fromFrameworkMessage(call.arguments), + style: EditableTextStyle.fromFrameworkMessage( + call.arguments as Map, + ), ); break; @@ -1823,9 +1836,9 @@ class EditableTextStyle { assert(flutterStyle.containsKey('textAlignIndex')); assert(flutterStyle.containsKey('textDirectionIndex')); - final int textAlignIndex = flutterStyle['textAlignIndex']; - final int textDirectionIndex = flutterStyle['textDirectionIndex']; - final int? fontWeightIndex = flutterStyle['fontWeightIndex']; + final int textAlignIndex = flutterStyle['textAlignIndex'] as int; + final int textDirectionIndex = flutterStyle['textDirectionIndex'] as int; + final int? fontWeightIndex = flutterStyle['fontWeightIndex'] as int?; // Convert [fontWeightIndex] to its CSS equivalent value. final String fontWeight = fontWeightIndex != null @@ -1836,8 +1849,8 @@ class EditableTextStyle { // corresponding enum values in [ui.TextAlign] and [ui.TextDirection] // respectively. return EditableTextStyle( - fontSize: flutterStyle['fontSize'], - fontFamily: flutterStyle['fontFamily'], + fontSize: flutterStyle.tryDouble('fontSize'), + fontFamily: flutterStyle.tryString('fontFamily'), textAlign: ui.TextAlign.values[textAlignIndex], textDirection: ui.TextDirection.values[textDirectionIndex], fontWeight: fontWeight, @@ -1885,10 +1898,10 @@ class EditableTextGeometry { assert(encodedGeometry.containsKey('transform')); final List transformList = - List.from(encodedGeometry['transform']); + List.from(encodedGeometry.readList('transform')); return EditableTextGeometry( - width: encodedGeometry['width'], - height: encodedGeometry['height'], + width: encodedGeometry.readDouble('width'), + height: encodedGeometry.readDouble('height'), globalTransform: Float32List.fromList(transformList), ); } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/util.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/util.dart index 63ba7a1e6a..026a459a7f 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/util.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/util.dart @@ -390,7 +390,7 @@ String colorComponentsToCssString(int r, int g, int b, int a) { /// We need this in [BitmapCanvas] and [RecordingCanvas] to swallow this /// Firefox exception without interfering with others (potentially useful /// for the programmer). -bool isNsErrorFailureException(dynamic e) { +bool isNsErrorFailureException(Object e) { return js_util.getProperty(e, 'name') == 'NS_ERROR_FAILURE'; } @@ -560,3 +560,83 @@ String blurSigmasToCssString(double sigmaX, double sigmaY) { bool unsafeIsNull(dynamic object) { return object == null; } + +/// A typed variant of [html.Window.fetch]. +Future httpFetch(String url) async { + final dynamic result = await html.window.fetch(url); + return result as html.Body; +} + +/// Extensions to [Map] that make it easier to treat it as a JSON object. The +/// keys are `dynamic` because when JSON is deserialized from method channels +/// it arrives as `Map`. +// TODO(yjbanov): use Json typedef when type aliases are shipped +extension JsonExtensions on Map { + Map readJson(String propertyName) { + return this[propertyName] as Map; + } + + Map? tryJson(String propertyName) { + return this[propertyName] as Map?; + } + + Map readDynamicJson(String propertyName) { + return this[propertyName] as Map; + } + + Map? tryDynamicJson(String propertyName) { + return this[propertyName] as Map?; + } + + List readList(String propertyName) { + return this[propertyName] as List; + } + + List? tryList(String propertyName) { + return this[propertyName] as List?; + } + + List castList(String propertyName) { + return (this[propertyName] as List).cast(); + } + + List? tryCastList(String propertyName) { + final List? rawList = tryList(propertyName); + if (rawList == null) { + return null; + } + return rawList.cast(); + } + + String readString(String propertyName) { + return this[propertyName] as String; + } + + String? tryString(String propertyName) { + return this[propertyName] as String?; + } + + bool readBool(String propertyName) { + return this[propertyName] as bool; + } + + bool? tryBool(String propertyName) { + return this[propertyName] as bool?; + } + + int readInt(String propertyName) { + return this[propertyName] as int; + } + + int? tryInt(String propertyName) { + return this[propertyName] as int?; + } + + double readDouble(String propertyName) { + return this[propertyName] as double; + } + + double? tryDouble(String propertyName) { + return this[propertyName] as double?; + } +} diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/vector_math.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/vector_math.dart index 2b59550575..2c30a4e4e3 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/vector_math.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/vector_math.dart @@ -375,22 +375,6 @@ class Matrix4 { det3_201_012 * m[15]; } - /// Returns a new vector or matrix by multiplying [this] with [arg]. - dynamic operator *(dynamic arg) { - if (arg is double) { - return scaled(arg); - } - if (arg is Vector3) { - final Vector3 copy = arg.clone(); - transform3(copy.storage); - return copy; - } - if (arg is Matrix4) { - return multiplied(arg); - } - throw ArgumentError(arg); - } - /// Transform [arg] of type [Vector3] using the perspective transformation /// defined by [this]. Vector3 perspectiveTransform(Vector3 arg) { diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart index 0e5d6f9aa2..6f89a08dd0 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart @@ -21,6 +21,7 @@ import 'navigation/url_strategy.dart'; import 'platform_dispatcher.dart'; import 'services.dart'; import 'test_embedding.dart'; +import 'util.dart'; typedef _HandleMessageCallBack = Future Function(); @@ -152,7 +153,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { Future handleNavigationMessage(ByteData? data) async { return _waitInTheLine(() async { final MethodCall decoded = const JSONMethodCodec().decodeMethodCall(data); - final Map? arguments = decoded.arguments; + final Map? arguments = decoded.arguments as Map?; switch (decoded.method) { case 'selectMultiEntryHistory': await _useMultiEntryBrowserHistory(); @@ -164,14 +165,14 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { case 'routeUpdated': // deprecated assert(arguments != null); await _useSingleEntryBrowserHistory(); - browserHistory.setRouteName(arguments!['routeName']); + browserHistory.setRouteName(arguments!.tryString('routeName')); return true; case 'routeInformationUpdated': assert(arguments != null); browserHistory.setRouteName( - arguments!['location'], - state: arguments['state'], - replace: arguments['replace'] ?? false, + arguments!.tryString('location'), + state: arguments.tryString('state'), + replace: arguments.tryBool('replace') ?? false, ); return true; } diff --git a/engine/src/flutter/lib/web_ui/test/clipboard_test.dart b/engine/src/flutter/lib/web_ui/test/clipboard_test.dart index 9746400b60..1e6174e233 100644 --- a/engine/src/flutter/lib/web_ui/test/clipboard_test.dart +++ b/engine/src/flutter/lib/web_ui/test/clipboard_test.dart @@ -40,7 +40,7 @@ Future testMain() async { const MethodCodec codec = JSONMethodCodec(); final Completer completer = Completer(); void callback(ByteData? data) { - completer.complete(codec.decodeEnvelope(data!)); + completer.complete(codec.decodeEnvelope(data!) as bool); } clipboardMessageHandler.setDataMethodCall( @@ -78,7 +78,7 @@ Future testMain() async { const MethodCodec codec = JSONMethodCodec(); final Completer> completer = Completer>(); void callback(ByteData? data) { - completer.complete(codec.decodeEnvelope(data!)); + completer.complete(codec.decodeEnvelope(data!) as Map); } clipboardMessageHandler.getDataMethodCall(callback); diff --git a/engine/src/flutter/lib/web_ui/test/engine/pointer_binding_test.dart b/engine/src/flutter/lib/web_ui/test/engine/pointer_binding_test.dart index 31559b1c6f..8840f0c5fe 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/pointer_binding_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/pointer_binding_test.dart @@ -2325,7 +2325,7 @@ mixin _ButtonedEventMixin on _BasicEventContext { required double? deltaX, required double? deltaY, }) { - final Function jsWheelEvent = js_util.getProperty(html.window, 'WheelEvent'); + final Function jsWheelEvent = js_util.getProperty(html.window, 'WheelEvent') as Function; final List eventArgs = [ 'wheel', { @@ -2336,7 +2336,10 @@ mixin _ButtonedEventMixin on _BasicEventContext { 'deltaY': deltaY, } ]; - return js_util.callConstructor(jsWheelEvent, js_util.jsify(eventArgs)); + return js_util.callConstructor( + jsWheelEvent, + js_util.jsify(eventArgs) as List, + ) as html.Event; } } @@ -2550,7 +2553,7 @@ class _MouseEventContext extends _BasicEventContext double? clientY, }) { final Function jsMouseEvent = - js_util.getProperty(html.window, 'MouseEvent'); + js_util.getProperty(html.window, 'MouseEvent') as Function; final List eventArgs = [ type, { @@ -2560,7 +2563,10 @@ class _MouseEventContext extends _BasicEventContext 'clientY': clientY, } ]; - return js_util.callConstructor(jsMouseEvent, js_util.jsify(eventArgs)); + return js_util.callConstructor( + jsMouseEvent, + js_util.jsify(eventArgs) as List, + ) as html.MouseEvent; } } diff --git a/engine/src/flutter/lib/web_ui/test/engine/profiler_test.dart b/engine/src/flutter/lib/web_ui/test/engine/profiler_test.dart index 9c017ba134..4bce4c906c 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/profiler_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/profiler_test.dart @@ -77,8 +77,9 @@ void _profilerTests() { expect(data, isEmpty); // Not even a callback. + jsOnBenchmark('string'); expect( - () => jsOnBenchmark('string'), + () => Profiler.instance.benchmark('foo', 123), throwsA(isA()), ); }); @@ -159,5 +160,11 @@ class BenchmarkDatapoint { } void jsOnBenchmark(dynamic listener) { - js_util.setProperty(html.window, '_flutter_internal_on_benchmark', listener != null ? js.allowInterop(listener) : null); + js_util.setProperty( + html.window, + '_flutter_internal_on_benchmark', + listener is Function + ? js.allowInterop(listener) + : listener, + ); } diff --git a/engine/src/flutter/lib/web_ui/test/engine/surface/scene_builder_test.dart b/engine/src/flutter/lib/web_ui/test/engine/surface/scene_builder_test.dart index c1e512dbf5..53635774a8 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/surface/scene_builder_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/surface/scene_builder_test.dart @@ -918,6 +918,6 @@ HtmlImage createTestImage({int width = 100, int height = 50}) { ctx.fillRect(66, 0, 33, 50); ctx.fill(); final html.ImageElement imageElement = html.ImageElement(); - imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); + imageElement.src = js_util.callMethod(canvas, 'toDataURL', []) as String; return HtmlImage(imageElement, width, height); } diff --git a/engine/src/flutter/lib/web_ui/test/html/canvas_clip_path_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/canvas_clip_path_golden_test.dart index 5e0f2e29d5..fc8ce74b0f 100644 --- a/engine/src/flutter/lib/web_ui/test/html/canvas_clip_path_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/canvas_clip_path_golden_test.dart @@ -140,6 +140,6 @@ engine.HtmlImage createTestImage({int width = 200, int height = 150}) { ctx.fillRect(2 * width / 3, 0, width / 3, height); ctx.fill(); final html.ImageElement imageElement = html.ImageElement(); - imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); + imageElement.src = js_util.callMethod(canvas, 'toDataURL', []) as String; return engine.HtmlImage(imageElement, width, height); } diff --git a/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_blend_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_blend_golden_test.dart index c56a1612a2..f873ff491a 100644 --- a/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_blend_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/compositing/canvas_blend_golden_test.dart @@ -120,6 +120,6 @@ HtmlImage createTestImage() { ctx.fillRect(66, 0, 33, 50); ctx.fill(); final html.ImageElement imageElement = html.ImageElement(); - imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); + imageElement.src = js_util.callMethod(canvas, 'toDataURL', []) as String; return HtmlImage(imageElement, width, height); } diff --git a/engine/src/flutter/lib/web_ui/test/html/compositing/color_filter_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/compositing/color_filter_golden_test.dart index 28dfd443bb..6a3a509743 100644 --- a/engine/src/flutter/lib/web_ui/test/html/compositing/color_filter_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/compositing/color_filter_golden_test.dart @@ -189,6 +189,6 @@ HtmlImage createTestImage({int width = 200, int height = 150}) { ctx.fillRect(2 * width / 3, 0, width / 3, height); ctx.fill(); final html.ImageElement imageElement = html.ImageElement(); - imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); + imageElement.src = js_util.callMethod(canvas, 'toDataURL', []) as String; return HtmlImage(imageElement, width, height); } diff --git a/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart index 627e6c4358..8c5808cf28 100644 --- a/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/drawing/canvas_draw_image_golden_test.dart @@ -734,7 +734,7 @@ HtmlImage createTestImage({int width = 100, int height = 50}) { ctx.fillRect(66, 0, 33, 50); ctx.fill(); final html.ImageElement imageElement = html.ImageElement(); - imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); + imageElement.src = js_util.callMethod(canvas, 'toDataURL', []) as String; return HtmlImage(imageElement, width, height); } diff --git a/engine/src/flutter/lib/web_ui/test/html/drawing/draw_vertices_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/drawing/draw_vertices_golden_test.dart index f2045319cf..6e7faae60c 100644 --- a/engine/src/flutter/lib/web_ui/test/html/drawing/draw_vertices_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/drawing/draw_vertices_golden_test.dart @@ -424,6 +424,6 @@ Future createTestImage({int width = 50, int height = 40}) { imageElement.onLoad.listen((html.Event event) { completer.complete(HtmlImage(imageElement, width, height)); }); - imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); + imageElement.src = js_util.callMethod(canvas, 'toDataURL', []) as String; return completer.future; } diff --git a/engine/src/flutter/lib/web_ui/test/html/shaders/image_shader_golden_test.dart b/engine/src/flutter/lib/web_ui/test/html/shaders/image_shader_golden_test.dart index d6dd92843d..082ce39f1a 100644 --- a/engine/src/flutter/lib/web_ui/test/html/shaders/image_shader_golden_test.dart +++ b/engine/src/flutter/lib/web_ui/test/html/shaders/image_shader_golden_test.dart @@ -145,6 +145,6 @@ HtmlImage createTestImage() { ctx.fillRect(width2, width2, width2, width2); ctx.fill(); final html.ImageElement imageElement = html.ImageElement(); - imageElement.src = js_util.callMethod(canvas, 'toDataURL', []); + imageElement.src = js_util.callMethod(canvas, 'toDataURL', []) as String; return HtmlImage(imageElement, width, height); } diff --git a/engine/src/flutter/lib/web_ui/test/keyboard_test.dart b/engine/src/flutter/lib/web_ui/test/keyboard_test.dart index e08ee22219..c0897d02f1 100644 --- a/engine/src/flutter/lib/web_ui/test/keyboard_test.dart +++ b/engine/src/flutter/lib/web_ui/test/keyboard_test.dart @@ -48,7 +48,7 @@ void testMain() { ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { channelReceived = channel; - dataReceived = const JSONMessageCodec().decodeMessage(data); + dataReceived = const JSONMessageCodec().decodeMessage(data) as Map?; }; html.KeyboardEvent event; @@ -78,7 +78,7 @@ void testMain() { ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { channelReceived = channel; - dataReceived = const JSONMessageCodec().decodeMessage(data); + dataReceived = const JSONMessageCodec().decodeMessage(data) as Map?; }; html.KeyboardEvent event; @@ -107,7 +107,7 @@ void testMain() { Map? dataReceived; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { - dataReceived = const JSONMessageCodec().decodeMessage(data); + dataReceived = const JSONMessageCodec().decodeMessage(data) as Map?; }; html.KeyboardEvent event; @@ -157,7 +157,7 @@ void testMain() { final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { - messages.add(const JSONMessageCodec().decodeMessage(data)); + messages.add(const JSONMessageCodec().decodeMessage(data) as Map); }; html.KeyboardEvent event; @@ -339,7 +339,7 @@ void testMain() { final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { - messages.add(const JSONMessageCodec().decodeMessage(data)); + messages.add(const JSONMessageCodec().decodeMessage(data) as Map); }; dispatchKeyboardEvent( @@ -442,7 +442,7 @@ void testMain() { final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { - messages.add(const JSONMessageCodec().decodeMessage(data)); + messages.add(const JSONMessageCodec().decodeMessage(data) as Map); }; dispatchKeyboardEvent( @@ -514,7 +514,7 @@ void testMain() { final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { - messages.add(const JSONMessageCodec().decodeMessage(data)); + messages.add(const JSONMessageCodec().decodeMessage(data) as Map); }; dispatchKeyboardEvent( @@ -544,7 +544,7 @@ void testMain() { final List> messages = >[]; ui.window.onPlatformMessage = (String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback) { - messages.add(const JSONMessageCodec().decodeMessage(data)); + messages.add(const JSONMessageCodec().decodeMessage(data) as Map); }; dispatchKeyboardEvent( @@ -625,7 +625,7 @@ html.KeyboardEvent dispatchKeyboardEvent( target ??= html.window; final Function jsKeyboardEvent = - js_util.getProperty(html.window, 'KeyboardEvent'); + js_util.getProperty(html.window, 'KeyboardEvent') as Function; final List eventArgs = [ type, { @@ -640,8 +640,10 @@ html.KeyboardEvent dispatchKeyboardEvent( 'cancelable': true, } ]; - final html.KeyboardEvent event = - js_util.callConstructor(jsKeyboardEvent, js_util.jsify(eventArgs)); + final html.KeyboardEvent event = js_util.callConstructor( + jsKeyboardEvent, + js_util.jsify(eventArgs) as List, + ) as html.KeyboardEvent; target.dispatchEvent(event); return event; diff --git a/engine/src/flutter/lib/web_ui/test/matchers.dart b/engine/src/flutter/lib/web_ui/test/matchers.dart index e6b6c0a167..d21407222f 100644 --- a/engine/src/flutter/lib/web_ui/test/matchers.dart +++ b/engine/src/flutter/lib/web_ui/test/matchers.dart @@ -303,6 +303,9 @@ String canonicalizeHtml(String htmlContent, if (mode != HtmlComparisonMode.noAttributes) { original.attributes.forEach((dynamic name, String value) { + if (name is! String) { + throw '"$name" should be String but was ${name.runtimeType}.'; + } if (name == 'style') { return; } diff --git a/engine/src/flutter/lib/web_ui/test/text/font_loading_test.dart b/engine/src/flutter/lib/web_ui/test/text/font_loading_test.dart index 331e1a67b9..81d925c187 100644 --- a/engine/src/flutter/lib/web_ui/test/text/font_loading_test.dart +++ b/engine/src/flutter/lib/web_ui/test/text/font_loading_test.dart @@ -41,7 +41,7 @@ Future testMain() async { final html.HttpRequest response = await html.HttpRequest.request( _testFontUrl, responseType: 'arraybuffer'); - await ui.loadFontFromList(Uint8List.view(response.response), + await ui.loadFontFromList(Uint8List.view(response.response as ByteBuffer), fontFamily: 'Blehm'); expect(_containsFontFamily('Blehm'), isTrue); @@ -73,7 +73,7 @@ Future testMain() async { final html.HttpRequest response = await html.HttpRequest.request( _testFontUrl, responseType: 'arraybuffer'); - await ui.loadFontFromList(Uint8List.view(response.response), + await ui.loadFontFromList(Uint8List.view(response.response as ByteBuffer), fontFamily: 'Blehm'); // Verifies the font is loaded, and the cache is cleaned. @@ -101,7 +101,7 @@ Future testMain() async { final html.HttpRequest response = await html.HttpRequest.request( _testFontUrl, responseType: 'arraybuffer'); - await ui.loadFontFromList(Uint8List.view(response.response), + await ui.loadFontFromList(Uint8List.view(response.response as ByteBuffer), fontFamily: 'Blehm'); final Completer completer = Completer(); html.window.requestAnimationFrame( (_) { completer.complete(); } ); diff --git a/engine/src/flutter/lib/web_ui/test/text_editing_test.dart b/engine/src/flutter/lib/web_ui/test/text_editing_test.dart index e8f201ffa6..acc84cef5e 100644 --- a/engine/src/flutter/lib/web_ui/test/text_editing_test.dart +++ b/engine/src/flutter/lib/web_ui/test/text_editing_test.dart @@ -390,7 +390,7 @@ void testMain() { int clientId = 0; /// Emulates sending of a message by the framework to the engine. - void sendFrameworkMessage(dynamic message) { + void sendFrameworkMessage(ByteData? message) { textEditing!.channel.handleTextInput(message, (ByteData? data) {}); } @@ -2000,7 +2000,7 @@ KeyboardEvent dispatchKeyboardEvent( String type, { required int keyCode, }) { - final Function jsKeyboardEvent = js_util.getProperty(window, 'KeyboardEvent'); + final Function jsKeyboardEvent = js_util.getProperty(window, 'KeyboardEvent') as Function; final List eventArgs = [ type, { @@ -2009,7 +2009,7 @@ KeyboardEvent dispatchKeyboardEvent( } ]; final KeyboardEvent event = - js_util.callConstructor(jsKeyboardEvent, js_util.jsify(eventArgs)); + js_util.callConstructor(jsKeyboardEvent, js_util.jsify(eventArgs) as List?) as KeyboardEvent; target.dispatchEvent(event); return event; diff --git a/engine/src/flutter/lib/web_ui/tool/unicode_sync_script.dart b/engine/src/flutter/lib/web_ui/tool/unicode_sync_script.dart index 4123a6073c..6b87fb014b 100644 --- a/engine/src/flutter/lib/web_ui/tool/unicode_sync_script.dart +++ b/engine/src/flutter/lib/web_ui/tool/unicode_sync_script.dart @@ -119,9 +119,9 @@ final String lineBreakCodegen = Future main(List arguments) async { final ArgResults result = argParser.parse(arguments); final PropertiesSyncer syncer = getSyncer( - result['words'], - result['lines'], - result['dry'], + result['words'] as String?, + result['lines'] as String?, + result['dry'] as bool, ); syncer.perform();