| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (number->IsSmi()) return Smi::cast(number)->value(); | 120 if (number->IsSmi()) return Smi::cast(number)->value(); |
| 121 return DoubleToInt32(number->Number()); | 121 return DoubleToInt32(number->Number()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 | 124 |
| 125 uint32_t NumberToUint32(Object* number) { | 125 uint32_t NumberToUint32(Object* number) { |
| 126 if (number->IsSmi()) return Smi::cast(number)->value(); | 126 if (number->IsSmi()) return Smi::cast(number)->value(); |
| 127 return DoubleToUint32(number->Number()); | 127 return DoubleToUint32(number->Number()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 int64_t NumberToInt64(Object* number) { | |
| 131 if (number->IsSmi()) return Smi::cast(number)->value(); | |
| 132 return static_cast<int64_t>(number->Number()); | |
| 133 } | |
| 134 | 130 |
| 135 bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result) { | 131 bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result) { |
| 136 SealHandleScope shs(isolate); | 132 SealHandleScope shs(isolate); |
| 137 if (number->IsSmi()) { | 133 if (number->IsSmi()) { |
| 138 int value = Smi::cast(number)->value(); | 134 int value = Smi::cast(number)->value(); |
| 139 DCHECK(static_cast<unsigned>(Smi::kMaxValue) <= | 135 DCHECK(static_cast<unsigned>(Smi::kMaxValue) <= |
| 140 std::numeric_limits<size_t>::max()); | 136 std::numeric_limits<size_t>::max()); |
| 141 if (value >= 0) { | 137 if (value >= 0) { |
| 142 *result = static_cast<size_t>(value); | 138 *result = static_cast<size_t>(value); |
| 143 return true; | 139 return true; |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 buffer[buffer_pos] = '\0'; | 754 buffer[buffer_pos] = '\0'; |
| 759 | 755 |
| 760 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 756 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
| 761 return (sign == NEGATIVE) ? -converted : converted; | 757 return (sign == NEGATIVE) ? -converted : converted; |
| 762 } | 758 } |
| 763 | 759 |
| 764 } // namespace internal | 760 } // namespace internal |
| 765 } // namespace v8 | 761 } // namespace v8 |
| 766 | 762 |
| 767 #endif // V8_CONVERSIONS_INL_H_ | 763 #endif // V8_CONVERSIONS_INL_H_ |
| OLD | NEW |