| 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 runtime operations on objects used by the code | 5 /// This library defines runtime operations on objects used by the code | 
| 6 /// generator. | 6 /// generator. | 
| 7 part of dart._runtime; | 7 part of dart._runtime; | 
| 8 | 8 | 
| 9 class InvocationImpl extends Invocation { | 9 class InvocationImpl extends Invocation { | 
| 10   final Symbol memberName; | 10   final Symbol memberName; | 
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 475         !!$isSubtype(type, $StreamSubscription) && | 475         !!$isSubtype(type, $StreamSubscription) && | 
| 476         !!$isSubtype(actual, $StreamSubscription)) { | 476         !!$isSubtype(actual, $StreamSubscription)) { | 
| 477       console.warn('Ignoring cast fail from ' + $typeName(actual) + | 477       console.warn('Ignoring cast fail from ' + $typeName(actual) + | 
| 478                    ' to ' + $typeName(type)); | 478                    ' to ' + $typeName(type)); | 
| 479       return true; | 479       return true; | 
| 480     } | 480     } | 
| 481     return false; | 481     return false; | 
| 482   }); | 482   }); | 
| 483 })()'''); | 483 })()'''); | 
| 484 | 484 | 
| 485 /// Returns true if [obj] is an instance of [type] | 485 /// Returns true if [obj] is an instance of [type] in strong mode, otherwise | 
| 486 /// Returns true if [obj] is a JS function and [type] is a function type | 486 /// false. | 
| 487 /// Returns false if [obj] is not an instance of [type] in both spec | 487 /// | 
| 488 ///  and strong mode | 488 /// This also allows arbitrary JS function objects to be subtypes of every Dart | 
| 489 /// Returns null if [obj] is not an instance of [type] in strong mode | 489 /// function types. | 
| 490 ///  but might be in spec mode |  | 
| 491 bool strongInstanceOf(obj, type, ignoreFromWhiteList) => JS('', '''(() => { | 490 bool strongInstanceOf(obj, type, ignoreFromWhiteList) => JS('', '''(() => { | 
| 492   let actual = $getReifiedType($obj); | 491   let actual = $getReifiedType($obj); | 
| 493   let result = $isSubtype(actual, $type); | 492   let result = $isSubtype(actual, $type); | 
| 494   if (result || (actual == $int && $isSubtype($double, $type))) return true; | 493   if (result || | 
| 495   if (actual == $jsobject && $_isFunctionType(type) && | 494       (actual == $int && $isSubtype($double, $type)) || | 
| 496       typeof(obj) === 'function') { | 495       (actual == $jsobject && $_isFunctionType(type) && | 
|  | 496           typeof(obj) === 'function')) { | 
| 497     return true; | 497     return true; | 
| 498   } | 498   } | 
| 499   if (result === false) return false; | 499   if (result === null && | 
| 500   if (!dart.__ignoreWhitelistedErrors || | 500       dart.__ignoreWhitelistedErrors && | 
| 501       ($ignoreFromWhiteList == void 0)) { | 501       $ignoreFromWhiteList && | 
| 502     return result; | 502       $_ignoreTypeFailure(actual, $type)) { | 
|  | 503     return true; | 
| 503   } | 504   } | 
| 504   if ($_ignoreTypeFailure(actual, $type)) return true; | 505   return false; | 
| 505   return result; |  | 
| 506 })()'''); | 506 })()'''); | 
| 507 | 507 | 
| 508 /// Returns true if [obj] is null or an instance of [type] | 508 /// Returns true if [obj] is null or an instance of [type] | 
| 509 /// Returns false if [obj] is non-null and not an instance of [type] | 509 /// Returns false if [obj] is non-null and not an instance of [type] | 
| 510 /// in strong mode | 510 /// in strong mode | 
| 511 instanceOfOrNull(obj, type) => JS('', '''(() => { | 511 bool instanceOfOrNull(obj, type) { | 
| 512   // If strongInstanceOf returns null, convert to false here. | 512   // If strongInstanceOf returns null, convert to false here. | 
| 513   if (($obj == null) || $strongInstanceOf($obj, $type, true)) return true; | 513   return obj == null || JS('bool', '#', strongInstanceOf(obj, type, true)); | 
| 514   return false; | 514 } | 
| 515 })()'''); |  | 
| 516 | 515 | 
| 517 @JSExportName('is') | 516 @JSExportName('is') | 
| 518 bool instanceOf(obj, type) => JS('', '''(() => { | 517 bool instanceOf(obj, type) { | 
| 519   if ($obj == null) { | 518   if (obj == null) { | 
| 520     return $type == $Null || $_isTop($type); | 519     return JS('bool', '# == # || #', type, Null, _isTop(type)); | 
| 521   } | 520   } | 
| 522   let result = $strongInstanceOf($obj, $type); | 521   return strongInstanceOf(obj, type, false); | 
| 523   if (result !== null) return result; | 522 } | 
| 524   if (!dart.__failForWeakModeIsChecks) return false; |  | 
| 525   let actual = $getReifiedType($obj); |  | 
| 526   let message = 'Strong mode is-check failure: ' + |  | 
| 527       $typeName(actual) + ' does not soundly subtype ' + |  | 
| 528       $typeName($type); |  | 
| 529   if (!dart.__ignoreAllErrors) { |  | 
| 530     $throwStrongModeError(message); |  | 
| 531   } |  | 
| 532   console.error(message); |  | 
| 533   return true; // Match Dart 1.0 Semantics when ignoring errors. |  | 
| 534 })()'''); |  | 
| 535 | 523 | 
| 536 @JSExportName('as') | 524 @JSExportName('as') | 
| 537 cast(obj, type) { | 525 cast(obj, type) { | 
| 538   if (JS('bool', '# == #', type, dynamic) || obj == null) return obj; | 526   if (JS('bool', '# == #', type, dynamic) || obj == null) return obj; | 
| 539   bool result = strongInstanceOf(obj, type, true); | 527   bool result = strongInstanceOf(obj, type, true); | 
| 540   if (JS('bool', '#', result)) return obj; | 528   if (JS('bool', '#', result)) return obj; | 
| 541   if (JS('bool', '!dart.__ignoreAllErrors')) { | 529   if (JS('bool', '!dart.__ignoreAllErrors')) { | 
| 542     _throwCastError(obj, type, result); | 530     _throwCastError(obj, type, result); | 
| 543   } | 531   } | 
| 544   JS('', 'console.error(#)', | 532   JS('', 'console.error(#)', | 
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1006 /// Libraries are not actually deferred in DDC, so this just returns a future | 994 /// Libraries are not actually deferred in DDC, so this just returns a future | 
| 1007 /// that completes immediately. | 995 /// that completes immediately. | 
| 1008 Future loadLibrary() => new Future.value(); | 996 Future loadLibrary() => new Future.value(); | 
| 1009 | 997 | 
| 1010 /// Defines lazy statics. | 998 /// Defines lazy statics. | 
| 1011 void defineLazy(to, from) { | 999 void defineLazy(to, from) { | 
| 1012   for (var name in getOwnNamesAndSymbols(from)) { | 1000   for (var name in getOwnNamesAndSymbols(from)) { | 
| 1013     defineLazyProperty(to, name, getOwnPropertyDescriptor(from, name)); | 1001     defineLazyProperty(to, name, getOwnPropertyDescriptor(from, name)); | 
| 1014   } | 1002   } | 
| 1015 } | 1003 } | 
| OLD | NEW | 
|---|