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

let/const/class allow local binding of "undefined" #830

Open
allenwb opened this Issue Mar 1, 2017 · 9 comments

Comments

Projects
None yet
7 participants
@allenwb
Member

allenwb commented Mar 1, 2017

I was rather shocked today to discover that since their introduction in ES2015 let, const, class and other new binding forms have allowed undefined to be used as a local binding identifier. Even in strict mode.

I think this was an oversight in ES2015. In ES5 we made the global property "undefined" non-configurable and non-writable. But we did not prevent var and function declarations from binding undefined. This was necessary because there were widely used coding patterns where the mutability of the global "undefined" property was mitigated by usingvar to redeclare undefined.

But, let/const/class were new constructs in ES2015 and that backwards compat constraint should not have applied to them.

I don't know if we could get away with fixing this now but I think we should at least investigate the possibility.

@NE-SmallTown

This comment has been minimized.

Show comment
Hide comment
@NE-SmallTown

NE-SmallTown Mar 2, 2017

I am in chrome 53,my test shows that they can't.

Sorry,I am not a member,I don't know much details about you say of the spec,just hope that this will helps.

NE-SmallTown commented Mar 2, 2017

I am in chrome 53,my test shows that they can't.

Sorry,I am not a member,I don't know much details about you say of the spec,just hope that this will helps.

@bakkot

This comment has been minimized.

Show comment
Hide comment
@bakkot

bakkot Mar 2, 2017

Contributor

@NE-SmallTown, at the top level they're prohibited because they're restricted globals. Allen is observing that they're not restricted elsewhere: { let undefined; } is legal.

Contributor

bakkot commented Mar 2, 2017

@NE-SmallTown, at the top level they're prohibited because they're restricted globals. Allen is observing that they're not restricted elsewhere: { let undefined; } is legal.

@NE-SmallTown

This comment has been minimized.

Show comment
Hide comment
@NE-SmallTown

NE-SmallTown Mar 2, 2017

@bakkot Sorry for the cursory test.I test again,Allen is right,it does questionable.

NE-SmallTown commented Mar 2, 2017

@bakkot Sorry for the cursory test.I test again,Allen is right,it does questionable.

@allenwb allenwb changed the title from let/const/class allow binding of "undefined" to let/const/class allow local binding of "undefined" Mar 2, 2017

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson Mar 2, 2017

Member

I recall raising this back in the day but the thinking was it's fine since you can't redeclare undefined and you can only look up to an undefined binding in your own code (so it is much less bad than ye olde undefined = true). I'm ok fixing it still :)

Member

bterlson commented Mar 2, 2017

I recall raising this back in the day but the thinking was it's fine since you can't redeclare undefined and you can only look up to an undefined binding in your own code (so it is much less bad than ye olde undefined = true). I'm ok fixing it still :)

@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb Mar 2, 2017

Member

It seems similar, to the strict mode restriction on redeclaring eval and arguments. It just shouldn't be allowed.

Member

allenwb commented Mar 2, 2017

It seems similar, to the strict mode restriction on redeclaring eval and arguments. It just shouldn't be allowed.

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Mar 21, 2018

Member

Is this something that could be a Needs-Consensus PR?

Member

ljharb commented Mar 21, 2018

Is this something that could be a Needs-Consensus PR?

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Apr 4, 2018

Member

For the reasons in #830 (comment) , I am not convinced this is a problem.

Member

littledan commented Apr 4, 2018

For the reasons in #830 (comment) , I am not convinced this is a problem.

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

claudepache Apr 5, 2018

Contributor

Note that undefined is not alone in that case, as other ”global constants”, namely NaN and Infinity, may be locally rebound as well.

(BTW, I wonder why global.NaN is nonwritable, whilst global.eval is writable.)

Contributor

claudepache commented Apr 5, 2018

Note that undefined is not alone in that case, as other ”global constants”, namely NaN and Infinity, may be locally rebound as well.

(BTW, I wonder why global.NaN is nonwritable, whilst global.eval is writable.)

@claudepache

This comment has been minimized.

Show comment
Hide comment
@claudepache

claudepache Apr 5, 2018

Contributor

(BTW, I wonder why global.NaN is nonwritable, whilst global.eval is writable.)

(Ok, I guess that window.eval = function(x) { throw new EvalError; } /* let’s remove dangerous toys! */ is reasonable, but window.Infinity = 2038; /* it’s distant enough! */ is not.)

Contributor

claudepache commented Apr 5, 2018

(BTW, I wonder why global.NaN is nonwritable, whilst global.eval is writable.)

(Ok, I guess that window.eval = function(x) { throw new EvalError; } /* let’s remove dangerous toys! */ is reasonable, but window.Infinity = 2038; /* it’s distant enough! */ is not.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment