Index: src/conversions-inl.h |
diff --git a/src/conversions-inl.h b/src/conversions-inl.h |
index 2086f8184a1d212c8555d7d0fa4b24900be03fa7..d7789f9180880868baac232fbc4eeab9e58cb4d9 100644 |
--- a/src/conversions-inl.h |
+++ b/src/conversions-inl.h |
@@ -128,12 +128,26 @@ int32_t NumberToInt32(Object* number) { |
return DoubleToInt32(number->Number()); |
} |
- |
uint32_t NumberToUint32(Object* number) { |
if (number->IsSmi()) return Smi::cast(number)->value(); |
return DoubleToUint32(number->Number()); |
} |
+uint32_t PositiveNumberToUint32(Object* number) { |
+ if (number->IsSmi()) { |
+ int value = Smi::cast(number)->value(); |
+ if (value <= 0) return 0; |
+ return value; |
+ } |
+ DCHECK(number->IsHeapNumber()); |
+ double value = number->Number(); |
+ // Catch all values smaller than 1 and use the double-negation trick for NANs. |
+ if (!(value >= 1)) return 0; |
+ uint32_t max = std::numeric_limits<uint32_t>::max(); |
+ if (value < max) return static_cast<uint32_t>(value); |
+ return max; |
+} |
+ |
int64_t NumberToInt64(Object* number) { |
if (number->IsSmi()) return Smi::cast(number)->value(); |
return static_cast<int64_t>(number->Number()); |