Chromium Code Reviews| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 #endif | 193 #endif |
| 194 | 194 |
| 195 DEFINE_NATIVE_ENTRY(Double_toInt, 1) { | 195 DEFINE_NATIVE_ENTRY(Double_toInt, 1) { |
| 196 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 196 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
| 197 return DoubleToInteger(arg.value(), "Infinity or NaN toInt"); | 197 return DoubleToInteger(arg.value(), "Infinity or NaN toInt"); |
| 198 } | 198 } |
| 199 | 199 |
| 200 | 200 |
| 201 DEFINE_NATIVE_ENTRY(Double_parse, 1) { | 201 DEFINE_NATIVE_ENTRY(Double_parse, 1) { |
| 202 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); | 202 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); |
| 203 if (value.IsOneByteString()) { | |
| 204 // Quick conversion for unpadded doubles in strings. | |
| 205 const intptr_t len = value.Length(); | |
| 206 if (len > 0) { | |
| 207 char* p_end = NULL; | |
|
siva
2013/02/22 21:47:09
Can this local declaration be moved down under
if
srdjan
2013/02/22 22:27:37
Done.
| |
| 208 const char* cstr = value.ToCString(); | |
|
siva
2013/02/22 21:47:09
ASSERT(cstr != NULL);
srdjan
2013/02/22 22:27:37
Done.
| |
| 209 // Dart differences from strtod: | |
| 210 // a) '5.' is not a valid double (no digit after period). | |
| 211 // b) '+5.0' is not a valid double (leading plus). | |
| 212 if (cstr[0] != '+') { | |
| 213 bool dot_ok = true; | |
| 214 const char* tmp = cstr; | |
| 215 while (*tmp != '\0') { | |
| 216 const char ch = *tmp++; | |
| 217 if (ch == '.') { | |
| 218 const char nextCh = *tmp; | |
| 219 dot_ok = ('0' <= nextCh) && (nextCh <= '9'); | |
| 220 break; | |
| 221 } | |
| 222 } | |
| 223 if (dot_ok) { | |
| 224 const double double_value = strtod(cstr, &p_end); | |
| 225 if (p_end == (cstr + len)) { | |
| 226 return Double::New(double_value); | |
| 227 } | |
| 228 } | |
| 229 } | |
| 230 } | |
| 231 } | |
| 203 Scanner scanner(value, Symbols::Empty()); | 232 Scanner scanner(value, Symbols::Empty()); |
| 204 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); | 233 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); |
| 205 String* number_string; | 234 String* number_string; |
| 206 bool is_positive; | 235 bool is_positive; |
| 207 if (Scanner::IsValidLiteral(tokens, | 236 if (Scanner::IsValidLiteral(tokens, |
| 208 Token::kDOUBLE, | 237 Token::kDOUBLE, |
| 209 &is_positive, | 238 &is_positive, |
| 210 &number_string)) { | 239 &number_string)) { |
| 211 const char* cstr = number_string->ToCString(); | 240 const char* cstr = number_string->ToCString(); |
| 212 char* p_end = NULL; | 241 char* p_end = NULL; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 | 352 |
| 324 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { | 353 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
| 325 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 354 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
| 326 // Include negative zero, infinity. | 355 // Include negative zero, infinity. |
| 327 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 356 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); |
| 328 } | 357 } |
| 329 | 358 |
| 330 // Add here only functions using/referring to old-style casts. | 359 // Add here only functions using/referring to old-style casts. |
| 331 | 360 |
| 332 } // namespace dart | 361 } // namespace dart |
| OLD | NEW |