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

Unified Diff: runtime/lib/integers_patch.dart

Issue 23685004: Don't throw when there is an "onError" for int.parse. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | « runtime/lib/integers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/integers_patch.dart
diff --git a/runtime/lib/integers_patch.dart b/runtime/lib/integers_patch.dart
index fb749d752185b8fe865c559c3e9b0ab923d0a1e6..fab603f03eca71b21c3b7fe088aeb40adcaa6f9e 100644
--- a/runtime/lib/integers_patch.dart
+++ b/runtime/lib/integers_patch.dart
@@ -74,20 +74,21 @@ patch class int {
/* patch */ static int parse(String source,
{ int radix,
int onError(String str) }) {
- if ((radix == null) && (onError == null)) return _parse(source);
+ if (radix == null) {
+ int result = _parse(source);
+ if (result == null) {
+ if (onError == null) {
+ throw new FormatException(source);
+ }
+ return onError(source);
+ }
+ return result;
+ }
return _slowParse(source, radix, onError);
}
static int _slowParse(String source, int radix, int onError(String str)) {
if (source is! String) throw new ArgumentError(source);
- if (radix == null) {
- assert(onError != null);
- try {
- return _parse(source);
- } on FormatException {
- return onError(source);
- }
- }
if (radix is! int) throw new ArgumentError("Radix is not an integer");
if (radix < 2 || radix > 36) {
throw new RangeError("Radix $radix not in range 2..36");
« no previous file with comments | « runtime/lib/integers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698