TemplateMap: split TemplateMap cache test into own file

This commit is contained in:
Rick Waldron 2018-06-07 23:12:16 -04:00
parent 9388d6ad70
commit 2f201e5561
2 changed files with 42 additions and 16 deletions

View File

@ -0,0 +1,40 @@
// Copyright (C) 2018 Andrea Giammarchi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-gettemplateobject
description: >
Template objects are canonicalized separately for each realm using its Realm Record's [[TemplateMap]]. Each [[Site]] value is a Parse Node that is a TemplateLiteral
info: |
Let rawStrings be TemplateStrings of templateLiteral with argument true.
Let realm be the current Realm Record.
Let templateRegistry be realm.[[TemplateMap]].
For each element e of templateRegistry, do
If e.[[Site]] is the same Parse Node as templateLiteral, then
Return e.[[Array]].
---*/
var expect;
var cache = [];
function sameSite() {
tag`${Math.random()}`;
}
function tag(parameter) {
if (!expect) {
expect = parameter;
}
cache.push(parameter);
}
sameSite();
sameSite();
tag`${1}`;
sameSite();
sameSite();
assert(cache[0] === expect);
assert(cache[1] === expect);
assert(cache[2] !== expect);
assert(cache[3] === expect);
assert(cache[4] === expect);

View File

@ -1,18 +1,14 @@
// 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.3.7
esid: sec-gettemplateobject
description: Properties of the template object
info: |
The first argument to a tagged template should be a template object as
defined by the GetTemplateObject abstract operation.
includes: [propertyHelper.js]
---*/
var templateObject, sameObject;
function sameSite() {
tag`${Math.random()}`;
}
var templateObject
function tag(parameter) {
templateObject = parameter;
@ -44,13 +40,3 @@ verifyNotConfigurable(templateObject.raw, '0');
verifyNotEnumerable(templateObject.raw, 'length');
verifyNotWritable(templateObject.raw, 'length')
verifyNotConfigurable(templateObject.raw, 'length');
sameSite();
sameObject = templateObject;
sameSite();
assert(
templateObject === sameObject,
'Normative: Cache templates per site, rather than by contents'
// https://github.com/tc39/ecma262/pull/890
);