Bug 1055472 - Part 8 prelim: Rename InitializeRegExp to RegExpObject::initFromAtom for readability. (r=Waldo)
authorEric Faust <efaustbmo@gmail.com>
Fri, 13 Nov 2015 18:22:21 -0800
changeset 309836 e22cd35d3c39d5719a98a6602f75496f1d9672e8
parent 309835 ad1086bc97448cdc735af0a012ef07a57bbf1698
child 309837 e38d42f7ba2bee86e49b7dab94f6951c1752efa0
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1055472
milestone45.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 1055472 - Part 8 prelim: Rename InitializeRegExp to RegExpObject::initFromAtom for readability. (r=Waldo)
js/src/builtin/RegExp.cpp
js/src/vm/RegExpObject.cpp
js/src/vm/RegExpObject.h
--- a/js/src/builtin/RegExp.cpp
+++ b/js/src/builtin/RegExp.cpp
@@ -180,17 +180,17 @@ RegExpInitialize(JSContext* cx, Handle<R
     if (staticsUse == UseRegExpStatics) {
         RegExpStatics* res = cx->global()->getRegExpStatics(cx);
         if (!res)
             return false;
         flags = RegExpFlag(flags | res->getFlags());
     }
 
     /* Steps 11-15. */
-    if (!InitializeRegExp(cx, obj, pattern, flags))
+    if (!RegExpObject::initFromAtom(cx, obj, pattern, flags))
         return false;
 
     /* Step 16. */
     return true;
 }
 
 MOZ_ALWAYS_INLINE bool
 IsRegExpObject(HandleValue v)
@@ -263,17 +263,17 @@ regexp_compile_impl(JSContext* cx, const
             if (!RegExpToShared(cx, patternObj, &g))
                 return false;
 
             sourceAtom = g->getSource();
             flags = g->getFlags();
         }
 
         // Step 5.
-        if (!InitializeRegExp(cx, regexp, sourceAtom, flags))
+        if (!RegExpObject::initFromAtom(cx, regexp, sourceAtom, flags))
             return false;
 
         args.rval().setObject(*regexp);
         return true;
     }
 
     // Step 4.
     RootedValue P(cx, patternValue);
@@ -368,17 +368,17 @@ js::regexp_construct(JSContext* cx, unsi
 
         // Steps 8-9.
         // XXX Note bug in step 5c, with respect to step 8.
         Rooted<RegExpObject*> regexp(cx, RegExpAlloc(cx));
         if (!regexp)
             return false;
 
         // Step 10.
-        if (!InitializeRegExp(cx, regexp, sourceAtom, flags))
+        if (!RegExpObject::initFromAtom(cx, regexp, sourceAtom, flags))
             return false;
 
         args.rval().setObject(*regexp);
         return true;
     }
 
     RootedValue P(cx);
     RootedValue F(cx);
@@ -694,17 +694,19 @@ js::CreateRegExpPrototype(JSContext* cx,
     MOZ_ASSERT(key == JSProto_RegExp);
 
     Rooted<RegExpObject*> proto(cx, cx->global()->createBlankPrototype<RegExpObject>(cx));
     if (!proto)
         return nullptr;
     proto->NativeObject::setPrivate(nullptr);
 
     RootedAtom source(cx, cx->names().empty);
-    return InitializeRegExp(cx, proto, source, RegExpFlag(0));
+    if (!RegExpObject::initFromAtom(cx, proto, source, RegExpFlag(0)))
+        return nullptr;
+    return proto;
 }
 
 static bool
 ReportLastIndexNonwritable(JSContext* cx)
 {
     JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_READ_ONLY, "\"lastIndex\"");
     return false;
 }
--- a/js/src/vm/RegExpObject.cpp
+++ b/js/src/vm/RegExpObject.cpp
@@ -48,23 +48,16 @@ js::RegExpAlloc(ExclusiveContext* cx)
     RegExpObject* regexp = NewBuiltinClassInstance<RegExpObject>(cx, TenuredObject);
     if (!regexp)
         return nullptr;
 
     regexp->initPrivate(nullptr);
     return regexp;
 }
 
-RegExpObject*
-js::InitializeRegExp(ExclusiveContext* cx, Handle<RegExpObject*> regexp, HandleAtom source,
-                     RegExpFlag flags)
-{
-    return regexp->init(cx, source, flags) ? regexp : nullptr;
-}
-
 /* MatchPairs */
 
 bool
 MatchPairs::initArrayFrom(MatchPairs& copyFrom)
 {
     MOZ_ASSERT(copyFrom.pairCount() > 0);
 
     if (!allocOrExpandArray(copyFrom.pairCount()))
@@ -150,16 +143,23 @@ RegExpObject::trace(JSTracer* trc, JSObj
         !obj->asTenured().zone()->isPreservingCode())
     {
         obj->as<RegExpObject>().NativeObject::setPrivate(nullptr);
     } else {
         shared->trace(trc);
     }
 }
 
