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

Unified Diff: runtime/lib/errors_patch.dart

Issue 2574003003: Add optional message argument to assert statements in the VM. (Closed)
Patch Set: Update dart2js status file Created 4 years 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 | « runtime/lib/errors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/errors_patch.dart
diff --git a/runtime/lib/errors_patch.dart b/runtime/lib/errors_patch.dart
index 26358027749c23366f3d179cda7675cbd548186e..6bd0881471a5043718aab09c049ae6685d6ec832 100644
--- a/runtime/lib/errors_patch.dart
+++ b/runtime/lib/errors_patch.dart
@@ -18,29 +18,37 @@
class _AssertionError extends Error implements AssertionError {
_AssertionError._create(
- this._failedAssertion, this._url, this._line, this._column);
+ this._failedAssertion, this._url, this._line, this._column,
+ this.message);
- static _throwNew(int assertionStart, int assertionEnd)
- native "AssertionError_throwNew";
- static void _checkAssertion(condition, int start, int end) {
+ // AssertionError_throwNew in errors.cc fishes the assertion source code
+ // out of the script. It expects a Dart stack frame from class
+ // _AssertionError. Thus we need a Dart stub that calls the native code.
+ static _throwNew(int assertionStart, int assertionEnd, Object message) {
+ _doThrowNew(assertionStart, assertionEnd, message);
+ }
+
+ static _doThrowNew(int assertionStart, int assertionEnd, Object message)
+ native "AssertionError_throwNew";
+
+ static _evaluateAssertion(condition) {
if (condition is Function) {
condition = condition();
}
- if (!condition) {
- _throwNew(start, end);
- }
+ return condition;
}
- static void _checkConstAssertion(bool condition, int start, int end) {
- if (!condition) {
- _throwNew(start, end);
- }
+ String get _messageString {
+ if (message == null) return "is not true.";
+ if (message is String) return message;
+ return Error.safeToString(message);
}
String toString() {
if (_url == null) {
- return _failedAssertion;
+ if (message == null) return _failedAssertion;
+ return "'$_failedAssertion': $_messageString";
}
var columnInfo = "";
if (_column > 0) {
@@ -48,17 +56,18 @@ class _AssertionError extends Error implements AssertionError {
columnInfo = " pos $_column";
}
return "'$_url': Failed assertion: line $_line$columnInfo: "
- "'$_failedAssertion' is not true.";
+ "'$_failedAssertion': $_messageString";
}
final String _failedAssertion;
final String _url;
final int _line;
final int _column;
+ final Object message;
}
class _TypeError extends _AssertionError implements TypeError {
- _TypeError._create(String url, int line, int column, this._errorMsg)
- : super._create("is assignable", url, line, column);
+ _TypeError._create(String url, int line, int column, String errorMsg)
+ : super._create("is assignable", url, line, column, errorMsg);
static _throwNew(int location,
Object src_value,
@@ -78,9 +87,7 @@ class _TypeError extends _AssertionError implements TypeError {
}
}
- String toString() => _errorMsg;
-
- final String _errorMsg;
+ String toString() => super.message;
}
class _CastError extends Error implements CastError {
« no previous file with comments | « runtime/lib/errors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698