Catching "eval"
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.
On Wed, Jul 28, 2010 at 1:59 AM, Michael Day <mikeday at yeslogic.com> wrote:
Any comments on this code:
try { throw eval; } catch (x) { alert(x("3")); }
ES3 and ES5 require the same behavior for this code. Firefox implements that. Not much to say.
It does not appear to throw an EvalError in Firefox 3.6.7, even though many other indirect uses of eval will.
What did you have in mind? It should be pretty hard to get us to throw an EvalError. I think we throw sometimes if you pass two or more arguments to eval, or if you arrange to have eval called not-from-script (e.g. using it as an event handler). So, don't do that.
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.
Best ,
Michael