OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <math.h> | 5 #include <math.h> |
6 | 6 |
7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
8 | 8 |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/code_generator.h" // DartModulo. | 10 #include "vm/code_generator.h" // DartModulo. |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 const char* tmp = cstr; | 214 const char* tmp = cstr; |
215 while (*tmp != '\0') { | 215 while (*tmp != '\0') { |
216 const char ch = *tmp++; | 216 const char ch = *tmp++; |
217 if (ch == '.') { | 217 if (ch == '.') { |
218 const char nextCh = *tmp; | 218 const char nextCh = *tmp; |
219 dot_ok = ('0' <= nextCh) && (nextCh <= '9'); | 219 dot_ok = ('0' <= nextCh) && (nextCh <= '9'); |
220 break; | 220 break; |
221 } | 221 } |
222 } | 222 } |
223 if (dot_ok) { | 223 if (dot_ok) { |
224 char* p_end = NULL; | 224 double double_value; |
225 const double double_value = strtod(cstr, &p_end); | 225 if (CStringToDouble(cstr, len, &double_value)) { |
226 if (p_end == (cstr + len)) { | |
227 return Double::New(double_value); | 226 return Double::New(double_value); |
228 } | 227 } |
229 } | 228 } |
230 } | 229 } |
231 } | 230 } |
232 } | 231 } |
233 Scanner scanner(value, Symbols::Empty()); | 232 Scanner scanner(value, Symbols::Empty()); |
234 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); | 233 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); |
235 String* number_string; | 234 String* number_string; |
236 bool is_positive; | 235 bool is_positive; |
237 if (Scanner::IsValidLiteral(tokens, | 236 if (Scanner::IsValidLiteral(tokens, |
238 Token::kDOUBLE, | 237 Token::kDOUBLE, |
239 &is_positive, | 238 &is_positive, |
240 &number_string)) { | 239 &number_string)) { |
240 ASSERT(number_string->IsOneByteString()); | |
Ivan Posva
2013/04/05 21:56:42
Please explain here why you are allowed to make th
Vyacheslav Egorov (Google)
2013/04/08 14:25:04
Done.
| |
241 const char* cstr = number_string->ToCString(); | 241 const char* cstr = number_string->ToCString(); |
242 char* p_end = NULL; | 242 |
243 double double_value = strtod(cstr, &p_end); | 243 double double_value; |
244 ASSERT(p_end != cstr); | 244 bool ok = CStringToDouble(cstr, number_string->Length(), &double_value); |
245 USE(ok); | |
Ivan Posva
2013/04/05 21:56:42
I would have thought USE is not necessary here.
Vyacheslav Egorov (Google)
2013/04/08 14:25:04
Done.
| |
246 ASSERT(ok); | |
247 | |
245 if (!is_positive) { | 248 if (!is_positive) { |
246 double_value = -double_value; | 249 double_value = -double_value; |
247 } | 250 } |
248 return Double::New(double_value); | 251 return Double::New(double_value); |
249 } | 252 } |
250 | 253 |
251 if (Scanner::IsValidLiteral(tokens, | 254 if (Scanner::IsValidLiteral(tokens, |
252 Token::kINTEGER, | 255 Token::kINTEGER, |
253 &is_positive, | 256 &is_positive, |
254 &number_string)) { | 257 &number_string)) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 | 356 |
354 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { | 357 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
355 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 358 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
356 // Include negative zero, infinity. | 359 // Include negative zero, infinity. |
357 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 360 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); |
358 } | 361 } |
359 | 362 |
360 // Add here only functions using/referring to old-style casts. | 363 // Add here only functions using/referring to old-style casts. |
361 | 364 |
362 } // namespace dart | 365 } // namespace dart |
OLD | NEW |