Landing a patch from Feng Qian <feng.qian.moz@gmail.com> to avoid long-running regexps from hanging the browser forever by calling the branch callback at regular intervals. bug 307456, r=brendan/mrbkap

This commit is contained in:
mrbkap%gmail.com 2006-07-06 20:13:04 +00:00
Родитель 0f54abe47e
Коммит a75f7d6b96
1 изменённых файлов: 16 добавлений и 1 удалений

Просмотреть файл

@ -2681,7 +2681,20 @@ ExecuteREBytecode(REGlobalData *gData, REMatchState *x)
jschar matchCh1, matchCh2;
RECharSet *charSet;
JSBranchCallback onbranch = gData->cx->branchCallback;
uintN onbranchCalls = 0;
#define ONBRANCH_CALLS_MASK 127
#define CHECK_BRANCH() \
JS_BEGIN_MACRO \
if (onbranch && \
(++onbranchCalls & ONBRANCH_CALLS_MASK) == 0 && \
!(*onbranch)(gData->cx, NULL)) { \
gData->ok = JS_FALSE; \
return NULL; \
} \
JS_END_MACRO
JSBool anchor;
jsbytecode *pc = gData->regexp->program;
REOp op = (REOp) *pc++;
@ -2954,6 +2967,7 @@ ExecuteREBytecode(REGlobalData *gData, REMatchState *x)
continue;
case REOP_REPEAT:
CHECK_BRANCH();
--curState;
do {
--gData->stateStackTop;
@ -3051,6 +3065,7 @@ ExecuteREBytecode(REGlobalData *gData, REMatchState *x)
continue;
case REOP_MINIMALREPEAT:
CHECK_BRANCH();
--gData->stateStackTop;
--curState;