[web_ui] move several uses of (deprecated) pkg:js to js_interop_unsafe (#164264)
This commit is contained in:
parent
1ecd9fcea1
commit
671bcbe6d6
@ -6,8 +6,8 @@
|
||||
library js_loader;
|
||||
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
|
||||
import 'package:js/js_util.dart' as js_util;
|
||||
import 'package:ui/src/engine.dart';
|
||||
|
||||
@JS()
|
||||
@ -29,7 +29,7 @@ class FlutterLoader {}
|
||||
|
||||
extension FlutterLoaderExtension on FlutterLoader {
|
||||
external void didCreateEngineInitializer(FlutterEngineInitializer initializer);
|
||||
bool get isAutoStart => !js_util.hasProperty(this, 'didCreateEngineInitializer');
|
||||
bool get isAutoStart => !(this as JSObject).has('didCreateEngineInitializer');
|
||||
}
|
||||
|
||||
/// Typedef for the function that initializes the flutter engine.
|
||||
|
@ -1,7 +1,10 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
import 'package:js/js_util.dart' as js_util;
|
||||
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
@ -20,12 +23,12 @@ void testMain() {
|
||||
|
||||
// window.exports and window.module should be undefined!
|
||||
expect(
|
||||
js_util.hasProperty(domWindow, 'exports'),
|
||||
(domWindow as JSObject).has('exports'),
|
||||
isFalse,
|
||||
reason: '`window.exports` should not be defined.',
|
||||
);
|
||||
expect(
|
||||
js_util.hasProperty(domWindow, 'module'),
|
||||
(domWindow as JSObject).has('module'),
|
||||
isFalse,
|
||||
reason: '`window.module` should not be defined.',
|
||||
);
|
||||
|
@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:js/js_util.dart' as js_util;
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:ui/src/engine.dart';
|
||||
@ -15,15 +17,16 @@ void testMain() {
|
||||
group('initializeEngineServices', () {
|
||||
test('stores user configuration', () async {
|
||||
final JsFlutterConfiguration config = JsFlutterConfiguration();
|
||||
// `canvasKitBaseUrl` is required for the test to actually run.
|
||||
js_util.setProperty(config, 'canvasKitBaseUrl', '/canvaskit/');
|
||||
// A property under test, that we'll try to read later.
|
||||
js_util.setProperty(config, 'nonce', 'some_nonce');
|
||||
// A non-existing property to verify our js-interop doesn't crash.
|
||||
js_util.setProperty(config, 'nonexistentProperty', 32.0);
|
||||
(config as JSObject)
|
||||
// `canvasKitBaseUrl` is required for the test to actually run.
|
||||
..['canvasKitBaseUrl'] = '/canvaskit/'.toJS
|
||||
// A property under test, that we'll try to read later.
|
||||
..['nonce'] = 'some_nonce'.toJS
|
||||
// A non-existing property to verify our js-interop doesn't crash.
|
||||
..['nonexistentProperty'] = 32.0.toJS;
|
||||
|
||||
// Remove window.flutterConfiguration (if it's there)
|
||||
js_util.setProperty(domWindow, 'flutterConfiguration', null);
|
||||
(domWindow as JSObject)['flutterConfiguration'] = null;
|
||||
|
||||
// TODO(web): Replace the above nullification by the following assertion
|
||||
// when wasm and JS tests initialize their config the same way:
|
||||
|
@ -3,8 +3,8 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
|
||||
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' as engine;
|
||||
@ -20,14 +20,15 @@ external set didCreateEngineInitializer(JSFunction? callback);
|
||||
|
||||
void main() {
|
||||
// Prepare _flutter.loader.didCreateEngineInitializer, so it's ready in the page ASAP.
|
||||
loader = js_util.jsify(<String, Object>{
|
||||
'loader': <String, Object>{
|
||||
'didCreateEngineInitializer':
|
||||
() {
|
||||
print('not mocked');
|
||||
}.toJS,
|
||||
},
|
||||
});
|
||||
loader =
|
||||
<String, Object>{
|
||||
'loader': <String, Object>{
|
||||
'didCreateEngineInitializer':
|
||||
() {
|
||||
print('not mocked');
|
||||
}.toJS,
|
||||
},
|
||||
}.jsify();
|
||||
internalBootstrapBrowserTest(() => testMain);
|
||||
}
|
||||
|
||||
@ -52,12 +53,12 @@ void testMain() {
|
||||
// Check that the object we captured is actually a loader
|
||||
expect(engineInitializer, isNotNull);
|
||||
expect(
|
||||
js_util.hasProperty(engineInitializer!, 'initializeEngine'),
|
||||
(engineInitializer! as JSObject).has('initializeEngine'),
|
||||
isTrue,
|
||||
reason: 'Missing FlutterEngineInitializer method: initializeEngine.',
|
||||
);
|
||||
expect(
|
||||
js_util.hasProperty(engineInitializer!, 'autoStart'),
|
||||
(engineInitializer! as JSObject).has('autoStart'),
|
||||
isTrue,
|
||||
reason: 'Missing FlutterEngineInitializer method: autoStart.',
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user