| 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 return true; | 516 return true; |
| 517 } | 517 } |
| 518 | 518 |
| 519 bool areAssignableMaps(var s, var t) { | 519 bool areAssignableMaps(var s, var t) { |
| 520 if (isNull(t)) return true; | 520 if (isNull(t)) return true; |
| 521 if (isNull(s)) return false; | 521 if (isNull(s)) return false; |
| 522 | 522 |
| 523 assert(isJsObject(s)); | 523 assert(isJsObject(s)); |
| 524 assert(isJsObject(t)); | 524 assert(isJsObject(t)); |
| 525 | 525 |
| 526 return JS('bool', r''' | 526 List names = |
| 527 function (t, s, isAssignable) { | 527 JSArray.markFixedList(JS('', 'Object.getOwnPropertyNames(#)', t)); |
| 528 for (var $name in t) { | 528 for (int i = 0; i < names.length; i++) { |
| 529 if (!s.hasOwnProperty($name)) { | 529 var name = names[i]; |
| 530 return false; | 530 if (JS('bool', '!Object.hasOwnProperty.call(#, #)', s, name)) { |
| 531 } | 531 return false; |
| 532 var tType = t[$name]; | 532 } |
| 533 var sType = s[$name]; | 533 var tType = JS('', '#[#]', t, name); |
| 534 if (!isAssignable.call$2(sType, tType)) { | 534 var sType = JS('', '#[#]', s, name); |
| 535 return false; | 535 if (!isAssignable(tType, sType)) return false; |
| 536 } | 536 } |
| 537 } | 537 return true; |
| 538 return true; | |
| 539 }(#, #, #) | |
| 540 ''', t, s, RAW_DART_FUNCTION_REF(isAssignable)); | |
| 541 } | 538 } |
| 542 | 539 |
| 543 bool isFunctionSubtype(var s, var t) { | 540 bool isFunctionSubtype(var s, var t) { |
| 544 assert(hasField(t, '${JS_FUNCTION_TYPE_TAG()}')); | 541 assert(hasField(t, '${JS_FUNCTION_TYPE_TAG()}')); |
| 545 if (hasNoField(s, '${JS_FUNCTION_TYPE_TAG()}')) return false; | 542 if (hasNoField(s, '${JS_FUNCTION_TYPE_TAG()}')) return false; |
| 546 if (hasField(s, '${JS_FUNCTION_TYPE_VOID_RETURN_TAG()}')) { | 543 if (hasField(s, '${JS_FUNCTION_TYPE_VOID_RETURN_TAG()}')) { |
| 547 if (hasNoField(t, '${JS_FUNCTION_TYPE_VOID_RETURN_TAG()}') && | 544 if (hasNoField(t, '${JS_FUNCTION_TYPE_VOID_RETURN_TAG()}') && |
| 548 hasField(t, '${JS_FUNCTION_TYPE_RETURN_TYPE_TAG()}')) { | 545 hasField(t, '${JS_FUNCTION_TYPE_RETURN_TYPE_TAG()}')) { |
| 549 return false; | 546 return false; |
| 550 } | 547 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 * and [t] are Dart values. | 693 * and [t] are Dart values. |
| 697 */ | 694 */ |
| 698 bool isIdentical(var s, var t) => JS('bool', '# === #', s, t); | 695 bool isIdentical(var s, var t) => JS('bool', '# === #', s, t); |
| 699 | 696 |
| 700 /** | 697 /** |
| 701 * Returns [:true:] if the JavaScript values [s] and [t] are not identical. We | 698 * Returns [:true:] if the JavaScript values [s] and [t] are not identical. We |
| 702 * use this helper to avoid generating code under the invalid assumption that | 699 * use this helper to avoid generating code under the invalid assumption that |
| 703 * [s] and [t] are Dart values. | 700 * [s] and [t] are Dart values. |
| 704 */ | 701 */ |
| 705 bool isNotIdentical(var s, var t) => JS('bool', '# !== #', s, t); | 702 bool isNotIdentical(var s, var t) => JS('bool', '# !== #', s, t); |
| OLD | NEW |