Subj : Re: Stopping scripte execution [JS_SetBranchCallback users, please To : Jun Kim From : Brendan Eich Date : Thu Dec 02 2004 06:36 pm Jun Kim wrote: > Oh, and perhaps, with a example code? > Thank you~~ :) Several examples can be found via http://lxr.mozilla.org/mozilla/search?string=JS_SetBranchCallback. Of course you need to set the branch callback *before* executing scripts whose backward branches and returns you wish to monitor. This reminds me: I'm thinking, and patching in https://bugzilla.mozilla.org/show_bug.cgi?id=272880, of extended the branch callback so that native loops and other costly native code structures invoke it with a null |script| (2nd) parameter. This would help catch runaway or nearly-runaway cases such as the much-duplicated bug testcase in https://bugzilla.mozilla.org/show_bug.cgi?id=271716. This is not a compatible API change, since until now, the branch callback has always been invoked with a non-null script parameter. So the backward compatible way to make this change is to condition the new calls from native code on a JSOPTION_NATIVE_BRANCH_CALLBACK (or shorter named) option. The best way to use the branch callback will always be to avoid doing anything (return as soon as possible) most of the time, but every 2^n calls (which can be cheaply tested with an unsigned counter masked against a constant), check that too much time hasn't passed since the script started. That implies the counter is zeroed at start of script execution. Hope this helps, /be .