[[VarNames]],
What Is It Good For?
"Well, I think absolutely nothing."
– Shu-yu Guo (Google), Feb Apr 2024 TC39
What is [[VarNames]]
So,
What is [[VarNames]]
<script>
var x;
</script>
<script>
let x;
</script>
This is disallowed.
Fine. Good. Whatever.
What is [[VarNames]]
<script>
Object.defineProperty(
globalThis, 'x',
{ value:42, configurable:false });
</script>
<script>
let x;
</script>
This is also disallowed.
…Okay. Sure. Seems fine.
What is [[VarNames]]
<script>
eval('var x');
</script>
<script>
let x;
</script>
This is also disallowed.
Seems fine, except…
how do you implement it?
Remember the direct eval var semantics
<script>
globalThis.x = 42;
</script>
<script>
let x;
</script>
[[VarNames]] distinguishes eval-introduced vars
So [[VarNames]] is a list on the global environment whose sole purpose is to distinguish sloppy-direct-eval-introduced vars from ordinary configurable properties
Are there actual use cases?
Current semantics
In the global scope,
Proposal
In the global scope,
Upshot
<script>
eval('var x');
</script>
<script>
let x;
</script>
This is now allowed.
let x will shadow.
Updates from last time
Stage 2.7?