Commit 9c983910 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[numeric separator] Ban implicit octal support

Bug: v8:7317
Change-Id: I20fb706c05852668a5a6ae8b69c150ae2e6b2f65
Reviewed-on: https://chromium-review.googlesource.com/960901Reviewed-by: 's avatarMathias Bynens <mathias@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51943}
parent 0b67384a
...@@ -555,6 +555,8 @@ class ErrorUtils : public AllStatic { ...@@ -555,6 +555,8 @@ class ErrorUtils : public AllStatic {
T(LetInLexicalBinding, "let is disallowed as a lexically bound name") \ T(LetInLexicalBinding, "let is disallowed as a lexically bound name") \
T(LocaleMatcher, "Illegal value for localeMatcher:%") \ T(LocaleMatcher, "Illegal value for localeMatcher:%") \
T(NormalizationForm, "The normalization form should be one of %.") \ T(NormalizationForm, "The normalization form should be one of %.") \
T(ZeroDigitNumericSeparator, \
"Numeric separator can not be used after leading 0.") \
T(NumberFormatRange, "% argument must be between 0 and 100") \ T(NumberFormatRange, "% argument must be between 0 and 100") \
T(TrailingNumericSeparator, \ T(TrailingNumericSeparator, \
"Numeric separators are not allowed at the end of numeric literals") \ "Numeric separators are not allowed at the end of numeric literals") \
......
...@@ -1342,49 +1342,10 @@ bool Scanner::ScanOctalDigits(int start_pos) { ...@@ -1342,49 +1342,10 @@ bool Scanner::ScanOctalDigits(int start_pos) {
return true; return true;
} }
bool Scanner::ScanImplicitOctalDigitsWithNumericSeparators(
int start_pos, Scanner::NumberKind* kind) {
bool separator_seen = false;
while (true) {
if (c0_ == '_') {
Advance<false, false>();
if (c0_ == '_') {
ReportScannerError(Location(start_pos, source_pos()),
MessageTemplate::kContinuousNumericSeparator);
return false;
}
separator_seen = true;
continue;
}
if (c0_ == '8' || c0_ == '9') {
*kind = DECIMAL_WITH_LEADING_ZERO;
return true;
}
if (c0_ < '0' || '7' < c0_) {
// Octal literal finished.
octal_pos_ = Location(start_pos, source_pos());
octal_message_ = MessageTemplate::kStrictOctalLiteral;
if (separator_seen) {
ReportScannerError(Location(start_pos, source_pos()),
MessageTemplate::kTrailingNumericSeparator);
return false;
}
return true;
}
separator_seen = false;
AddLiteralCharAdvance();
}
}
bool Scanner::ScanImplicitOctalDigits(int start_pos, bool Scanner::ScanImplicitOctalDigits(int start_pos,
Scanner::NumberKind* kind) { Scanner::NumberKind* kind) {
*kind = IMPLICIT_OCTAL; *kind = IMPLICIT_OCTAL;
if (allow_harmony_numeric_separator()) {
return ScanImplicitOctalDigitsWithNumericSeparators(start_pos, kind);
}
while (true) { while (true) {
// (possible) octal number // (possible) octal number
if (c0_ == '8' || c0_ == '9') { if (c0_ == '8' || c0_ == '9') {
...@@ -1469,6 +1430,10 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -1469,6 +1430,10 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
} }
} else if (c0_ == '8' || c0_ == '9') { } else if (c0_ == '8' || c0_ == '9') {
kind = DECIMAL_WITH_LEADING_ZERO; kind = DECIMAL_WITH_LEADING_ZERO;
} else if (allow_harmony_numeric_separator() && c0_ == '_') {
ReportScannerError(Location(source_pos(), source_pos() + 1),
MessageTemplate::kZeroDigitNumericSeparator);
return Token::ILLEGAL;
} }
} }
......
...@@ -747,8 +747,6 @@ class Scanner { ...@@ -747,8 +747,6 @@ class Scanner {
bool ScanSignedInteger(int start_pos); bool ScanSignedInteger(int start_pos);
bool ScanOctalDigits(int start_pos); bool ScanOctalDigits(int start_pos);
bool ScanImplicitOctalDigits(int start_pos, NumberKind* kind); bool ScanImplicitOctalDigits(int start_pos, NumberKind* kind);
bool ScanImplicitOctalDigitsWithNumericSeparators(int start_pos,
NumberKind* kind);
Token::Value ScanNumber(bool seen_period); Token::Value ScanNumber(bool seen_period);
Token::Value ScanIdentifierOrKeyword(); Token::Value ScanIdentifierOrKeyword();
......
...@@ -1523,30 +1523,16 @@ TEST(NumericSeparatorErrors) { ...@@ -1523,30 +1523,16 @@ TEST(NumericSeparatorErrors) {
RunParserSyncTest(context_data, statement_data, kError); RunParserSyncTest(context_data, statement_data, kError);
} }
TEST(NumericSeparatorImplicitOctals) {
v8::HandleScope handles(CcTest::isolate());
v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
v8::Context::Scope context_scope(context);
const char* context_data[][2] = {
{"", ""}, {nullptr, nullptr}, {nullptr, nullptr}};
const char* statement_data[] = {"07_7_7", "0_7_7_7", "0_777", nullptr};
static const ParserFlag flags[] = {kAllowHarmonyNumericSeparator};
RunParserSyncTest(context_data, statement_data, kSuccess, nullptr, 0, flags,
1);
RunParserSyncTest(context_data, statement_data, kError);
}
TEST(NumericSeparatorImplicitOctalsErrors) { TEST(NumericSeparatorImplicitOctalsErrors) {
v8::HandleScope handles(CcTest::isolate()); v8::HandleScope handles(CcTest::isolate());
v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
const char* context_data[][2] = { const char* context_data[][2] = {
{"", ""}, {nullptr, nullptr}, {nullptr, nullptr}}; {"", ""}, {"\"use strict\";", ""}, {nullptr, nullptr}};
const char* statement_data[] = {"07_7_7_", "07__77", "0__777", nullptr}; const char* statement_data[] = {"00_122", "0_012", "07_7_7",
"0_7_7_7", "0_777", "07_7_7_",
"07__77", "0__777", nullptr};
static const ParserFlag flags[] = {kAllowHarmonyNumericSeparator}; static const ParserFlag flags[] = {kAllowHarmonyNumericSeparator};
RunParserSyncTest(context_data, statement_data, kError, nullptr, 0, flags, 1, RunParserSyncTest(context_data, statement_data, kError, nullptr, 0, flags, 1,
......
...@@ -24,11 +24,6 @@ ...@@ -24,11 +24,6 @@
const octal = 0o7_7_7; const octal = 0o7_7_7;
assertEquals(octal, 0o777); assertEquals(octal, 0o777);
} }
{
const implicitOctal = 07_7_7;
assertEquals(implicitOctal, 0o777);
}
{ {
let exception = false; let exception = false;
try { try {
...@@ -66,3 +61,4 @@ assertThrows('0o_777', SyntaxError); ...@@ -66,3 +61,4 @@ assertThrows('0o_777', SyntaxError);
assertThrows('0o7__77', SyntaxError); assertThrows('0o7__77', SyntaxError);
assertThrows('0777_', SyntaxError); assertThrows('0777_', SyntaxError);
assertThrows('07__77', SyntaxError); assertThrows('07__77', SyntaxError);
assertThrows('07_7_7', SyntaxError);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment