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> |
11 | 11 |
12 #include "allocation.h" | 12 #include "allocation.h" |
13 #include "checks.h" | 13 #include "checks.h" |
| 14 #include "list.h" |
14 #include "globals.h" | 15 #include "globals.h" |
15 #include "platform.h" | 16 #include "platform.h" |
16 #include "vector.h" | 17 #include "vector.h" |
17 | 18 |
18 namespace v8 { | 19 namespace v8 { |
19 namespace internal { | 20 namespace internal { |
20 | 21 |
21 // ---------------------------------------------------------------------------- | 22 // ---------------------------------------------------------------------------- |
22 // General helper functions | 23 // General helper functions |
23 | 24 |
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 // Add formatted contents to the builder just like printf(). | 1545 // Add formatted contents to the builder just like printf(). |
1545 void AddFormatted(const char* format, ...); | 1546 void AddFormatted(const char* format, ...); |
1546 | 1547 |
1547 // Add formatted contents like printf based on a va_list. | 1548 // Add formatted contents like printf based on a va_list. |
1548 void AddFormattedList(const char* format, va_list list); | 1549 void AddFormattedList(const char* format, va_list list); |
1549 private: | 1550 private: |
1550 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 1551 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
1551 }; | 1552 }; |
1552 | 1553 |
1553 | 1554 |
| 1555 bool DoubleToBoolean(double d); |
| 1556 |
| 1557 template <typename Stream> |
| 1558 bool StringToArrayIndex(Stream* stream, uint32_t* index) { |
| 1559 uint16_t ch = stream->GetNext(); |
| 1560 |
| 1561 // If the string begins with a '0' character, it must only consist |
| 1562 // of it to be a legal array index. |
| 1563 if (ch == '0') { |
| 1564 *index = 0; |
| 1565 return !stream->HasMore(); |
| 1566 } |
| 1567 |
| 1568 // Convert string to uint32 array index; character by character. |
| 1569 int d = ch - '0'; |
| 1570 if (d < 0 || d > 9) return false; |
| 1571 uint32_t result = d; |
| 1572 while (stream->HasMore()) { |
| 1573 d = stream->GetNext() - '0'; |
| 1574 if (d < 0 || d > 9) return false; |
| 1575 // Check that the new result is below the 32 bit limit. |
| 1576 if (result > 429496729U - ((d > 5) ? 1 : 0)) return false; |
| 1577 result = (result * 10) + d; |
| 1578 } |
| 1579 |
| 1580 *index = result; |
| 1581 return true; |
| 1582 } |
| 1583 |
| 1584 |
1554 } } // namespace v8::internal | 1585 } } // namespace v8::internal |
1555 | 1586 |
1556 #endif // V8_UTILS_H_ | 1587 #endif // V8_UTILS_H_ |
OLD | NEW |