How to get a local variable value (inside a function) with Jint?

134 Views Asked by At

In C# and using Jint, how can I get value of a local defined variable in a JavaScript function?

For example, I have the following JavaScript code in the string "testStr". And I can't modify JS code as it is dynamic and not generated by me.

var globalVar = 5;

function myFunc(a, b) {

    var localVar1 = { "Hello" : 987 };

    var localVar2 = a + b;

    return;
}

And given the following C# code:

jintEngine.Execute(testStr);

// the following method do not exist in Jint, just here for example...
var valueStr = jintEngine.GoToFunc("myFunc").GetValue("localVar1").ToString();

And get the localVar1 value as string.

Thanks!

0

There are 0 best solutions below