| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_CONVERSIONS_INL_H_ | 5 #ifndef V8_CONVERSIONS_INL_H_ |
| 6 #define V8_CONVERSIONS_INL_H_ | 6 #define V8_CONVERSIONS_INL_H_ |
| 7 | 7 |
| 8 #include <float.h> // Required for DBL_MAX and on Win32 for finite() | 8 #include <float.h> // Required for DBL_MAX and on Win32 for finite() |
| 9 #include <limits.h> // Required for INT_MAX etc. | 9 #include <limits.h> // Required for INT_MAX etc. |
| 10 #include <stdarg.h> | 10 #include <stdarg.h> |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 uint32_t NumberToUint32(Object* number) { | 132 uint32_t NumberToUint32(Object* number) { |
| 133 if (number->IsSmi()) return Smi::cast(number)->value(); | 133 if (number->IsSmi()) return Smi::cast(number)->value(); |
| 134 return DoubleToUint32(number->Number()); | 134 return DoubleToUint32(number->Number()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 int64_t NumberToInt64(Object* number) { | 137 int64_t NumberToInt64(Object* number) { |
| 138 if (number->IsSmi()) return Smi::cast(number)->value(); | 138 if (number->IsSmi()) return Smi::cast(number)->value(); |
| 139 return static_cast<int64_t>(number->Number()); | 139 return static_cast<int64_t>(number->Number()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result) { | 142 bool TryNumberToSize(Object* number, size_t* result) { |
| 143 // Do not create handles in this function! Don't use SealHandleScope because | 143 // Do not create handles in this function! Don't use SealHandleScope because |
| 144 // the function can be used concurrently. | 144 // the function can be used concurrently. |
| 145 if (number->IsSmi()) { | 145 if (number->IsSmi()) { |
| 146 int value = Smi::cast(number)->value(); | 146 int value = Smi::cast(number)->value(); |
| 147 DCHECK(static_cast<unsigned>(Smi::kMaxValue) <= | 147 DCHECK(static_cast<unsigned>(Smi::kMaxValue) <= |
| 148 std::numeric_limits<size_t>::max()); | 148 std::numeric_limits<size_t>::max()); |
| 149 if (value >= 0) { | 149 if (value >= 0) { |
| 150 *result = static_cast<size_t>(value); | 150 *result = static_cast<size_t>(value); |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 return false; | 153 return false; |
| 154 } else { | 154 } else { |
| 155 DCHECK(number->IsHeapNumber()); | 155 DCHECK(number->IsHeapNumber()); |
| 156 double value = HeapNumber::cast(number)->value(); | 156 double value = HeapNumber::cast(number)->value(); |
| 157 if (value >= 0 && value <= std::numeric_limits<size_t>::max()) { | 157 if (value >= 0 && value <= std::numeric_limits<size_t>::max()) { |
| 158 *result = static_cast<size_t>(value); | 158 *result = static_cast<size_t>(value); |
| 159 return true; | 159 return true; |
| 160 } else { | 160 } else { |
| 161 return false; | 161 return false; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 size_t NumberToSize(Object* number) { |
| 167 size_t NumberToSize(Isolate* isolate, Object* number) { | |
| 168 size_t result = 0; | 167 size_t result = 0; |
| 169 bool is_valid = TryNumberToSize(isolate, number, &result); | 168 bool is_valid = TryNumberToSize(number, &result); |
| 170 CHECK(is_valid); | 169 CHECK(is_valid); |
| 171 return result; | 170 return result; |
| 172 } | 171 } |
| 173 | 172 |
| 174 | 173 |
| 175 uint32_t DoubleToUint32(double x) { | 174 uint32_t DoubleToUint32(double x) { |
| 176 return static_cast<uint32_t>(DoubleToInt32(x)); | 175 return static_cast<uint32_t>(DoubleToInt32(x)); |
| 177 } | 176 } |
| 178 | 177 |
| 179 | 178 |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 buffer[buffer_pos] = '\0'; | 765 buffer[buffer_pos] = '\0'; |
| 767 | 766 |
| 768 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 767 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
| 769 return (sign == NEGATIVE) ? -converted : converted; | 768 return (sign == NEGATIVE) ? -converted : converted; |
| 770 } | 769 } |
| 771 | 770 |
| 772 } // namespace internal | 771 } // namespace internal |
| 773 } // namespace v8 | 772 } // namespace v8 |
| 774 | 773 |
| 775 #endif // V8_CONVERSIONS_INL_H_ | 774 #endif // V8_CONVERSIONS_INL_H_ |
| OLD | NEW |