Cancel/stop a run

Jan 20, 2012 at 11:26 AM

Hello all,

I am developing another Javascript editor/debugger. My last problem on the Jint is that I want to cancel the execution of the script when the user click stop. It can occur at any moment: during a normal run, a step or a break.

I tried to set the private field exit of the execution visitor to true thinking it could stop the execution but it does not. And I am now out of idea.

Anyone already found a way to do this?

Jan 20, 2012 at 1:30 PM

Look at jeti.codeplex.com for source code on how to do this.

Jan 23, 2012 at 7:11 AM

Oh Yes I read your code at the beginning of my dev.

Then you throw an exception. Is it a clean way of dealing with this?

Now I am thinking about this solution. Exceptions are to avoid because they could "slow" a system. But here we are stopping so anyway... Oki, I'll this idea then. Thank you jorgeleo

Jan 23, 2012 at 2:23 PM

There is no cleaner way to handle this for the moment, as far as I know. So it is just create a state machine se we can track what is the status of the ide, and throw a very specific exception so we can differentiate the stopping the code from other exceptions.

I agree that it is corky... that is why I decided to do that project so the corky solution is well known.

Jan 23, 2012 at 2:37 PM
Edited Feb 1, 2012 at 9:55 AM

Very well. Thank you for this code by the way. It helped me a lot for other points also.

Feb 1, 2012 at 8:43 AM

Hello jorgeleo,

I had the same problem (stopping the script) when implementing an instrumentation controller with embedded jint. I had the same idea with throwing an exception within the single step event handler, but it did not work. So I downloaded your code (btw, thanks a lot!) and try it out, but the symptoms were the same.

The actual problem is: The exception thrown within the single step event handler is not being handled by the try-catch mechanism encompassing the jintEngine.Run() statement. If I try to throw an exception at the level of the jintEngine.Run() statement, everything works fine.

Any idea why? Thanks in advance. IgorH.

Feb 1, 2012 at 5:39 PM

Maybe one of you could create a fork. A solution would be to provide a callback to JintEngine which would be executed before each statement, and could return a Stop, or Skip token. That plus a unit test and I would pull it into the core.

Feb 1, 2012 at 6:55 PM

@sebastienros:

Maybe the Jint.Debugger.DebugInformation class passed in the Step event handler should have a property AbortExecution. With that set the exit variable of the visitor = true. I'll fork it.

@igorh:

The current version is rethrowing the exception wrapped as a jint exception... look at JintEngine.cs in Run(Program program, bool Unwrap)

I was using an older version of the engine.

 

Feb 2, 2012 at 7:12 AM

Very good! That will be a useful feature

Feb 3, 2012 at 7:41 AM

Thanks, jorgeleo.

My apologies, the code was OK. I have been confused by the VS exception assistant, which reproducibly reported 'Exception has not been caught', but actually, if you ignore the message and proceed, the exception is processed correctly. This is of course just a debugging issue. In release, everything works fine.

I still do not understand why the VS exception assistant is not reacting properly in this situation (even if you disable it, you would still get a VS exception message) , but maybe this is intended behavior.

Anyway, the suggestion with the AbortExecution property seems to be a proper solution to the issue.

Feb 7, 2012 at 7:02 PM

Wating for the approval:

http://jint.codeplex.com/SourceControl/network/Forks/jorgeleo/StopExecution/contribution/1841