eval

Geoffrey Garen ggaren at apple.com
Wed Mar 5 19:26:28 PST 2008


Hi all.

I'm trying to implement an ES4-compliant version of eval, but I'm  
having trouble understanding what the specified behavior is.

In ES4,

     eval(x)

is distinct from all of

     window.eval(x)

     eval.call(myThisObject, x)

     frames[0].eval(x)

in that the first form is an operator, and the last three forms are  
function calls.

Right?

OK, for the eval operator, the eval function, the eval function called  
with a specified 'this' object, and the eval function called on  
another global object, respectively:

What scope chain should be used?

What variable object should be used?

What value should 'this' take on?

What gets called if window.eval has been overridden, as in (at global  
scope):

eval = function() { return "overridden"; }
eval(x);

or

window.eval = function() { return "overridden"; }
window.eval(x);

What gets called if the "eval" identifier has been shadowed by a  
variable in scope, as in:

with({ eval: function() { return "overridden"; } }) {
	eval(x);
}

or

try {
	throw function() { return "overridden"; };
} catch(eval) {
	eval(x);
}

?

Thanks,
Geoff



More information about the Es4-discuss mailing list