Catching "eval"

Brendan Eich brendan at mozilla.com
Tue Aug 3 11:03:18 PDT 2010


On Jul 27, 2010, at 11:59 PM, Michael Day wrote:

> Hi all,
> 
> Any comments on this code:
> 
> try
> {
>    throw eval;
> }
> catch (x)
> {
>    alert(x("3"));
> }
> 
> It does not appear to throw an EvalError in Firefox 3.6.7, even though many other indirect uses of eval will.

The important question is whether it's an indirect eval. It is:

js> var x = "global";
js> function f(s,x) {
    try { throw eval; } catch (e) {
        print(e(s));
    }
}
js> f("x", "local");
global

Why it's not a cause for EvalError in Firefox 3.6.x, when EvalError is gone from ES5 except as a memory, is secondary. It is not web-compatible to throw EvalError for indirecting to eval via a local (arg,var,let) binding. So we don't.

The better question for Firefox or really SpiderMonkey is why have any EvalError throwing.

/be

> 
> Best regards,
> 
> Michael
> 
> -- 
> Print XML with Prince!
> http://www.princexml.com
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list