let t = "tag`hello, ${world}.`";
eval(t);
eval(t);
or
new Function(t)();
new Function(t)();
Do each of these pairs compile into different call sites or are they the same call site? I'm inclined to say different. That each parse of an input string whether via eval, the function constructor, or module/script loading represent a logically distinct input into the ES environment.
Needs to be explicitly clarified in the spec.
I think they must be different. I don't see how any other answer is possible without very surprising sharing of object-identity.
(In reply to comment #1)
I generally agree with you, but is two new function calls on the same string really that different from two closures created from the same source code?
Hi Allen, I didn't understand your response. Can you expand? Thanks.
(In reply to Mark Miller from comment #3)
> Hi Allen, I didn't understand your response. Can you expand? Thanks.
What meant is that that there is really not very much difference (ignoring scoping issues) between:
function makeFunction() {return function inner() {return tag`hello, ${world}.`}};
var c1 = makeFunction();
var c2 = makeFunction();
//c1 and c2 are different function objects derived from the same source code //definition,
// there is a single template string call site shared by both of them.
and this:
let t = "tag`hello, ${world}.`";
var c3 = new Function(t);
var c4 = new Function(t);
//c3 and c4 are different function objects derived from the same source code //definition,
//There is a different template string call site for each of them.
except that in the second case isn't very different from the first case, except we are arbitrarily saying two call sites are created instead of one.
fixed in rev29 draft
template caching is now per realm and based upon string equality of list of raw template segments.