| 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() |
| 9 #include <limits.h> // Required for INT_MAX etc. |
| 10 #include <stdarg.h> |
| 8 #include <cmath> | 11 #include <cmath> |
| 9 #include <cstdarg> | 12 #include "src/globals.h" // Required for V8_INFINITY |
| 10 #include <limits> | |
| 11 | 13 |
| 12 // ---------------------------------------------------------------------------- | 14 // ---------------------------------------------------------------------------- |
| 13 // Extra POSIX/ANSI functions for Win32/MSVC. | 15 // Extra POSIX/ANSI functions for Win32/MSVC. |
| 14 | 16 |
| 15 #include "src/base/bits.h" | 17 #include "src/base/bits.h" |
| 16 #include "src/base/platform/platform.h" | 18 #include "src/base/platform/platform.h" |
| 17 #include "src/conversions.h" | 19 #include "src/conversions.h" |
| 18 #include "src/double.h" | 20 #include "src/double.h" |
| 19 #include "src/scanner.h" | 21 #include "src/scanner.h" |
| 20 #include "src/strtod.h" | 22 #include "src/strtod.h" |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 if (!SubStringEquals(¤t, end, kInfinityString)) { | 476 if (!SubStringEquals(¤t, end, kInfinityString)) { |
| 475 return JunkStringValue(); | 477 return JunkStringValue(); |
| 476 } | 478 } |
| 477 | 479 |
| 478 if (!allow_trailing_junk && | 480 if (!allow_trailing_junk && |
| 479 AdvanceToNonspace(unicode_cache, ¤t, end)) { | 481 AdvanceToNonspace(unicode_cache, ¤t, end)) { |
| 480 return JunkStringValue(); | 482 return JunkStringValue(); |
| 481 } | 483 } |
| 482 | 484 |
| 483 DCHECK(buffer_pos == 0); | 485 DCHECK(buffer_pos == 0); |
| 484 return (sign == NEGATIVE) ? -std::numeric_limits<double>::infinity() | 486 return (sign == NEGATIVE) ? -V8_INFINITY : V8_INFINITY; |
| 485 : std::numeric_limits<double>::infinity(); | |
| 486 } | 487 } |
| 487 | 488 |
| 488 bool leading_zero = false; | 489 bool leading_zero = false; |
| 489 if (*current == '0') { | 490 if (*current == '0') { |
| 490 ++current; | 491 ++current; |
| 491 if (current == end) return SignedZero(sign == NEGATIVE); | 492 if (current == end) return SignedZero(sign == NEGATIVE); |
| 492 | 493 |
| 493 leading_zero = true; | 494 leading_zero = true; |
| 494 | 495 |
| 495 // It could be hexadecimal value. | 496 // It could be hexadecimal value. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 } | 636 } |
| 636 | 637 |
| 637 if (current == end || *current < '0' || *current > '9') { | 638 if (current == end || *current < '0' || *current > '9') { |
| 638 if (allow_trailing_junk) { | 639 if (allow_trailing_junk) { |
| 639 goto parsing_done; | 640 goto parsing_done; |
| 640 } else { | 641 } else { |
| 641 return JunkStringValue(); | 642 return JunkStringValue(); |
| 642 } | 643 } |
| 643 } | 644 } |
| 644 | 645 |
| 645 const int max_exponent = std::numeric_limits<int>::max() / 2; | 646 const int max_exponent = INT_MAX / 2; |
| 646 DCHECK(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2); | 647 DCHECK(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2); |
| 647 int num = 0; | 648 int num = 0; |
| 648 do { | 649 do { |
| 649 // Check overflow. | 650 // Check overflow. |
| 650 int digit = *current - '0'; | 651 int digit = *current - '0'; |
| 651 if (num >= max_exponent / 10 | 652 if (num >= max_exponent / 10 |
| 652 && !(num == max_exponent / 10 && digit <= max_exponent % 10)) { | 653 && !(num == max_exponent / 10 && digit <= max_exponent % 10)) { |
| 653 num = max_exponent; | 654 num = max_exponent; |
| 654 } else { | 655 } else { |
| 655 num = num * 10 + digit; | 656 num = num * 10 + digit; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 684 SLOW_DCHECK(buffer_pos < kBufferSize); | 685 SLOW_DCHECK(buffer_pos < kBufferSize); |
| 685 buffer[buffer_pos] = '\0'; | 686 buffer[buffer_pos] = '\0'; |
| 686 | 687 |
| 687 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 688 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
| 688 return (sign == NEGATIVE) ? -converted : converted; | 689 return (sign == NEGATIVE) ? -converted : converted; |
| 689 } | 690 } |
| 690 | 691 |
| 691 } } // namespace v8::internal | 692 } } // namespace v8::internal |
| 692 | 693 |
| 693 #endif // V8_CONVERSIONS_INL_H_ | 694 #endif // V8_CONVERSIONS_INL_H_ |
| OLD | NEW |