Display progress when script is executing...

May 13, 2015 at 8:48 AM
Hi,

Firstly, I should congratulate on this wonderful project. Among all V8 .NET projects that I have come across this seems the best. Easy to use, feature rich and most usage scenarios are explained in the discussion forum.

In my case, I am using the V8 engine to run a lengthy javascript which would run for several minutes. I need to be able to display progress to users. Is there some way to get notified from the script engine upon completion of each line of javascript? A generic method/property interception call or an event notification mechanism would be good. I didn't come across any solution in the forum though I have seen few discuss about debug option.

Please let me know if there are better alternatives.

Regards,
Ram
Coordinator
May 13, 2015 at 3:41 PM
Hi Ram,

Thank you very much for the positive feedback!

Unfortunately none of the script engines supported by ClearScript appear to provide the sort of notifications you're looking for. V8 has several low-level profiling hooks, but we haven't explored those and it isn't clear how useful they'd be for your purposes.

If your script code often calls into the host, you might be able to use ScriptEngine.GetStackTrace() as a basis for gauging execution progress, but stack trace parsing is a fragile approach. A better solution, if practical, is to have the script code report its own progress via a host API that you provide.

Thanks again, and good luck!
May 14, 2015 at 11:38 AM
Edited May 14, 2015 at 11:46 AM
Thanks for your reply... This is a very critical requirement for us. The javascript itself is written by a different class of users of the program and hence would be considered cumbersome for them to write additional progress code.

I had come across V8's interceptors (link) and its [usage] (http://markmail.org/message/ul5dkze73tbqj2su).

Can the same be done with Clearscript? If yes, can you please tell how?

Regards,
Ram
Coordinator
May 14, 2015 at 7:22 PM
Hello Ram,

Interception is the mechanism that allows JavaScript code running in V8 to invoke host methods and properties. The code that implements those methods and properties is free to examine the script environment, and we're evaluating a feature that would allow the host to be notified of all such invocations in one place.

However, this feature, if implemented, wouldn't notify the host of native script function calls or property access, so it probably wouldn't be sufficient for any meaningful determination of progress. Script code could spin forever within the script engine without the host knowing anything about it. Even if it were possible to hook all calls, buggy or malicious script code could still get stuck within a function.

Can you say more about how you'd use an interception or notification mechanism to measure progress?

Thanks!
May 15, 2015 at 10:48 AM
I agree that native script function calls won't be notified. However, getting notified of all host method/property invocation in a single place where we can also get the script line index would be useful. With this we will be able to tell the user the line that is getting executed. This will not give clear progress info in terms of 'how much is done and still to go'. But then in case of loops and branches it would anyway be a challenge to give extent complete. So, I guess, interception with line index would be a good start.

Regards,
Ram