[web] Migrate Flutter Web to JS static interop - 3. (flutter/engine#32458)

This commit is contained in:
joshualitt
2022-04-13 16:04:33 -07:00
committed by GitHub
parent 989bc6a386
commit a9622821ec
2 changed files with 15 additions and 11 deletions

View File

@@ -55,7 +55,10 @@ external set debugH5vccSetter(H5vcc? value);
@JS()
@anonymous
abstract class H5vcc {
@staticInterop
abstract class H5vcc {}
extension H5vccExtension on H5vcc {
external CanvasKit? get canvasKit;
}

View File

@@ -3,8 +3,9 @@
// found in the LICENSE file.
import 'dart:html' as html;
import 'dart:js' as js;
import 'package:js/js.dart';
import 'package:js/js_util.dart' as js_util;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
@@ -23,18 +24,18 @@ void testMain() {
setUpAll(() async {
// Set `window.h5vcc` to PatchedH5vcc which uses a downloaded CanvasKit.
final CanvasKit downloadedCanvasKit = await downloadCanvasKit();
debugH5vccSetter = PatchedH5vcc(downloadedCanvasKit);
debugH5vccSetter = PatchedH5vcc(canvasKit: downloadedCanvasKit);
// Monkey-patch the getH5vccSkSurface function of
// `window.h5vcc.canvasKit`.
js.context['h5vcc']['canvasKit']['getH5vccSkSurface'] = () {
js_util.setProperty(h5vcc!.canvasKit!, 'getH5vccSkSurface', allowInterop(() {
getH5vccSkSurfaceCalledCount++;
// Returns a fake [SkSurface] object with a minimal implementation.
return js.JsObject.jsify(<String, dynamic>{
'dispose': () {}
return js_util.jsify(<String, dynamic>{
'dispose': allowInterop(() {})
});
};
}));
});
setUpCanvasKitTest();
@@ -65,9 +66,9 @@ void testMain() {
}, testOn: 'chrome');
}
@JS()
@anonymous
@staticInterop
class PatchedH5vcc implements H5vcc {
@override
final CanvasKit canvasKit;
PatchedH5vcc(this.canvasKit);
external factory PatchedH5vcc({CanvasKit canvasKit});
}