Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  97] [ 2]  / answers: 1 / hits: 19727  / 16 Years ago, thu, february 12, 2009, 12:00:00

I have a javascript file that reads another file which may contain javascript fragments that need to be eval()-ed. The script fragments are supposed to conform to a strict subset of javascript that limits what they can do and which variables they can change, but I want to know if there is some way to enforce this by preventing the eval from seeing variables in the global scope. Something like the following:



function safeEval( fragment )
{
var localVariable = g_Variable;

{
// do magic scoping here so that the eval fragment can see localVariable
// but not g_Variable or anything else outside function scope

eval( fragment );
}
}


The actual code doesn't need to look like this--I'm open to any and all weird tricks with closures, etc. But I do want to know if this is even possible.


More From » eval

 Answers
There are no answers for this question yet.
Only authorized users can answer the question. Please sign in first, or register a free account.
albert

Total Points: 652
Total Questions: 105
Total Answers: 108

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;