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_H_ | 5 #ifndef V8_CONVERSIONS_H_ |
6 #define V8_CONVERSIONS_H_ | 6 #define V8_CONVERSIONS_H_ |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "src/base/logging.h" | 10 #include "src/base/logging.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // located inside the buffer, but not necessarily at the start. | 140 // located inside the buffer, but not necessarily at the start. |
141 const char* IntToCString(int n, Vector<char> buffer); | 141 const char* IntToCString(int n, Vector<char> buffer); |
142 | 142 |
143 // Additional number to string conversions for the number type. | 143 // Additional number to string conversions for the number type. |
144 // The caller is responsible for calling free on the returned pointer. | 144 // The caller is responsible for calling free on the returned pointer. |
145 char* DoubleToFixedCString(double value, int f); | 145 char* DoubleToFixedCString(double value, int f); |
146 char* DoubleToExponentialCString(double value, int f); | 146 char* DoubleToExponentialCString(double value, int f); |
147 char* DoubleToPrecisionCString(double value, int f); | 147 char* DoubleToPrecisionCString(double value, int f); |
148 char* DoubleToRadixCString(double value, int radix); | 148 char* DoubleToRadixCString(double value, int radix); |
149 | 149 |
150 | |
151 static inline bool IsMinusZero(double value) { | 150 static inline bool IsMinusZero(double value) { |
152 return bit_cast<int64_t>(value) == bit_cast<int64_t>(-0.0); | 151 return bit_cast<int64_t>(value) == bit_cast<int64_t>(-0.0); |
153 } | 152 } |
154 | 153 |
| 154 // Returns true if value can be converted to a SMI, and returns the resulting |
| 155 // integer value of the SMI in |smi_int_value|. |
| 156 inline bool DoubleToSmiInteger(double value, int* smi_int_value); |
155 | 157 |
156 inline bool IsSmiDouble(double value); | 158 inline bool IsSmiDouble(double value); |
157 | 159 |
158 | |
159 // Integer32 is an integer that can be represented as a signed 32-bit | 160 // Integer32 is an integer that can be represented as a signed 32-bit |
160 // integer. It has to be in the range [-2^31, 2^31 - 1]. | 161 // integer. It has to be in the range [-2^31, 2^31 - 1]. |
161 // We also have to check for negative 0 as it is not an Integer32. | 162 // We also have to check for negative 0 as it is not an Integer32. |
162 inline bool IsInt32Double(double value); | 163 inline bool IsInt32Double(double value); |
163 | 164 |
164 | |
165 // UInteger32 is an integer that can be represented as an unsigned 32-bit | 165 // UInteger32 is an integer that can be represented as an unsigned 32-bit |
166 // integer. It has to be in the range [0, 2^32 - 1]. | 166 // integer. It has to be in the range [0, 2^32 - 1]. |
167 // We also have to check for negative 0 as it is not a UInteger32. | 167 // We also have to check for negative 0 as it is not a UInteger32. |
168 inline bool IsUint32Double(double value); | 168 inline bool IsUint32Double(double value); |
169 | 169 |
170 | |
171 // Convert from Number object to C integer. | 170 // Convert from Number object to C integer. |
172 inline int32_t NumberToInt32(Object* number); | 171 inline int32_t NumberToInt32(Object* number); |
173 inline uint32_t NumberToUint32(Object* number); | 172 inline uint32_t NumberToUint32(Object* number); |
174 inline int64_t NumberToInt64(Object* number); | 173 inline int64_t NumberToInt64(Object* number); |
175 | 174 |
176 double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string, | 175 double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string, |
177 int flags, double empty_string_val = 0.0); | 176 int flags, double empty_string_val = 0.0); |
178 | 177 |
179 | 178 |
180 inline bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result); | 179 inline bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result); |
181 | 180 |
182 | 181 |
183 // Converts a number into size_t. | 182 // Converts a number into size_t. |
184 inline size_t NumberToSize(Isolate* isolate, Object* number); | 183 inline size_t NumberToSize(Isolate* isolate, Object* number); |
185 | 184 |
186 | 185 |
187 // returns DoubleToString(StringToDouble(string)) == string | 186 // returns DoubleToString(StringToDouble(string)) == string |
188 bool IsSpecialIndex(UnicodeCache* unicode_cache, String* string); | 187 bool IsSpecialIndex(UnicodeCache* unicode_cache, String* string); |
189 | 188 |
190 } // namespace internal | 189 } // namespace internal |
191 } // namespace v8 | 190 } // namespace v8 |
192 | 191 |
193 #endif // V8_CONVERSIONS_H_ | 192 #endif // V8_CONVERSIONS_H_ |
OLD | NEW |