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

Unified Diff: src/parsing/scanner.cc

Issue 2665513002: [parser] Lift template literal invalid escape restriction (Closed)
Patch Set: add test 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 86aadcff9fae2e74e7e6d11172ab2aac91d4f62a..e1eed27b473fb1da313dafd5b865963d31f98fd3 100644
--- a/src/parsing/scanner.cc
+++ b/src/parsing/scanner.cc
@@ -948,16 +948,12 @@ bool Scanner::ScanEscape() {
break;
}
- // According to ECMA-262, section 7.8.4, characters not covered by the
- // above cases should be illegal, but they are commonly handled as
- // non-escaped characters by JS VMs.
+ // Other escaped characters are interpreted as their non-escaped version.
AddLiteralChar(c);
return true;
}
-// Octal escapes of the forms '\0xx' and '\xxx' are not a part of
-// ECMA-262. Other JS VMs support them.
template <bool capture_raw>
uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
uc32 x = c - '0';
@@ -1039,6 +1035,16 @@ Token::Value Scanner::ScanTemplateSpan() {
// TEMPLATE_TAIL terminates a TemplateLiteral and does not need to be
// followed by an Expression.
+ MessageTemplate::Template old_scanner_error = scanner_error_;
+ Location old_scanner_error_location = scanner_error_location_;
+ scanner_error_ = MessageTemplate::kNone;
+ scanner_error_location_ = Location::invalid();
vogelheim 2017/02/20 11:23:20 This logic (here & below) is a bit obtuse. I don't
bakkot1 2017/02/21 21:54:15 Added a ErrorState scoped helper which does this.
vogelheim 2017/02/22 10:03:02 Thanks.
+
+ MessageTemplate::Template old_octal_message = octal_message_;
+ Location old_octal_pos = octal_pos_;
+ octal_message_ = MessageTemplate::kNone;
+ octal_pos_ = Location::invalid();
+
Token::Value result = Token::TEMPLATE_SPAN;
LiteralScope literal(this);
StartRawLiteral();
@@ -1069,8 +1075,27 @@ Token::Value Scanner::ScanTemplateSpan() {
AddRawLiteralChar('\n');
}
}
- } else if (!ScanEscape<capture_raw, in_template_literal>()) {
- return Token::ILLEGAL;
+ } else {
+ ScanEscape<capture_raw, in_template_literal>();
+ // For templates, invalid escape sequence checking is handled in the
+ // parser.
+ if (has_error()) {
+ if (!has_invalid_template_escape()) {
+ invalid_template_escape_message_ = scanner_error_;
+ invalid_template_escape_location_ = scanner_error_location_;
+ }
+ scanner_error_ = MessageTemplate::kNone;
+ scanner_error_location_ = Location::invalid();
+ }
+ if (octal_message_ != MessageTemplate::kNone) {
+ if (!has_invalid_template_escape()) {
+ invalid_template_escape_message_ =
+ MessageTemplate::kTemplateOctalLiteral;
+ invalid_template_escape_location_ = octal_pos_;
+ }
+ octal_message_ = MessageTemplate::kNone;
+ octal_pos_ = Location::invalid();
+ }
}
} else if (c < 0) {
// Unterminated template literal
@@ -1095,6 +1120,11 @@ Token::Value Scanner::ScanTemplateSpan() {
literal.Complete();
next_.location.end_pos = source_pos();
next_.token = result;
+
+ scanner_error_ = old_scanner_error;
+ scanner_error_location_ = old_scanner_error_location;
+ octal_message_ = old_octal_message;
+ octal_pos_ = old_octal_pos;
return result;
}

Powered by Google App Engine
This is Rietveld 408576698