Index: sdk/lib/_internal/js_runtime/lib/js_helper.dart |
diff --git a/sdk/lib/_internal/js_runtime/lib/js_helper.dart b/sdk/lib/_internal/js_runtime/lib/js_helper.dart |
index 91049cda0fe66872d542cdc2d79fdb2ac2b06f45..658123e4cd86a49613b02d1d935f8db85137980e 100644 |
--- a/sdk/lib/_internal/js_runtime/lib/js_helper.dart |
+++ b/sdk/lib/_internal/js_runtime/lib/js_helper.dart |
@@ -3298,8 +3298,11 @@ class FallThroughErrorImplementation extends FallThroughError { |
/** |
* Helper function for implementing asserts. The compiler treats this specially. |
+ * |
+ * Returns the negation of the condition. That is: `true` if the assert should |
+ * fail. |
*/ |
-void assertHelper(condition) { |
+bool assertTest(condition) { |
// Do a bool check first because it is common and faster than 'is Function'. |
if (condition is !bool) { |
if (condition is Function) condition = condition(); |
@@ -3307,9 +3310,23 @@ void assertHelper(condition) { |
throw new TypeErrorImplementation(condition, 'bool'); |
} |
} |
- // Compare to true to avoid boolean conversion check in checked |
- // mode. |
- if (true != condition) throw new AssertionError(); |
+ return !condition; |
+} |
+ |
+/** |
+ * Helper function for implementing asserts with messages. |
+ * The compiler treats this specially. |
+ */ |
+void assertThrow(Object message) { |
+ throw new _AssertionError(message); |
+} |
+ |
+/** |
+ * Helper function for implementing asserts without messages. |
+ * The compiler treats this specially. |
+ */ |
+void assertHelper(condition) { |
+ if (assertTest(condition)) throw new AssertError(); |
sra1
2015/09/15 23:52:55
AssertionError()
|
} |
/** |
@@ -3972,3 +3989,10 @@ void badMain() { |
void mainHasTooManyParameters() { |
throw new MainError("'main' expects too many parameters."); |
} |
+ |
+class _AssertionError extends AssertionError { |
+ final _message; |
+ _AssertionError(this._message); |
+ |
+ String toString() => "Assertion failed: " + Error.safeToString(_message); |
+} |