#include <limits>
-#include "checks.h"
-#include "handles.h"
-#include "objects.h"
-#include "utils.h"
+#include "src/base/logging.h"
+#include "src/handles.h"
+#include "src/objects.h"
+#include "src/utils.h"
namespace v8 {
namespace internal {
// The fast double-to-(unsigned-)int conversion routine does not guarantee
// rounding towards zero.
-// For NaN and values outside the int range, return INT_MIN or INT_MAX.
+// If x is NaN, the result is INT_MIN. Otherwise the result is the argument x,
+// clamped to [INT_MIN, INT_MAX] and then rounded to an integer.
inline int FastD2IChecked(double x) {
if (!(x >= INT_MIN)) return INT_MIN; // Negation to catch NaNs.
if (x > INT_MAX) return INT_MAX;
}
+// This function should match the exact semantics of ECMA-262 20.2.2.17.
+inline float DoubleToFloat32(double x);
+
+
// This function should match the exact semantics of ECMA-262 9.4.
inline double DoubleToInteger(double x);
}
+static inline bool IsSmiDouble(double value) {
+ return !IsMinusZero(value) && value >= Smi::kMinValue &&
+ value <= Smi::kMaxValue && value == FastI2D(FastD2I(value));
+}
+
+
// Integer32 is an integer that can be represented as a signed 32-bit
// integer. It has to be in the range [-2^31, 2^31 - 1].
// We also have to check for negative 0 as it is not an Integer32.
}
+// UInteger32 is an integer that can be represented as an unsigned 32-bit
+// integer. It has to be in the range [0, 2^32 - 1].
+// We also have to check for negative 0 as it is not a UInteger32.
+static inline bool IsUint32Double(double value) {
+ return !IsMinusZero(value) &&
+ value >= 0 &&
+ value <= kMaxUInt32 &&
+ value == FastUI2D(FastD2UI(value));
+}
+
+
// Convert from Number object to C integer.
inline int32_t NumberToInt32(Object* number) {
if (number->IsSmi()) return Smi::cast(number)->value();
}
-double StringToDouble(UnicodeCache* unicode_cache,
- String* string,
- int flags,
- double empty_string_val = 0.0);
+double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string,
+ int flags, double empty_string_val = 0.0);
inline bool TryNumberToSize(Isolate* isolate,
SealHandleScope shs(isolate);
if (number->IsSmi()) {
int value = Smi::cast(number)->value();
- ASSERT(static_cast<unsigned>(Smi::kMaxValue)
+ DCHECK(static_cast<unsigned>(Smi::kMaxValue)
<= std::numeric_limits<size_t>::max());
if (value >= 0) {
*result = static_cast<size_t>(value);
}
return false;
} else {
- ASSERT(number->IsHeapNumber());
+ DCHECK(number->IsHeapNumber());
double value = HeapNumber::cast(number)->value();
if (value >= 0 &&
value <= std::numeric_limits<size_t>::max()) {