OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * This part contains helpers for supporting runtime type information. | 6 * This part contains helpers for supporting runtime type information. |
7 * | 7 * |
8 * The helper use a mixture of Dart and JavaScript objects. To indicate which is | 8 * The helper use a mixture of Dart and JavaScript objects. To indicate which is |
9 * used where we adopt the scheme of using explicit type annotation for Dart | 9 * used where we adopt the scheme of using explicit type annotation for Dart |
10 * objects and 'var' or omitted return type for JavaScript objects. | 10 * objects and 'var' or omitted return type for JavaScript objects. |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 var typeArguments = getRuntimeTypeArguments(context, contextName); | 357 var typeArguments = getRuntimeTypeArguments(context, contextName); |
358 return invokeOn(signature, context, typeArguments); | 358 return invokeOn(signature, context, typeArguments); |
359 } | 359 } |
360 | 360 |
361 /** | 361 /** |
362 * Returns `true` if the runtime type representation [type] is a supertype of | 362 * Returns `true` if the runtime type representation [type] is a supertype of |
363 * [Null]. | 363 * [Null]. |
364 */ | 364 */ |
365 bool isSupertypeOfNull(var type) { | 365 bool isSupertypeOfNull(var type) { |
366 // `null` means `dynamic`. | 366 // `null` means `dynamic`. |
367 return type == null || getDartTypeName(type) == JS_OBJECT_CLASS_NAME() | 367 return type == null || isDartObjectTypeRti(type) || isNullTypeRti(type); |
368 || getDartTypeName(type) == JS_NULL_CLASS_NAME(); | |
369 } | 368 } |
370 | 369 |
371 /** | 370 /** |
372 * Tests whether the Dart object [o] is a subtype of the runtime type | 371 * Tests whether the Dart object [o] is a subtype of the runtime type |
373 * representation [t]. | 372 * representation [t]. |
374 * | 373 * |
375 * See the comment in the beginning of this file for a description of type | 374 * See the comment in the beginning of this file for a description of type |
376 * representations. | 375 * representations. |
377 */ | 376 */ |
378 bool checkSubtypeOfRuntimeType(o, t) { | 377 bool checkSubtypeOfRuntimeType(o, t) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 bool isSubtype(var s, var t) { | 436 bool isSubtype(var s, var t) { |
438 // Subtyping is reflexive. | 437 // Subtyping is reflexive. |
439 if (isIdentical(s, t)) return true; | 438 if (isIdentical(s, t)) return true; |
440 // If either type is dynamic, [s] is a subtype of [t]. | 439 // If either type is dynamic, [s] is a subtype of [t]. |
441 if (s == null || t == null) return true; | 440 if (s == null || t == null) return true; |
442 if (isDartFunctionType(t)) { | 441 if (isDartFunctionType(t)) { |
443 return isFunctionSubtype(s, t); | 442 return isFunctionSubtype(s, t); |
444 } | 443 } |
445 // Check function types against the Function class. | 444 // Check function types against the Function class. |
446 if (isDartFunctionType(s)) { | 445 if (isDartFunctionType(s)) { |
447 return isDartFunctionTypeLiteral(t); | 446 return isDartFunctionTypeRti(t); |
448 } | 447 } |
449 | 448 |
450 // Get the object describing the class and check for the subtyping flag | 449 // Get the object describing the class and check for the subtyping flag |
451 // constructed from the type of [t]. | 450 // constructed from the type of [t]. |
452 var typeOfS = isJsArray(s) ? getIndex(s, 0) : s; | 451 var typeOfS = isJsArray(s) ? getIndex(s, 0) : s; |
453 var typeOfT = isJsArray(t) ? getIndex(t, 0) : t; | 452 var typeOfT = isJsArray(t) ? getIndex(t, 0) : t; |
454 | 453 |
455 // Check for a subtyping flag. | 454 // Check for a subtyping flag. |
456 // Get the necessary substitution of the type arguments, if there is one. | 455 // Get the necessary substitution of the type arguments, if there is one. |
457 var substitution; | 456 var substitution; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 * `null` and `undefined` (which we can avoid). | 668 * `null` and `undefined` (which we can avoid). |
670 */ | 669 */ |
671 bool isIdentical(var s, var t) => JS('bool', '# === #', s, t); | 670 bool isIdentical(var s, var t) => JS('bool', '# === #', s, t); |
672 | 671 |
673 /** | 672 /** |
674 * Returns `true` if the JavaScript values [s] and [t] are not identical. We use | 673 * Returns `true` if the JavaScript values [s] and [t] are not identical. We use |
675 * this helper instead of [identical] because `identical` needs to merge | 674 * this helper instead of [identical] because `identical` needs to merge |
676 * `null` and `undefined` (which we can avoid). | 675 * `null` and `undefined` (which we can avoid). |
677 */ | 676 */ |
678 bool isNotIdentical(var s, var t) => JS('bool', '# !== #', s, t); | 677 bool isNotIdentical(var s, var t) => JS('bool', '# !== #', s, t); |
OLD | NEW |