Execution loop detection

Oct 15, 2010 at 4:47 PM

While testing "my" javascript editor/debugger my boss tried to do this:

function foo()
  return 1;

Jint did a stack overflow, and from my point of view, I could expect it, but my boss doesn't agree: he would like to prevent such errors.

What do you think about it ? Is it something that an interpreter should catch before executing and consequently throw an exception, or, being a "semantic" error condition (I don't know how to say better), it is "user responsibility" ?

Thank you

Oct 15, 2010 at 5:14 PM

In my opinion it's a user specific issue. But this is interesting because I have tested this code on IE9 and Firefox and they stop the script after 25000 and 2000 loops resprectively. Actually this would be very easy to prevent stackoverflow by just counting the number of scopes in the Scope array of the ExecutionVisitor. There could be a constant with the allowed number of recursions, and when reached, would just "exit" the script. This could also be optional. Let me add it.

Oct 15, 2010 at 5:14 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.