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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 // This function should match the exact semantics of ECMA-262 9.4. | 83 // This function should match the exact semantics of ECMA-262 9.4. |
84 inline double DoubleToInteger(double x); | 84 inline double DoubleToInteger(double x); |
85 | 85 |
86 | 86 |
87 // This function should match the exact semantics of ECMA-262 9.5. | 87 // This function should match the exact semantics of ECMA-262 9.5. |
88 inline int32_t DoubleToInt32(double x); | 88 inline int32_t DoubleToInt32(double x); |
89 | 89 |
90 | 90 |
91 // This function should match the exact semantics of ECMA-262 9.6. | 91 // This function should match the exact semantics of ECMA-262 9.6. |
92 inline uint32_t DoubleToUint32(double x) { | 92 inline uint32_t DoubleToUint32(double x); |
93 return static_cast<uint32_t>(DoubleToInt32(x)); | |
94 } | |
95 | 93 |
96 | 94 |
97 // Enumeration for allowing octals and ignoring junk when converting | 95 // Enumeration for allowing octals and ignoring junk when converting |
98 // strings to numbers. | 96 // strings to numbers. |
99 enum ConversionFlags { | 97 enum ConversionFlags { |
100 NO_FLAGS = 0, | 98 NO_FLAGS = 0, |
101 ALLOW_HEX = 1, | 99 ALLOW_HEX = 1, |
102 ALLOW_OCTAL = 2, | 100 ALLOW_OCTAL = 2, |
103 ALLOW_IMPLICIT_OCTAL = 4, | 101 ALLOW_IMPLICIT_OCTAL = 4, |
104 ALLOW_BINARY = 8, | 102 ALLOW_BINARY = 8, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 char* DoubleToPrecisionCString(double value, int f); | 147 char* DoubleToPrecisionCString(double value, int f); |
150 char* DoubleToRadixCString(double value, int radix); | 148 char* DoubleToRadixCString(double value, int radix); |
151 | 149 |
152 | 150 |
153 static inline bool IsMinusZero(double value) { | 151 static inline bool IsMinusZero(double value) { |
154 static const DoubleRepresentation minus_zero(-0.0); | 152 static const DoubleRepresentation minus_zero(-0.0); |
155 return DoubleRepresentation(value) == minus_zero; | 153 return DoubleRepresentation(value) == minus_zero; |
156 } | 154 } |
157 | 155 |
158 | 156 |
159 static inline bool IsSmiDouble(double value); | 157 inline bool IsSmiDouble(double value); |
160 | 158 |
161 | 159 |
162 // 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 |
163 // 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]. |
164 // 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. |
165 static inline bool IsInt32Double(double value); | 163 inline bool IsInt32Double(double value); |
166 | 164 |
167 | 165 |
168 // UInteger32 is an integer that can be represented as an unsigned 32-bit | 166 // UInteger32 is an integer that can be represented as an unsigned 32-bit |
169 // integer. It has to be in the range [0, 2^32 - 1]. | 167 // integer. It has to be in the range [0, 2^32 - 1]. |
170 // We also have to check for negative 0 as it is not a UInteger32. | 168 // We also have to check for negative 0 as it is not a UInteger32. |
171 static inline bool IsUint32Double(double value); | 169 inline bool IsUint32Double(double value); |
172 | 170 |
173 | 171 |
174 // Convert from Number object to C integer. | 172 // Convert from Number object to C integer. |
175 inline int32_t NumberToInt32(Object* number); | 173 inline int32_t NumberToInt32(Object* number); |
176 inline uint32_t NumberToUint32(Object* number); | 174 inline uint32_t NumberToUint32(Object* number); |
177 | 175 |
178 | 176 |
179 double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string, | 177 double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string, |
180 int flags, double empty_string_val = 0.0); | 178 int flags, double empty_string_val = 0.0); |
181 | 179 |
182 | 180 |
183 inline bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result); | 181 inline bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result); |
184 | 182 |
185 | 183 |
186 // Converts a number into size_t. | 184 // Converts a number into size_t. |
187 inline size_t NumberToSize(Isolate* isolate, Object* number); | 185 inline size_t NumberToSize(Isolate* isolate, Object* number); |
188 | 186 |
189 | 187 |
190 // returns DoubleToString(StringToDouble(string)) == string | 188 // returns DoubleToString(StringToDouble(string)) == string |
191 bool IsSpecialIndex(UnicodeCache* unicode_cache, String* string); | 189 bool IsSpecialIndex(UnicodeCache* unicode_cache, String* string); |
192 | 190 |
193 } // namespace internal | 191 } // namespace internal |
194 } // namespace v8 | 192 } // namespace v8 |
195 | 193 |
196 #endif // V8_CONVERSIONS_H_ | 194 #endif // V8_CONVERSIONS_H_ |
OLD | NEW |