| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// This library defines the representation of runtime types. | 5 /// This library defines the representation of runtime types. |
| 6 part of dart._runtime; | 6 part of dart._runtime; |
| 7 | 7 |
| 8 final metadata = JS('', 'Symbol("metadata")'); | 8 final metadata = JS('', 'Symbol("metadata")'); |
| 9 | 9 |
| 10 /// The symbol used to store the cached `Type` object associated with a class. | 10 /// The symbol used to store the cached `Type` object associated with a class. |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 functionType(returnType, args, extra) => | 506 functionType(returnType, args, extra) => |
| 507 _functionType(false, returnType, args, extra); | 507 _functionType(false, returnType, args, extra); |
| 508 | 508 |
| 509 /// | 509 /// |
| 510 /// Create a definite function type. No substitution of dynamic for | 510 /// Create a definite function type. No substitution of dynamic for |
| 511 /// bottom occurs. | 511 /// bottom occurs. |
| 512 /// | 512 /// |
| 513 definiteFunctionType(returnType, args, extra) => | 513 definiteFunctionType(returnType, args, extra) => |
| 514 _functionType(true, returnType, args, extra); | 514 _functionType(true, returnType, args, extra); |
| 515 | 515 |
| 516 bool isType(obj) => JS( |
| 517 '', |
| 518 '''(() => { |
| 519 return $_getRuntimeType($obj) === $Type; |
| 520 })()'''); |
| 521 |
| 516 String typeName(type) => JS( | 522 String typeName(type) => JS( |
| 517 '', | 523 '', |
| 518 '''(() => { | 524 '''(() => { |
| 519 if ($type === void 0) return "undefined type"; | 525 if ($type === void 0) return "undefined type"; |
| 520 if ($type === null) return "null type"; | 526 if ($type === null) return "null type"; |
| 521 // Non-instance types | 527 // Non-instance types |
| 522 if ($type instanceof $TypeRep) { | 528 if ($type instanceof $TypeRep) { |
| 523 if ($type instanceof $Typedef) { | 529 if ($type instanceof $Typedef) { |
| 524 return $type.name + "(" + $type.functionType.toString() + ")"; | 530 return $type.name + "(" + $type.functionType.toString() + ")"; |
| 525 } | 531 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 /// mode may differ | 697 /// mode may differ |
| 692 final isSubtype = JS( | 698 final isSubtype = JS( |
| 693 '', '$_subtypeMemo((t1, t2) => (t1 === t2) || $_isSubtype(t1, t2, true))'); | 699 '', '$_subtypeMemo((t1, t2) => (t1 === t2) || $_isSubtype(t1, t2, true))'); |
| 694 | 700 |
| 695 _isBottom(type) => JS('bool', '# == # || # == #', type, bottom, type, Null); | 701 _isBottom(type) => JS('bool', '# == # || # == #', type, bottom, type, Null); |
| 696 | 702 |
| 697 _isTop(type) { | 703 _isTop(type) { |
| 698 if (JS('bool', '# === #', getGenericClass(type), getGenericClass(FutureOr))) { | 704 if (JS('bool', '# === #', getGenericClass(type), getGenericClass(FutureOr))) { |
| 699 return _isTop(JS('', '#[0]', getGenericArgs(type))); | 705 return _isTop(JS('', '#[0]', getGenericArgs(type))); |
| 700 } | 706 } |
| 701 return JS('bool', '# == # || # == # || # == #', | 707 return JS('bool', '# == # || # == # || # == #', type, Object, type, dynamic, |
| 702 type, Object, type, dynamic, type, _void); | 708 type, _void); |
| 703 } | 709 } |
| 704 | 710 |
| 705 _isSubtype(t1, t2, isCovariant) => JS( | 711 _isSubtype(t1, t2, isCovariant) => JS( |
| 706 '', | 712 '', |
| 707 '''(() => { | 713 '''(() => { |
| 708 if ($t1 === $t2) return true; | 714 if ($t1 === $t2) return true; |
| 709 | 715 |
| 710 // Trivially true. | 716 // Trivially true. |
| 711 if ($_isTop($t2) || $_isBottom($t1)) { | 717 if ($_isTop($t2) || $_isBottom($t1)) { |
| 712 return true; | 718 return true; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 return true; | 871 return true; |
| 866 } | 872 } |
| 867 | 873 |
| 868 let typeArgs = $getGenericArgs($type); | 874 let typeArgs = $getGenericArgs($type); |
| 869 if (!typeArgs) return true; | 875 if (!typeArgs) return true; |
| 870 for (let t of typeArgs) { | 876 for (let t of typeArgs) { |
| 871 if (t != $Object && t != $dynamic) return false; | 877 if (t != $Object && t != $dynamic) return false; |
| 872 } | 878 } |
| 873 return true; | 879 return true; |
| 874 })()'''); | 880 })()'''); |
| OLD | NEW |