Bug 1242810. r=jandem
authorJeff Walden <jwalden@mit.edu>
Wed, 02 Mar 2016 17:52:08 -0800
changeset 289898 5e251884f69f8e4ab1149d6ca7f9dc18b7414646
parent 289897 928b0a26ff0f5468b3ffd8a4ff02c42d055c782c
child 289899 131a296d48a96a30104572f6dd1c9cd078f4d4be
push id30112
push usercbook@mozilla.com
push dateWed, 23 Mar 2016 15:25:32 +0000
treeherdermozilla-central@6202ade0e6d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1242810
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1242810. r=jandem
js/src/vm/RegExpObject.cpp
--- a/js/src/vm/RegExpObject.cpp
+++ b/js/src/vm/RegExpObject.cpp
@@ -913,59 +913,54 @@ RegExpCompartment::sizeOfExcludingThis(m
 
 /* Functions */
 
 JSObject*
 js::CloneRegExpObject(JSContext* cx, JSObject* obj_)
 {
     Rooted<RegExpObject*> regex(cx, &obj_->as<RegExpObject>());
 
-    // Check that the RegExpShared for |regex| is okay to reuse in the clone.
-    // If the |RegExpStatics| provides additional flags, we'll need a new
-    // |RegExpShared|.
-    RegExpStatics* currentStatics = regex->getProto()->global().getRegExpStatics(cx);
-    if (!currentStatics)
+    // Unlike RegExpAlloc, all clones must use |regex|'s group.  Allocate
+    // in the tenured heap to simplify embedding them in JIT code.
+    RootedObjectGroup group(cx, regex->group());
+    Rooted<RegExpObject*> clone(cx, NewObjectWithGroup<RegExpObject>(cx, group, TenuredObject));
+    if (!clone)
         return nullptr;
+    clone->initPrivate(nullptr);
 
     if (!EmptyShape::ensureInitialCustomShape<RegExpObject>(cx, clone))
         return nullptr;
 
     Rooted<JSAtom*> source(cx, regex->getSource());
 
+    // Check that the RegExpShared for |regex| is okay to reuse in the clone.
+    RegExpStatics* currentStatics = regex->getProto()->global().getRegExpStatics(cx);
+    if (!currentStatics)
+        return nullptr;
+
     RegExpFlag origFlags = regex->getFlags();
     RegExpFlag staticsFlags = currentStatics->getFlags();
     if ((origFlags & staticsFlags) != staticsFlags) {
-        Rooted<RegExpObject*> clone(cx, RegExpAlloc(cx));
-        if (!clone)
+        // If |currentStatics| provides additional flags, we'll have to use a
+        // new |RegExpShared|.
+        if (!RegExpObject::initFromAtom(cx, clone, source, RegExpFlag(origFlags | staticsFlags)))
+            return nullptr;
+    } else {
+        // Otherwise we can use |regexp|'s RegExpShared.  Initialize using its
+        // flags and associate it with the clone.
+        RegExpGuard g(cx);
+        if (!regex->getShared(cx, &g))
             return nullptr;
 
-        if (!RegExpObject::initFromAtom(cx, clone, source, RegExpFlag(origFlags | staticsFlags)))
+        if (!RegExpObject::initFromAtom(cx, clone, source, g->getFlags()))
             return nullptr;
 
-        return clone;
+        clone->setShared(*g.re());
     }
 
-    // Otherwise, the clone can use |regexp|'s RegExpShared.
-    RootedObjectGroup group(cx, regex->group());
-
-    // Note: RegExp objects are always allocated in the tenured heap. This is
-    // not strictly required, but it simplifies embedding them in jitcode.
-    Rooted<RegExpObject*> clone(cx, NewObjectWithGroup<RegExpObject>(cx, group, TenuredObject));
-    if (!clone)
-        return nullptr;
-    clone->initPrivate(nullptr);
-
-    RegExpGuard g(cx);
-    if (!regex->getShared(cx, &g))
-        return nullptr;
-
-    if (!RegExpObject::initFromAtom(cx, clone, source, g->getFlags()))
-        return nullptr;
-
-    clone->setShared(*g.re());
     return clone;
 }
 
 static bool
 HandleRegExpFlag(RegExpFlag flag, RegExpFlag* flags)
 {
     if (*flags & flag)
         return false;