Subj : Re: Stopping Script Execution To : netscape.public.mozilla.jseng From : Brendan Eich Date : Wed Sep 24 2003 11:42 pm Damian Slee wrote: > initialisation > JS_SetBranchCallback(m_Context, BranchCallback); > > callback > #define SCRIPT_TIMEOUT 3000 > > JSBool BranchCallback(JSContext *Context, JSScript *Script) > { > JSObject *global = JS_GetGlobalObject(Context); > if (global) > { > if (m_scriptTimer.Expired(SCRIPT_TIMEOUT)) > { > JS_ReportError(Context,"Script execution halted, possible infinite loop"); > return JS_FALSE; > } > } > } > > return JS_TRUE; > } > You don't show what m_scriptTimer looks like. It's best to keep the branch callback a leaf function that tests an unsigned counter mod a power of two. Remember that it will be called on *every* backward branch and return statement, so it should be as fast as possible. /be .