Skip to content
Snippets Groups Projects
Commit 02227bee authored by rswindell's avatar rswindell
Browse files

js_BranchCallback() now generates JavaScript errors if locally terminated or

an infinite loop is detected.
js_execfile() now resets loop counter before executing scripts.
parent ad3d2bc4
Branches
Tags
No related merge requests found
......@@ -534,12 +534,18 @@ js_BranchCallback(JSContext *cx, JSScript *script)
sbbs->js_loop++;
/* Termination and infinite loop detection */
if(sbbs->terminated || sbbs->js_loop>JAVASCRIPT_BRANCH_LIMIT) {
/* Terminated? */
if(sbbs->terminated) {
JS_ReportError(cx,"Terminated");
sbbs->js_loop=0;
return(JS_FALSE);
}
/* Infinite loop? */
if(sbbs->js_loop>JAVASCRIPT_BRANCH_LIMIT) {
JS_ReportError(cx,"Infinite loop (%lu branches) detected",sbbs->js_loop);
sbbs->js_loop=0;
return(JS_FALSE);
}
/* Give up timeslices every once in a while */
if(!(sbbs->js_loop%JAVASCRIPT_YIELD_FREQUENCY))
mswait(1);
......@@ -630,6 +636,8 @@ long sbbs_t::js_execfile(char *cmd)
return(-1);
}
js_loop=0; // Reset loop counter
JS_SetBranchCallback(js_cx, js_BranchCallback);
JS_ExecuteScript(js_cx, js_scope, js_script, &rval);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment