Bug 1259194 (part 3) - Remove PopulateJSClass(). r=mrbkap.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 24 Mar 2016 06:58:23 +1100
changeset 290780 a8ec435d22564e64fdd03a71604ebf003b40a48a
parent 290779 d1af522c298bfc1cc383bcf5f6b9bae25aff7bef
child 290781 7a043400e5be3b3199017e85d9853721f880abcc
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1259194
milestone48.0a1
Bug 1259194 (part 3) - Remove PopulateJSClass(). r=mrbkap. PopulateJSClass() is only called immediately after the constructor, so it can be merged into the constructor. (This helps with the next patch.) The patch also removes an unnecessary |new| check.
js/xpconnect/src/XPCMaps.cpp
js/xpconnect/src/XPCWrappedNativeJSOps.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCMaps.cpp
+++ b/js/xpconnect/src/XPCMaps.cpp
@@ -538,29 +538,27 @@ XPCNativeScriptableSharedMap::~XPCNative
 bool
 XPCNativeScriptableSharedMap::GetNewOrUsed(uint32_t flags,
                                            char* name,
                                            XPCNativeScriptableInfo* si)
 {
     NS_PRECONDITION(name,"bad param");
     NS_PRECONDITION(si,"bad param");
 
-    XPCNativeScriptableShared key(flags, name);
+    XPCNativeScriptableShared key(flags, name, /* populate = */ false);
     auto entry = static_cast<Entry*>(mTable->Add(&key, fallible));
     if (!entry)
         return false;
 
     XPCNativeScriptableShared* shared = entry->key;
 
     if (!shared) {
         entry->key = shared =
-            new XPCNativeScriptableShared(flags, key.TransferNameOwnership());
-        if (!shared)
-            return false;
-        shared->PopulateJSClass();
+            new XPCNativeScriptableShared(flags, key.TransferNameOwnership(),
+                                          /* populate = */ true);
     }
     si->SetScriptableShared(shared);
     return true;
 }
 
 /***************************************************************************/
 // implement XPCWrappedNativeProtoMap...
 
--- a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp
@@ -952,20 +952,28 @@ XPCNativeScriptableInfo::Construct(const
     if (!success) {
         delete newObj;
         return nullptr;
     }
 
     return newObj;
 }
 
-void
-XPCNativeScriptableShared::PopulateJSClass()
+XPCNativeScriptableShared::XPCNativeScriptableShared(uint32_t aFlags,
+                                                     char* aName,
+                                                     bool aPopulate)
+    : mFlags(aFlags)
 {
-    MOZ_ASSERT(mJSClass.name, "bad state!");
+    MOZ_COUNT_CTOR(XPCNativeScriptableShared);
+
+    memset(&mJSClass, 0, sizeof(mJSClass));
+    mJSClass.name = aName;  // take ownership
+
+    if (!aPopulate)
+        return;
 
     mJSClass.flags = WRAPPER_FLAGS | JSCLASS_PRIVATE_IS_NSISUPPORTS;
 
     if (mFlags.IsGlobalObject())
         mJSClass.flags |= XPCONNECT_GLOBAL_FLAGS;
 
     JSAddPropertyOp addProperty;
     if (mFlags.WantAddProperty())
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -1667,38 +1667,30 @@ public:
 
 class XPCNativeScriptableShared
 {
 public:
     const XPCNativeScriptableFlags& GetFlags() const { return mFlags; }
 
     const JSClass* GetJSClass() { return Jsvalify(&mJSClass); }
 
-    XPCNativeScriptableShared(uint32_t aFlags, char* aName)
-        : mFlags(aFlags)
-    {
-        memset(&mJSClass, 0, sizeof(mJSClass));
-        mJSClass.name = aName;  // take ownership
-        MOZ_COUNT_CTOR(XPCNativeScriptableShared);
-    }
+    XPCNativeScriptableShared(uint32_t aFlags, char* aName, bool aPopulate);
 
     ~XPCNativeScriptableShared() {
         if (mJSClass.name)
             free((void*)mJSClass.name);
         MOZ_COUNT_DTOR(XPCNativeScriptableShared);
     }
 
     char* TransferNameOwnership() {
         char* name = (char*)mJSClass.name;
         mJSClass.name = nullptr;
         return name;
     }
 
-    void PopulateJSClass();
-
     void Mark()   { mFlags.Mark(); }
     void Unmark() { mFlags.Unmark(); }
     bool IsMarked() const { return mFlags.IsMarked(); }
 
 private:
     XPCNativeScriptableFlags mFlags;
     js::Class mJSClass;
 };