Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Unified Diff: src/parsing/scanner.cc

Issue 2724003006: [parser] Correctly handle invalid escapes in adjacent template tokens. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/parsing/scanner.cc
diff --git a/src/parsing/scanner.cc b/src/parsing/scanner.cc
index c1580bbeae7dd23d69d0e02c13b0090474cb1773..c961ff758e77f96ff76e9ff8e96e5c2d1d3f4d94 100644
--- a/src/parsing/scanner.cc
+++ b/src/parsing/scanner.cc
@@ -397,6 +397,7 @@ Token::Value Scanner::Next() {
next_.location.end_pos = pos + 1;
next_.literal_chars = nullptr;
next_.raw_literal_chars = nullptr;
+ next_.invalid_template_escape_message_ = MessageTemplate::kNone;
Advance();
return current_.token;
}
@@ -609,6 +610,7 @@ Token::Value Scanner::ScanHtmlComment() {
void Scanner::Scan() {
next_.literal_chars = NULL;
next_.raw_literal_chars = NULL;
+ next_.invalid_template_escape_message_ = MessageTemplate::kNone;
Token::Value token;
do {
// Remember the position of the next token
@@ -889,6 +891,8 @@ void Scanner::SanityCheckTokenDesc(const TokenDesc& token) const {
// - TEMPLATE_*: need both literal + raw literal chars.
// - IDENTIFIERS, STRINGS, etc.: need a literal, but no raw literal.
// - all others: should have neither.
+ // Furthermore, only TEMPLATE_* tokens can have a
+ // invalid_template_escape_message_.
switch (token.token) {
case Token::UNINITIALIZED:
@@ -909,10 +913,12 @@ void Scanner::SanityCheckTokenDesc(const TokenDesc& token) const {
case Token::STRING:
DCHECK_NOT_NULL(token.literal_chars);
DCHECK_NULL(token.raw_literal_chars);
+ DCHECK_EQ(token.invalid_template_escape_message_, MessageTemplate::kNone);
break;
default:
DCHECK_NULL(token.literal_chars);
DCHECK_NULL(token.raw_literal_chars);
+ DCHECK_EQ(token.invalid_template_escape_message_, MessageTemplate::kNone);
break;
}
}
@@ -1117,10 +1123,11 @@ Token::Value Scanner::ScanTemplateSpan() {
DCHECK_EQ(!success, has_error());
// For templates, invalid escape sequence checking is handled in the
// parser.
- scanner_error_state.MoveErrorTo(&invalid_template_escape_message_,
- &invalid_template_escape_location_);
- octal_error_state.MoveErrorTo(&invalid_template_escape_message_,
- &invalid_template_escape_location_);
+ scanner_error_state.MoveErrorTo(
vogelheim 2017/03/03 10:40:08 nitpick: With this change, it might be slightly ni
bakkot1 2017/03/03 20:50:17 TokenDesc is private in Scanner. I could make it p
vogelheim 2017/03/03 21:26:19 Oops. Hrmm, yeah, I think I asked you to take Erro
+ &next_.invalid_template_escape_message_,
+ &next_.invalid_template_escape_location_);
+ octal_error_state.MoveErrorTo(&next_.invalid_template_escape_message_,
+ &next_.invalid_template_escape_location_);
}
} else if (c < 0) {
// Unterminated template literal
@@ -1736,7 +1743,9 @@ void Scanner::SeekNext(size_t position) {
// 1, Reset the current_, next_ and next_next_ tokens
// (next_ + next_next_ will be overwrittem by Next(),
// current_ will remain unchanged, so overwrite it fully.)
- current_ = {{0, 0}, nullptr, nullptr, 0, Token::UNINITIALIZED};
+ current_ = {
+ {0, 0}, nullptr, nullptr, 0, Token::UNINITIALIZED, MessageTemplate::kNone,
+ {0, 0}};
next_.token = Token::UNINITIALIZED;
next_next_.token = Token::UNINITIALIZED;
// 2, reset the source to the desired position,
« src/parsing/scanner.h ('K') | « src/parsing/scanner.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698