Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normative: Remove [[VarNames]] from the global #3226

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

syg
Copy link
Contributor

@syg syg commented Nov 20, 2023

I noticed this due to a recent test262 test from @shvaikalesh: tc39/test262#3914

The explainer has been pulled into a proposal repo: https://github.com/tc39-transfer/proposal-redeclarable-global-eval-vars

This PR still serves as the spec draft.

The upshot of this change is that global var bindings introduced by
sloppy direct eval becomes redeclarable by lexical bindings.
@syg syg added the normative change Affects behavior required to correctly evaluate some ECMAScript source text label Nov 20, 2023
@syg syg added the needs consensus This needs committee consensus before it can be eligible to be merged. label Nov 20, 2023
@michaelficarra michaelficarra added the needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 label Nov 21, 2023
@shvaikalesh
Copy link
Member

@syg This is a totally awesome proposal! Would love to implement.

@bakkot
Copy link
Contributor

bakkot commented Jan 29, 2024

To be clear, the only observable change here is that if you have something like

<script>
eval('var x;')
</script>
<script>
let x;
</script>

that is current an error (per spec), and with this PR it would not be?

@syg
Copy link
Contributor Author

syg commented Jan 29, 2024

Re: #3226 (comment)

Yep, that's the intention. Same for functions introduced by sloppy eval also no longer erroring. That is, the following would no longer error with this PR.

<script>
eval('function x() {}')
</script>
<script>
let x;
</script>

Edit: Another importance difference is also that you shadow the binding. So in the function example above, x after let x evaluates will now be undefined, while globalThis.x remains the function.

This may be an unintuitive and undesirable result, but my feeling with that is, as with many things, "just don't do that".

@syg
Copy link
Contributor Author

syg commented Feb 6, 2024

At the February 2024 TC39 it was decided that this PR be moved into its own proposal (which I will do after plenary).

@syg syg added the pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. label Feb 14, 2024
syg added a commit to syg/test262 that referenced this pull request Apr 8, 2024
ptomato pushed a commit to syg/test262 that referenced this pull request Apr 12, 2024
ptomato pushed a commit to tc39/test262 that referenced this pull request Apr 12, 2024
@syg syg added has test262 tests and removed needs consensus This needs committee consensus before it can be eligible to be merged. needs test262 tests The proposal should specify how to test an implementation. Ideally via github.com/tc39/test262 labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants