Andreas Rossberg (2013-08-19T17:20:46.000Z)
domenic at domenicdenicola.com (2013-08-23T16:05:15.847Z)
On 19 August 2013 19:02, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote: > I don't think so. according to ES5 10.4.2 The VariableEnvironment of the eval'ed code should be set to the VariableEnvironment of the calling context. That variable environment is the outer cope of function f that has 0 as the value of its x binding. When g is instantiated that variable environment will be its [[Scope]] so "return x" should return 0. You are right, although the discrepancy between FunctionExpression and FunctionDeclaration feels really odd -- I wonder how that came about. It also means that both Firefox and Safari handle the example incorrectly (though at least they don't crash :) ). > It seems like this could be specified such that sloppy direct eval instantiates such functions using exactly the ES5 scoping rules. However, I suspect that is likely to cause even more confusion in the future. I agree, that sounds like a rather unattractive solution. > Does V8 crash on the simpler example? Does it produce a ReferenceError (not conforming to ES5) on the call to g()? You're implementation may be the best test of what occurs in practice. V8 works fine on the simpler example, and it seems that FF and Safari do, too. So such code could be out in the wild.