Reviewers: arv, Dmitry Lomov (chromium), marja,

Message:
PTAL

Things on the TODO list:

  - Don't duplicate code between ParseLeftHandSideExpression and
ParseMemberExpressionContinuation
  - More tests?

Description:
[es6] support template literals after MemberExpression

BUG=v8:3958, 450942
LOG=N
[email protected], [email protected]

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

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

Affected files (+65, -5 lines):
  M src/parser.cc
  M src/preparser.h
  M src/scanner.h
  M test/mjsunit/harmony/templates.js


Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index b57a545ffe0c6940f3d1fcc6dc6bfc71221081e9..7892089714f0f419e84a9965c12a73c529e475a0 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -5456,7 +5456,6 @@ Expression* Parser::CloseTemplateLiteral(TemplateLiteralState* state, int start,
     return expr;
   } else {
     uint32_t hash = ComputeTemplateLiteralHash(lit);
-
     int cooked_idx = function_state_->NextMaterializedLiteralIndex();
     int raw_idx = function_state_->NextMaterializedLiteralIndex();

Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index a17296349b362df6afefbb5b8538d7c030915270..e2c7d04077bc314aa9b75d930308c6c3a2346d64 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -2842,6 +2842,22 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(ExpressionT expression,
         }
         break;
       }
+      case Token::TEMPLATE_SPAN:
+      case Token::TEMPLATE_TAIL: {
+        int pos;
+        if (scanner()->current_token() == Token::IDENTIFIER) {
+          pos = position();
+        } else {
+          pos = peek_position();
+          if (expression->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
+ // If the tag function looks like an IIFE, set_parenthesized() to
+            // force eager compilation.
+            expression->AsFunctionLiteral()->set_parenthesized();
+          }
+        }
+        expression = ParseTemplateLiteral(expression, pos, CHECK_OK);
+        break;
+      }
       default:
         return expression;
     }
Index: src/scanner.h
diff --git a/src/scanner.h b/src/scanner.h
index 416b5a11ac3248488eff2f499891accb09bb3356..1ef6aa8f53b09434c75de2b4d356c71143c7e963 100644
--- a/src/scanner.h
+++ b/src/scanner.h
@@ -532,8 +532,11 @@ class Scanner {
   }

   inline void StartRawLiteral() {
-    raw_literal_buffer_.Reset();
-    next_.raw_literal_chars = &raw_literal_buffer_;
+    LiteralBuffer* free_buffer =
+        (current_.raw_literal_chars == &raw_literal_buffer1_) ?
+            &raw_literal_buffer2_ : &raw_literal_buffer1_;
+    free_buffer->Reset();
+    next_.raw_literal_chars = free_buffer;
   }

   INLINE(void AddLiteralChar(uc32 c)) {
@@ -716,7 +719,8 @@ class Scanner {
   LiteralBuffer source_mapping_url_;

   // Buffer to store raw string values
-  LiteralBuffer raw_literal_buffer_;
+  LiteralBuffer raw_literal_buffer1_;
+  LiteralBuffer raw_literal_buffer2_;

   TokenDesc current_;  // desc for current token (as returned by Next())
   TokenDesc next_;     // desc for next token (one token look-ahead)
Index: test/mjsunit/harmony/templates.js
diff --git a/test/mjsunit/harmony/templates.js b/test/mjsunit/harmony/templates.js index a884f58fb657b31d2cce4e51dd39e7ed831dd73c..49452f48ddb3668431b0de7e43b2d2a958a726c8 100644
--- a/test/mjsunit/harmony/templates.js
+++ b/test/mjsunit/harmony/templates.js
@@ -423,10 +423,12 @@ var obj = {
   Object.defineProperty(Array.prototype, 0, {
     set: function() {
       assertUnreachable();
-    }
+    },
+    configurable: true
   });
   function tag(){}
   tag`a${1}b`;
+  delete Array.prototype[0];
 })();


@@ -518,3 +520,42 @@ var obj = {
   assertThrows("`${(function() { \"use strict\"; return \"\\07\"; })()}`",
                SyntaxError);
 })();
+
+
+var global = this;
+(function testCallNew() {
+  "use strict";
+  var called = false;
+  var calledWith;
+  global.log = function(x) { called = true; calledWith = x; }
+
+  assertInstanceof(new(Function`log("test")`), Object);
+  assertTrue(called);
+  assertSame("test", calledWith);
+  delete global.log;
+})();
+
+
+(function testCallResultOfTagFn() {
+  "use strict";
+  var i = 0;
+  var raw = [];
+  function tag(cs) {
+    var args = Array.prototype.slice.call(arguments, 1);
+    args.unshift(cs);
+    var text = String.raw.apply(null, args);
+    if (i++ < 2) {
+      raw.push("tag;" + text);
+      return tag;
+    }
+
+    raw.push("raw;" + text);
+    return text;
+  }
+  assertEquals("test3", tag`test1``test2``test3`);
+  assertEquals([
+    "tag;test1",
+    "tag;test2",
+    "raw;test3"
+  ], raw);
+})();


--
--
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