55/// This library defines the representation of runtime types.
66part of dart._runtime;
77
8+ bool _strictSubtypeChecks = false ;
9+
810/// Sets the mode of the runtime subtype checks.
911///
1012/// Changing the mode after any calls to dart.isSubtype() is not supported.
1113void strictSubtypeChecks (bool flag) {
12- JS ( '' , 'dart.__strictSubtypeChecks = #' , flag) ;
14+ _strictSubtypeChecks = flag;
1315}
1416
1517final metadata = JS ('' , 'Symbol("metadata")' );
@@ -256,7 +258,7 @@ Object nullable(type) {
256258 return JS <NullableType >('!' , '#[#]' , type, _cachedNullable);
257259 }
258260 // Cache a canonical nullable version of this type on this type.
259- var cachedType = NullableType (type);
261+ var cachedType = NullableType (JS < Type >( '!' , '#' , type) );
260262 JS ('' , '#[#] = #' , type, _cachedNullable, cachedType);
261263 return cachedType;
262264}
@@ -276,7 +278,7 @@ Object legacy(type) {
276278 return JS <LegacyType >('!' , '#[#]' , type, _cachedLegacy);
277279 }
278280 // Cache a canonical legacy version of this type on this type.
279- var cachedType = LegacyType (type);
281+ var cachedType = LegacyType (JS < Type >( '!' , '#' , type) );
280282 JS ('' , '#[#] = #' , type, _cachedLegacy, cachedType);
281283 return cachedType;
282284}
@@ -285,9 +287,7 @@ Object legacy(type) {
285287class NullableType extends DartType {
286288 final Type type;
287289
288- NullableType (this .type)
289- : assert (type is ! NullableType ),
290- assert (type is ! LegacyType );
290+ NullableType (this .type);
291291
292292 @override
293293 String get name => '$type ?' ;
@@ -313,9 +313,7 @@ class NullableType extends DartType {
313313class LegacyType extends DartType {
314314 final Type type;
315315
316- LegacyType (this .type)
317- : assert (type is ! LegacyType ),
318- assert (type is ! NullableType );
316+ LegacyType (this .type);
319317
320318 @override
321319 String get name => '$type ' ;
@@ -328,7 +326,7 @@ class LegacyType extends DartType {
328326 if (obj == null ) {
329327 // Object and Never are the only legacy types that should return true if
330328 // obj is `null`.
331- return type == unwrapType ( Object ) || type == unwrapType ( Never );
329+ return JS < bool >( '!' , '# === # || # === #' , type, Object , type, never_ );
332330 }
333331 return JS <bool >('!' , '#.is(#)' , type, obj);
334332 }
@@ -1172,7 +1170,7 @@ bool isSubtypeOf(Object t1, Object t2) {
11721170 }
11731171 var validSubtype = _isSubtype (t1, t2, true );
11741172
1175- if (! validSubtype && ! JS < bool >( '!' , 'dart.__strictSubtypeChecks' ) ) {
1173+ if (! validSubtype && ! _strictSubtypeChecks ) {
11761174 validSubtype = _isSubtype (t1, t2, false );
11771175 if (validSubtype) {
11781176 // TODO(nshahan) Need more information to be helpful here.
@@ -1205,20 +1203,22 @@ bool _isTop(type) {
12051203
12061204/// Returns `true` if [type] represents a nullable (question, ?) type.
12071205@notNull
1208- bool _isNullable (Type type) => JS <bool >('!' , '$ type instanceof $ NullableType ' );
1206+ bool _isNullable (type) => JS <bool >('!' , '# instanceof #' , type, NullableType );
12091207
12101208/// Returns `true` if [type] represents a legacy (star, *) type.
12111209@notNull
1212- bool _isLegacy (Type type) => JS <bool >('!' , '$ type instanceof $ LegacyType ' );
1210+ bool _isLegacy (type) => JS <bool >('!' , '# instanceof #' , type, LegacyType );
12131211
12141212/// Returns `true` if [type] is the [Null] type.
12151213@notNull
1216- bool _isNullType (Object type) =>
1217- JS <bool >('!' , '# === #' , type, unwrapType (Null ));
1214+ bool _isNullType (type) => JS <bool >('!' , '# === #' , type, unwrapType (Null ));
12181215
12191216@notNull
1220- bool _isFutureOr (type) =>
1221- JS <bool >('!' , '# === #' , getGenericClass (type), getGenericClass (FutureOr ));
1217+ bool _isFutureOr (type) {
1218+ var genericClass = getGenericClass (type);
1219+ return JS <bool >('!' , '# && # === #' , genericClass, genericClass,
1220+ getGenericClass (FutureOr ));
1221+ }
12221222
12231223bool _isSubtype (t1, t2, bool strictMode) => JS ('bool' , '''(() => {
12241224 if (!$strictMode ) {
0 commit comments