diff --git a/src/jsrs_parser.cc b/src/jsrs_parser.cc index 476fcf9..245591a 100644 --- a/src/jsrs_parser.cc +++ b/src/jsrs_parser.cc @@ -299,11 +299,8 @@ MaybeLocal ParseNumber(Isolate* isolate, const char* end, size_t* size) { bool negate_result = false; - bool is_noctal = false; const char* number_start = begin; - MaybeLocal result; - if (*begin == '+' || *begin == '-') { negate_result = *begin == '-'; number_start++; @@ -324,25 +321,25 @@ MaybeLocal ParseNumber(Isolate* isolate, base = 16; number_start++; } else if (isdigit(*number_start)) { - is_noctal = true; - result = ParseNoctalNumber(isolate, number_start, end, size, - negate_result); + THROW_EXCEPTION(SyntaxError, + "Legacy octal and non-octal integer literals are not supported"); + return MaybeLocal(); } else { number_start--; } } - if (!is_noctal) { - if (base == 10) { - result = ParseDecimalNumber(isolate, number_start, end, size, - negate_result); - } else { - result = ParseIntegerNumber(isolate, number_start, end, size, - base, negate_result); - if (*size == 0) { - THROW_EXCEPTION(SyntaxError, "Empty number value"); - return MaybeLocal(); - } + MaybeLocal result; + + if (base == 10) { + result = ParseDecimalNumber(isolate, number_start, end, size, + negate_result); + } else { + result = ParseIntegerNumber(isolate, number_start, end, size, + base, negate_result); + if (*size == 0) { + THROW_EXCEPTION(SyntaxError, "Empty number value"); + return MaybeLocal(); } } *size += number_start - begin; @@ -429,55 +426,6 @@ Local ParseBigIntegerNumber(Isolate* isolate, return Number::New(isolate, negate_result ? -result : result); } -MaybeLocal ParseNoctalNumber(Isolate* isolate, - const char* begin, - const char* end, - size_t* size, - bool negate_result) { - *size = end - begin; - bool is_octal = true; - int64_t result = 0; - bool int32_overflow = false; - double overflow_result = 0.0; - char current_digit; - - for (size_t i = 0; i < *size; i++) { - if (!isdigit(begin[i])) { - *size = i; - break; - } - - current_digit = begin[i] - '0'; - if (current_digit > 7) { - is_octal = false; - } - - if (!int32_overflow) { - result *= 10; - result += current_digit; - } else { - overflow_result *= 10.0; - overflow_result += current_digit; - } - - if (!int32_overflow && (result < INT32_MIN || INT32_MAX < result)) { - int32_overflow = true; - overflow_result = result; - } - } - - if (is_octal) { - THROW_EXCEPTION(SyntaxError, "Use new octal literal syntax"); - return MaybeLocal(); - } - - if (!int32_overflow) { - return Integer::New(isolate, negate_result ? -result : result); - } else { - return Number::New(isolate, negate_result ? -overflow_result : overflow_result); - } -} - static bool GetControlChar(Isolate* isolate, const char* str, size_t* res_len, @@ -669,7 +617,22 @@ static bool GetControlChar(Isolate* isolate, break; } + case '0': { + if (isdigit(str[1])) { + THROW_EXCEPTION(SyntaxError, + "Decimal digits after \\0 are not allowed in strings"); + return false; + } + *write_to = 0; + break; + } + default: { + if ('0' <= str[0] && str[0] <= '7') { + THROW_EXCEPTION(SyntaxError, + "Octal escape sequences are not allowed in strings"); + return false; + } *write_to = str[0]; } } diff --git a/src/jsrs_parser.h b/src/jsrs_parser.h index e0c0f34..502358d 100644 --- a/src/jsrs_parser.h +++ b/src/jsrs_parser.h @@ -127,14 +127,6 @@ v8::Local ParseBigIntegerNumber(v8::Isolate* isolate, int base, bool negate_result); -// Parses a noctal integer number. -v8::MaybeLocal ParseNoctalNumber(v8::Isolate* isolate, - const char* begin, - const char* end, - std::size_t* size, - bool negate_result); - - } // namespace internal } // namespace parser diff --git a/test/todo/json5.js b/test/todo/json5.js index fbb38be..f7cebee 100644 --- a/test/todo/json5.js +++ b/test/todo/json5.js @@ -9,12 +9,6 @@ const supportedByUs = { arrays: [ 'leading-comma-array', 'lone-trailing-comma-array' - ], - numbers: [ - 'negative-noctal', - 'noctal-with-leading-octal-digit', - 'noctal', - 'positive-noctal' ] };