Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Retrieving javascript line index during execution

Is it possible to get currently executing script line number without resorting to the debugger?
I would like to highlight certain lines whenever they are being executed. For example:
public class Test() {
    public void method1(string str){};
    public void method2(string str){};

var engine = new V8ScriptEngine(V8ScriptEngineFlags.EnableDebugging, port);
engine.AddHostObject("test", new Test());
engine.Execute("test_script", script_js);
and I would like to retrieve the line number whenever the test.method1 or test.method2 is being executed (from within the host C# code).

What I have tried so far but without any success:
  1. V8ScriptEngine.getStackTrace() - Doesn't work since it essentially terminates the script execution.
  2. Adding
function getStackTrace(){ return new Error().stack; }
to the script and calling it from the host method e.g.
var st = (string)engine.Script.getStackTrace();
Doesn't work either. It seems to enter infinite recursive loop and just keeps calling the same host method over and over again.

Are there any other options available for V8ScriptEngine?

Viewing all articles
Browse latest Browse all 2297