Follow up fix 2 for bug 623435. (r=brendan)
authorChris Leary <cdleary@mozilla.com>
Tue, 25 Jan 2011 18:00:31 -0800
changeset 61439 4003aacbc67503b2c6b7677f6e1edcbe8303f650
parent 61438 3489b017fd2a9f7766fb5b3f075ca1287dad5cdc
child 61440 82727ded88e6a38cdbe2b96ad148c7d5f079d16e
push idunknown
push userunknown
push dateunknown
reviewersbrendan
bugs623435
milestone2.0b10pre
Follow up fix 2 for bug 623435. (r=brendan)
js/src/jsregexp.cpp
js/src/jsregexpinlines.h
--- a/js/src/jsregexp.cpp
+++ b/js/src/jsregexp.cpp
@@ -247,17 +247,16 @@ RegExp::handlePCREError(JSContext *cx, i
     }
 #undef REPORT
 }
 
 bool
 RegExp::parseFlags(JSContext *cx, JSString *flagStr, uintN *flagsOut)
 {
     size_t n = flagStr->length();
-    Anchor<JSString *> afs(flagStr);
     const jschar *s = flagStr->getChars(cx);
     if (!s)
         return false;
 
     *flagsOut = 0;
     for (size_t i = 0; i < n; i++) {
 #define HANDLE_FLAG(name_)                                                    \
         JS_BEGIN_MACRO                                                        \
@@ -842,17 +841,20 @@ regexp_construct(JSContext *cx, uintN ar
     /* Coerce to string and compile. */
     JSString *sourceStr = js_ValueToString(cx, sourceValue);
     if (!sourceStr)
         return false;
 
     uintN flags = 0;
     if (argc > 1 && !argv[1].isUndefined()) {
         JSString *flagStr = js_ValueToString(cx, argv[1]);
-        if (!flagStr || !RegExp::parseFlags(cx, flagStr, &flags))
+        if (!flagStr)
+            return false;
+        argv[1].setString(flagStr);
+        if (!RegExp::parseFlags(cx, flagStr, &flags))
             return false;
     }
 
     JSString *escapedSourceStr = EscapeNakedForwardSlashes(cx, sourceStr);
     if (!escapedSourceStr)
         return false;
 
     return SwapRegExpInternals(cx, obj, rval, escapedSourceStr, flags);
--- a/js/src/jsregexpinlines.h
+++ b/js/src/jsregexpinlines.h
@@ -135,16 +135,18 @@ class RegExp
 
   public:
     static inline bool isMetaChar(jschar c);
     static inline bool hasMetaChars(const jschar *chars, size_t length);
 
     /*
      * Parse regexp flags. Report an error and return false if an invalid
      * sequence of flags is encountered (repeat/invalid flag).
+     *
+     * N.B. flagStr must be rooted.
      */
     static bool parseFlags(JSContext *cx, JSString *flagStr, uintN *flagsOut);
 
     /*
      * Execute regexp on |input| at |*lastIndex|.
      *
      * On match:    Update |*lastIndex| and RegExp class statics.
      *              Return true if test is true. Place an array in |*rval| if test is false.