| 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 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 } | 1020 } |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 // We found no definite supertypes, and at least one indefinite supertype | 1023 // We found no definite supertypes, and at least one indefinite supertype |
| 1024 // so the answer is indefinite. | 1024 // so the answer is indefinite. |
| 1025 if (indefinite) return null; | 1025 if (indefinite) return null; |
| 1026 // We found no definite supertypes and no indefinite supertypes, so we | 1026 // We found no definite supertypes and no indefinite supertypes, so we |
| 1027 // can return false. | 1027 // can return false. |
| 1028 return false; | 1028 return false; |
| 1029 })()'''); | 1029 })()'''); |
| 1030 | |
| 1031 // TODO(jmesserly): this isn't currently used, but it could be if we want | |
| 1032 // `obj is NonGroundType<T,S>` to be rejected at runtime instead of compile | |
| 1033 // time. | |
| 1034 isGroundType(type) => JS( | |
| 1035 '', | |
| 1036 '''(() => { | |
| 1037 // TODO(vsm): Cache this if we start using it at runtime. | |
| 1038 | |
| 1039 // TODO(jmesserly): implement for generic function types if we start using? | |
| 1040 if ($type instanceof $Typedef) $type = $type.functionType; | |
| 1041 | |
| 1042 if ($type instanceof $FunctionType) { | |
| 1043 if (!$_isTop($type.returnType)) return false; | |
| 1044 for (let i = 0; i < $type.args.length; ++i) { | |
| 1045 if (!$_isBottom($type.args[i])) return false; | |
| 1046 } | |
| 1047 for (let i = 0; i < $type.optionals.length; ++i) { | |
| 1048 if (!$_isBottom($type.optionals[i])) return false; | |
| 1049 } | |
| 1050 let names = $getOwnPropertyNames($type.named); | |
| 1051 for (let i = 0; i < names.length; ++i) { | |
| 1052 if (!$_isBottom($type.named[names[i]])) return false; | |
| 1053 } | |
| 1054 return true; | |
| 1055 } | |
| 1056 | |
| 1057 let typeArgs = $getGenericArgs($type); | |
| 1058 if (!typeArgs) return true; | |
| 1059 for (let t of typeArgs) { | |
| 1060 if (t != $Object && t != $dynamic) return false; | |
| 1061 } | |
| 1062 return true; | |
| 1063 })()'''); | |
| OLD | NEW |