Backed out changeset b4bd9455a5a3 (bug 820124)

This commit is contained in:
Josh Matthews 2013-01-12 01:57:11 +01:00
Родитель 0e12472abd
Коммит 1bc23d67b7
6 изменённых файлов: 0 добавлений и 146 удалений

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

@ -1,5 +0,0 @@
// Don't assert.
verifyprebarriers();
r = /()()()\3/.test();
gc();
RegExp().test();

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

@ -1,3 +0,0 @@
// Don't assert.
'123456'.replace(/1(\d+)3/, '');
RegExp.lastMatch.toString();

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

@ -1,8 +0,0 @@
// Don't assert.
eval("\
x = RegExp(\"()\", \"y\");\
x.test();\
x = {};\
")
gc()
RegExp.$6

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

@ -1,8 +0,0 @@
// Don't assert.
eval("\
r = RegExp(\"(?!()(((!))))\", \"g\");\
\"^\".replace(r, '');\
r = (\"1+\")\
")
gc()
RegExp.$8

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

@ -2342,116 +2342,6 @@ BuildDollarReplacement(JSContext *cx, JSString *textstrArg, JSLinearString *reps
return true; return true;
} }
struct StringRange
{
size_t start;
size_t length;
StringRange(size_t s, size_t l)
: start(s), length(l)
{ }
};
static JSString *
AppendSubstrings(JSContext *cx, Handle<JSStableString*> stableStr,
const StringRange *ranges, size_t rangesLen)
{
JS_ASSERT(rangesLen);
/* For single substrings, construct a dependent string. */
if (rangesLen == 1)
return js_NewDependentString(cx, stableStr, ranges[0].start, ranges[0].length);
/* Collect substrings into a rope. */
RopeBuilder rope(cx);
for (size_t i = 0; i < rangesLen; i++) {
const StringRange &sr = ranges[i];
RootedString substr(cx, js_NewDependentString(cx, stableStr, sr.start, sr.length));
if (!substr)
return NULL;
/* Appending to the rope permanently roots the substring. */
rope.append(substr);
}
return rope.result();
}
static bool
str_replace_regexp_remove(JSContext *cx, CallArgs args, HandleString str, RegExpShared &re)
{
Rooted<JSStableString*> stableStr(cx, str->ensureStable(cx));
if (!stableStr)
return false;
Vector<StringRange, 16, SystemAllocPolicy> ranges;
StableCharPtr chars = stableStr->chars();
size_t charsLen = stableStr->length();
MatchPair match;
size_t startIndex = 0; /* Index used for iterating through the string. */
size_t lastIndex = 0; /* Index after last successful match. */
size_t lazyIndex = 0; /* Index before last successful match. */
/* Accumulate StringRanges for unmatched substrings. */
while (startIndex <= charsLen) {
if (!JS_CHECK_OPERATION_LIMIT(cx))
return false;
RegExpRunStatus status = re.executeMatchOnly(cx, chars, charsLen, &startIndex, match);
if (status == RegExpRunStatus_Error)
return false;
if (status == RegExpRunStatus_Success_NotFound)
break;
/* Include the latest unmatched substring. */
if (size_t(match.start) > lastIndex) {
if (!ranges.append(StringRange(lastIndex, match.start - lastIndex)))
return false;
}
lazyIndex = lastIndex;
lastIndex = startIndex;
/* Non-global removal executes at most once. */
if (!re.global())
break;
if (match.isEmpty())
startIndex++;
}
/* If unmatched, return the input string. */
if (!lastIndex) {
args.rval().setString(str);
return true;
}
/* The last successful match updates the RegExpStatics. */
cx->regExpStatics()->updateLazily(cx, stableStr, &re, lazyIndex);
/* Include any remaining part of the string. */
if (lastIndex < charsLen) {
if (!ranges.append(StringRange(lastIndex, charsLen - lastIndex)))
return false;
}
/* Handle the empty string before calling .begin(). */
if (ranges.empty()) {
args.rval().setString(cx->runtime->emptyString);
return true;
}
JSString *result = AppendSubstrings(cx, stableStr, ranges.begin(), ranges.length());
if (!result)
return false;
args.rval().setString(result);
return true;
}
static inline bool static inline bool
str_replace_regexp(JSContext *cx, CallArgs args, ReplaceData &rdata) str_replace_regexp(JSContext *cx, CallArgs args, ReplaceData &rdata)
{ {
@ -2464,12 +2354,6 @@ str_replace_regexp(JSContext *cx, CallArgs args, ReplaceData &rdata)
RegExpStatics *res = cx->regExpStatics(); RegExpStatics *res = cx->regExpStatics();
RegExpShared &re = rdata.g.regExp(); RegExpShared &re = rdata.g.regExp();
/* Optimize removal. */
if (rdata.repstr && rdata.repstr->length() == 0 && !rdata.dollar) {
JS_ASSERT(!rdata.lambda && !rdata.elembase);
return str_replace_regexp_remove(cx, args, rdata.str, re);
}
Value tmp; Value tmp;
if (!DoMatch(cx, res, rdata.str, re, ReplaceRegExpCallback, &rdata, REPLACE_ARGS, &tmp)) if (!DoMatch(cx, res, rdata.str, re, ReplaceRegExpCallback, &rdata, REPLACE_ARGS, &tmp))
return false; return false;

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

@ -91,12 +91,6 @@ RegExpStatics::executeLazy(JSContext *cx)
if (status == RegExpRunStatus_Error) if (status == RegExpRunStatus_Error)
return false; return false;
/*
* RegExpStatics are only updated on successful (matching) execution.
* Re-running the same expression must therefore produce a matching result.
*/
JS_ASSERT(status == RegExpRunStatus_Success);
/* Unset lazy state and remove rooted values that now have no use. */ /* Unset lazy state and remove rooted values that now have no use. */
pendingLazyEvaluation = false; pendingLazyEvaluation = false;
regexp.release(); regexp.release();