Four static scoping violations in ES5 sloppy

Domenic Denicola domenic at
Mon Mar 18 06:30:26 PDT 2013

From: Sam Tobin-Hochstadt

> On Mon, Mar 18, 2013 at 8:40 AM, Andreas Rossberg <rossberg at> wrote:
>> Nothing, but Sam probably meant to write:
>> if (something_random()) xxx = 7;
>> xxx; // ReferenceError or not?
> Right, I was confusing the problem this code describes, which is what I think Mark meant, with the problem of the global object being on the scope chain.
>>> It actually demonstrates how the situation is exactly the same with *explicit* global variable creation. Strict mode does nothing to change the result.
>>> Similarly, in case 3, the code could be `delete` and we still cannot statically predict whether there's a `ReferenceError` on the subsequent line or not. Again, strict mode does not change the result.
>> That is true, and the proper answer is that the global object should be on the above list as well. Not sure why Mark did not include it.
> I believe that Mark would distinguish 1-4, which are fixed by strict mode, from the global object, which is the remaining issue in ES5.

Last time this came up:

it was clarified that the global object is not a static scoping violation, since it's the top-most in the scope chain. Thus we know that every binding that's not in the nested function environments must be on the global object—or not exist.

That's the essence of my confusion. Cases 1 and 3 do not change things. That is, `xxx = 7` versus ` = 7` doesn't change where we determine `xxx` to be: it must be global (if it exists at all). Similarly, `delete xxx` versus `delete` doesn't change that `xxx` must be global or not exist. And strict mode prohibits the former of these two forms, but doesn't prohibit the latter, and so seems to have no impact.

Now, if `with` and sloppy `eval` weren't removed, I could see the argument, at least for `delete`:

but with those two gone (i.e. with 2 and 4 gone), 1 and 3 seem to not matter.

> But only Mark can answer this for sure.

Indeed :)

More information about the es-discuss mailing list