| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library dart2js.diagnostics.invariant; | 5 library dart2js.diagnostics.invariant; |
| 6 | 6 |
| 7 import 'spannable.dart'; | 7 import 'spannable.dart'; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * If true, print a warning for each method that was resolved, but not | 10 * If true, print a warning for each method that was resolved, but not |
| 11 * compiled. | 11 * compiled. |
| 12 */ | 12 */ |
| 13 const bool REPORT_EXCESS_RESOLUTION = false; | 13 const bool REPORT_EXCESS_RESOLUTION = false; |
| 14 | 14 |
| 15 /// Flag that can be used in assertions to assert that a code path is only | 15 /// Flag that can be used in assertions to assert that a code path is only |
| 16 /// executed as part of development. | 16 /// executed as part of development. |
| 17 /// | 17 /// |
| 18 /// This flag is automatically set to true if helper methods like, [debugPrint], | 18 /// This flag is automatically set to true if helper methods like, [debugPrint], |
| 19 /// [debugWrapPrint], [trace], and [reportHere] are called. | 19 /// [debugWrapPrint], [trace], and [reportHere] are called. |
| 20 bool DEBUG_MODE = false; | 20 bool DEBUG_MODE = false; |
| 21 | 21 |
| 22 /// Assert that [DEBUG_MODE] is `true` and provide [message] as part of the | 22 /// Assert that [DEBUG_MODE] is `true` and provide [message] as part of the |
| 23 /// error message. | 23 /// error message. |
| 24 assertDebugMode(String message) { | 24 assertDebugMode(String message) { |
| 25 assert(invariant(NO_LOCATION_SPANNABLE, DEBUG_MODE, | 25 assert(DEBUG_MODE, |
| 26 message: 'Debug mode is not enabled: $message')); | 26 failedAt(NO_LOCATION_SPANNABLE, 'Debug mode is not enabled: $message')); |
| 27 } | 27 } |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * Throws a [SpannableAssertionFailure] if [condition] is | 30 * Throws a [SpannableAssertionFailure] if [condition] is |
| 31 * [:false:]. [condition] must be either a [:bool:] or a no-arg | 31 * [:false:]. [condition] must be either a [:bool:] or a no-arg |
| 32 * function returning a [:bool:]. | 32 * function returning a [:bool:]. |
| 33 * | 33 * |
| 34 * Use this method to provide better information for assertion by calling | 34 * Use this method to provide better information for assertion by calling |
| 35 * [invariant] as the argument to an [:assert:] statement: | 35 * [invariant] as the argument to an [:assert:] statement: |
| 36 * | 36 * |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 'Spannable was null for failedInvariant. ' | 80 'Spannable was null for failedInvariant. ' |
| 81 'Use CURRENT_ELEMENT_SPANNABLE.'); | 81 'Use CURRENT_ELEMENT_SPANNABLE.'); |
| 82 } | 82 } |
| 83 if (message is Function) { | 83 if (message is Function) { |
| 84 message = message(); | 84 message = message(); |
| 85 } | 85 } |
| 86 throw new SpannableAssertionFailure(spannable, message); | 86 throw new SpannableAssertionFailure(spannable, message); |
| 87 } | 87 } |
| 88 | 88 |
| 89 typedef void InternalErrorFunction(Spannable location, String message); | 89 typedef void InternalErrorFunction(Spannable location, String message); |
| OLD | NEW |