diff options
Diffstat (limited to 'src/3rdparty/v8/src/conversions-inl.h')
-rw-r--r-- | src/3rdparty/v8/src/conversions-inl.h | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/3rdparty/v8/src/conversions-inl.h b/src/3rdparty/v8/src/conversions-inl.h index 77b260f..e272fe6 100644 --- a/src/3rdparty/v8/src/conversions-inl.h +++ b/src/3rdparty/v8/src/conversions-inl.h @@ -51,6 +51,11 @@ inline double JunkStringValue() { } +inline double SignedZero(bool negative) { + return negative ? uint64_to_double(Double::kSignMask) : 0.0; +} + + // The fast double-to-unsigned-int conversion routine does not guarantee // rounding towards zero, or any reasonable value if the argument is larger // than what fits in an unsigned 32-bit integer. @@ -263,6 +268,7 @@ double InternalStringToInt(UnicodeCache* unicode_cache, if (radix == 0) { // Radix detection. + radix = 10; if (*current == '0') { ++current; if (current == end) return SignedZero(negative); @@ -271,11 +277,8 @@ double InternalStringToInt(UnicodeCache* unicode_cache, ++current; if (current == end) return JunkStringValue(); } else { - radix = 8; leading_zero = true; } - } else { - radix = 10; } } else if (radix == 16) { if (*current == '0') { @@ -459,16 +462,23 @@ double InternalStringToDouble(UnicodeCache* unicode_cache, int insignificant_digits = 0; bool nonzero_digit_dropped = false; - bool negative = false; + enum Sign { + NONE, + NEGATIVE, + POSITIVE + }; + + Sign sign = NONE; if (*current == '+') { // Ignore leading sign. ++current; if (current == end) return JunkStringValue(); + sign = POSITIVE; } else if (*current == '-') { ++current; if (current == end) return JunkStringValue(); - negative = true; + sign = NEGATIVE; } static const char kInfinitySymbol[] = "Infinity"; @@ -483,34 +493,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 != NONE) { 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 +565,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 +657,7 @@ double InternalStringToDouble(UnicodeCache* unicode_cache, return InternalStringToIntDouble<3>(unicode_cache, buffer, buffer + buffer_pos, - negative, + sign == NEGATIVE, allow_trailing_junk); } @@ -660,7 +670,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 |