+/* static */ bool
+RegExpObject::initFromAtom(ExclusiveContext* cx, Handle<RegExpObject*> regexp, HandleAtom source,
+                           RegExpFlag flags)
+{
+    return regexp->init(cx, source, flags);
+}
+
 const Class RegExpObject::class_ = {
     js_RegExp_str,
     JSCLASS_HAS_PRIVATE |
     JSCLASS_HAS_RESERVED_SLOTS(RegExpObject::RESERVED_SLOTS) |
     JSCLASS_HAS_CACHED_PROTO(JSProto_RegExp),
     nullptr, /* addProperty */
     nullptr, /* delProperty */
     nullptr, /* getProperty */
@@ -219,17 +219,20 @@ RegExpObject::createNoStatics(ExclusiveC
 
     if (!irregexp::ParsePatternSyntax(*tokenStream, alloc, source))
         return nullptr;
 
     Rooted<RegExpObject*> regexp(cx, RegExpAlloc(cx));
     if (!regexp)
         return nullptr;
 
-    return InitializeRegExp(cx, regexp, source, flags);
+    if (!RegExpObject::initFromAtom(cx, regexp, source, flags))
+        return nullptr;
+
+    return regexp;
 }
 
 bool
 RegExpObject::createShared(JSContext* cx, RegExpGuard* g)
 {
     Rooted<RegExpObject*> self(cx, this);
 
     MOZ_ASSERT(!maybeShared());
@@ -889,34 +892,37 @@ js::CloneRegExpObject(JSContext* cx, JSO
 
     RegExpFlag origFlags = regex->getFlags();
     RegExpFlag staticsFlags = currentStatics->getFlags();
     if ((origFlags & staticsFlags) != staticsFlags) {
         Rooted<RegExpObject*> clone(cx, RegExpAlloc(cx));
         if (!clone)
             return nullptr;
 
-        return InitializeRegExp(cx, clone, source, RegExpFlag(origFlags | staticsFlags));
+        if (!RegExpObject::initFromAtom(cx, clone, source, RegExpFlag(origFlags | staticsFlags)))
+            return nullptr;
+
+        return clone;
     }
 
     // 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 (!InitializeRegExp(cx, clone, source, g->getFlags()))
+    if (!RegExpObject::initFromAtom(cx, clone, source, g->getFlags()))
         return nullptr;
 
     clone->setShared(*g.re());
     return clone;
 }
 
 static bool
 HandleRegExpFlag(RegExpFlag flag, RegExpFlag* flags)
--- a/js/src/vm/RegExpObject.h
+++ b/js/src/vm/RegExpObject.h
@@ -61,20 +61,16 @@ enum RegExpRunStatus
     RegExpRunStatus_Error,
     RegExpRunStatus_Success,
     RegExpRunStatus_Success_NotFound
 };
 
 extern RegExpObject*
 RegExpAlloc(ExclusiveContext* cx);
 
-extern RegExpObject*
-InitializeRegExp(ExclusiveContext* cx, Handle<RegExpObject*> regexp, HandleAtom source,
-                 RegExpFlag flags);
-
 // |regexp| is under-typed because this function's used in the JIT.
 extern JSObject*
 CloneRegExpObject(JSContext* cx, JSObject* regexp);
 
 extern JSObject*
 CreateRegExpPrototype(JSContext* cx, JSProtoKey key);
 
 /*
@@ -442,21 +438,20 @@ class RegExpObject : public NativeObject
 
     void setShared(RegExpShared& shared) {
         MOZ_ASSERT(!maybeShared());
         NativeObject::setPrivate(&shared);
     }
 
     static void trace(JSTracer* trc, JSObject* obj);
 
+    static bool initFromAtom(ExclusiveContext* cx, Handle<RegExpObject*> regexp, HandleAtom source,
+                             RegExpFlag flags);
+
   private:
-    friend RegExpObject*
-    InitializeRegExp(ExclusiveContext* cx, Handle<RegExpObject*> regexp, HandleAtom source,
-                     RegExpFlag flags);
-
     bool init(ExclusiveContext* cx, HandleAtom source, RegExpFlag flags);
 
     /*
      * Precondition: the syntax for |source| has already been validated.
      * Side effect: sets the private field.
      */
     bool createShared(JSContext* cx, RegExpGuard* g);
     RegExpShared* maybeShared() const {