| 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 // We need to set these properties while the sdk is only partially initialized |
| 7 bool _ignoreWhitelistedErrors = true; | 7 // so we cannot use regular Dart fields. |
| 8 bool _failForWeakModeIsChecks = true; | 8 // The default values for these properties are set when the global_ final field |
| 9 // in runtime.dart is initialized. |
| 10 bool get _trapRuntimeErrors => JS('bool', 'dart.__trapRuntimeErrors'); |
| 11 bool get _ignoreWhitelistedErrors => |
| 12 JS('bool', 'dart.__ignoreWhitelistedErrors'); |
| 13 bool get _failForWeakModeIsChecks => |
| 14 JS('bool', 'dart.__failForWeakModeIsChecks'); |
| 9 | 15 |
| 10 // Override, e.g., for testing | 16 // Override, e.g., for testing |
| 11 void trapRuntimeErrors(bool flag) { | 17 void trapRuntimeErrors(bool flag) { |
| 12 _trapRuntimeErrors = flag; | 18 JS('', 'dart.__trapRuntimeErrors = #', flag); |
| 13 } | 19 } |
| 14 | 20 |
| 15 void ignoreWhitelistedErrors(bool flag) { | 21 void ignoreWhitelistedErrors(bool flag) { |
| 16 _ignoreWhitelistedErrors = flag; | 22 JS('', 'dart.__ignoreWhitelistedErrors = #', flag); |
| 17 } | 23 } |
| 18 | 24 |
| 19 /// Throw an exception on `is` checks that would return an unsound answer in | 25 /// Throw an exception on `is` checks that would return an unsound answer in |
| 20 /// non-strong mode Dart. | 26 /// non-strong mode Dart. |
| 21 /// | 27 /// |
| 22 /// For example `x is List<int>` where `x = <Object>['hello']`. | 28 /// For example `x is List<int>` where `x = <Object>['hello']`. |
| 23 /// | 29 /// |
| 24 /// These checks behave correctly in strong mode (they return false), however, | 30 /// 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 | 31 /// 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 | 32 /// mode. As a debugging feature, these checks can be configured to throw, to |
| 27 /// avoid seeing different behavior between modes. | 33 /// avoid seeing different behavior between modes. |
| 28 /// | 34 /// |
| 29 /// (There are many other ways that different `is` behavior can be observed, | 35 /// (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 | 36 /// 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 | 37 /// generic type parameters. This affects generic functions and methods, as |
| 32 /// well as generic types when the type parameter was inferred. Setting this | 38 /// well as generic types when the type parameter was inferred. Setting this |
| 33 /// flag to `true` will not catch these differences in behavior..) | 39 /// flag to `true` will not catch these differences in behavior..) |
| 34 void failForWeakModeIsChecks(bool flag) { | 40 void failForWeakModeIsChecks(bool flag) { |
| 35 _failForWeakModeIsChecks = flag; | 41 JS('', 'dart.__failForWeakModeIsChecks = #', flag); |
| 36 } | 42 } |
| 37 | 43 |
| 38 throwCastError(object, actual, type) => JS( | 44 throwCastError(object, actual, type) => JS( |
| 39 '', | 45 '', |
| 40 '''(() => { | 46 '''(() => { |
| 41 var found = $typeName($actual); | 47 var found = $typeName($actual); |
| 42 var expected = $typeName($type); | 48 var expected = $typeName($type); |
| 43 if ($_trapRuntimeErrors) debugger; | 49 if ($_trapRuntimeErrors) debugger; |
| 44 $throw_(new $CastErrorImplementation($object, found, expected)); | 50 $throw_(new $CastErrorImplementation($object, found, expected)); |
| 45 })()'''); | 51 })()'''); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 })()'''); | 111 })()'''); |
| 106 | 112 |
| 107 throwNoSuchMethodError( | 113 throwNoSuchMethodError( |
| 108 receiver, memberName, positionalArguments, namedArguments) => | 114 receiver, memberName, positionalArguments, namedArguments) => |
| 109 JS( | 115 JS( |
| 110 '', | 116 '', |
| 111 '''(() => { | 117 '''(() => { |
| 112 if ($_trapRuntimeErrors) debugger; | 118 if ($_trapRuntimeErrors) debugger; |
| 113 $throw_(new $NoSuchMethodError($receiver, $memberName, $positionalArguments, $
namedArguments)); | 119 $throw_(new $NoSuchMethodError($receiver, $memberName, $positionalArguments, $
namedArguments)); |
| 114 })()'''); | 120 })()'''); |
| OLD | NEW |