In what ways does the following "eval" regularity break?

Maciej Stachowiak mjs at apple.com
Thu Oct 30 11:00:19 PDT 2008


On Oct 30, 2008, at 10:20 AM, Mark S. Miller wrote:

> On Thu, Oct 30, 2008 at 8:35 AM, Brendan Eich <brendan at mozilla.com>  
> wrote:
>> [...] Browser intersection semantics make indirect eval global, [...]
>
>
> I had hoped so. This came up at Redmond, and unfortunately, without
> either you or Lars there, I was unable to reconstruct why we thought
> it would be upwards compatible to make indirect eval global. The
> specification of indirect eval was also discussed in this morning's
> ES3.1 phone call. Based on the ES3 spec and a quick testing of the
> browsers, as well as the memory of those who had an opinion about this
> in Redmond, we've been proceeding with the assumption that the ES3
> spec should be read as:
>
> An implementation may implement an indirect eval either by throwing an
> EvalError or by treating it as equivalent to the eval operator.
>
> Testing on FF3.0.3 and FF3.1Beta, with and without TraceMonkey
> enabled, seemed to bear this out:
>
>    function foo(a, b, c) { return b(c); }
>    foo(3, eval, 'a'); // yields 3
>    foo(3, window.eval, 'a'); // yields 3
>
> However, a bit more testing reveals something truly bizarre:
>
>    window.a = 'x';
>    foo(3, window.eval, 'a') // yields 'x'
>    foo(3, eval, 'a'); // yields 'x'
>
> I can't think of any semantics that would account for both behaviors.
> Is this a bug?

In recent WebKit versions, this test prints PASS twice:

<pre><script>
var a = "PASS";
function foo(a, b, c) { return b(c); }
document.writeln(foo(3, eval, 'a'));
document.writeln(foo(3, window.eval, 'a'));
</script></pre>

(prints nothing if you remove the to-level var a declaration).

Opera matches this behavior.

In a recent Firefox nightly it also prints PASS twice, but FAIL twice  
if you remove the top-level declaration. That seems in line with your  
results above. I agree that is puzzling.

  - Maciej




More information about the Es-discuss mailing list