2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- /// **WARNING**:
6
- /// The following types will be sealed in the near future. Do *not* subtype
7
- /// the types in this library as the subtypes will be broken.
8
-
9
5
/// A library for JS interop. Includes a JS type hierarchy to facilitate sound
10
6
/// interop with JS. The JS type hierarchy is modeled after the actual type
11
7
/// hierarchy in JS, and not the Dart type hierarchy.
14
10
/// implementation. JS backends currently support conflating Dart types and JS
15
11
/// types, whereas Wasm backends do not. Over time we will try and unify backend
16
12
/// semantics as much as possible.
13
+ ///
14
+ /// **WARNING**:
15
+ /// The following types will be sealed in the near future. Do *not* subtype
16
+ /// the types in this library as the subtypes will be broken.
17
+ ///
18
+ /// {@category Web}
19
+ library dart.js_interop;
20
+
17
21
import 'dart:_js_types' as js_types;
18
22
import 'dart:typed_data' ;
19
23
@@ -33,11 +37,11 @@ typedef JSAny = js_types.JSAny;
33
37
/// primitives. This is the only allowed `on` type for inline classes written by
34
38
/// users to model JS interop objects. See https://dart.dev/web/js-interop for
35
39
/// more details on how to use JS interop.
36
- /// TODO(srujzs): This class _must_ be sealed before we can make this library
37
- /// public. Either use the CFE mechanisms that exist today, or use the Dart 3
38
- /// sealed classes feature.
39
- /// TODO(joshualitt): Do we need to seal any other JS types on JS backends? We
40
- /// probably want to seal all JS types on Wasm backends.
40
+ // TODO(srujzs): This class _must_ be sealed before we can make this library
41
+ // public. Either use the CFE mechanisms that exist today, or use the Dart 3
42
+ // sealed classes feature.
43
+ // TODO(joshualitt): Do we need to seal any other JS types on JS backends? We
44
+ // probably want to seal all JS types on Wasm backends.
41
45
typedef JSObject = js_types.JSObject ;
42
46
43
47
/// The type of all JS functions, [JSFunction] <: [JSObject] .
@@ -46,7 +50,7 @@ typedef JSFunction = js_types.JSFunction;
46
50
/// The type of all Dart functions adapted to be callable from JS. We only allow
47
51
/// a subset of Dart functions to be callable from JS, [JSExportedDartFunction]
48
52
/// <: [JSFunction] .
49
- /// TODO(joshualitt): Detail exactly what are the requirements.
53
+ // TODO(joshualitt): Detail exactly what are the requirements.
50
54
typedef JSExportedDartFunction = js_types.JSExportedDartFunction ;
51
55
52
56
/// The type of JS promises and promise-like objects, [JSPromise] <: [JSObject] .
@@ -80,9 +84,9 @@ typedef JSUint32Array = js_types.JSUint32Array;
80
84
typedef JSFloat32Array = js_types.JSFloat32Array ;
81
85
typedef JSFloat64Array = js_types.JSFloat64Array ;
82
86
83
- /// The various JS primitive types. Crucially, unlike the Dart type hierarchy,
84
- /// none of these are subtypes of [JSObject] , but rather they are logically
85
- /// subtypes of [JSAny] .
87
+ // The various JS primitive types. Crucially, unlike the Dart type hierarchy,
88
+ // none of these are subtypes of [JSObject], but rather they are logically
89
+ // subtypes of [JSAny].
86
90
87
91
/// The type of JS numbers, [JSNumber] <: [JSAny] .
88
92
typedef JSNumber = js_types.JSNumber ;
@@ -100,8 +104,8 @@ typedef JSString = js_types.JSString;
100
104
/// null`, users should use the provided helpers below to determine if it is
101
105
/// safe to downcast a potentially `JSNullable` or `JSUndefineable` object to a
102
106
/// defined and non-null JS type.
103
- /// TODO(joshualitt): Investigate whether or not it will be possible to reify
104
- /// `JSUndefined` and `JSNull` on all backends.
107
+ // TODO(joshualitt): Investigate whether or not it will be possible to reify
108
+ // `JSUndefined` and `JSNull` on all backends.
105
109
extension NullableUndefineableJSAnyExtension on JSAny ? {
106
110
external bool get isUndefined;
107
111
external bool get isNull;
@@ -113,10 +117,10 @@ extension NullableUndefineableJSAnyExtension on JSAny? {
113
117
/// no actual object will be returned.
114
118
typedef JSVoid = js_types.JSVoid ;
115
119
116
- /// Extension members to support conversions between Dart types and JS types.
117
- /// Not all Dart types can be converted to JS types and vice versa.
118
- /// TODO(joshualitt): We might want to investigate using inline classes instead
119
- /// of extension methods for these methods.
120
+ // Extension members to support conversions between Dart types and JS types.
121
+ // Not all Dart types can be converted to JS types and vice versa.
122
+ // TODO(joshualitt): We might want to investigate using inline classes instead
123
+ // of extension methods for these methods.
120
124
121
125
/// [JSExportedDartFunction] <-> [Function]
122
126
extension JSExportedDartFunctionToFunction on JSExportedDartFunction {
@@ -141,9 +145,9 @@ extension JSPromiseToFuture on JSPromise {
141
145
external Future <JSAny ?> get toDart;
142
146
}
143
147
144
- /// TODO(joshualitt): On Wasm backends List / Array conversion methods will
145
- /// copy, and on JS backends they will not. We should find a path towards
146
- /// consistent semantics.
148
+ // TODO(joshualitt): On Wasm backends List / Array conversion methods will
149
+ // copy, and on JS backends they will not. We should find a path towards
150
+ // consistent semantics.
147
151
/// [JSArrayBuffer] <-> [ByteBuffer]
148
152
extension JSArrayBufferToByteBuffer on JSArrayBuffer {
149
153
external ByteBuffer get toDart;
0 commit comments