| 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 association between runtime objects and | 5 /// This library defines the association between runtime objects and |
| 6 /// runtime types. | 6 /// runtime types. |
| 7 part of dart._runtime; | 7 part of dart._runtime; |
| 8 | 8 |
| 9 /// | 9 /// |
| 10 /// Runtime type information. This module defines the mapping from | 10 /// Runtime type information. This module defines the mapping from |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 case "symbol": | 86 case "symbol": |
| 87 return Symbol; | 87 return Symbol; |
| 88 } | 88 } |
| 89 // Undefined is handled above. For historical reasons, | 89 // Undefined is handled above. For historical reasons, |
| 90 // typeof null == "object" in JS. | 90 // typeof null == "object" in JS. |
| 91 if ($obj === null) return $Null; | 91 if ($obj === null) return $Null; |
| 92 return null; | 92 return null; |
| 93 })()'''); | 93 })()'''); |
| 94 | 94 |
| 95 runtimeType(obj) => JS('', '''(() => { | 95 runtimeType(obj) => JS('', '''(() => { |
| 96 // Lookup primitive (int/double/string) |
| 96 let result = $checkPrimitiveType($obj); | 97 let result = $checkPrimitiveType($obj); |
| 97 if (result !== null) return result; | 98 if (result !== null) return result; |
| 98 return $obj.runtimeType; | 99 |
| 100 // Lookup recorded type |
| 101 result = $obj.runtimeType; |
| 102 if (result) return result; |
| 103 |
| 104 return $_nonPrimitiveRuntimeType(obj); |
| 99 })()'''); | 105 })()'''); |
| 100 | 106 |
| 101 getFunctionType(obj) => JS('', '''(() => { | 107 getFunctionType(obj) => JS('', '''(() => { |
| 102 // TODO(vsm): Encode this properly on the function for Dart-generated code. | 108 // TODO(vsm): Encode this properly on the function for Dart-generated code. |
| 103 let args = Array($obj.length).fill($dynamicR); | 109 let args = Array($obj.length).fill($dynamicR); |
| 104 return $definiteFunctionType($bottom, args); | 110 return $definiteFunctionType($bottom, args); |
| 105 })()'''); | 111 })()'''); |
| 106 | 112 |
| 107 /// | 113 /// |
| 108 /// Returns the runtime type of obj. This is the same as `obj.realRuntimeType` | 114 /// Returns the runtime type of obj. This is the same as `obj.realRuntimeType` |
| 109 /// but will not call an overridden getter. | 115 /// but will not call an overridden getter. |
| 110 /// | 116 /// |
| 111 /// Currently this will return null for non-Dart objects. | 117 /// Currently this will return null for non-Dart objects. |
| 112 /// | 118 /// |
| 113 realRuntimeType(obj) => JS('', '''(() => { | 119 realRuntimeType(obj) => JS('', '''(() => { |
| 120 // Lookup primitive type |
| 114 let result = $checkPrimitiveType($obj); | 121 let result = $checkPrimitiveType($obj); |
| 115 if (result !== null) return result; | 122 if (result !== null) return result; |
| 123 |
| 124 return $_nonPrimitiveRuntimeType(obj); |
| 125 })()'''); |
| 126 |
| 127 _nonPrimitiveRuntimeType(obj) => JS('', '''(() => { |
| 128 // Lookup recorded *real* type (not user definable runtimeType) |
| 116 // TODO(vsm): Should we treat Dart and JS objects differently here? | 129 // TODO(vsm): Should we treat Dart and JS objects differently here? |
| 117 // E.g., we can check if obj instanceof core.Object to differentiate. | 130 // E.g., we can check if obj instanceof core.Object to differentiate. |
| 118 result = $obj[$_runtimeType]; | 131 let result = $obj[$_runtimeType]; |
| 119 if (result) return result; | 132 if (result) return result; |
| 133 |
| 134 // Lookup extension type |
| 135 result = $obj[$_extensionType]; |
| 136 if (result) return result; |
| 137 |
| 138 // Fallback on constructor for class types |
| 120 result = $obj.constructor; | 139 result = $obj.constructor; |
| 121 if (result == Function) { | 140 if (result == Function) { |
| 122 // An undecorated Function should have come from | 141 // An undecorated Function should have come from |
| 123 // JavaScript. Treat as untyped. | 142 // JavaScript. Treat as untyped. |
| 124 return $jsobject; | 143 return $jsobject; |
| 125 } | 144 } |
| 126 return result; | 145 return result; |
| 127 })()'''); | 146 })()'''); |
| 128 | 147 |
| 129 LazyTagged(infoFn) => JS('', '''(() => { | 148 LazyTagged(infoFn) => JS('', '''(() => { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 148 tagMemoized(value, compute) => JS('', '''(() => { | 167 tagMemoized(value, compute) => JS('', '''(() => { |
| 149 let cache = null; | 168 let cache = null; |
| 150 function getter() { | 169 function getter() { |
| 151 if ($compute == null) return cache; | 170 if ($compute == null) return cache; |
| 152 cache = $compute(); | 171 cache = $compute(); |
| 153 $compute = null; | 172 $compute = null; |
| 154 return cache; | 173 return cache; |
| 155 } | 174 } |
| 156 $tagComputed($value, getter); | 175 $tagComputed($value, getter); |
| 157 })()'''); | 176 })()'''); |
| OLD | NEW |