Reviewers: arv, Dmitry Lomov (chromium),

Message:
PTAL

I guess `!token` isn't good enough for Token::EOS and Token::ILLEGAL :(

Description:
Report SyntaxError on Token::ILLEGAL in ParseTemplateLiteral

BUG=v8:3820, v8:3821
LOG=N
[email protected], [email protected]

Please review this at https://codereview.chromium.org/857433004/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+36, -2 lines):
  M src/preparser.h
  M test/cctest/test-parsing.cc


Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index f67c7563d04099b0f080e9b1995abb4c07631074..09f6b1dc3d51c26b9cc1b7badc3b11a9139bf78a 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2942,11 +2942,17 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) {
   do {
     CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK);
     next = peek();
-    if (!next) {
+    if (next == Token::EOS) {
       ReportMessageAt(Scanner::Location(start, peek_position()),
                       "unterminated_template");
       *ok = false;
       return Traits::EmptyExpression();
+    } else if (next == Token::ILLEGAL) {
+      Traits::ReportMessageAt(
+          Scanner::Location(position() + 1, peek_position()),
+          "unexpected_token", "ILLEGAL", false);
+      *ok = false;
+      return Traits::EmptyExpression();
     }

     int expr_pos = peek_position();
@@ -2966,10 +2972,16 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) {
     Next();
     pos = position();

-    if (!next) {
+    if (next == Token::EOS) {
ReportMessageAt(Scanner::Location(start, pos), "unterminated_template");
       *ok = false;
       return Traits::EmptyExpression();
+    } else if (next == Token::ILLEGAL) {
+      Traits::ReportMessageAt(
+          Scanner::Location(position() + 1, peek_position()),
+          "unexpected_token", "ILLEGAL", false);
+      *ok = false;
+      return Traits::EmptyExpression();
     }

     Traits::AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL);
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index f08f9b31d901eb4c1b0483d4f2426d8437a8104f..24da4c7a06bc06164895dda8ab62462d111e117d 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -4552,6 +4552,28 @@ TEST(ScanUnterminatedTemplateLiterals) {
 }


+TEST(TemplateLiteralsIllegalTokens) {
+  const char* context_data[][2] = {{"'use strict';", ""},
+                                   {"function foo(){ 'use strict';"
+                                    "  var a, b, c; return ", "}"},
+                                   {NULL, NULL}};
+  const char* data[] = {
+      "`hello\\x`",
+      "`hello\\x${1}`",
+      "`hello${1}\\x`",
+      "`hello${1}\\x${2}`",
+      "`hello\\x\n`",
+      "`hello\\x\n${1}`",
+      "`hello${1}\\x\n`",
+      "`hello${1}\\x\n${2}`",
+      NULL};
+
+  static const ParserFlag always_flags[] = {kAllowHarmonyTemplates};
+  RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+                    arraysize(always_flags));
+}
+
+
 TEST(LexicalScopingSloppyMode) {
   const char* context_data[][2] = {
       {"", ""},


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to