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

Brendan Eich brendan at mozilla.com
Thu Oct 30 13:27:55 PDT 2008


On Oct 30, 2008, at 1:09 PM, Brendan Eich wrote:

> These bugs involved, e.g. Prototype (the JS library) and its  
> Ajax.Updater (with evalScripts set to true). The code in question  
> used Prototype's forEach. A javascript: URL reduction:
>
> javascript: (function xxx(){ ["var x"].forEach(eval); })();


Prototype 1.5.1.1 (and older, I think we suggested this as a  
workaround) has

   evalScripts: function() {
     return this.extractScripts().map(function(script) { return  
eval(script) });
   },

No indirect eval called from map, but the operator eval here does not  
depend on its environment at all (it can't, since neither function in  
which it nests has any formal parameters or other local bindings). It  
could be optimized nicely in ES1-3.

/be



More information about the Es-discuss mailing list