ecma262 icon indicating copy to clipboard operation
ecma262 copied to clipboard

Note about [[TemplateMap]] in spec

Open dSalieri opened this issue 2 years ago • 2 comments

Note 1 of the [[TemplateMap]] says:

Once a Parse Node becomes unreachable, the corresponding [[Array]] is also unreachable, and it would be unobservable if an implementation removed the pair from the [[TemplateMap]] list.

So this must work as said above:

let tag = (arg) => arg;
let value = tag`test`;
tag = null;

Over the time occurs gc. Due with unreachable Parse Node the value will get undefined value.

But in fact it doesn't work properly as it said in note 1, value all the time will have value from [[Array]]


But if we use weakSet or weakMap or weakRef, so in that case it will follow to note 1.

let tag = (arg) => arg;
let value = new weakRef(tag`test`);
tag = null;

So when gc will have worked, we get value.deref() equal to undefined value


As a conclusion: If implementations works as spec says, so why does spec nothing message about weak structures and versa vice about "hard refs"? This note confuses you.

dSalieri avatar Sep 27 '23 21:09 dSalieri

The array becomes unreachable via the template map, but certainly if anything else has a reference to it it’ll still be reachable that way.

ljharb avatar Sep 27 '23 23:09 ljharb

I guess we could change the wording to say "unreachable via [[TemplateMap]]", though it's hard to believe anyone may seriously be confused by this.

michaelficarra avatar Sep 28 '23 04:09 michaelficarra