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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 bool result = strongInstanceOf(obj, type, true); | 541 bool result = strongInstanceOf(obj, type, true); |
542 if (JS('bool', '#', result)) return obj; | 542 if (JS('bool', '#', result)) return obj; |
543 if (JS('bool', '!dart.__ignoreAllErrors')) { | 543 if (JS('bool', '!dart.__ignoreAllErrors')) { |
544 _throwTypeError(obj, type, result); | 544 _throwTypeError(obj, type, result); |
545 } | 545 } |
546 JS('', 'console.error(#)', | 546 JS('', 'console.error(#)', |
547 'Actual: ${typeName(getReifiedType(obj))} Expected: ${typeName(type)}'); | 547 'Actual: ${typeName(getReifiedType(obj))} Expected: ${typeName(type)}'); |
548 return obj; | 548 return obj; |
549 } | 549 } |
550 | 550 |
551 bool test(obj) { | 551 bool test(bool obj) { |
552 if (obj is bool) return obj; | 552 if (obj == null) _throwBooleanConversionError(); |
553 return booleanConversionFailed(obj); | 553 return obj; |
554 } | 554 } |
555 | 555 |
556 bool booleanConversionFailed(obj) { | 556 bool dtest(obj) { |
| 557 if (obj is! bool) booleanConversionFailed(obj); |
| 558 return obj; |
| 559 } |
| 560 |
| 561 void _throwBooleanConversionError() => |
| 562 throw new BooleanConversionAssertionError(); |
| 563 |
| 564 void booleanConversionFailed(obj) { |
557 if (obj == null) { | 565 if (obj == null) { |
558 throw new BooleanConversionAssertionError(); | 566 _throwBooleanConversionError(); |
559 } | 567 } |
560 var actual = getReifiedType(obj); | 568 var actual = getReifiedType(obj); |
561 var expected = JS('', '#', bool); | 569 var expected = JS('', '#', bool); |
562 throw new TypeErrorImplementation.fromMessage( | 570 throw new TypeErrorImplementation.fromMessage( |
563 "type '${typeName(actual)}' is not a subtype of " | 571 "type '${typeName(actual)}' is not a subtype of " |
564 "type '${typeName(expected)}' in boolean expression"); | 572 "type '${typeName(expected)}' in boolean expression"); |
565 } | 573 } |
566 | 574 |
567 void _throwCastError(obj, type, bool result) { | 575 void _throwCastError(obj, type, bool result) { |
568 var actual = getReifiedType(obj); | 576 var actual = getReifiedType(obj); |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 JS('', '# = "+" + #', name, name); | 1003 JS('', '# = "+" + #', name, name); |
996 } | 1004 } |
997 return name; | 1005 return name; |
998 } | 1006 } |
999 | 1007 |
1000 /// Emulates the implicit "loadLibrary" function provided by a deferred library. | 1008 /// Emulates the implicit "loadLibrary" function provided by a deferred library. |
1001 /// | 1009 /// |
1002 /// Libraries are not actually deferred in DDC, so this just returns a future | 1010 /// Libraries are not actually deferred in DDC, so this just returns a future |
1003 /// that completes immediately. | 1011 /// that completes immediately. |
1004 Future loadLibrary() => new Future.value(); | 1012 Future loadLibrary() => new Future.value(); |
OLD | NEW |