-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for change to cache templates by site, not contents (#972)
* Test for change to cache templates by site, not contents These tests are against a specification change based on discussion in tc39/ecma262#840 The tests here passed on SpiderMonkey but failed on other implementations, which implement the current specification. * Add a test that caching is by source location, not function identity * Update existing tests to reference the spec properly
- Loading branch information
Showing
12 changed files
with
159 additions
and
54 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
test/language/expressions/tagged-template/cache-different-functions-same-site.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
test/language/expressions/tagged-template/cache-differing-raw-strings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
test/language/expressions/tagged-template/cache-differing-string-count.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/language/expressions/tagged-template/cache-same-site-top-level.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
); | ||
|
||
|
36 changes: 36 additions & 0 deletions
36
test/language/expressions/tagged-template/cache-same-site.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
); | ||
|