Index: src/conversions-inl.h |
diff --git a/src/conversions-inl.h b/src/conversions-inl.h |
index ae87dc4d31b01763eef756a1058a05ca0dc1561e..d9f16ade2eda6b69e2d2c2e3892acc0bd5ffea63 100644 |
--- a/src/conversions-inl.h |
+++ b/src/conversions-inl.h |
@@ -18,6 +18,7 @@ |
#include "src/base/platform/platform.h" |
#include "src/conversions.h" |
#include "src/double.h" |
+#include "src/objects-inl.h" |
#include "src/scanner.h" |
#include "src/strtod.h" |
@@ -97,6 +98,68 @@ int32_t DoubleToInt32(double x) { |
} |
+bool IsSmiDouble(double value) { |
+ return !IsMinusZero(value) && value >= Smi::kMinValue && |
+ value <= Smi::kMaxValue && value == FastI2D(FastD2I(value)); |
+} |
+ |
+ |
+bool IsInt32Double(double value) { |
+ return !IsMinusZero(value) && value >= kMinInt && value <= kMaxInt && |
+ value == FastI2D(FastD2I(value)); |
+} |
+ |
+ |
+bool IsUint32Double(double value) { |
+ return !IsMinusZero(value) && value >= 0 && value <= kMaxUInt32 && |
+ value == FastUI2D(FastD2UI(value)); |
+} |
+ |
+ |
+int32_t NumberToInt32(Object* number) { |
+ if (number->IsSmi()) return Smi::cast(number)->value(); |
+ return DoubleToInt32(number->Number()); |
+} |
+ |
+ |
+uint32_t NumberToUint32(Object* number) { |
+ if (number->IsSmi()) return Smi::cast(number)->value(); |
+ return DoubleToUint32(number->Number()); |
+} |
+ |
+ |
+bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result) { |
+ SealHandleScope shs(isolate); |
+ if (number->IsSmi()) { |
+ int value = Smi::cast(number)->value(); |
+ DCHECK(static_cast<unsigned>(Smi::kMaxValue) <= |
+ std::numeric_limits<size_t>::max()); |
+ if (value >= 0) { |
+ *result = static_cast<size_t>(value); |
+ return true; |
+ } |
+ return false; |
+ } else { |
+ DCHECK(number->IsHeapNumber()); |
+ double value = HeapNumber::cast(number)->value(); |
+ if (value >= 0 && value <= std::numeric_limits<size_t>::max()) { |
+ *result = static_cast<size_t>(value); |
+ return true; |
+ } else { |
+ return false; |
+ } |
+ } |
+} |
+ |
+ |
+size_t NumberToSize(Isolate* isolate, Object* number) { |
+ size_t result = 0; |
+ bool is_valid = TryNumberToSize(isolate, number, &result); |
+ CHECK(is_valid); |
+ return result; |
+} |
+ |
+ |
template <class Iterator, class EndMark> |
bool SubStringEquals(Iterator* current, |
EndMark end, |