Fix error message for octal escapes in templates

This updates the scanner to use the correct error message when it
encounters an octal escape sequence in a template literal. Previously,
the error message referred to strict mode, even when the template
literal was not in strict mode code.

Bug: v8:7502
Change-Id: I37bb1338cf796c471108bc10f35f824cdf3ce0b7
Reviewed-on: https://chromium-review.googlesource.com/945411
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51823}
This commit is contained in:
Teddy Katz 2018-03-02 21:26:52 -05:00 committed by Commit Bot
parent 1b9f518d21
commit bf021c3c1b
5 changed files with 18 additions and 5 deletions

View File

@ -137,6 +137,7 @@ Seo Sanghyeon <sanxiyn@gmail.com>
Stefan Penner <stefan.penner@gmail.com>
Sylvestre Ledru <sledru@mozilla.com>
Taketoshi Aono <brn@b6n.ch>
Teddy Katz <teddy.katz@gmail.com>
Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Tobias Burnus <burnus@net-b.de>
Victor Costan <costan@gmail.com>

View File

@ -1015,7 +1015,7 @@ bool Scanner::ScanEscape() {
case '5': // fall through
case '6': // fall through
case '7':
c = ScanOctalEscape<capture_raw>(c, 2);
c = ScanOctalEscape<capture_raw>(c, 2, in_template_literal);
break;
}
@ -1024,9 +1024,8 @@ bool Scanner::ScanEscape() {
return true;
}
template <bool capture_raw>
uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
uc32 Scanner::ScanOctalEscape(uc32 c, int length, bool in_template_literal) {
uc32 x = c - '0';
int i = 0;
for (; i < length; i++) {
@ -1044,7 +1043,9 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
// occur before the "use strict" directive.
if (c != '0' || i > 0 || c0_ == '8' || c0_ == '9') {
octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1);
octal_message_ = MessageTemplate::kStrictOctalEscape;
octal_message_ = in_template_literal
? MessageTemplate::kTemplateOctalLiteral
: MessageTemplate::kStrictOctalEscape;
}
return x;
}

View File

@ -510,7 +510,7 @@ class Scanner {
// Scans octal escape sequence. Also accepts "\0" decimal escape sequence.
template <bool capture_raw>
uc32 ScanOctalEscape(uc32 c, int length);
uc32 ScanOctalEscape(uc32 c, int length, bool in_template_literal);
// Call this after setting source_ to the input.
void Init() {

View File

@ -0,0 +1,7 @@
// Copyright 2018 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.
//
//
`\123`

View File

@ -0,0 +1,4 @@
*%(basename)s:7: SyntaxError: Octal escape sequences are not allowed in template strings.
`\123`
^^
SyntaxError: Octal escape sequences are not allowed in template strings.