Hold a reference to the regexp that we're using so that it doesn't go away. bug 327170, r=brendan a=dveditz
git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@190920 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -2034,10 +2034,6 @@ js_NewRegExpOpt(JSContext *cx, JSTokenStream *ts,
|
||||
return js_NewRegExp(cx, ts, str, flags, flat);
|
||||
}
|
||||
|
||||
|
||||
#define HOLD_REGEXP(cx, re) JS_ATOMIC_INCREMENT(&(re)->nrefs)
|
||||
#define DROP_REGEXP(cx, re) js_DestroyRegExp(cx, re)
|
||||
|
||||
/*
|
||||
* Save the current state of the match - the position in the input
|
||||
* text as well as the position in the bytecode. The state of any
|
||||
|
||||
@@ -117,6 +117,9 @@ extern JSRegExp *
|
||||
js_NewRegExpOpt(JSContext *cx, JSTokenStream *ts,
|
||||
JSString *str, JSString *opt, JSBool flat);
|
||||
|
||||
#define HOLD_REGEXP(cx, re) JS_ATOMIC_INCREMENT(&(re)->nrefs)
|
||||
#define DROP_REGEXP(cx, re) js_DestroyRegExp(cx, re)
|
||||
|
||||
extern void
|
||||
js_DestroyRegExp(JSContext *cx, JSRegExp *re);
|
||||
|
||||
|
||||
@@ -1168,7 +1168,9 @@ match_or_replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
return JS_FALSE;
|
||||
reobj = NULL;
|
||||
}
|
||||
/* From here on, all control flow must reach the matching DROP. */
|
||||
data->regexp = re;
|
||||
HOLD_REGEXP(cx, re);
|
||||
|
||||
if (re->flags & JSREG_GLOB)
|
||||
data->flags |= GLOBAL_REGEXP;
|
||||
@@ -1184,23 +1186,23 @@ match_or_replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
if (reobj) {
|
||||
/* Set the lastIndex property's reserved slot to 0. */
|
||||
ok = js_SetLastIndex(cx, reobj, 0);
|
||||
if (!ok)
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
ok = JS_TRUE;
|
||||
}
|
||||
length = JSSTRING_LENGTH(str);
|
||||
for (count = 0; index <= length; count++) {
|
||||
ok = js_ExecuteRegExp(cx, re, str, &index, JS_TRUE, rval);
|
||||
if (!ok || *rval != JSVAL_TRUE)
|
||||
break;
|
||||
ok = glob(cx, count, data);
|
||||
if (!ok)
|
||||
break;
|
||||
if (cx->regExpStatics.lastMatch.length == 0) {
|
||||
if (index == length)
|
||||
if (ok) {
|
||||
length = JSSTRING_LENGTH(str);
|
||||
for (count = 0; index <= length; count++) {
|
||||
ok = js_ExecuteRegExp(cx, re, str, &index, JS_TRUE, rval);
|
||||
if (!ok || *rval != JSVAL_TRUE)
|
||||
break;
|
||||
index++;
|
||||
ok = glob(cx, count, data);
|
||||
if (!ok)
|
||||
break;
|
||||
if (cx->regExpStatics.lastMatch.length == 0) {
|
||||
if (index == length)
|
||||
break;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1241,6 +1243,7 @@ match_or_replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
ok = js_ExecuteRegExp(cx, re, str, &index, test, rval);
|
||||
}
|
||||
|
||||
DROP_REGEXP(cx, re);
|
||||
if (reobj) {
|
||||
/* Tell our caller that it doesn't need to destroy data->regexp. */
|
||||
data->flags &= ~KEEP_REGEXP;
|
||||
@@ -1249,6 +1252,7 @@ match_or_replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
data->regexp = NULL;
|
||||
js_DestroyRegExp(cx, re);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user