I'm using Jint and I wonder if there is a way from the C# perspective to get all defined variables and functions available in the global scope of the script.
For example, given the following Javascript code in the file "test.js":
function globalFunc(a, b) {
var localVar = a + b;
return localVar;
}
var globalVar = 5;
... and given the following C# code (using Jint 2.4.0):
Jint.Engine engine = new Jint.Engine();
engine.Execute(System.IO.File.ReadAllText("test.js");
// the following method call do not exist in Jint, just here for example...
JsValue[] variables = engine.GetGlobalScopeVariables();
then expecting variables to contains two values, namely a variable named "globalFunc" of type "Function" and a variable named "globalVar" of type "Number".
Expected answers may lead to some Jint hacking. I'm open to that as well.
Thanks!
The variables and functions are accessible in engine.Global.Properties. It does however also hold 'system variables'.
By comparing the entries in the dictionary after you executed your script to the entries before you executed it you can get information about which variables and functions that was added.