Originally Posted by
sheetalw
I need a mechanism to check in script is user has written correct function names, parameters, object is created and used to call function- is that function belong to that class or not.
I am telling you this is not possible. JavaScript is not C++ where a simple syntax check would be sufficient to do what you want. In JavaScript there are no classes and you can add and remove methods from objects dynamically from within the script. If you want a static analysis that assumes nobody will do anything that modifies the environment, then do the parsing yourself or just execute the script in a controlled environment where each function that performs some task is substituted by a stub that will do nothing but report success. If you get an exception then the code is invalid in context of provided input parametrs. If you don't get an exception then the script is valid in context of provided input parameters and environment (but not valid in general).
For instance, is this script valid or not (as the whole script)?
var a = b
var a = b
To copy to clipboard, switch view to plain text mode
Is this one valid?
var a = "aaa"
b = a+7
var a = "aaa"
b = a+7
To copy to clipboard, switch view to plain text mode
What about this one?
var a;
if(Math.random() < 0.5)
a = new Array()
else
a = 7
a.splice(1, 1)
var a;
if(Math.random() < 0.5)
a = new Array()
else
a = 7
a.splice(1, 1)
To copy to clipboard, switch view to plain text mode
It's a bit like Schroedinger's cat, you never know if it's dead or alive until you check, so until you do it's both dead and alive at the same time
Bookmarks