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

Unified Diff: sdk/lib/_internal/js_runtime/lib/js_helper.dart

Issue 1325843003: Add optional message to assert in Dart2js. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Reintroduce assertHelper for asserts without messages. Created 5 years, 3 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/world.dart ('k') | sdk/lib/core/errors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« no previous file with comments | « pkg/compiler/lib/src/world.dart ('k') | sdk/lib/core/errors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698