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

Unified Diff: sdk/lib/core/errors.dart

Issue 11369243: Make Exception a class, not an interface, and remove the const constructor. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated. Moved safeToString to Error. Created 8 years, 1 month 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 | « sdk/lib/_internal/compiler/implementation/lib/core_patch.dart ('k') | sdk/lib/core/exceptions.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/errors.dart
diff --git a/sdk/lib/core/errors.dart b/sdk/lib/core/errors.dart
index 7ce86289ebc5f80a42b5e5def06444527435701a..dc03a4af289a503a9f51bd32a355573763c018f6 100644
--- a/sdk/lib/core/errors.dart
+++ b/sdk/lib/core/errors.dart
@@ -4,6 +4,31 @@
class Error {
const Error();
+
+ /**
+ * Safely convert a value to a [String] description.
+ *
+ * The conversion is guaranteed to not throw, so it won't use the object's
+ * toString method.
+ */
+ static String safeToString(Object object) {
+ if (object is int || object is double || object is bool || null == object) {
+ return object.toString();
+ }
+ if (object is String) {
+ // TODO(ahe): Remove backslash when http://dartbug.com/4995 is fixed.
+ const backslash = '\\';
+ String escaped = object
+ .replaceAll('$backslash', '$backslash$backslash')
+ .replaceAll('\n', '${backslash}n')
+ .replaceAll('\r', '${backslash}r')
+ .replaceAll('"', '$backslash"');
+ return '"$escaped"';
+ }
+ return _objectToString(object);
+ }
+
+ external static String _objectToString(Object object);
}
/**
@@ -120,7 +145,7 @@ class NoSuchMethodError implements Error {
if (i > 0) {
sb.add(", ");
}
- sb.add(safeToString(_arguments[i]));
+ sb.add(Error.safeToString(_arguments[i]));
}
}
if (_namedArguments != null) {
@@ -130,13 +155,13 @@ class NoSuchMethodError implements Error {
}
sb.add(key);
sb.add(": ");
- sb.add(safeToString(value));
+ sb.add(Error.safeToString(value));
i++;
});
}
if (_existingArgumentNames == null) {
return "NoSuchMethodError : method not found: '$_memberName'\n"
- "Receiver: ${safeToString(_receiver)}\n"
+ "Receiver: ${Error.safeToString(_receiver)}\n"
"Arguments: [$sb]";
} else {
String actualParameters = sb.toString();
@@ -150,30 +175,11 @@ class NoSuchMethodError implements Error {
String formalParameters = sb.toString();
return "NoSuchMethodError: incorrect number of arguments passed to "
"method named '$_memberName'\n"
- "Receiver: ${safeToString(_receiver)}\n"
+ "Receiver: ${Error.safeToString(_receiver)}\n"
"Tried calling: $_memberName($actualParameters)\n"
"Found: $_memberName($formalParameters)";
}
}
-
- static String safeToString(Object object) {
- if (object is int || object is double || object is bool || null == object) {
- return object.toString();
- }
- if (object is String) {
- // TODO(ahe): Remove backslash when http://dartbug.com/4995 is fixed.
- const backslash = '\\';
- String escaped = object
- .replaceAll('$backslash', '$backslash$backslash')
- .replaceAll('\n', '${backslash}n')
- .replaceAll('\r', '${backslash}r')
- .replaceAll('"', '$backslash"');
- return '"$escaped"';
- }
- return _objectToString(object);
- }
-
- external static String _objectToString(Object object);
}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/core_patch.dart ('k') | sdk/lib/core/exceptions.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698