On Mon, 28 Feb 2011 15:57:35 +0100, mcot <[email protected]> wrote:
I want to reassign eval but still be able to do indirect calls. Is
there any possible way to do this in chrome?
[corrected to "do correct calls" in followup mail]
Not currently. There is a bug/JSC compatibility feature in V8 that makes
local
variables called "eval" be considered indirect calls to eval (which is
incorrect
according to the specification). See:
http://code.google.com/p/v8/issues/detail?id=994
According to the ES5 specification, the following code:
function test() {
var x = "Not this!";
var oldEval = eval;
eval = function() { throw "DON'T CALL ME"; };
function foo() {
var eval = oldEval;
eval("var x = 'This!';");
return x;
}
alert(foo());
}
test();
should alert "This!". The call to eval is a direct call because it
1) is just the identifier "eval", which
2) refers to the original value of global.eval,
so it will evaluate the variable declaration locally in foo, and return
the "This!" value.
What V8 does is to consider any local variable as "not the original eval".
That means that it evaluates the variable declaration in the global scope,
and returns the x declared in test instead.
I.e., to get "direct call to eval" functionality in Chrome and Safari, you
need to use an direct reference to the "eval" property of the global
object.
Nothing else will work.
/L
--
Lasse Reichstein - [email protected]
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]