Four static scoping violations in ES5 sloppy

Domenic Denicola domenic at domenicdenicola.com
Mon Mar 18 05:28:10 PDT 2013


On Mar 18, 2013, at 7:54, "Sam Tobin-Hochstadt" <samth at ccs.neu.edu> wrote:

> On Sun, Mar 17, 2013 at 11:44 PM, Domenic Denicola
> <domenic at domenicdenicola.com> wrote:
>> 
>> 1. implicit global variable creation
>> 2. `with`
>> 3. `delete`ing free variables
>> 4. `eval` introducing local bindings
>> 
>> 2 and 4 make perfect sense, but I don't understand how 1 and 3 interfere with static scoping. In particular, given a language with no `with` and with ES5-strict semantics for `eval`, I was unable to contrive scenarios where implicit global variable creation or `delete`ing a free variable introduced an ambiguity in the scope chain that prevented static knowledge of what an identifier referred to.
>> 
>> Does anyone have any idea how 1 and 3 interfere with static scoping?
> 
> The point is that given these features, you can't predict statically
> whether a variable reference is bound to a global variable, or is
> unbound and will produce a ReferenceError.
> 
> Here's case 1:
> 
> if (something_random()) window.xxx = 7;
> xxx; // ReferenceError or not?
> 
> And here's case 3:
> 
> if (something_else_random()) delete xxx;
> xxx; // ReferenceError or not?

Thanks, but what does your example for case 1 have to do with implicit global variable creation? 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 window.xxx` 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.


More information about the es-discuss mailing list