зеркало из https://github.com/mozilla/gecko-dev.git
Merge. a=blockers
This commit is contained in:
Коммит
4c22b63c0d
|
@ -2359,30 +2359,6 @@ struct JSContext
|
|||
void assertValidStackDepth(uintN /*depth*/) {}
|
||||
#endif
|
||||
|
||||
enum DollarPath {
|
||||
DOLLAR_LITERAL = 1,
|
||||
DOLLAR_AMP,
|
||||
DOLLAR_PLUS,
|
||||
DOLLAR_TICK,
|
||||
DOLLAR_QUOT,
|
||||
DOLLAR_EMPTY,
|
||||
DOLLAR_1,
|
||||
DOLLAR_2,
|
||||
DOLLAR_3,
|
||||
DOLLAR_4,
|
||||
DOLLAR_5,
|
||||
DOLLAR_OTHER
|
||||
};
|
||||
#ifdef XP_WIN
|
||||
volatile DollarPath *dollarPath;
|
||||
volatile JSSubString *sub;
|
||||
volatile jschar *blackBox;
|
||||
volatile jschar **repstrChars;
|
||||
volatile jschar **repstrDollar;
|
||||
volatile jschar **repstrDollarEnd;
|
||||
volatile size_t *peekLen;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
/*
|
||||
|
|
|
@ -134,19 +134,19 @@ class RegExpStatics
|
|||
* range [1, pairCount).
|
||||
*/
|
||||
void checkParenNum(size_t pairNum) const {
|
||||
JS_CRASH_UNLESS(1 <= pairNum);
|
||||
JS_CRASH_UNLESS(pairNum < pairCount());
|
||||
JS_ASSERT(1 <= pairNum);
|
||||
JS_ASSERT(pairNum < pairCount());
|
||||
}
|
||||
|
||||
bool pairIsPresent(size_t pairNum) const {
|
||||
return getCrash(pairNum, 0) >= 0;
|
||||
return get(pairNum, 0) >= 0;
|
||||
}
|
||||
|
||||
/* Precondition: paren is present. */
|
||||
size_t getParenLength(size_t pairNum) const {
|
||||
checkParenNum(pairNum);
|
||||
JS_CRASH_UNLESS(pairIsPresent(pairNum));
|
||||
return getCrash(pairNum, 1) - getCrash(pairNum, 0);
|
||||
JS_ASSERT(pairIsPresent(pairNum));
|
||||
return get(pairNum, 1) - get(pairNum, 0);
|
||||
}
|
||||
|
||||
int get(size_t pairNum, bool which) const {
|
||||
|
@ -154,11 +154,6 @@ class RegExpStatics
|
|||
return matchPairs[2 * pairNum + which];
|
||||
}
|
||||
|
||||
int getCrash(size_t pairNum, bool which) const {
|
||||
JS_CRASH_UNLESS(pairNum < pairCountCrash());
|
||||
return get(pairNum, which);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether the index at |checkValidIndex| is valid (>= 0).
|
||||
* If so, construct a string for it and place it in |*out|.
|
||||
|
@ -241,15 +236,10 @@ class RegExpStatics
|
|||
return matchPairs.length() / 2;
|
||||
}
|
||||
|
||||
size_t pairCountCrash() const {
|
||||
JS_CRASH_UNLESS(matchPairs.length() % 2 == 0);
|
||||
return pairCount();
|
||||
}
|
||||
|
||||
public:
|
||||
size_t parenCount() const {
|
||||
size_t pc = pairCount();
|
||||
JS_CRASH_UNLESS(pc);
|
||||
JS_ASSERT(pc);
|
||||
return pc - 1;
|
||||
}
|
||||
|
||||
|
@ -293,7 +283,7 @@ class RegExpStatics
|
|||
|
||||
/* @param pairNum Any number >= 1. */
|
||||
bool createParen(JSContext *cx, size_t pairNum, Value *out) const {
|
||||
JS_CRASH_UNLESS(pairNum >= 1);
|
||||
JS_ASSERT(pairNum >= 1);
|
||||
if (pairNum >= pairCount()) {
|
||||
out->setString(cx->runtime->emptyString);
|
||||
return true;
|
||||
|
|
|
@ -161,7 +161,11 @@ class RegExp
|
|||
bool multiline() const { return flags & JSREG_MULTILINE; }
|
||||
bool sticky() const { return flags & JSREG_STICKY; }
|
||||
|
||||
const uint32 &getFlags() const { JS_ASSERT((flags & allFlags) == flags); return flags; }
|
||||
const uint32 &getFlags() const {
|
||||
JS_ASSERT((flags & allFlags) == flags);
|
||||
return flags;
|
||||
}
|
||||
|
||||
uint32 flagCount() const;
|
||||
};
|
||||
|
||||
|
@ -621,55 +625,55 @@ RegExpStatics::getParen(size_t pairNum, JSSubString *out) const
|
|||
*out = js_EmptySubString;
|
||||
return;
|
||||
}
|
||||
out->chars = matchPairsInput->chars() + getCrash(pairNum, 0);
|
||||
out->chars = matchPairsInput->chars() + get(pairNum, 0);
|
||||
out->length = getParenLength(pairNum);
|
||||
}
|
||||
|
||||
inline void
|
||||
RegExpStatics::getLastMatch(JSSubString *out) const
|
||||
{
|
||||
if (!pairCountCrash()) {
|
||||
if (!pairCount()) {
|
||||
*out = js_EmptySubString;
|
||||
return;
|
||||
}
|
||||
JS_CRASH_UNLESS(matchPairsInput);
|
||||
out->chars = matchPairsInput->chars() + getCrash(0, 0);
|
||||
JS_CRASH_UNLESS(getCrash(0, 1) >= getCrash(0, 0));
|
||||
JS_ASSERT(matchPairsInput);
|
||||
out->chars = matchPairsInput->chars() + get(0, 0);
|
||||
JS_ASSERT(get(0, 1) >= get(0, 0));
|
||||
out->length = get(0, 1) - get(0, 0);
|
||||
}
|
||||
|
||||
inline void
|
||||
RegExpStatics::getLastParen(JSSubString *out) const
|
||||
{
|
||||
size_t pairCount = pairCountCrash();
|
||||
size_t pc = pairCount();
|
||||
/* Note: the first pair is the whole match. */
|
||||
if (pairCount <= 1) {
|
||||
if (pc <= 1) {
|
||||
*out = js_EmptySubString;
|
||||
return;
|
||||
}
|
||||
getParen(pairCount - 1, out);
|
||||
getParen(pc - 1, out);
|
||||
}
|
||||
|
||||
inline void
|
||||
RegExpStatics::getLeftContext(JSSubString *out) const
|
||||
{
|
||||
if (!pairCountCrash()) {
|
||||
if (!pairCount()) {
|
||||
*out = js_EmptySubString;
|
||||
return;
|
||||
}
|
||||
out->chars = matchPairsInput->chars();
|
||||
out->length = getCrash(0, 0);
|
||||
out->length = get(0, 0);
|
||||
}
|
||||
|
||||
inline void
|
||||
RegExpStatics::getRightContext(JSSubString *out) const
|
||||
{
|
||||
if (!pairCountCrash()) {
|
||||
if (!pairCount()) {
|
||||
*out = js_EmptySubString;
|
||||
return;
|
||||
}
|
||||
out->chars = matchPairsInput->chars() + getCrash(0, 1);
|
||||
JS_CRASH_UNLESS(get(0, 1) <= int(matchPairsInput->length()));
|
||||
out->chars = matchPairsInput->chars() + get(0, 1);
|
||||
JS_ASSERT(get(0, 1) <= int(matchPairsInput->length()));
|
||||
out->length = matchPairsInput->length() - get(0, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1990,7 +1990,7 @@ struct ReplaceData
|
|||
|
||||
static bool
|
||||
InterpretDollar(JSContext *cx, RegExpStatics *res, jschar *dp, jschar *ep, ReplaceData &rdata,
|
||||
JSSubString *out, size_t *skip, volatile JSContext::DollarPath *path)
|
||||
JSSubString *out, size_t *skip)
|
||||
{
|
||||
JS_ASSERT(*dp == '$');
|
||||
|
||||
|
@ -2019,16 +2019,7 @@ InterpretDollar(JSContext *cx, RegExpStatics *res, jschar *dp, jschar *ep, Repla
|
|||
|
||||
*skip = cp - dp;
|
||||
|
||||
JS_CRASH_UNLESS(num <= res->parenCount());
|
||||
|
||||
switch (num) {
|
||||
case 1: *path = JSContext::DOLLAR_1; break;
|
||||
case 2: *path = JSContext::DOLLAR_2; break;
|
||||
case 3: *path = JSContext::DOLLAR_3; break;
|
||||
case 4: *path = JSContext::DOLLAR_4; break;
|
||||
case 5: *path = JSContext::DOLLAR_5; break;
|
||||
default: *path = JSContext::DOLLAR_OTHER;
|
||||
}
|
||||
JS_ASSERT(num <= res->parenCount());
|
||||
|
||||
/*
|
||||
* Note: we index to get the paren with the (1-indexed) pair
|
||||
|
@ -2044,23 +2035,18 @@ InterpretDollar(JSContext *cx, RegExpStatics *res, jschar *dp, jschar *ep, Repla
|
|||
rdata.dollarStr.chars = dp;
|
||||
rdata.dollarStr.length = 1;
|
||||
*out = rdata.dollarStr;
|
||||
*path = JSContext::DOLLAR_LITERAL;
|
||||
return true;
|
||||
case '&':
|
||||
res->getLastMatch(out);
|
||||
*path = JSContext::DOLLAR_AMP;
|
||||
return true;
|
||||
case '+':
|
||||
res->getLastParen(out);
|
||||
*path = JSContext::DOLLAR_PLUS;
|
||||
return true;
|
||||
case '`':
|
||||
res->getLeftContext(out);
|
||||
*path = JSContext::DOLLAR_TICK;
|
||||
return true;
|
||||
case '\'':
|
||||
res->getRightContext(out);
|
||||
*path = JSContext::DOLLAR_QUOT;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -2173,11 +2159,10 @@ FindReplaceLength(JSContext *cx, RegExpStatics *res, ReplaceData &rdata, size_t
|
|||
|
||||
JSString *repstr = rdata.repstr;
|
||||
size_t replen = repstr->length();
|
||||
JSContext::DollarPath path;
|
||||
for (jschar *dp = rdata.dollar, *ep = rdata.dollarEnd; dp; dp = js_strchr_limit(dp, '$', ep)) {
|
||||
JSSubString sub;
|
||||
size_t skip;
|
||||
if (InterpretDollar(cx, res, dp, ep, rdata, &sub, &skip, &path)) {
|
||||
if (InterpretDollar(cx, res, dp, ep, rdata, &sub, &skip)) {
|
||||
replen += sub.length - skip;
|
||||
dp += skip;
|
||||
} else {
|
||||
|
@ -2194,12 +2179,6 @@ DoReplace(JSContext *cx, RegExpStatics *res, ReplaceData &rdata, jschar *chars)
|
|||
JSString *repstr = rdata.repstr;
|
||||
jschar *cp;
|
||||
jschar *bp = cp = repstr->chars();
|
||||
volatile JSContext::DollarPath path;
|
||||
#ifdef XP_WIN
|
||||
cx->dollarPath = &path;
|
||||
jschar sourceBuf[128];
|
||||
cx->blackBox = sourceBuf;
|
||||
#endif
|
||||
|
||||
for (jschar *dp = rdata.dollar, *ep = rdata.dollarEnd; dp; dp = js_strchr_limit(dp, '$', ep)) {
|
||||
size_t len = dp - cp;
|
||||
|
@ -2209,26 +2188,7 @@ DoReplace(JSContext *cx, RegExpStatics *res, ReplaceData &rdata, jschar *chars)
|
|||
|
||||
JSSubString sub;
|
||||
size_t skip;
|
||||
if (InterpretDollar(cx, res, dp, ep, rdata, &sub, &skip, &path)) {
|
||||
#ifdef XP_WIN
|
||||
if (((size_t(sub.chars) & 0xfffffU) + sub.length) > 0x100000U) {
|
||||
/* Going to cross a 0xffffe address, so take a gander at the replace value. */
|
||||
volatile JSSubString vsub = sub;
|
||||
volatile jschar *repstrChars = rdata.repstr->chars();
|
||||
volatile jschar *repstrDollar = rdata.dollar;
|
||||
volatile jschar *repstrDollarEnd = rdata.dollarEnd;
|
||||
cx->sub = &vsub;
|
||||
cx->repstrChars = &repstrChars;
|
||||
cx->repstrDollar = &repstrDollar;
|
||||
cx->repstrDollarEnd = &repstrDollarEnd;
|
||||
ptrdiff_t dollarDistance = rdata.dollarEnd - rdata.dollar;
|
||||
JS_CRASH_UNLESS(dollarDistance >= 0);
|
||||
volatile size_t peekLen = JS_MIN(rdata.repstr->length(), 128);
|
||||
cx->peekLen = &peekLen;
|
||||
js_strncpy(sourceBuf, rdata.repstr->chars(), peekLen);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (InterpretDollar(cx, res, dp, ep, rdata, &sub, &skip)) {
|
||||
len = sub.length;
|
||||
js_strncpy(chars, sub.chars, len);
|
||||
chars += len;
|
||||
|
|
Загрузка…
Ссылка в новой задаче