| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
| 6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
| 7 | 7 |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 } | 1683 } |
| 1684 | 1684 |
| 1685 // Convert string to uint32 array index; character by character. | 1685 // Convert string to uint32 array index; character by character. |
| 1686 int d = ch - '0'; | 1686 int d = ch - '0'; |
| 1687 if (d < 0 || d > 9) return false; | 1687 if (d < 0 || d > 9) return false; |
| 1688 uint32_t result = d; | 1688 uint32_t result = d; |
| 1689 while (stream->HasMore()) { | 1689 while (stream->HasMore()) { |
| 1690 d = stream->GetNext() - '0'; | 1690 d = stream->GetNext() - '0'; |
| 1691 if (d < 0 || d > 9) return false; | 1691 if (d < 0 || d > 9) return false; |
| 1692 // Check that the new result is below the 32 bit limit. | 1692 // Check that the new result is below the 32 bit limit. |
| 1693 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false; | 1693 if (result > 429496729U - ((d + 3) >> 3)) return false; |
| 1694 result = (result * 10) + d; | 1694 result = (result * 10) + d; |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 *index = result; | 1697 *index = result; |
| 1698 return true; | 1698 return true; |
| 1699 } | 1699 } |
| 1700 | 1700 |
| 1701 | 1701 |
| 1702 // Returns current value of top of the stack. Works correctly with ASAN. | 1702 // Returns current value of top of the stack. Works correctly with ASAN. |
| 1703 DISABLE_ASAN | 1703 DISABLE_ASAN |
| 1704 inline uintptr_t GetCurrentStackPosition() { | 1704 inline uintptr_t GetCurrentStackPosition() { |
| 1705 // Takes the address of the limit variable in order to find out where | 1705 // Takes the address of the limit variable in order to find out where |
| 1706 // the top of stack is right now. | 1706 // the top of stack is right now. |
| 1707 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); | 1707 uintptr_t limit = reinterpret_cast<uintptr_t>(&limit); |
| 1708 return limit; | 1708 return limit; |
| 1709 } | 1709 } |
| 1710 | 1710 |
| 1711 } // namespace internal | 1711 } // namespace internal |
| 1712 } // namespace v8 | 1712 } // namespace v8 |
| 1713 | 1713 |
| 1714 #endif // V8_UTILS_H_ | 1714 #endif // V8_UTILS_H_ |
| OLD | NEW |