Four static scoping violations in ES5 sloppy

Sam Tobin-Hochstadt samth at ccs.neu.edu
Mon Mar 18 04:54:20 PDT 2013


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?

Sam


More information about the es-discuss mailing list