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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 instanceOf(obj, type) => JS( | 504 instanceOf(obj, type) => JS( |
505 '', | 505 '', |
506 '''(() => { | 506 '''(() => { |
507 if ($obj == null) { | 507 if ($obj == null) { |
508 return $type == $Null || $_isTop($type); | 508 return $type == $Null || $_isTop($type); |
509 } | 509 } |
510 let result = $strongInstanceOf($obj, $type); | 510 let result = $strongInstanceOf($obj, $type); |
511 if (result !== null) return result; | 511 if (result !== null) return result; |
512 if (!dart.__failForWeakModeIsChecks) return false; | 512 if (!dart.__failForWeakModeIsChecks) return false; |
513 let actual = $getReifiedType($obj); | 513 let actual = $getReifiedType($obj); |
514 $throwStrongModeError('Strong mode is-check failure: ' + | 514 let message = 'Strong mode is-check failure: ' + |
515 $typeName(actual) + ' does not soundly subtype ' + | 515 $typeName(actual) + ' does not soundly subtype ' + |
516 $typeName($type)); | 516 $typeName($type); |
| 517 if (!dart.__ignoreAllErrors) { |
| 518 $throwStrongModeError(message); |
| 519 } |
| 520 console.error(message); |
| 521 return true; // Match Dart 1.0 Semantics when ignoring errors. |
517 })()'''); | 522 })()'''); |
518 | 523 |
519 @JSExportName('as') | 524 @JSExportName('as') |
520 cast(obj, type) { | 525 cast(obj, type) { |
521 if (JS('bool', '# == #', type, dynamic) || obj == null) return obj; | 526 if (JS('bool', '# == #', type, dynamic) || obj == null) return obj; |
522 bool result = strongInstanceOf(obj, type, true); | 527 bool result = strongInstanceOf(obj, type, true); |
523 if (JS('bool', '#', result)) return obj; | 528 if (JS('bool', '#', result)) return obj; |
524 _throwCastError(obj, type, result); | 529 if (JS('bool', '!dart.__ignoreAllErrors')) { |
| 530 _throwCastError(obj, type, result); |
| 531 } |
| 532 JS('', 'console.error(#)', |
| 533 'Actual: ${typeName(getReifiedType(obj))} Expected: ${typeName(type)}'); |
| 534 return obj; |
525 } | 535 } |
526 | 536 |
527 check(obj, type) { | 537 check(obj, type) { |
528 if (JS('bool', '# == #', type, dynamic) || obj == null) return obj; | 538 if (JS('bool', '# == #', type, dynamic) || obj == null) return obj; |
529 bool result = strongInstanceOf(obj, type, true); | 539 bool result = strongInstanceOf(obj, type, true); |
530 if (JS('bool', '#', result)) return obj; | 540 if (JS('bool', '#', result)) return obj; |
531 _throwTypeError(obj, type, result); | 541 if (JS('bool', '!dart.__ignoreAllErrors')) { |
| 542 _throwTypeError(obj, type, result); |
| 543 } |
| 544 JS('', 'console.error(#)', |
| 545 'Actual: ${typeName(getReifiedType(obj))} Expected: ${typeName(type)}'); |
| 546 return obj; |
532 } | 547 } |
533 | 548 |
534 bool test(obj) { | 549 bool test(obj) { |
535 if (obj is bool) return obj; | 550 if (obj is bool) return obj; |
536 return booleanConversionFailed(obj); | 551 return booleanConversionFailed(obj); |
537 } | 552 } |
538 | 553 |
539 bool booleanConversionFailed(obj) { | 554 bool booleanConversionFailed(obj) { |
540 if (obj == null) { | 555 if (obj == null) { |
541 throw new BooleanConversionAssertionError(); | 556 throw new BooleanConversionAssertionError(); |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 name = '+' + name; | 1010 name = '+' + name; |
996 } | 1011 } |
997 return name; | 1012 return name; |
998 } | 1013 } |
999 | 1014 |
1000 /// Emulates the implicit "loadLibrary" function provided by a deferred library. | 1015 /// Emulates the implicit "loadLibrary" function provided by a deferred library. |
1001 /// | 1016 /// |
1002 /// Libraries are not actually deferred in DDC, so this just returns a future | 1017 /// Libraries are not actually deferred in DDC, so this just returns a future |
1003 /// that completes immediately. | 1018 /// that completes immediately. |
1004 Future loadLibrary() => new Future.value(); | 1019 Future loadLibrary() => new Future.value(); |
OLD | NEW |