Chromium Code Reviews| Index: src/conversions-inl.h |
| diff --git a/src/conversions-inl.h b/src/conversions-inl.h |
| index 77b260f036483962892a88ec04f46624fca30aec..e2d38c2a64f1feaf60c94fcc622c2ee81f54ac65 100644 |
| --- a/src/conversions-inl.h |
| +++ b/src/conversions-inl.h |
| @@ -459,16 +459,23 @@ double InternalStringToDouble(UnicodeCache* unicode_cache, |
| int insignificant_digits = 0; |
| bool nonzero_digit_dropped = false; |
| - bool negative = false; |
| + enum Sign { |
| + POSITIVE, |
| + NEGATIVE, |
| + EXPLICIT_POSITIVE |
|
rossberg
2012/07/23 09:59:20
For symmetry, I'd call this POSITIVE, and the othe
|
| + }; |
| + |
| + Sign sign = POSITIVE; |
| if (*current == '+') { |
| // Ignore leading sign. |
| ++current; |
| if (current == end) return JunkStringValue(); |
| + sign = EXPLICIT_POSITIVE; |
| } else if (*current == '-') { |
| ++current; |
| if (current == end) return JunkStringValue(); |
| - negative = true; |
| + sign = NEGATIVE; |
| } |
| static const char kInfinitySymbol[] = "Infinity"; |
| @@ -483,34 +490,34 @@ double InternalStringToDouble(UnicodeCache* unicode_cache, |
| } |
| ASSERT(buffer_pos == 0); |
| - return negative ? -V8_INFINITY : V8_INFINITY; |
| + return (sign == NEGATIVE) ? -V8_INFINITY : V8_INFINITY; |
| } |
| bool leading_zero = false; |
| if (*current == '0') { |
| ++current; |
| - if (current == end) return SignedZero(negative); |
| + if (current == end) return SignedZero(sign == NEGATIVE); |
| leading_zero = true; |
| // It could be hexadecimal value. |
| if ((flags & ALLOW_HEX) && (*current == 'x' || *current == 'X')) { |
| ++current; |
| - if (current == end || !isDigit(*current, 16)) { |
| + if (current == end || !isDigit(*current, 16) || sign != POSITIVE) { |
| return JunkStringValue(); // "0x". |
| } |
| return InternalStringToIntDouble<4>(unicode_cache, |
| current, |
| end, |
| - negative, |
| + false, |
| allow_trailing_junk); |
| } |
| // Ignore leading zeros in the integer part. |
| while (*current == '0') { |
| ++current; |
| - if (current == end) return SignedZero(negative); |
| + if (current == end) return SignedZero(sign == NEGATIVE); |
| } |
| } |
| @@ -555,7 +562,7 @@ double InternalStringToDouble(UnicodeCache* unicode_cache, |
| // leading zeros (if any). |
| while (*current == '0') { |
| ++current; |
| - if (current == end) return SignedZero(negative); |
| + if (current == end) return SignedZero(sign == NEGATIVE); |
| exponent--; // Move this 0 into the exponent. |
| } |
| } |
| @@ -647,7 +654,7 @@ double InternalStringToDouble(UnicodeCache* unicode_cache, |
| return InternalStringToIntDouble<3>(unicode_cache, |
| buffer, |
| buffer + buffer_pos, |
| - negative, |
| + sign == NEGATIVE, |
| allow_trailing_junk); |
| } |
| @@ -660,7 +667,7 @@ double InternalStringToDouble(UnicodeCache* unicode_cache, |
| buffer[buffer_pos] = '\0'; |
| double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
| - return negative ? -converted : converted; |
| + return (sign == NEGATIVE) ? -converted : converted; |
| } |
| } } // namespace v8::internal |