Upgrade to 3.29
Update V8 to 3.29.88.17 and update makefiles to support building on
all the relevant platforms.
Bug: 17370214
Change-Id: Ia3407c157fd8d72a93e23d8318ccaf6ecf77fa4e
diff --git a/src/conversions-inl.h b/src/conversions-inl.h
index b098a1c..ae87dc4 100644
--- a/src/conversions-inl.h
+++ b/src/conversions-inl.h
@@ -1,53 +1,36 @@
// Copyright 2011 the V8 project authors. All rights reserved.
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef V8_CONVERSIONS_INL_H_
#define V8_CONVERSIONS_INL_H_
-#include <limits.h> // Required for INT_MAX etc.
-#include <math.h>
#include <float.h> // Required for DBL_MAX and on Win32 for finite()
+#include <limits.h> // Required for INT_MAX etc.
#include <stdarg.h>
-#include "globals.h" // Required for V8_INFINITY
+#include <cmath>
+#include "src/globals.h" // Required for V8_INFINITY
// ----------------------------------------------------------------------------
// Extra POSIX/ANSI functions for Win32/MSVC.
-#include "conversions.h"
-#include "double.h"
-#include "platform.h"
-#include "scanner.h"
-#include "strtod.h"
+#include "src/base/bits.h"
+#include "src/base/platform/platform.h"
+#include "src/conversions.h"
+#include "src/double.h"
+#include "src/scanner.h"
+#include "src/strtod.h"
namespace v8 {
namespace internal {
inline double JunkStringValue() {
- return BitCast<double, uint64_t>(kQuietNaNMask);
+ return bit_cast<double, uint64_t>(kQuietNaNMask);
+}
+
+
+inline double SignedZero(bool negative) {
+ return negative ? uint64_to_double(Double::kSignMask) : 0.0;
}
@@ -70,7 +53,11 @@
if (x < k2Pow52) {
x += k2Pow52;
uint32_t result;
+#ifndef V8_TARGET_BIG_ENDIAN
Address mantissa_ptr = reinterpret_cast<Address>(&x);
+#else
+ Address mantissa_ptr = reinterpret_cast<Address>(&x) + kIntSize;
+#endif
// Copy least significant 32 bits of mantissa.
memcpy(&result, mantissa_ptr, sizeof(result));
return negative ? ~result + 1 : result;
@@ -80,10 +67,18 @@
}
+inline float DoubleToFloat32(double x) {
+ // TODO(yanggou): This static_cast is implementation-defined behaviour in C++,
+ // so we may need to do the conversion manually instead to match the spec.
+ volatile float f = static_cast<float>(x);
+ return f;
+}
+
+
inline double DoubleToInteger(double x) {
- if (isnan(x)) return 0;
- if (!isfinite(x) || x == 0) return x;
- return (x >= 0) ? floor(x) : ceil(x);
+ if (std::isnan(x)) return 0;
+ if (!std::isfinite(x) || x == 0) return x;
+ return (x >= 0) ? std::floor(x) : std::ceil(x);
}
@@ -106,7 +101,7 @@
bool SubStringEquals(Iterator* current,
EndMark end,
const char* substring) {
- ASSERT(**current == *substring);
+ DCHECK(**current == *substring);
for (substring++; *substring != '\0'; substring++) {
++*current;
if (*current == end || **current != *substring) return false;
@@ -123,7 +118,7 @@
Iterator* current,
EndMark end) {
while (*current != end) {
- if (!unicode_cache->IsWhiteSpace(**current)) return true;
+ if (!unicode_cache->IsWhiteSpaceOrLineTerminator(**current)) return true;
++*current;
}
return false;
@@ -137,7 +132,7 @@
EndMark end,
bool negative,
bool allow_trailing_junk) {
- ASSERT(current != end);
+ DCHECK(current != end);
// Skip leading 0s.
while (*current == '0') {
@@ -207,7 +202,7 @@
}
// Rounding up may cause overflow.
- if ((number & ((int64_t)1 << 53)) != 0) {
+ if ((number & (static_cast<int64_t>(1) << 53)) != 0) {
exponent++;
number >>= 1;
}
@@ -216,8 +211,8 @@
++current;
} while (current != end);
- ASSERT(number < ((int64_t)1 << 53));
- ASSERT(static_cast<int64_t>(static_cast<double>(number)) == number);
+ DCHECK(number < ((int64_t)1 << 53));
+ DCHECK(static_cast<int64_t>(static_cast<double>(number)) == number);
if (exponent == 0) {
if (negative) {
@@ -227,10 +222,8 @@
return static_cast<double>(number);
}
- ASSERT(number != 0);
- // The double could be constructed faster from number (mantissa), exponent
- // and sign. Assuming it's a rare case more simple code is used.
- return static_cast<double>(negative ? -number : number) * pow(2.0, exponent);
+ DCHECK(number != 0);
+ return std::ldexp(static_cast<double>(negative ? -number : number), exponent);
}
@@ -265,6 +258,7 @@
if (radix == 0) {
// Radix detection.
+ radix = 10;
if (*current == '0') {
++current;
if (current == end) return SignedZero(negative);
@@ -273,11 +267,8 @@
++current;
if (current == end) return JunkStringValue();
} else {
- radix = 8;
leading_zero = true;
}
- } else {
- radix = 10;
}
} else if (radix == 16) {
if (*current == '0') {
@@ -306,7 +297,7 @@
return JunkStringValue();
}
- if (IsPowerOf2(radix)) {
+ if (base::bits::IsPowerOfTwo32(radix)) {
switch (radix) {
case 2:
return InternalStringToIntDouble<1>(
@@ -342,7 +333,7 @@
if (buffer_pos <= kMaxSignificantDigits) {
// If the number has more than kMaxSignificantDigits it will be parsed
// as infinity.
- ASSERT(buffer_pos < kBufferSize);
+ DCHECK(buffer_pos < kBufferSize);
buffer[buffer_pos++] = static_cast<char>(*current);
}
++current;
@@ -354,7 +345,7 @@
return JunkStringValue();
}
- ASSERT(buffer_pos < kBufferSize);
+ SLOW_DCHECK(buffer_pos < kBufferSize);
buffer[buffer_pos] = '\0';
Vector<const char> buffer_vector(buffer, buffer_pos);
return negative ? -Strtod(buffer_vector, 0) : Strtod(buffer_vector, 0);
@@ -402,7 +393,7 @@
if (m > kMaximumMultiplier) break;
part = part * radix + d;
multiplier = m;
- ASSERT(multiplier > part);
+ DCHECK(multiplier > part);
++current;
if (current == end) {
@@ -461,21 +452,28 @@
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";
- if (*current == kInfinitySymbol[0]) {
- if (!SubStringEquals(¤t, end, kInfinitySymbol)) {
+ static const char kInfinityString[] = "Infinity";
+ if (*current == kInfinityString[0]) {
+ if (!SubStringEquals(¤t, end, kInfinityString)) {
return JunkStringValue();
}
@@ -484,44 +482,70 @@
return JunkStringValue();
}
- ASSERT(buffer_pos == 0);
- return negative ? -V8_INFINITY : V8_INFINITY;
+ DCHECK(buffer_pos == 0);
+ 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);
+
+ // It could be an explicit octal value.
+ } else if ((flags & ALLOW_OCTAL) && (*current == 'o' || *current == 'O')) {
+ ++current;
+ if (current == end || !isDigit(*current, 8) || sign != NONE) {
+ return JunkStringValue(); // "0o".
+ }
+
+ return InternalStringToIntDouble<3>(unicode_cache,
+ current,
+ end,
+ false,
+ allow_trailing_junk);
+
+ // It could be a binary value.
+ } else if ((flags & ALLOW_BINARY) && (*current == 'b' || *current == 'B')) {
+ ++current;
+ if (current == end || !isBinaryDigit(*current) || sign != NONE) {
+ return JunkStringValue(); // "0b".
+ }
+
+ return InternalStringToIntDouble<1>(unicode_cache,
+ current,
+ end,
+ 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);
}
}
- bool octal = leading_zero && (flags & ALLOW_OCTALS) != 0;
+ bool octal = leading_zero && (flags & ALLOW_IMPLICIT_OCTAL) != 0;
// Copy significant digits of the integer part (if any) to the buffer.
while (*current >= '0' && *current <= '9') {
if (significant_digits < kMaxSignificantDigits) {
- ASSERT(buffer_pos < kBufferSize);
+ DCHECK(buffer_pos < kBufferSize);
buffer[buffer_pos++] = static_cast<char>(*current);
significant_digits++;
// Will later check if it's an octal in the buffer.
@@ -557,7 +581,7 @@
// 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.
}
}
@@ -566,7 +590,7 @@
// instead.
while (*current >= '0' && *current <= '9') {
if (significant_digits < kMaxSignificantDigits) {
- ASSERT(buffer_pos < kBufferSize);
+ DCHECK(buffer_pos < kBufferSize);
buffer[buffer_pos++] = static_cast<char>(*current);
significant_digits++;
exponent--;
@@ -620,7 +644,7 @@
}
const int max_exponent = INT_MAX / 2;
- ASSERT(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2);
+ DCHECK(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2);
int num = 0;
do {
// Check overflow.
@@ -649,7 +673,7 @@
return InternalStringToIntDouble<3>(unicode_cache,
buffer,
buffer + buffer_pos,
- negative,
+ sign == NEGATIVE,
allow_trailing_junk);
}
@@ -658,11 +682,11 @@
exponent--;
}
- ASSERT(buffer_pos < kBufferSize);
+ SLOW_DCHECK(buffer_pos < kBufferSize);
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