Check for octals in template spans only, not expressions

BUG=v8:3806
LOG=N
R=arv@chromium.org, dslomov@chromium.org

Review URL: https://codereview.chromium.org/808793004

Cr-Commit-Position: refs/heads/master@{#26028}
This commit is contained in:
caitpotter88 2015-01-12 07:07:36 -08:00 committed by Commit bot
parent 0e8a6d4ec8
commit 4b6316c5ff
2 changed files with 16 additions and 2 deletions

View File

@ -2874,6 +2874,7 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) {
// case, representing a TemplateMiddle).
do {
CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK);
next = peek();
if (!next) {
ReportMessageAt(Scanner::Location(start, peek_position()),
@ -2897,10 +2898,10 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) {
// TEMPLATE_SPAN or TEMPLATE_TAIL.
next = scanner()->ScanTemplateContinuation();
Next();
pos = position();
if (!next) {
ReportMessageAt(Scanner::Location(start, position()),
"unterminated_template");
ReportMessageAt(Scanner::Location(start, pos), "unterminated_template");
*ok = false;
return Traits::EmptyExpression();
}

View File

@ -505,3 +505,16 @@ var obj = {
assertEquals("\u00008", `\08`);
assertEquals("\u00009", `\09`);
})();
(function testLegacyOctalEscapesInExpressions() {
// Allowed in sloppy expression
assertEquals("\x07", `${"\07"}`);
// Disallowed in template tail
assertThrows("`${\"\\07\"}\\07`", SyntaxError);
// Disallowed in strict expression
assertThrows("`${(function() { \"use strict\"; return \"\\07\"; })()}`",
SyntaxError);
})();