While polishing some remaining corners of lexical scoping support in
V8, we stumbled over the following.

ES5 has the invariant that any identifier not found on the scope chain
_has to be_ a property of the global object (except in the presence of
'with' or sloppy direct eval), or be a reference error. In particular,
this guarantees that the compiler usually knows that 'undefined' is
bound to the undefined value, and similarly for other frozen
properties of the global object.

In ES6, this no longer seems to be the case, due to the mutable
toplevel lexical scope. At least I wasn't able to find language in the
draft that would make the following example illegal:

  <>
  function f(x) { return x === undefined }
  </>

  <>
  let undefined = 666
  f()  // false
  </>

Is that correct?

(I would have expected the VarNames list of the initial global
environment to contain all global names from Sec. 18, but that doesn't
seem to be the case.)

If so, how do we fix this? Allowing shadowing after the fact is pretty
bad, since it will probably make all accesses to builtin globals
slower in ES6. But it is particularly bad for 'undefined', where the
ability to rebind would break various assumptions and optimisations
based on its immutability.

/Andreas
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to