Check for octals in template spans only, not expressions
authorcaitpotter88 <caitpotter88@gmail.com>
Mon, 12 Jan 2015 15:07:36 +0000 (07:07 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 12 Jan 2015 15:07:47 +0000 (15:07 +0000)
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
test/mjsunit/harmony/templates.js

index 18004a5..2ffd358 100644 (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();
     }
index c339bb8..a884f58 100644 (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);
+})();