From 0b54908dba8d4fdad41e4c6216d13149f6ecf379 Mon Sep 17 00:00:00 2001
From: Daniel Ehrenberg <littledan@chromium.org>
Date: Tue, 27 Feb 2018 23:46:44 +0100
Subject: [PATCH] Add test for eval-in-function template tags (#1457)

Thanks to Caitin Potter for highlighting this test case.
---
 .../cache-eval-inner-function.js              | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 test/language/expressions/tagged-template/cache-eval-inner-function.js

diff --git a/test/language/expressions/tagged-template/cache-eval-inner-function.js b/test/language/expressions/tagged-template/cache-eval-inner-function.js
new file mode 100644
index 0000000000..4963d04c51
--- /dev/null
+++ b/test/language/expressions/tagged-template/cache-eval-inner-function.js
@@ -0,0 +1,35 @@
+// Copyright (C) 2018 Igalia, S. L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-gettemplateobject
+description: Templates are cached by source location inside a function
+info: >
+    Each time eval is called, it is a different site. However, a loop within
+    the eval is considered the same site. This is a regression test for an
+    issue that Caitlin Potter faced in implementations of the new template
+    caching semantics in both V8 and JSC.
+
+    1. For each element _e_ of _templateRegistry_, do
+      1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then
+        1. Return _e_.[[Array]].
+---*/
+
+let objs = [];
+function tag(templateObject) {
+  objs.push(templateObject);
+}
+
+for (let a = 0; a < 2; a++) {
+  eval("\
+    (function() {\
+      for (let b = 0; b < 2; b++) {\
+        tag`${a}${b}`;\
+      }\
+    })();\
+  ");
+}
+
+assert.sameValue(objs[0], objs[1]);
+assert.notSameValue(objs[1], objs[2]);
+assert.sameValue(objs[2], objs[3]);
+
-- 
GitLab