From 4b6316c5ff5e88bd38ffed453c70052be175eecd Mon Sep 17 00:00:00 2001 From: caitpotter88 Date: Mon, 12 Jan 2015 07:07:36 -0800 Subject: [PATCH] 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} --- src/preparser.h | 5 +++-- test/mjsunit/harmony/templates.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/preparser.h b/src/preparser.h index 18004a5096..2ffd358022 100644 --- a/src/preparser.h +++ b/src/preparser.h @@ -2874,6 +2874,7 @@ ParserBase::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::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(); } diff --git a/test/mjsunit/harmony/templates.js b/test/mjsunit/harmony/templates.js index c339bb8cc7..a884f58fb6 100644 --- a/test/mjsunit/harmony/templates.js +++ b/test/mjsunit/harmony/templates.js @@ -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); +})();