Commit bf021c3c authored by Teddy Katz's avatar Teddy Katz Committed by Commit Bot

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/945411Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51823}
parent 1b9f518d
......@@ -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>
......
......@@ -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;
}
......
......@@ -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() {
......
// 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`
*%(basename)s:7: SyntaxError: Octal escape sequences are not allowed in template strings.
`\123`
^^
SyntaxError: Octal escape sequences are not allowed in template strings.
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