diff --git a/test/language/expressions/tagged-template/cache-different-functions-same-site.js b/test/language/expressions/tagged-template/cache-different-functions-same-site.js new file mode 100644 index 0000000000000000000000000000000000000000..91a554b8b194a22ed3a88f41eee5d54e19719462 --- /dev/null +++ b/test/language/expressions/tagged-template/cache-different-functions-same-site.js @@ -0,0 +1,38 @@ +// Copyright (C) 2017 the V8 project authors. 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: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. +---*/ +function tag(templateObject) { + previousObject = templateObject; +} + +var a = 1; +var firstObject = null; +var previousObject = null; + +function factory() { + return function() { + tag`head${a}tail`; + } +} + +factory()(); +firstObject = previousObject; + +assert(firstObject !== null); +previousObject = null; + +factory()(); + +assert.sameValue( + previousObject, + firstObject, + 'The realm\'s template cache is for source code locations in a function' +); + diff --git a/test/language/expressions/tagged-template/cache-differing-expressions-eval.js b/test/language/expressions/tagged-template/cache-differing-expressions-eval.js index 1ae1f2d9927595ac2256451c53304218fb0276ef..3c89f7fcdab0fb2769107fd7771408ca3366187e 100644 --- a/test/language/expressions/tagged-template/cache-differing-expressions-eval.js +++ b/test/language/expressions/tagged-template/cache-differing-expressions-eval.js @@ -1,13 +1,12 @@ // Copyright (C) 2014 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 12.2.8 +esid: sec-gettemplateobject description: Template caching using distinct expressions within `eval` -info: | - Previously-created template objects should be retrieved from the internal - template registry when their source is identical but their expressions - evaluate to different values and the tagged template is being evaluated in - an `eval` context. +info: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. ---*/ function tag(templateObject) { previousObject = templateObject; @@ -23,4 +22,4 @@ assert(firstObject !== null); previousObject = null; eval('tag`head${b}tail`'); -assert.sameValue(previousObject, firstObject); +assert.notSameValue(previousObject, firstObject); diff --git a/test/language/expressions/tagged-template/cache-differing-expressions-new-function.js b/test/language/expressions/tagged-template/cache-differing-expressions-new-function.js index f909e9b9441bebef3e3608541c7e47d53409b185..35dcf4485fea3a2973c411fc4b1683246b5c1b38 100644 --- a/test/language/expressions/tagged-template/cache-differing-expressions-new-function.js +++ b/test/language/expressions/tagged-template/cache-differing-expressions-new-function.js @@ -1,13 +1,12 @@ // Copyright (C) 2014 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 12.2.8 +esid: sec-gettemplateobject description: Template caching using distinct expressions within `new Function` -info: | - Previously-created template objects should be retrieved from the internal - template registry when their source is identical but their expressions - evaluate to different values and the tagged template is being evaluated in - an `eval` context. +info: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. ---*/ function tag(templateObject) { previousObject = templateObject; @@ -23,8 +22,8 @@ assert(firstObject !== null); previousObject = null; (new Function('tag', 'a', 'b', 'return tag`head${b}tail`;'))(tag, 1, 2); -assert.sameValue( +assert.notSameValue( previousObject, firstObject, - 'The realm\'s template cache is referenced when tagged templates are declared within "new Function" contexts and templated values differ' + 'The realm\'s template cache is by site, not string contents' ); diff --git a/test/language/expressions/tagged-template/cache-differing-expressions.js b/test/language/expressions/tagged-template/cache-differing-expressions.js index 17689d87dfedebe5787454424d08cfda7348709a..dd0b70cc40d1e9c492d61aa9c8dfdf916ca9da10 100644 --- a/test/language/expressions/tagged-template/cache-differing-expressions.js +++ b/test/language/expressions/tagged-template/cache-differing-expressions.js @@ -1,12 +1,12 @@ // Copyright (C) 2014 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 12.2.8 +esid: sec-gettemplateobject description: Template caching using distinct expressions -info: | - Previously-created template objects should be retrieved from the internal - template registry when their source is identical but their expressions - evaluate to different values. +info: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. ---*/ function tag(templateObject) { previousObject = templateObject; @@ -22,4 +22,4 @@ assert(firstObject !== null); previousObject = null; tag`head${b}tail`; -assert.sameValue(previousObject, firstObject); +assert.notSameValue(previousObject, firstObject); diff --git a/test/language/expressions/tagged-template/cache-differing-raw-strings.js b/test/language/expressions/tagged-template/cache-differing-raw-strings.js index 7e3cbeceff6270b0687d3a52de57cf2d602b6968..54ee21ba485f3fd4d6e32b506915926ab562345b 100644 --- a/test/language/expressions/tagged-template/cache-differing-raw-strings.js +++ b/test/language/expressions/tagged-template/cache-differing-raw-strings.js @@ -1,11 +1,12 @@ // Copyright (C) 2014 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 12.2.8 -description: Templates are cached according to their "raw" representation -info: | - The internal template registry should be queried according to the "raw" - strings of the tagged template. +esid: sec-gettemplateobject +description: Templates are cached according to their site +info: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. ---*/ var previousObject = null; var firstObject = null; diff --git a/test/language/expressions/tagged-template/cache-differing-string-count.js b/test/language/expressions/tagged-template/cache-differing-string-count.js index 6e02a124bea7151cbe3ab2cdab52a8cd29d407c6..bebf79b1a0ff1f2c4ca3508e52603eb199a0a23b 100644 --- a/test/language/expressions/tagged-template/cache-differing-string-count.js +++ b/test/language/expressions/tagged-template/cache-differing-string-count.js @@ -1,11 +1,12 @@ // Copyright (C) 2014 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 12.2.8 -description: Templates are cached according to the number of "raw" strings -info: | - The internal template registry should be queried according to the number of - "raw" strings in the tagged template. +esid: sec-gettemplateobject +description: Templates are cached according to the site +info: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. ---*/ var previousObject = null; var firstObject = null; diff --git a/test/language/expressions/tagged-template/cache-identical-source-eval.js b/test/language/expressions/tagged-template/cache-identical-source-eval.js index e7e3078e64c2616bbb584ac6e5aac1421f36bb8e..3a2a24f2c75a5469a1ed010d38800dcbe1867d30 100644 --- a/test/language/expressions/tagged-template/cache-identical-source-eval.js +++ b/test/language/expressions/tagged-template/cache-identical-source-eval.js @@ -1,12 +1,12 @@ // Copyright (C) 2014 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 12.2.8 -description: Template caching using identical expressions within `eval` -info: | - Previously-created template objects should be retrieved from the internal - template registry when their source is identical and the tagged template is - being evaluated in an `eval` context. +esid: sec-gettemplateobject +description: Templates are cached by site, even using identical expressions within `eval` +info: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. ---*/ function tag(templateObject) { previousObject = templateObject; @@ -21,4 +21,4 @@ assert(firstObject !== null); previousObject = null; eval('tag`head${a}tail`'); -assert.sameValue(previousObject, firstObject); +assert.notSameValue(previousObject, firstObject); diff --git a/test/language/expressions/tagged-template/cache-identical-source-new-function.js b/test/language/expressions/tagged-template/cache-identical-source-new-function.js index da0393f7233b9534a4968b1363cd227471c15383..01a5dd57ff1d3a8e2401bc211b89ac75623f9b01 100644 --- a/test/language/expressions/tagged-template/cache-identical-source-new-function.js +++ b/test/language/expressions/tagged-template/cache-identical-source-new-function.js @@ -1,12 +1,12 @@ // Copyright (C) 2014 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 12.2.8 -description: Template caching using identical expressions within `new Function` -info: | - Previously-created template objects should be retrieved from the internal - template registry when their source is identical and the tagged template is - being evaluated in a `new Function` context. +esid: sec-gettemplateobject +description: Template caching is by site, using identical expressions within `new Function` +info: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. ---*/ function tag(templateObject) { previousObject = templateObject; @@ -21,4 +21,4 @@ assert(firstObject !== null); previousObject = null; (new Function('tag', 'a', 'b', 'return tag`head${b}tail`;'))(tag, 1, 2); -assert.sameValue(previousObject, firstObject); +assert.notSameValue(previousObject, firstObject); diff --git a/test/language/expressions/tagged-template/cache-identical-source.js b/test/language/expressions/tagged-template/cache-identical-source.js index c6a5644a06fb6554ce6bce43608268fdba6f2fed..436aea6bdede9e274e6d1463404278d0073afb3f 100644 --- a/test/language/expressions/tagged-template/cache-identical-source.js +++ b/test/language/expressions/tagged-template/cache-identical-source.js @@ -1,11 +1,12 @@ // Copyright (C) 2014 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 12.2.8 -description: Template caching using identical expressions -info: | - Previously-created template objects should be retrieved from the internal - template registry when their source is identical. +esid: sec-gettemplateobject +description: Templates are cached by site, even when using identical expressions +info: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. ---*/ function tag(templateObject) { previousObject = templateObject; @@ -20,8 +21,8 @@ assert(firstObject !== null); previousObject = null; tag`head${a}tail`; -assert.sameValue( +assert.notSameValue( previousObject, firstObject, - 'The realm\'s template cache is used when tagged templates are executed in the source code directly' + 'The realm\'s template cache is by site, not string contents' ); diff --git a/test/language/expressions/tagged-template/cache-realm.js b/test/language/expressions/tagged-template/cache-realm.js index 039d9ba171efd6e34249a1ceb494db3ba9ee76ef..2d185391c12050f7454cbbfe8604812f435cfb6f 100644 --- a/test/language/expressions/tagged-template/cache-realm.js +++ b/test/language/expressions/tagged-template/cache-realm.js @@ -25,8 +25,7 @@ info: | 2. Let realm be the current Realm Record. 3. Let templateRegistry be realm.[[TemplateMap]]. 4. For each element e of templateRegistry, do - a, If e.[[Strings]] and rawStrings contain the same values in the same - order, then + a. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then i. Return e.[[Array]]. features: [cross-realm] ---*/ diff --git a/test/language/expressions/tagged-template/cache-same-site-top-level.js b/test/language/expressions/tagged-template/cache-same-site-top-level.js new file mode 100644 index 0000000000000000000000000000000000000000..6968f3f3c3bc8a97ef0690f731582f999ff208cc --- /dev/null +++ b/test/language/expressions/tagged-template/cache-same-site-top-level.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 the V8 project authors. 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: > + 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 templates = []; + +function tag(templateObject) { + templates.push(templateObject); +} + +let a = 1; +for (let i = 0; i < 2; i++) { + tag`head${a}tail`; +} + +assert.sameValue(templates.length, 2); + +assert.sameValue( + templates[0], + templates[1], + 'The realm\'s template cache is for source code locations in a top-level script' +); + + diff --git a/test/language/expressions/tagged-template/cache-same-site.js b/test/language/expressions/tagged-template/cache-same-site.js new file mode 100644 index 0000000000000000000000000000000000000000..ab37d62502b8048f5aaf8f689c7ea33ffb181b4c --- /dev/null +++ b/test/language/expressions/tagged-template/cache-same-site.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 the V8 project authors. 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: > + 1. For each element _e_ of _templateRegistry_, do + 1. If _e_.[[Site]] is the same Parse Node as _templateLiteral_, then + 1. Return _e_.[[Array]]. +---*/ +function tag(templateObject) { + previousObject = templateObject; +} + +var a = 1; +var firstObject = null; +var previousObject = null; + +function runTemplate() { + tag`head${a}tail`; +} + +runTemplate(); +firstObject = previousObject; + +assert(firstObject !== null); +previousObject = null; + +runTemplate(); + +assert.sameValue( + previousObject, + firstObject, + 'The realm\'s template cache is for source code locations in a function' +); +