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

Unified Diff: src/runtime.cc

Issue 1579004: Reverting r4329 due to failure in webkit tests. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 9 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 | « src/conversions.cc ('k') | test/mjsunit/parse-int-float.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
===================================================================
--- src/runtime.cc (revision 4329)
+++ src/runtime.cc (working copy)
@@ -4686,9 +4686,49 @@
s->TryFlatten();
- RUNTIME_ASSERT(radix == 0 || (2 <= radix && radix <= 36));
- double value = StringToInt(s, radix);
- return Heap::NumberFromDouble(value);
+ int len = s->length();
+ int i;
+
+ // Skip leading white space.
+ for (i = 0; i < len && Scanner::kIsWhiteSpace.get(s->Get(i)); i++) ;
+ if (i == len) return Heap::nan_value();
+
+ // Compute the sign (default to +).
+ int sign = 1;
+ if (s->Get(i) == '-') {
+ sign = -1;
+ i++;
+ } else if (s->Get(i) == '+') {
+ i++;
+ }
+
+ // Compute the radix if 0.
+ if (radix == 0) {
+ radix = 10;
+ if (i < len && s->Get(i) == '0') {
+ radix = 8;
+ if (i + 1 < len) {
+ int c = s->Get(i + 1);
+ if (c == 'x' || c == 'X') {
+ radix = 16;
+ i += 2;
+ }
+ }
+ }
+ } else if (radix == 16) {
+ // Allow 0x or 0X prefix if radix is 16.
+ if (i + 1 < len && s->Get(i) == '0') {
+ int c = s->Get(i + 1);
+ if (c == 'x' || c == 'X') i += 2;
+ }
+ }
+
+ RUNTIME_ASSERT(2 <= radix && radix <= 36);
+ double value;
+ int end_index = StringToInt(s, i, radix, &value);
+ if (end_index != i) {
+ return Heap::NumberFromDouble(sign * value);
+ }
return Heap::nan_value();
}
« no previous file with comments | « src/conversions.cc ('k') | test/mjsunit/parse-int-float.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698