| Index: src/utils.h
|
| diff --git a/src/utils.h b/src/utils.h
|
| index 8f07ab3f2b520c325be4397d4ff9e6cae66ce0a6..898553a61b7a9ac1a35361b0d81b0e791cd9eb97 100644
|
| --- a/src/utils.h
|
| +++ b/src/utils.h
|
| @@ -1553,6 +1553,36 @@ class StringBuilder : public SimpleStringBuilder {
|
| };
|
|
|
|
|
| +bool DoubleToBoolean(double d);
|
| +
|
| +template <typename Stream>
|
| +bool StringToArrayIndex(Stream* stream, uint32_t* index) {
|
| + uint16_t ch = stream->GetNext();
|
| +
|
| + // If the string begins with a '0' character, it must only consist
|
| + // of it to be a legal array index.
|
| + if (ch == '0') {
|
| + *index = 0;
|
| + return !stream->HasMore();
|
| + }
|
| +
|
| + // Convert string to uint32 array index; character by character.
|
| + int d = ch - '0';
|
| + if (d < 0 || d > 9) return false;
|
| + uint32_t result = d;
|
| + while (stream->HasMore()) {
|
| + d = stream->GetNext() - '0';
|
| + if (d < 0 || d > 9) return false;
|
| + // Check that the new result is below the 32 bit limit.
|
| + if (result > 429496729U - ((d > 5) ? 1 : 0)) return false;
|
| + result = (result * 10) + d;
|
| + }
|
| +
|
| + *index = result;
|
| + return true;
|
| +}
|
| +
|
| +
|
| } } // namespace v8::internal
|
|
|
| #endif // V8_UTILS_H_
|
|
|