Skip to content

Commit 671bcbe

Browse files
authored
[web_ui] move several uses of (deprecated) pkg:js to js_interop_unsafe (flutter#164264)
1 parent 1ecd9fc commit 671bcbe

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

engine/src/flutter/lib/web_ui/lib/src/engine/js_interop/js_loader.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
library js_loader;
77

88
import 'dart:js_interop';
9+
import 'dart:js_interop_unsafe';
910

10-
import 'package:js/js_util.dart' as js_util;
1111
import 'package:ui/src/engine.dart';
1212

1313
@JS()
@@ -29,7 +29,7 @@ class FlutterLoader {}
2929

3030
extension FlutterLoaderExtension on FlutterLoader {
3131
external void didCreateEngineInitializer(FlutterEngineInitializer initializer);
32-
bool get isAutoStart => !js_util.hasProperty(this, 'didCreateEngineInitializer');
32+
bool get isAutoStart => !(this as JSObject).has('didCreateEngineInitializer');
3333
}
3434

3535
/// Typedef for the function that initializes the flutter engine.

engine/src/flutter/lib/web_ui/test/canvaskit/initialization/does_not_mock_module_exports_test.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
import 'package:js/js_util.dart' as js_util;
4+
5+
import 'dart:js_interop';
6+
import 'dart:js_interop_unsafe';
7+
58
import 'package:test/bootstrap/browser.dart';
69
import 'package:test/test.dart';
710
import 'package:ui/src/engine.dart';
@@ -20,12 +23,12 @@ void testMain() {
2023

2124
// window.exports and window.module should be undefined!
2225
expect(
23-
js_util.hasProperty(domWindow, 'exports'),
26+
(domWindow as JSObject).has('exports'),
2427
isFalse,
2528
reason: '`window.exports` should not be defined.',
2629
);
2730
expect(
28-
js_util.hasProperty(domWindow, 'module'),
31+
(domWindow as JSObject).has('module'),
2932
isFalse,
3033
reason: '`window.module` should not be defined.',
3134
);

engine/src/flutter/lib/web_ui/test/canvaskit/initialization/stores_config_test.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:js/js_util.dart' as js_util;
5+
import 'dart:js_interop';
6+
import 'dart:js_interop_unsafe';
7+
68
import 'package:test/bootstrap/browser.dart';
79
import 'package:test/test.dart';
810
import 'package:ui/src/engine.dart';
@@ -15,15 +17,16 @@ void testMain() {
1517
group('initializeEngineServices', () {
1618
test('stores user configuration', () async {
1719
final JsFlutterConfiguration config = JsFlutterConfiguration();
18-
// `canvasKitBaseUrl` is required for the test to actually run.
19-
js_util.setProperty(config, 'canvasKitBaseUrl', '/canvaskit/');
20-
// A property under test, that we'll try to read later.
21-
js_util.setProperty(config, 'nonce', 'some_nonce');
22-
// A non-existing property to verify our js-interop doesn't crash.
23-
js_util.setProperty(config, 'nonexistentProperty', 32.0);
20+
(config as JSObject)
21+
// `canvasKitBaseUrl` is required for the test to actually run.
22+
..['canvasKitBaseUrl'] = '/canvaskit/'.toJS
23+
// A property under test, that we'll try to read later.
24+
..['nonce'] = 'some_nonce'.toJS
25+
// A non-existing property to verify our js-interop doesn't crash.
26+
..['nonexistentProperty'] = 32.0.toJS;
2427

2528
// Remove window.flutterConfiguration (if it's there)
26-
js_util.setProperty(domWindow, 'flutterConfiguration', null);
29+
(domWindow as JSObject)['flutterConfiguration'] = null;
2730

2831
// TODO(web): Replace the above nullification by the following assertion
2932
// when wasm and JS tests initialize their config the same way:

engine/src/flutter/lib/web_ui/test/engine/initialization_test.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// found in the LICENSE file.
44

55
import 'dart:js_interop';
6+
import 'dart:js_interop_unsafe';
67

7-
import 'package:js/js_util.dart' as js_util;
88
import 'package:test/bootstrap/browser.dart';
99
import 'package:test/test.dart';
1010
import 'package:ui/src/engine.dart' as engine;
@@ -20,14 +20,15 @@ external set didCreateEngineInitializer(JSFunction? callback);
2020

2121
void main() {
2222
// Prepare _flutter.loader.didCreateEngineInitializer, so it's ready in the page ASAP.
23-
loader = js_util.jsify(<String, Object>{
24-
'loader': <String, Object>{
25-
'didCreateEngineInitializer':
26-
() {
27-
print('not mocked');
28-
}.toJS,
29-
},
30-
});
23+
loader =
24+
<String, Object>{
25+
'loader': <String, Object>{
26+
'didCreateEngineInitializer':
27+
() {
28+
print('not mocked');
29+
}.toJS,
30+
},
31+
}.jsify();
3132
internalBootstrapBrowserTest(() => testMain);
3233
}
3334

@@ -52,12 +53,12 @@ void testMain() {
5253
// Check that the object we captured is actually a loader
5354
expect(engineInitializer, isNotNull);
5455
expect(
55-
js_util.hasProperty(engineInitializer!, 'initializeEngine'),
56+
(engineInitializer! as JSObject).has('initializeEngine'),
5657
isTrue,
5758
reason: 'Missing FlutterEngineInitializer method: initializeEngine.',
5859
);
5960
expect(
60-
js_util.hasProperty(engineInitializer!, 'autoStart'),
61+
(engineInitializer! as JSObject).has('autoStart'),
6162
isTrue,
6263
reason: 'Missing FlutterEngineInitializer method: autoStart.',
6364
);

0 commit comments

Comments
 (0)