Merge. a=blockers
authorRobert Sayre <sayrer@gmail.com>
Mon, 06 Dec 2010 16:59:33 -0500
changeset 58727 2f96714fd6d2b46a79a9453bca2b45ab9288c121
parent 58726 25af9b539829ef7c04ba38515492a947c0c5aed9 (current diff)
parent 58678 e24641018d51da3572a087fd8ee14a32cae15352 (diff)
child 58728 686e646d23004d082909149f04b4aa0cd35b9200
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersblockers
milestone2.0b8pre
Merge. a=blockers
js/src/jscntxt.h
js/src/jsregexpinlines.h
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -2354,40 +2354,16 @@ struct JSContext
     void assertValidStackDepth(uintN depth) {
         JS_ASSERT(0 <= regs->sp - regs->fp->base());
         JS_ASSERT(depth <= uintptr_t(regs->sp - regs->fp->base()));
     }
 #else
     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:
 
     /*
      * The allocation code calls the function to indicate either OOM failure
      * when p is null or that a memory pressure counter has reached some
      * threshold when p is not null. The function takes the pointer and not
      * a boolean flag to minimize the amount of code in its inlined callers.
      */
--- a/js/src/jsregexp.h
+++ b/js/src/jsregexp.h
@@ -129,41 +129,36 @@ class RegExpStatics
 #endif
     }
 
     /* 
      * Since the first pair indicates the whole match, the paren pair numbers have to be in the
      * 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 {
         JS_ASSERT(pairNum < pairCount());
         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|.
      * If not, place undefined in |*out|.
      */
     bool makeMatch(JSContext *cx, size_t checkValidIndex, size_t pairNum, Value *out) const;
 
     static const uintN allFlags = JSREG_FOLD | JSREG_GLOB | JSREG_STICKY | JSREG_MULTILINE;
@@ -236,25 +231,20 @@ class RegExpStatics
      */
 
   private:
     size_t pairCount() const {
         JS_ASSERT(matchPairs.length() % 2 == 0);
         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;
     }
 
     JSString *getPendingInput() const { return pendingInput; }
     uintN getFlags() const { return flags; }
     bool multiline() const { return flags & JSREG_MULTILINE; }
 
     size_t matchStart() const {
@@ -288,17 +278,17 @@ class RegExpStatics
     bool createPendingInput(JSContext *cx, Value *out) const;
     bool createLastMatch(JSContext *cx, Value *out) const { return makeMatch(cx, 0, 0, out); }
     bool createLastParen(JSContext *cx, Value *out) const;
     bool createLeftContext(JSContext *cx, Value *out) const;
     bool createRightContext(JSContext *cx, Value *out) const;
 
     /* @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;
         }
         return makeMatch(cx, pairNum * 2, pairNum, out);
     }
 
     /* Substring creators. */
--- a/js/src/jsregexpinlines.h
+++ b/js/src/jsregexpinlines.h
@@ -156,17 +156,21 @@ class RegExp
     /* Accessors. */
     JSString *getSource() const { return source; }
     size_t getParenCount() const { return parenCount; }
     bool ignoreCase() const { return flags & JSREG_FOLD; }
     bool global() const { return flags & JSREG_GLOB; }
     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;
 };
 
 class RegExpMatchBuilder
 {
     JSContext   * const cx;
     JSObject    * const array;
 
@@ -616,63 +620,63 @@ RegExpStatics::createRightContext(JSCont
 inline void
 RegExpStatics::getParen(size_t pairNum, JSSubString *out) const
 {
     checkParenNum(pairNum);
     if (!pairIsPresent(pairNum)) {
         *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);
 }
 
 }
 
 #endif /* jsregexpinlines_h___ */
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -1985,17 +1985,17 @@ struct ReplaceData
     bool               calledBack;     /* record whether callback has been called */
     InvokeSessionGuard session;        /* arguments for repeated lambda Invoke call */
     InvokeArgsGuard    singleShot;     /* arguments for single lambda Invoke call */
     JSCharBuffer       cb;             /* buffer built during DoMatch */
 };
 
 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 == '$');
 
     /* If there is only a dollar, bail now */
     if (dp + 1 >= ep)
         return false;
 
     /* Interpret all Perl match-induced dollar variables. */
@@ -2014,58 +2014,44 @@ InterpretDollar(JSContext *cx, RegExpSta
                 num = tmp;
             }
         }
         if (num == 0)
             return false;
 
         *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
          * number, as opposed to a (0-indexed) paren number.
          */
         res->getParen(num, out);
         return true;
     }
 
     *skip = 2;
     switch (dc) {
       case '$':
         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;
 }
 
 static bool
 FindReplaceLength(JSContext *cx, RegExpStatics *res, ReplaceData &rdata, size_t *sizep)
 {
@@ -2168,72 +2154,46 @@ FindReplaceLength(JSContext *cx, RegExpS
             return false;
 
         *sizep = rdata.repstr->length();
         return true;
     }
 
     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 {
             dp++;
         }
     }
     *sizep = replen;
     return true;
 }
 
 static void
 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;
         js_strncpy(chars, cp, len);
         chars += len;
         cp = dp;
 
         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;
             cp += skip;
             dp += skip;
         } else {
             dp++;
         }