On Thu, Mar 3, 2011 at 4:21 AM, Lasse Reichstein <[email protected]
> wrote:

> 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.
>

I see the issue was closed as "DeliberateSpecViolation". Is this purely to
match webkit behavior? Or is there some back-compat concern? FF4 follows ES5
strictly there, and seems to be doing fine, so I would think there isn't
much web breakage involved. Why not align it with spec then? The less
differences among implementations the better ;)

I remember seeing these deviations in Chrome when working on
http://kangax.github.com/jstests/indirect-eval-testsuite/

Note how `with (window) eval(...)` and `Function('return eval(...)')()` are
considered indirect in Chrome (not in FF4).

test262 will likely catch things like that.

[...]

-- 
kangax

-- 
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]

Reply via email to