@@ -7,14 +7,12 @@ import 'dart:js_interop';
77import 'dart:math' as math;
88import 'dart:typed_data' ;
99
10+ import 'package:ui/src/engine/skwasm/skwasm_stub.dart' if (dart.library.ffi) 'package:ui/src/engine/skwasm/skwasm_impl.dart' ;
1011import 'package:js/js_util.dart' as js_util;
1112import 'package:meta/meta.dart' ;
1213
1314import 'browser_detection.dart' ;
1415
15- import 'dart_js_conversion.dart' ;
16- export 'dart_js_conversion.dart' ;
17-
1816/// This file contains static interop classes for interacting with the DOM and
1917/// some helpers. All of the classes in this file are named after their
2018/// counterparts in the DOM. To extend any of these classes, simply add an
@@ -28,6 +26,41 @@ export 'dart_js_conversion.dart';
2826// the boundary between Dart and JS interop exists, we should expose JS types
2927// directly to the engine.
3028
29+ /// Conversions methods to facilitate migrating to JS types.
30+ ///
31+ /// The existing behavior across the JS interop boundary involves many implicit
32+ /// conversions. For efficiency reasons, on JS backends we still want those
33+ /// implicit conversions, but on Wasm backends we need to 'shallowly' convert
34+ /// these types.
35+ ///
36+ /// Note: Due to discrepancies between how `null` , `JSNull` , and `JSUndefined`
37+ /// are currently represented across web backends, these extensions should be
38+ /// used carefully and only on types that are known to not contains `JSNull` and
39+ /// `JSUndefined` .
40+
41+ extension ObjectToJSAnyExtension on Object {
42+ // Once `Object.toJSBox` is faster (see
43+ // https://github.com/dart-lang/sdk/issues/55183) we can remove this
44+ // backend-specific workaround.
45+ @pragma ('wasm:prefer-inline' )
46+ @pragma ('dart2js:tryInline' )
47+ JSAny get toJSAnyShallow => dartToJsWrapper (this );
48+
49+ @pragma ('wasm:prefer-inline' )
50+ @pragma ('dart2js:tryInline' )
51+ JSAny get toJSAnyDeep => js_util.jsify (this ) as JSAny ;
52+ }
53+
54+ extension JSAnyToObjectExtension on JSAny {
55+ @pragma ('wasm:prefer-inline' )
56+ @pragma ('dart2js:tryInline' )
57+ Object get toObjectShallow => jsWrapperToDart (this );
58+
59+ @pragma ('wasm:prefer-inline' )
60+ @pragma ('dart2js:tryInline' )
61+ Object get toObjectDeep => js_util.dartify (this )! ;
62+ }
63+
3164@JS ('Object' )
3265external DomObjectConstructor get objectConstructor;
3366
0 commit comments