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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 283 } |
284 return allDynamic ? '' : '<$buffer>'; | 284 return allDynamic ? '' : '<$buffer>'; |
285 } | 285 } |
286 | 286 |
287 /** | 287 /** |
288 * Returns a human-readable representation of the type of [object]. | 288 * Returns a human-readable representation of the type of [object]. |
289 * | 289 * |
290 * In minified mode does *not* use unminified identifiers (even when present). | 290 * In minified mode does *not* use unminified identifiers (even when present). |
291 */ | 291 */ |
292 String getRuntimeTypeString(var object) { | 292 String getRuntimeTypeString(var object) { |
293 // Check for function type first, since non-tearoff closures look like classes | 293 if (object is Closure) { |
294 // due to closure conversion. | 294 // This excludes classes that implement Function via a `call` method, but |
295 var functionRti = extractFunctionTypeObjectFrom(object); | 295 // includes classes generated to represent closures in closure conversion. |
296 if (functionRti != null) return runtimeTypeToString(functionRti); | 296 var functionRti = extractFunctionTypeObjectFrom(object); |
| 297 if (functionRti != null) { |
| 298 return runtimeTypeToString(functionRti); |
| 299 } |
| 300 } |
297 String className = getClassName(object); | 301 String className = getClassName(object); |
298 if (object == null) return className; | 302 if (object == null) return className; |
299 String rtiName = JS_GET_NAME(JsGetName.RTI_NAME); | 303 String rtiName = JS_GET_NAME(JsGetName.RTI_NAME); |
300 var rti = JS('var', r'#[#]', object, rtiName); | 304 var rti = JS('var', r'#[#]', object, rtiName); |
301 return "$className${joinArguments(rti, 0)}"; | 305 return "$className${joinArguments(rti, 0)}"; |
302 } | 306 } |
303 | 307 |
304 Type getRuntimeType(var object) { | 308 Type getRuntimeType(var object) { |
305 String type = getRuntimeTypeString(object); | 309 String type = getRuntimeTypeString(object); |
306 return new TypeImpl(type); | 310 return new TypeImpl(type); |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 * `null` and `undefined` (which we can avoid). | 768 * `null` and `undefined` (which we can avoid). |
765 */ | 769 */ |
766 bool isIdentical(var s, var t) => JS('bool', '# === #', s, t); | 770 bool isIdentical(var s, var t) => JS('bool', '# === #', s, t); |
767 | 771 |
768 /** | 772 /** |
769 * Returns `true` if the JavaScript values [s] and [t] are not identical. We use | 773 * Returns `true` if the JavaScript values [s] and [t] are not identical. We use |
770 * this helper instead of [identical] because `identical` needs to merge | 774 * this helper instead of [identical] because `identical` needs to merge |
771 * `null` and `undefined` (which we can avoid). | 775 * `null` and `undefined` (which we can avoid). |
772 */ | 776 */ |
773 bool isNotIdentical(var s, var t) => JS('bool', '# !== #', s, t); | 777 bool isNotIdentical(var s, var t) => JS('bool', '# !== #', s, t); |
OLD | NEW |