1

Closed

eval() Error

description

var settings{
tip:2,
Empty:'ok'
};
var CtrlValue="yes";
var act="RunFun";
eval(act+"(settings,CtrlValue)");
 
“settings”, “CtrlValue”
Did not translate into

file attachments

Closed Jul 3, 2012 at 5:28 PM by ronlo
Need to use the proper -evals switch when your code uses eval-statements that reference local variables and functions.

comments

ntosss wrote Aug 26, 2011 at 1:44 AM

Supplement:

function Validator(CtrlID) {
var obj = $("#" + CtrlID);
var settings = obj.data("settings");
var _IsValid = true,_CtrlValue = "";
_CtrlValue = obj.val();
if (!_IsValid){
    if (typeof (eval(settings.CustomFunction)) == "function") {
        eval(settings.CustomFunction + "(settings,_CtrlValue)");
    }
}   
}

AjaxMin:

function Validator(n){var i=$("#"+n),t=i.data("settings"),u=!0,r="";r=i.val(),u||typeof eval(t.CustomFunction)=="function"&&eval(t.CustomFunction+"(settings,_CtrlValue)")}


Should be correct:

function Validator(n){var i=$("#"+n),t=i.data("settings"),u=!0,r="";r=i.val(),u||typeof eval(t.CustomFunction)=="function"&&eval(t.CustomFunction+"(t,r)")}

ronlo wrote Aug 26, 2011 at 4:16 PM

By default AjaxMin assumes eval statements are safe and do not reference local variables -- for instance, for generating JSON objects, etc. The sample code is obviously not in that class. For this code to compile correctly, you need to specify one of the other -evals switches: for this particular instance, since the settings and _CtrlValue variables are in the same scope as the eval statement, try -evals:immediate. If those variables were outside the scope of the eval statement, you would have to use -evals:safeall.

ronlo wrote Sep 1, 2011 at 8:02 PM

Please see the documentation tab, "Problems with evals" article for more information on how to fix this. Just a simple command-line switch that needs to be set.