| 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 part of dart._runtime; | 4 part of dart._runtime; |
| 5 | 5 |
| 6 bool _trapRuntimeErrors = true; | 6 bool _trapRuntimeErrors = true; |
| 7 bool _ignoreWhitelistedErrors = true; | 7 bool _ignoreWhitelistedErrors = true; |
| 8 bool _failForWeakModeIsChecks = true; |
| 8 | 9 |
| 9 // Override, e.g., for testing | 10 // Override, e.g., for testing |
| 10 void trapRuntimeErrors(bool flag) { | 11 void trapRuntimeErrors(bool flag) { |
| 11 _trapRuntimeErrors = flag; | 12 _trapRuntimeErrors = flag; |
| 12 } | 13 } |
| 13 | 14 |
| 14 void ignoreWhitelistedErrors(bool flag) { | 15 void ignoreWhitelistedErrors(bool flag) { |
| 15 _ignoreWhitelistedErrors = flag; | 16 _ignoreWhitelistedErrors = flag; |
| 16 } | 17 } |
| 17 | 18 |
| 19 /// Throw an exception on `is` checks that would return an unsound answer in |
| 20 /// non-strong mode Dart. |
| 21 /// |
| 22 /// For example `x is List<int>` where `x = <Object>['hello']`. |
| 23 /// |
| 24 /// These checks behave correctly in strong mode (they return false), however, |
| 25 /// they will produce a different answer if run on a platform without strong |
| 26 /// mode. As a debugging feature, these checks can be configured to throw, to |
| 27 /// avoid seeing different behavior between modes. |
| 28 /// |
| 29 /// (There are many other ways that different `is` behavior can be observed, |
| 30 /// however, even with this flag. The most obvious is due to lack of reified |
| 31 /// generic type parameters. This affects generic functions and methods, as |
| 32 /// well as generic types when the type parameter was inferred. Setting this |
| 33 /// flag to `true` will not catch these differences in behavior..) |
| 34 void failForWeakModeIsChecks(bool flag) { |
| 35 _failForWeakModeIsChecks = flag; |
| 36 } |
| 37 |
| 18 throwCastError(object, actual, type) => JS( | 38 throwCastError(object, actual, type) => JS( |
| 19 '', | 39 '', |
| 20 '''(() => { | 40 '''(() => { |
| 21 var found = $typeName($actual); | 41 var found = $typeName($actual); |
| 22 var expected = $typeName($type); | 42 var expected = $typeName($type); |
| 23 if ($_trapRuntimeErrors) debugger; | 43 if ($_trapRuntimeErrors) debugger; |
| 24 $throw_(new $CastErrorImplementation($object, found, expected)); | 44 $throw_(new $CastErrorImplementation($object, found, expected)); |
| 25 })()'''); | 45 })()'''); |
| 26 | 46 |
| 27 throwTypeError(object, actual, type) => JS( | 47 throwTypeError(object, actual, type) => JS( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 })()'''); | 100 })()'''); |
| 81 | 101 |
| 82 throwNoSuchMethodError( | 102 throwNoSuchMethodError( |
| 83 receiver, memberName, positionalArguments, namedArguments) => | 103 receiver, memberName, positionalArguments, namedArguments) => |
| 84 JS( | 104 JS( |
| 85 '', | 105 '', |
| 86 '''(() => { | 106 '''(() => { |
| 87 if ($_trapRuntimeErrors) debugger; | 107 if ($_trapRuntimeErrors) debugger; |
| 88 $throw_(new $NoSuchMethodError($receiver, $memberName, $positionalArguments, $
namedArguments)); | 108 $throw_(new $NoSuchMethodError($receiver, $memberName, $positionalArguments, $
namedArguments)); |
| 89 })()'''); | 109 })()'''); |
| OLD | NEW |