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

Unified Diff: lib/compiler/implementation/lib/js_helper.dart

Issue 10913271: Move parseInt parseDouble to int/double classes as a static method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make int.parse directly native. Created 8 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 | « lib/compiler/implementation/lib/coreimpl.dart ('k') | lib/compiler/implementation/lib/math_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/lib/js_helper.dart
diff --git a/lib/compiler/implementation/lib/js_helper.dart b/lib/compiler/implementation/lib/js_helper.dart
index 8d1f3013035ed67bb9683086263fe286aa45f756..e03c863bab5200f3b6476b4458b39775c83c6337 100644
--- a/lib/compiler/implementation/lib/js_helper.dart
+++ b/lib/compiler/implementation/lib/js_helper.dart
@@ -378,6 +378,41 @@ class Primitives {
}
}
+ static int parseInt(String string) {
+ checkString(string);
+ var match = JS('List',
+ @'/^\s*[+-]?(?:0(x)[a-f0-9]+|\d+)\s*$/i.exec(#)',
+ string);
+ if (match === null) {
+ throw new FormatException(string);
+ }
+ var base = 10;
+ if (match[1] !== null) base = 16;
+ var result = JS('num', @'parseInt(#, #)', string, base);
+ if (result.isNaN()) throw new FormatException(string);
+ return result;
+ }
+
+ static double parseDouble(String string) {
+ checkString(string);
+ // Notice that JS parseFloat accepts garbage at the end of the string.
+ // Accept, ignoring leading and trailing whitespace:
+ // - NaN
+ // - [+/-]Infinity
+ // - a Dart double literal
+ if (!JS('bool',
+ @'/^\s*(?:NaN|[+-]?(?:Infinity|'
+ @'(?:\.\d+|\d+(?:\.\d+)?)(?:[eE][+-]?\d+)?))\s*$/.test(#)',
+ string)) {
+ throw new FormatException(string);
+ }
+ var result = JS('num', @'parseFloat(#)', string);
+ if (result.isNaN() && string != 'NaN') {
+ throw new FormatException(string);
+ }
+ return result;
+ }
+
/** [: @"$".charCodeAt(0) :] */
static const int DOLLAR_CHAR_VALUE = 36;
« no previous file with comments | « lib/compiler/implementation/lib/coreimpl.dart ('k') | lib/compiler/implementation/lib/math_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698