Commit 93b87c89 authored by jwolfe's avatar jwolfe Committed by Commit bot

A decimal integer literal with a leading 0 is now an error in strict mode.

We're still collecting use counter data for this situation.

BUG=v8:4973
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2510873005
Cr-Commit-Position: refs/heads/master@{#41563}
parent 3bc53ad7
......@@ -595,6 +595,8 @@ class ErrorUtils : public AllStatic {
"In strict mode code, functions can only be declared at top level or " \
"inside a block.") \
T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \
T(StrictDecimalWithLeadingZero, \
"Decimals with leading zeros are not allowed in strict mode.") \
T(StrictOctalEscape, \
"Octal escape sequences are not allowed in strict mode.") \
T(StrictWith, "Strict mode code may not include a with statement") \
......
......@@ -883,19 +883,12 @@ class ParserBase {
DCHECK_NE(message, MessageTemplate::kNone);
impl()->ReportMessageAt(octal, message);
scanner()->clear_octal_position();
if (message == MessageTemplate::kStrictDecimalWithLeadingZero) {
impl()->CountUsage(v8::Isolate::kDecimalWithLeadingZeroInStrictMode);
}
*ok = false;
}
}
// for now, this check just collects statistics.
void CheckDecimalLiteralWithLeadingZero(int beg_pos, int end_pos) {
Scanner::Location token_location =
scanner()->decimal_with_leading_zero_position();
if (token_location.IsValid() && beg_pos <= token_location.beg_pos &&
token_location.end_pos <= end_pos) {
scanner()->clear_decimal_with_leading_zero_position();
impl()->CountUsage(v8::Isolate::kDecimalWithLeadingZeroInStrictMode);
}
}
inline void CheckStrictOctalLiteral(int beg_pos, int end_pos, bool* ok) {
CheckOctalLiteral(beg_pos, end_pos, false, ok);
......
......@@ -778,8 +778,6 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
if (ok && is_strict(language_mode())) {
CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
CheckDecimalLiteralWithLeadingZero(beg_pos,
scanner()->location().end_pos);
}
if (ok && is_sloppy(language_mode())) {
// TODO(littledan): Function bindings on the global object that modify
......@@ -2743,8 +2741,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
if (is_strict(language_mode)) {
CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
CHECK_OK);
CheckDecimalLiteralWithLeadingZero(scope->start_position(),
scope->end_position());
}
CheckConflictingVarDeclarations(scope, CHECK_OK);
} // DiscardableZoneScope goes out of scope.
......
......@@ -162,8 +162,6 @@ PreParser::PreParseResult PreParser::PreParseFunction(
if (is_strict(function_scope->language_mode())) {
int end_pos = scanner()->location().end_pos;
CheckStrictOctalLiteral(function_scope->start_position(), end_pos, ok);
CheckDecimalLiteralWithLeadingZero(function_scope->start_position(),
end_pos);
}
}
return kPreParseSuccess;
......@@ -237,7 +235,6 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
int end_position = scanner()->location().end_pos;
if (is_strict(language_mode)) {
CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
CheckDecimalLiteralWithLeadingZero(start_position, end_position);
}
function_scope->set_end_position(end_position);
......
......@@ -882,8 +882,6 @@ class PreParser : public ParserBase<PreParser> {
} else if (is_strict(this->scope()->language_mode())) {
CheckStrictOctalLiteral(start_position, scanner()->location().end_pos,
&ok);
CheckDecimalLiteralWithLeadingZero(start_position,
scanner()->location().end_pos);
}
if (materialized_literals) {
*materialized_literals = function_state_->materialized_literal_count();
......
......@@ -78,7 +78,6 @@ bool Scanner::BookmarkScope::HasBeenApplied() {
Scanner::Scanner(UnicodeCache* unicode_cache)
: unicode_cache_(unicode_cache),
octal_pos_(Location::invalid()),
decimal_with_leading_zero_pos_(Location::invalid()),
octal_message_(MessageTemplate::kNone),
found_html_comment_(false) {}
......@@ -1159,8 +1158,10 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
literal.Complete();
HandleLeadSurrogate();
if (kind == DECIMAL_WITH_LEADING_ZERO)
decimal_with_leading_zero_pos_ = Location(start_pos, source_pos());
if (kind == DECIMAL_WITH_LEADING_ZERO) {
octal_pos_ = Location(start_pos, source_pos());
octal_message_ = MessageTemplate::kStrictDecimalWithLeadingZero;
}
return Token::SMI;
}
HandleLeadSurrogate();
......@@ -1200,8 +1201,10 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
literal.Complete();
if (kind == DECIMAL_WITH_LEADING_ZERO)
decimal_with_leading_zero_pos_ = Location(start_pos, source_pos());
if (kind == DECIMAL_WITH_LEADING_ZERO) {
octal_pos_ = Location(start_pos, source_pos());
octal_message_ = MessageTemplate::kStrictDecimalWithLeadingZero;
}
return Token::NUMBER;
}
......
......@@ -278,13 +278,6 @@ class Scanner {
octal_pos_ = Location::invalid();
octal_message_ = MessageTemplate::kNone;
}
// Returns the location of the last seen decimal literal with a leading zero.
Location decimal_with_leading_zero_position() const {
return decimal_with_leading_zero_pos_;
}
void clear_decimal_with_leading_zero_position() {
decimal_with_leading_zero_pos_ = Location::invalid();
}
MessageTemplate::Template octal_message() const { return octal_message_; }
// Returns the value of the last smi that was scanned.
......@@ -789,7 +782,6 @@ class Scanner {
// Last-seen positions of potentially problematic tokens.
Location octal_pos_;
Location decimal_with_leading_zero_pos_;
MessageTemplate::Template octal_message_;
// One Unicode character look-ahead; c0_ < 0 at the end of the input.
......
......@@ -318,9 +318,6 @@
'annexB/built-ins/Object/prototype/__lookupGetter__/this-non-obj': [FAIL],
'annexB/built-ins/Object/prototype/__lookupSetter__/this-non-obj': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=4973
'language/literals/numeric/non-octal-decimal-integer-strict': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=5130
'annexB/built-ins/Object/prototype/__lookupGetter__/lookup-own-data': [FAIL],
'annexB/built-ins/Object/prototype/__lookupGetter__/lookup-own-get-err': [FAIL],
......
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