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:
parent
1b9f518d21
commit
bf021c3c1b
1
AUTHORS
1
AUTHORS
@ -137,6 +137,7 @@ Seo Sanghyeon <sanxiyn@gmail.com>
|
|||||||
Stefan Penner <stefan.penner@gmail.com>
|
Stefan Penner <stefan.penner@gmail.com>
|
||||||
Sylvestre Ledru <sledru@mozilla.com>
|
Sylvestre Ledru <sledru@mozilla.com>
|
||||||
Taketoshi Aono <brn@b6n.ch>
|
Taketoshi Aono <brn@b6n.ch>
|
||||||
|
Teddy Katz <teddy.katz@gmail.com>
|
||||||
Tiancheng "Timothy" Gu <timothygu99@gmail.com>
|
Tiancheng "Timothy" Gu <timothygu99@gmail.com>
|
||||||
Tobias Burnus <burnus@net-b.de>
|
Tobias Burnus <burnus@net-b.de>
|
||||||
Victor Costan <costan@gmail.com>
|
Victor Costan <costan@gmail.com>
|
||||||
|
@ -1015,7 +1015,7 @@ bool Scanner::ScanEscape() {
|
|||||||
case '5': // fall through
|
case '5': // fall through
|
||||||
case '6': // fall through
|
case '6': // fall through
|
||||||
case '7':
|
case '7':
|
||||||
c = ScanOctalEscape<capture_raw>(c, 2);
|
c = ScanOctalEscape<capture_raw>(c, 2, in_template_literal);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1024,9 +1024,8 @@ bool Scanner::ScanEscape() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <bool capture_raw>
|
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';
|
uc32 x = c - '0';
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < length; i++) {
|
for (; i < length; i++) {
|
||||||
@ -1044,7 +1043,9 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
|
|||||||
// occur before the "use strict" directive.
|
// occur before the "use strict" directive.
|
||||||
if (c != '0' || i > 0 || c0_ == '8' || c0_ == '9') {
|
if (c != '0' || i > 0 || c0_ == '8' || c0_ == '9') {
|
||||||
octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1);
|
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;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ class Scanner {
|
|||||||
|
|
||||||
// Scans octal escape sequence. Also accepts "\0" decimal escape sequence.
|
// Scans octal escape sequence. Also accepts "\0" decimal escape sequence.
|
||||||
template <bool capture_raw>
|
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.
|
// Call this after setting source_ to the input.
|
||||||
void Init() {
|
void Init() {
|
||||||
|
7
test/message/fail/octal-template-literal.js
Normal file
7
test/message/fail/octal-template-literal.js
Normal 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`
|
4
test/message/fail/octal-template-literal.out
Normal file
4
test/message/fail/octal-template-literal.out
Normal 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.
|
Loading…
Reference in New Issue
Block a user