(please throw any concern for security or anything out the window, as its a internal application)
basically What i want to do is store a javascript function in a db:
function x(name) {
return name + 1;
}
and then at a later time fetch the DB row
(pseudo code here)
x = db.get('function').where('id').equals(1);
console.log(x('bob'));
//should print "bob +1 "
so here is the scenario i am envisioning:
basically, i am getting a JSON object, and depending on certain criteria, i want to do some transformation to that json, and output the new transformed json. for the sake of the "main" app, i dont want to hard code the transformation logic, instead it will be dynamic (dynamic in the sense that a different developer will provide it at run time)
so a DB might contain:
ID | javascript
====================
1 | (some js code)
2 | (same func, different code)
what i want to do is execute that JS code stored in the DB, with an input of my choosing.
if it makes it easier, the function name will be standard.. i.e we can assume that the javascript saved in the DB will all follow:
function transform(input) {
/* below this line logic will change
* end diff logic/
return output
}
eval()at any time to execute some Javascript text (with the associated risks of doing so).application/javascriptmime type and regular text? That way you could just link to it without eval.