Commit 782f6401 authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

Revert "[parser] Implements proposal-numeric-separator."

This reverts commit 517df524.

Reason for revert: Fails MSAN tests - https://build.chromium.org/p/client.v8/builders/V8%20Linux%20-%20arm64%20-%20sim%20-%20MSAN/builds/20030

Original change's description:
> [parser] Implements proposal-numeric-separator.
> 
> https://github.com/tc39/proposal-numeric-separator
> 
> This proposal-numeric-separator extends NumericLiteral and
> allows developers to insert underscore(_) inside numeric literal.
> 
> Bug: v8:7317
> Change-Id: I2a1a45cd6fe09cc5df63433bc915988fde687a33
> Reviewed-on: https://chromium-review.googlesource.com/923441
> Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#51671}

TBR=adamk@chromium.org,jkummerow@chromium.org,hablich@chromium.org,gsathya@chromium.org,mathias@chromium.org,goto@google.com,brn@b6n.ch

Change-Id: I6dcf46820caf20f28fbc11d94a5e8ced3cbbc78d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7317
Reviewed-on: https://chromium-review.googlesource.com/944767Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51672}
parent 517df524
...@@ -4214,7 +4214,6 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_import_meta) ...@@ -4214,7 +4214,6 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_import_meta)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_restrict_constructor_return) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_restrict_constructor_return)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_optional_catch_binding) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_optional_catch_binding)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_subsume_json) EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_subsume_json)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_numeric_separator)
void InstallPublicSymbol(Factory* factory, Handle<Context> native_context, void InstallPublicSymbol(Factory* factory, Handle<Context> native_context,
const char* name, Handle<Symbol> value) { const char* name, Handle<Symbol> value) {
......
...@@ -48,21 +48,25 @@ inline bool IsDecimalDigit(uc32 c) { ...@@ -48,21 +48,25 @@ inline bool IsDecimalDigit(uc32 c) {
return IsInRange(c, '0', '9'); return IsInRange(c, '0', '9');
} }
inline bool IsHexDigit(uc32 c) { inline bool IsHexDigit(uc32 c) {
// ECMA-262, 3rd, 7.6 (p 15) // ECMA-262, 3rd, 7.6 (p 15)
return IsDecimalDigit(c) || IsInRange(AsciiAlphaToLower(c), 'a', 'f'); return IsDecimalDigit(c) || IsInRange(AsciiAlphaToLower(c), 'a', 'f');
} }
inline bool IsOctalDigit(uc32 c) { inline bool IsOctalDigit(uc32 c) {
// ECMA-262, 6th, 7.8.3 // ECMA-262, 6th, 7.8.3
return IsInRange(c, '0', '7'); return IsInRange(c, '0', '7');
} }
inline bool IsBinaryDigit(uc32 c) { inline bool IsBinaryDigit(uc32 c) {
// ECMA-262, 6th, 7.8.3 // ECMA-262, 6th, 7.8.3
return c == '0' || c == '1'; return c == '0' || c == '1';
} }
inline bool IsRegExpWord(uc16 c) { inline bool IsRegExpWord(uc16 c) {
return IsInRange(AsciiAlphaToLower(c), 'a', 'z') return IsInRange(AsciiAlphaToLower(c), 'a', 'z')
|| IsDecimalDigit(c) || IsDecimalDigit(c)
......
...@@ -213,8 +213,7 @@ DEFINE_IMPLICATION(harmony_class_fields, harmony_private_fields) ...@@ -213,8 +213,7 @@ DEFINE_IMPLICATION(harmony_class_fields, harmony_private_fields)
V(harmony_do_expressions, "harmony do-expressions") \ V(harmony_do_expressions, "harmony do-expressions") \
V(harmony_class_fields, "harmony fields in class literals") \ V(harmony_class_fields, "harmony fields in class literals") \
V(harmony_static_fields, "harmony static fields in class literals") \ V(harmony_static_fields, "harmony static fields in class literals") \
V(harmony_bigint, "harmony arbitrary precision integers") \ V(harmony_bigint, "harmony arbitrary precision integers")
V(harmony_numeric_separator, "harmony numeric separator between digits")
// Features that are complete (but still behind --harmony/es-staging flag). // Features that are complete (but still behind --harmony/es-staging flag).
#define HARMONY_STAGED(V) \ #define HARMONY_STAGED(V) \
......
...@@ -557,10 +557,6 @@ class ErrorUtils : public AllStatic { ...@@ -557,10 +557,6 @@ class ErrorUtils : public AllStatic {
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(NumberFormatRange, "% argument must be between 0 and 100") \ T(NumberFormatRange, "% argument must be between 0 and 100") \
T(TrailingNumericSeparator, \
"Numeric separators are not allowed at the end of numeric literals") \
T(ContinuousNumericSeparator, \
"Only one underscore is allowed as numeric separator") \
T(PropertyValueOutOfRange, "% value is out of range.") \ T(PropertyValueOutOfRange, "% value is out of range.") \
T(StackOverflow, "Maximum call stack size exceeded") \ T(StackOverflow, "Maximum call stack size exceeded") \
T(ToPrecisionFormatRange, \ T(ToPrecisionFormatRange, \
......
...@@ -307,12 +307,6 @@ class ParserBase { ...@@ -307,12 +307,6 @@ class ParserBase {
void set_allow_harmony_bigint(bool allow) { void set_allow_harmony_bigint(bool allow) {
scanner()->set_allow_harmony_bigint(allow); scanner()->set_allow_harmony_bigint(allow);
} }
bool allow_harmony_numeric_separator() const {
return scanner()->allow_harmony_numeric_separator();
}
void set_allow_harmony_numeric_separator(bool allow) {
scanner()->set_allow_harmony_numeric_separator(allow);
}
bool allow_harmony_private_fields() const { bool allow_harmony_private_fields() const {
return scanner()->allow_harmony_private_fields(); return scanner()->allow_harmony_private_fields();
......
...@@ -448,7 +448,6 @@ Parser::Parser(ParseInfo* info) ...@@ -448,7 +448,6 @@ Parser::Parser(ParseInfo* info)
set_allow_harmony_dynamic_import(FLAG_harmony_dynamic_import); set_allow_harmony_dynamic_import(FLAG_harmony_dynamic_import);
set_allow_harmony_import_meta(FLAG_harmony_import_meta); set_allow_harmony_import_meta(FLAG_harmony_import_meta);
set_allow_harmony_bigint(FLAG_harmony_bigint); set_allow_harmony_bigint(FLAG_harmony_bigint);
set_allow_harmony_numeric_separator(FLAG_harmony_numeric_separator);
set_allow_harmony_optional_catch_binding(FLAG_harmony_optional_catch_binding); set_allow_harmony_optional_catch_binding(FLAG_harmony_optional_catch_binding);
set_allow_harmony_private_fields(FLAG_harmony_private_fields); set_allow_harmony_private_fields(FLAG_harmony_private_fields);
for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
......
...@@ -1223,209 +1223,73 @@ Handle<String> Scanner::SourceMappingUrl(Isolate* isolate) const { ...@@ -1223,209 +1223,73 @@ Handle<String> Scanner::SourceMappingUrl(Isolate* isolate) const {
return tmp; return tmp;
} }
bool Scanner::ScanDigitsWithNumericSeparators(bool (*predicate)(uc32 ch), void Scanner::ScanDecimalDigits() {
int start_pos, while (IsDecimalDigit(c0_))
bool is_check_first_digit) {
// we must have at least one digit after 'x'/'b'/'o'
if (is_check_first_digit && !predicate(c0_)) return false;
bool separator_seen = false;
while (predicate(c0_) || c0_ == '_') {
if (c0_ == '_') {
Advance<false, false>();
if (c0_ == '_') {
ReportScannerError(Location(start_pos, source_pos()),
MessageTemplate::kContinuousNumericSeparator);
return false;
}
separator_seen = true;
continue;
}
separator_seen = false;
AddLiteralCharAdvance();
}
if (separator_seen) {
ReportScannerError(Location(start_pos, source_pos()),
MessageTemplate::kTrailingNumericSeparator);
return false;
}
return true;
}
bool Scanner::ScanDecimalDigits(int start_pos) {
if (allow_harmony_numeric_separator()) {
return ScanDigitsWithNumericSeparators(&IsDecimalDigit, start_pos, false);
}
while (IsDecimalDigit(c0_)) {
AddLiteralCharAdvance(); AddLiteralCharAdvance();
}
return true;
}
bool Scanner::ScanDecimalAsSmiWithNumericSeparators(int start_pos,
uint64_t* value) {
bool separator_seen = false;
while (IsDecimalDigit(c0_) || c0_ == '_') {
if (c0_ == '_') {
Advance<false, false>();
if (c0_ == '_') {
ReportScannerError(Location(start_pos, source_pos()),
MessageTemplate::kContinuousNumericSeparator);
return false;
}
separator_seen = true;
continue;
}
separator_seen = false;
*value = 10 * *value + (c0_ - '0');
uc32 first_char = c0_;
Advance<false, false>();
AddLiteralChar(first_char);
}
if (separator_seen) {
ReportScannerError(Location(start_pos, source_pos()),
MessageTemplate::kTrailingNumericSeparator);
return false;
}
return true;
}
bool Scanner::ScanDecimalAsSmi(int start_pos, uint64_t* value) {
if (allow_harmony_numeric_separator()) {
return ScanDecimalAsSmiWithNumericSeparators(start_pos, value);
}
while (IsDecimalDigit(c0_)) {
*value = 10 * *value + (c0_ - '0');
uc32 first_char = c0_;
Advance<false, false>();
AddLiteralChar(first_char);
}
return true;
} }
bool Scanner::ScanBinaryDigits(int start_pos) { bool Scanner::ScanBinaryDigits() {
if (allow_harmony_numeric_separator()) {
return ScanDigitsWithNumericSeparators(&IsBinaryDigit, start_pos, true);
}
// we must have at least one binary digit after 'b'/'B' // we must have at least one binary digit after 'b'/'B'
if (!IsBinaryDigit(c0_)) { if (!IsBinaryDigit(c0_)) return false;
return false;
}
while (IsBinaryDigit(c0_)) { while (IsBinaryDigit(c0_)) {
AddLiteralCharAdvance(); AddLiteralCharAdvance();
} }
return true; return true;
} }
bool Scanner::ScanOctalDigits(int start_pos) { bool Scanner::ScanOctalDigits() {
if (allow_harmony_numeric_separator()) {
return ScanDigitsWithNumericSeparators(&IsOctalDigit, start_pos, true);
}
// we must have at least one octal digit after 'o'/'O' // we must have at least one octal digit after 'o'/'O'
if (!IsOctalDigit(c0_)) { if (!IsOctalDigit(c0_)) return false;
return false;
}
while (IsOctalDigit(c0_)) { while (IsOctalDigit(c0_)) {
AddLiteralCharAdvance(); AddLiteralCharAdvance();
} }
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; return true;
}
separator_seen = false;
AddLiteralCharAdvance();
}
} }
bool Scanner::ScanImplicitOctalDigits(int start_pos, bool Scanner::ScanImplicitOctalDigits(int start_pos) {
Scanner::NumberKind* kind) {
*kind = IMPLICIT_OCTAL;
if (allow_harmony_numeric_separator()) {
return ScanImplicitOctalDigitsWithNumericSeparators(start_pos, kind);
}
while (true) {
// (possible) octal number // (possible) octal number
if (c0_ == '8' || c0_ == '9') { while (true) {
*kind = DECIMAL_WITH_LEADING_ZERO; if (c0_ == '8' || c0_ == '9') return false;
return true;
}
if (c0_ < '0' || '7' < c0_) { if (c0_ < '0' || '7' < c0_) {
// Octal literal finished. // Octal literal finished.
octal_pos_ = Location(start_pos, source_pos()); octal_pos_ = Location(start_pos, source_pos());
octal_message_ = MessageTemplate::kStrictOctalLiteral; octal_message_ = MessageTemplate::kStrictOctalLiteral;
return true; break;
} }
AddLiteralCharAdvance(); AddLiteralCharAdvance();
} }
return true;
} }
bool Scanner::ScanHexDigits(int start_pos) { bool Scanner::ScanHexDigits() {
if (allow_harmony_numeric_separator()) {
return ScanDigitsWithNumericSeparators(&IsHexDigit, start_pos, true);
}
// we must have at least one hex digit after 'x'/'X' // we must have at least one hex digit after 'x'/'X'
if (!IsHexDigit(c0_)) { if (!IsHexDigit(c0_)) return false;
return false;
}
while (IsHexDigit(c0_)) { while (IsHexDigit(c0_)) {
AddLiteralCharAdvance(); AddLiteralCharAdvance();
} }
return true; return true;
} }
bool Scanner::ScanSignedInteger(int start_pos) { bool Scanner::ScanSignedInteger() {
if (c0_ == '+' || c0_ == '-') AddLiteralCharAdvance(); if (c0_ == '+' || c0_ == '-') AddLiteralCharAdvance();
// we must have at least one decimal digit after 'e'/'E' // we must have at least one decimal digit after 'e'/'E'
if (!IsDecimalDigit(c0_)) return false; if (!IsDecimalDigit(c0_)) return false;
return ScanDecimalDigits(start_pos); ScanDecimalDigits();
return true;
} }
Token::Value Scanner::ScanNumber(bool seen_period) { Token::Value Scanner::ScanNumber(bool seen_period) {
DCHECK(IsDecimalDigit(c0_)); // the first digit of the number or the fraction DCHECK(IsDecimalDigit(c0_)); // the first digit of the number or the fraction
NumberKind kind = DECIMAL; enum {
DECIMAL,
DECIMAL_WITH_LEADING_ZERO,
HEX,
OCTAL,
IMPLICIT_OCTAL,
BINARY
} kind = DECIMAL;
LiteralScope literal(this); LiteralScope literal(this);
bool at_start = !seen_period; bool at_start = !seen_period;
...@@ -1433,11 +1297,8 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -1433,11 +1297,8 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
if (seen_period) { if (seen_period) {
// we have already seen a decimal point of the float // we have already seen a decimal point of the float
AddLiteralChar('.'); AddLiteralChar('.');
if (allow_harmony_numeric_separator() && c0_ == '_') { ScanDecimalDigits(); // we know we have at least one digit
return Token::ILLEGAL;
}
// we know we have at least one digit
if (!ScanDecimalDigits(start_pos)) return Token::ILLEGAL;
} else { } else {
// if the first character is '0' we must check for octals and hex // if the first character is '0' we must check for octals and hex
if (c0_ == '0') { if (c0_ == '0') {
...@@ -1448,21 +1309,19 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -1448,21 +1309,19 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
if (c0_ == 'x' || c0_ == 'X') { if (c0_ == 'x' || c0_ == 'X') {
AddLiteralCharAdvance(); AddLiteralCharAdvance();
kind = HEX; kind = HEX;
if (!ScanHexDigits(start_pos)) return Token::ILLEGAL; if (!ScanHexDigits()) return Token::ILLEGAL;
} else if (c0_ == 'o' || c0_ == 'O') { } else if (c0_ == 'o' || c0_ == 'O') {
AddLiteralCharAdvance(); AddLiteralCharAdvance();
kind = OCTAL; kind = OCTAL;
if (!ScanOctalDigits(start_pos)) return Token::ILLEGAL; if (!ScanOctalDigits()) return Token::ILLEGAL;
} else if (c0_ == 'b' || c0_ == 'B') { } else if (c0_ == 'b' || c0_ == 'B') {
AddLiteralCharAdvance(); AddLiteralCharAdvance();
kind = BINARY; kind = BINARY;
if (!ScanBinaryDigits(start_pos)) return Token::ILLEGAL; if (!ScanBinaryDigits()) return Token::ILLEGAL;
} else if ('0' <= c0_ && c0_ <= '7') { } else if ('0' <= c0_ && c0_ <= '7') {
kind = IMPLICIT_OCTAL; kind = IMPLICIT_OCTAL;
if (!ScanImplicitOctalDigits(start_pos, &kind)) { if (!ScanImplicitOctalDigits(start_pos)) {
return Token::ILLEGAL; kind = DECIMAL_WITH_LEADING_ZERO;
}
if (kind == DECIMAL_WITH_LEADING_ZERO) {
at_start = false; at_start = false;
} }
} else if (c0_ == '8' || c0_ == '9') { } else if (c0_ == '8' || c0_ == '9') {
...@@ -1475,9 +1334,12 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -1475,9 +1334,12 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
// This is an optimization for parsing Decimal numbers as Smi's. // This is an optimization for parsing Decimal numbers as Smi's.
if (at_start) { if (at_start) {
uint64_t value = 0; uint64_t value = 0;
// scan subsequent decimal digits while (IsDecimalDigit(c0_)) {
if (!ScanDecimalAsSmi(start_pos, &value)) { value = 10 * value + (c0_ - '0');
return Token::ILLEGAL;
uc32 first_char = c0_;
Advance<false, false>();
AddLiteralChar(first_char);
} }
if (next_.literal_chars->one_byte_literal().length() <= 10 && if (next_.literal_chars->one_byte_literal().length() <= 10 &&
...@@ -1496,14 +1358,11 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -1496,14 +1358,11 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
HandleLeadSurrogate(); HandleLeadSurrogate();
} }
if (!ScanDecimalDigits(start_pos)) return Token::ILLEGAL; ScanDecimalDigits(); // optional
if (c0_ == '.') { if (c0_ == '.') {
seen_period = true; seen_period = true;
AddLiteralCharAdvance(); AddLiteralCharAdvance();
if (allow_harmony_numeric_separator() && c0_ == '_') { ScanDecimalDigits(); // optional
return Token::ILLEGAL;
}
if (!ScanDecimalDigits(start_pos)) return Token::ILLEGAL;
} }
} }
} }
...@@ -1534,7 +1393,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -1534,7 +1393,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
// scan exponent // scan exponent
AddLiteralCharAdvance(); AddLiteralCharAdvance();
if (!ScanSignedInteger(start_pos)) return Token::ILLEGAL; if (!ScanSignedInteger()) return Token::ILLEGAL;
} }
// The source character immediately following a numeric literal must // The source character immediately following a numeric literal must
......
...@@ -366,12 +366,6 @@ class Scanner { ...@@ -366,12 +366,6 @@ class Scanner {
void set_allow_harmony_private_fields(bool allow) { void set_allow_harmony_private_fields(bool allow) {
allow_harmony_private_fields_ = allow; allow_harmony_private_fields_ = allow;
} }
bool allow_harmony_numeric_separator() const {
return allow_harmony_numeric_separator_;
}
void set_allow_harmony_numeric_separator(bool allow) {
allow_harmony_numeric_separator_ = allow;
}
private: private:
// Scoped helper for saving & restoring scanner error state. // Scoped helper for saving & restoring scanner error state.
...@@ -496,15 +490,6 @@ class Scanner { ...@@ -496,15 +490,6 @@ class Scanner {
Token::Value contextual_token; Token::Value contextual_token;
}; };
enum NumberKind {
BINARY,
OCTAL,
IMPLICIT_OCTAL,
HEX,
DECIMAL,
DECIMAL_WITH_LEADING_ZERO
};
static const int kCharacterLookaheadBufferSize = 1; static const int kCharacterLookaheadBufferSize = 1;
const int kMaxAscii = 127; const int kMaxAscii = 127;
...@@ -735,20 +720,12 @@ class Scanner { ...@@ -735,20 +720,12 @@ class Scanner {
// Scans a possible HTML comment -- begins with '<!'. // Scans a possible HTML comment -- begins with '<!'.
Token::Value ScanHtmlComment(); Token::Value ScanHtmlComment();
bool ScanDigitsWithNumericSeparators(bool (*predicate)(uc32 ch), void ScanDecimalDigits();
int start_pos, bool ScanHexDigits();
bool is_check_first_digit); bool ScanBinaryDigits();
bool ScanDecimalDigits(int start_pos); bool ScanSignedInteger();
// Optimized function to scan decimal number as Smi. bool ScanOctalDigits();
bool ScanDecimalAsSmi(int start_pos, uint64_t* value); bool ScanImplicitOctalDigits(int start_pos);
bool ScanDecimalAsSmiWithNumericSeparators(int start_pos, uint64_t* value);
bool ScanHexDigits(int start_pos);
bool ScanBinaryDigits(int start_pos);
bool ScanSignedInteger(int start_pos);
bool ScanOctalDigits(int start_pos);
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();
...@@ -840,7 +817,6 @@ class Scanner { ...@@ -840,7 +817,6 @@ class Scanner {
// Harmony flags to allow ESNext features. // Harmony flags to allow ESNext features.
bool allow_harmony_bigint_; bool allow_harmony_bigint_;
bool allow_harmony_private_fields_; bool allow_harmony_private_fields_;
bool allow_harmony_numeric_separator_;
MessageTemplate::Template scanner_error_; MessageTemplate::Template scanner_error_;
Location scanner_error_location_; Location scanner_error_location_;
......
...@@ -1122,7 +1122,6 @@ enum ParserFlag { ...@@ -1122,7 +1122,6 @@ enum ParserFlag {
kAllowHarmonyImportMeta, kAllowHarmonyImportMeta,
kAllowHarmonyDoExpressions, kAllowHarmonyDoExpressions,
kAllowHarmonyOptionalCatchBinding, kAllowHarmonyOptionalCatchBinding,
kAllowHarmonyNumericSeparator
}; };
enum ParserSyncTestResult { enum ParserSyncTestResult {
...@@ -1141,8 +1140,6 @@ void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { ...@@ -1141,8 +1140,6 @@ void SetGlobalFlags(i::EnumSet<ParserFlag> flags) {
i::FLAG_harmony_do_expressions = flags.Contains(kAllowHarmonyDoExpressions); i::FLAG_harmony_do_expressions = flags.Contains(kAllowHarmonyDoExpressions);
i::FLAG_harmony_optional_catch_binding = i::FLAG_harmony_optional_catch_binding =
flags.Contains(kAllowHarmonyOptionalCatchBinding); flags.Contains(kAllowHarmonyOptionalCatchBinding);
i::FLAG_harmony_numeric_separator =
flags.Contains(kAllowHarmonyNumericSeparator);
} }
void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
...@@ -1161,8 +1158,6 @@ void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { ...@@ -1161,8 +1158,6 @@ void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
flags.Contains(kAllowHarmonyDoExpressions)); flags.Contains(kAllowHarmonyDoExpressions));
parser->set_allow_harmony_optional_catch_binding( parser->set_allow_harmony_optional_catch_binding(
flags.Contains(kAllowHarmonyOptionalCatchBinding)); flags.Contains(kAllowHarmonyOptionalCatchBinding));
parser->set_allow_harmony_numeric_separator(
flags.Contains(kAllowHarmonyNumericSeparator));
} }
void TestParserSyncWithFlags(i::Handle<i::String> source, void TestParserSyncWithFlags(i::Handle<i::String> source,
...@@ -1485,91 +1480,6 @@ void RunModuleParserSyncTest( ...@@ -1485,91 +1480,6 @@ void RunModuleParserSyncTest(
always_false_len, true, test_preparser, ignore_error_msg); always_false_len, true, test_preparser, ignore_error_msg);
} }
TEST(NumericSeparator) {
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] = {
{"", ""}, {"\"use strict\";", ""}, {nullptr, nullptr}};
const char* statement_data[] = {
"1_0_0_0", "1_0e+1", "1_0e+1_0", "0xF_F_FF", "0o7_7_7", "0b0_1_0_1_0",
".3_2_1", "0.0_2_1", "1_0.0_1", ".0_1_2", nullptr};
static const ParserFlag flags[] = {kAllowHarmonyNumericSeparator};
RunParserSyncTest(context_data, statement_data, kSuccess, nullptr, 0, flags,
1);
RunParserSyncTest(context_data, statement_data, kError);
}
TEST(NumericSeparatorErrors) {
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] = {
{"", ""}, {"\"use strict\";", ""}, {nullptr, nullptr}};
const char* statement_data[] = {
"1_0_0_0_", "1e_1", "1e+_1", "1_e+1", "1__0", "0x_1",
"0x1__1", "0x1_", "0_x1", "0_x_1", "0b_0101", "0b11_",
"0b1__1", "0_b1", "0_b_1", "0o777_", "0o_777", "0o7__77",
"0.0_2_1_", "0.0__21", "0_.01", "0._01", nullptr};
static const ParserFlag flags[] = {kAllowHarmonyNumericSeparator};
RunParserSyncTest(context_data, statement_data, kError, nullptr, 0, flags, 1,
nullptr, 0, false, true, true);
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) {
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_", "07__77", "0__777", nullptr};
static const ParserFlag flags[] = {kAllowHarmonyNumericSeparator};
RunParserSyncTest(context_data, statement_data, kError, nullptr, 0, flags, 1,
nullptr, 0, false, true, true);
RunParserSyncTest(context_data, statement_data, kError);
}
TEST(NumericSeparatorUnicodeEscapeSequencesErrors) {
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] = {
{"", ""}, {"'use strict'", ""}, {nullptr, nullptr}};
// https://github.com/tc39/proposal-numeric-separator/issues/25
const char* statement_data[] = {"\\u{10_FFFF}", nullptr};
static const ParserFlag flags[] = {kAllowHarmonyNumericSeparator};
RunParserSyncTest(context_data, statement_data, kError, nullptr, 0, flags, 1);
RunParserSyncTest(context_data, statement_data, kError);
}
TEST(ErrorsEvalAndArguments) { TEST(ErrorsEvalAndArguments) {
// Tests that both preparsing and parsing produce the right kind of errors for // Tests that both preparsing and parsing produce the right kind of errors for
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-numeric-separator
{
const basic = 1_0_0_0;
assertEquals(basic, 1000);
}
{
const exponent = 1_0e+1;
assertEquals(exponent, 10e+1);
}
{
const exponent2 = 1_0e+1_0;
assertEquals(exponent2, 10e+10);
}
{
const hex = 0xF_F_FF;
assertEquals(hex, 0xFFFF);
}
{
const octal = 0o7_7_7;
assertEquals(octal, 0o777);
}
{
const implicitOctal = 07_7_7;
assertEquals(implicitOctal, 0o777);
}
{
let exception = false;
try {
const code = `"use strict" const implicitOctal = 07_7_7`;
eval(code);
} catch(e) {
exception = true;
assertInstanceof(e, SyntaxError);
}
assertTrue(exception);
}
{
const binary = 0b0_1_0_1_0;
assertEquals(binary, 0b01010);
}
{
const leadingZeros = 09_1_3;
assertEquals(leadingZeros, 0913);
}
assertThrows('1_0_0_0_', SyntaxError);
assertThrows('1e_1', SyntaxError);
assertThrows('1e+_1', SyntaxError);
assertThrows('1_e+1', SyntaxError);
assertThrows('1__0', SyntaxError);
assertThrows('0x_1', SyntaxError);
assertThrows('0x1__1', SyntaxError);
assertThrows('0x1_', SyntaxError);
assertThrows('0b_0101', SyntaxError);
assertThrows('0b11_', SyntaxError);
assertThrows('0b1__1', SyntaxError);
assertThrows('0o777_', SyntaxError);
assertThrows('0o_777', SyntaxError);
assertThrows('0o7__77', SyntaxError);
assertThrows('0777_', SyntaxError);
assertThrows('07__77', 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