Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: pkg/compiler/lib/src/diagnostics/invariant.dart

Issue 2904613002: Redo "dart2js: replace 'invariant' with 'failedAt' to defer interpolation" (Closed)
Patch Set: export failedAt Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/common.dart ('k') | pkg/compiler/lib/src/elements/modelx.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/diagnostics/invariant.dart
diff --git a/pkg/compiler/lib/src/diagnostics/invariant.dart b/pkg/compiler/lib/src/diagnostics/invariant.dart
index 7ad6f3580a0070cd7febe9c6e03aac04c6817b53..34a9f3e9ffaefbc15e246ea8f466cc643906b487 100644
--- a/pkg/compiler/lib/src/diagnostics/invariant.dart
+++ b/pkg/compiler/lib/src/diagnostics/invariant.dart
@@ -44,7 +44,7 @@ bool invariant(Spannable spannable, var condition, {var message: null}) {
// information on assertion errors.
if (spannable == null) {
throw new SpannableAssertionFailure(CURRENT_ELEMENT_SPANNABLE,
- "Spannable was null for invariant. Use CURRENT_ELEMENT_SPANNABLE.");
+ 'Spannable was null for invariant. Use CURRENT_ELEMENT_SPANNABLE.');
}
if (condition is Function) {
condition = condition();
@@ -62,4 +62,28 @@ bool invariant(Spannable spannable, var condition, {var message: null}) {
return true;
}
+/// Throws a [SpannableAssertionFailure].
+///
+/// Use this method to provide better information for assertion by calling
+/// [failedAt] as the second argument to an `assert` statement:
+///
+/// assert(condition, failedAt(position, message));
+///
+/// [spannable] must be non-null and will be used to provide positional
+/// information in the generated error message.
+bool failedAt(Spannable spannable, [var message]) {
+ // TODO(johnniwinther): Use [spannable] and [message] to provide better
+ // information on assertion errors.
+ if (spannable == null) {
+ throw new SpannableAssertionFailure(
+ CURRENT_ELEMENT_SPANNABLE,
+ 'Spannable was null for failedInvariant. '
+ 'Use CURRENT_ELEMENT_SPANNABLE.');
+ }
+ if (message is Function) {
+ message = message();
+ }
+ throw new SpannableAssertionFailure(spannable, message);
+}
+
typedef void InternalErrorFunction(Spannable location, String message);
« no previous file with comments | « pkg/compiler/lib/src/common.dart ('k') | pkg/compiler/lib/src/elements/modelx.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698