Bug 1259194 (part 2) - Remove XPCWrappedNativeJSClass. r=mrbkap.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 24 Mar 2016 06:53:28 +1100
changeset 290779 d1af522c298bfc1cc383bcf5f6b9bae25aff7bef
parent 290778 2a875129c6f35701ecfa2866fbcd319d2fb7d726
child 290780 a8ec435d22564e64fdd03a71604ebf003b40a48a
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 2) - Remove XPCWrappedNativeJSClass. r=mrbkap. It's a trivial and pointless wrapper for js::Class. This patch also fixes some ridiculous formatting in XPCNativeScriptableShared.
js/xpconnect/src/XPCWrappedNative.cpp
js/xpconnect/src/XPCWrappedNativeJSOps.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -762,17 +762,17 @@ XPCWrappedNative::Init(const XPCNativeSc
             if (!mScriptableInfo)
                 return false;
         }
     }
     XPCNativeScriptableInfo* si = mScriptableInfo;
 
     // create our flatJSObject
 
-    const JSClass* jsclazz = si ? si->GetJSClass() : Jsvalify(&XPC_WN_NoHelper_JSClass.base);
+    const JSClass* jsclazz = si ? si->GetJSClass() : Jsvalify(&XPC_WN_NoHelper_JSClass);
 
     // We should have the global jsclass flag if and only if we're a global.
     MOZ_ASSERT_IF(si, !!si->GetFlags().IsGlobalObject() == !!(jsclazz->flags & JSCLASS_IS_GLOBAL));
 
     MOZ_ASSERT(jsclazz &&
                jsclazz->name &&
                jsclazz->flags &&
                jsclazz->resolve &&
--- a/js/xpconnect/src/XPCWrappedNativeJSOps.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeJSOps.cpp
@@ -615,18 +615,17 @@ XPC_WN_NoHelper_Resolve(JSContext* cx, H
                                  set, nullptr, nullptr, wrapper->GetScope(),
                                  true, wrapper, wrapper, nullptr,
                                  JSPROP_ENUMERATE |
                                  JSPROP_READONLY |
                                  JSPROP_PERMANENT,
                                  resolvedp);
 }
 
-const XPCWrappedNativeJSClass XPC_WN_NoHelper_JSClass = {
-  { // base
+const js::Class XPC_WN_NoHelper_JSClass = {
     "XPCWrappedNative_NoHelper",    // name;
     WRAPPER_FLAGS |
     JSCLASS_PRIVATE_IS_NSISUPPORTS, // flags
 
     /* Mandatory non-null function pointer members. */
     XPC_WN_OnlyIWrite_AddPropertyStub, // addProperty
     XPC_WN_CantDeletePropertyStub,     // delProperty
     nullptr,                           // getProperty
@@ -660,17 +659,16 @@ const XPCWrappedNativeJSClass XPC_WN_NoH
         nullptr, // setProperty
         nullptr, // getOwnPropertyDescriptor
         nullptr, // deleteProperty
         nullptr, nullptr, // watch/unwatch
         nullptr, // getElements
         nullptr, // enumerate
         nullptr, // funToString
     }
-  }
 };
 
 
 /***************************************************************************/
 
 static bool
 XPC_WN_MaybeResolvingPropertyStub(JSContext* cx, HandleObject obj, HandleId id, HandleValue v)
 {
@@ -957,98 +955,97 @@ XPCNativeScriptableInfo::Construct(const
     }
 
     return newObj;
 }
 
 void
 XPCNativeScriptableShared::PopulateJSClass()
 {
-    MOZ_ASSERT(mJSClass.base.name, "bad state!");
+    MOZ_ASSERT(mJSClass.name, "bad state!");
 
-    mJSClass.base.flags = WRAPPER_FLAGS |
-                          JSCLASS_PRIVATE_IS_NSISUPPORTS;
+    mJSClass.flags = WRAPPER_FLAGS | JSCLASS_PRIVATE_IS_NSISUPPORTS;
 
     if (mFlags.IsGlobalObject())
-        mJSClass.base.flags |= XPCONNECT_GLOBAL_FLAGS;
+        mJSClass.flags |= XPCONNECT_GLOBAL_FLAGS;
 
     JSAddPropertyOp addProperty;
     if (mFlags.WantAddProperty())
         addProperty = XPC_WN_Helper_AddProperty;
     else if (mFlags.UseJSStubForAddProperty())
         addProperty = nullptr;
     else if (mFlags.AllowPropModsDuringResolve())
         addProperty = XPC_WN_MaybeResolvingPropertyStub;
     else
         addProperty = XPC_WN_CannotModifyPropertyStub;
-    mJSClass.base.addProperty = addProperty;
+    mJSClass.addProperty = addProperty;
 
     JSDeletePropertyOp delProperty;
     if (mFlags.UseJSStubForDelProperty())
         delProperty = nullptr;
     else if (mFlags.AllowPropModsDuringResolve())
         delProperty = XPC_WN_MaybeResolvingDeletePropertyStub;
     else
         delProperty = XPC_WN_CantDeletePropertyStub;
-    mJSClass.base.delProperty = delProperty;
+    mJSClass.delProperty = delProperty;
 
     if (mFlags.WantGetProperty())
-        mJSClass.base.getProperty = XPC_WN_Helper_GetProperty;
+        mJSClass.getProperty = XPC_WN_Helper_GetProperty;
     else
-        mJSClass.base.getProperty = nullptr;
+        mJSClass.getProperty = nullptr;
 
     JSSetterOp setProperty;
     if (mFlags.WantSetProperty())
         setProperty = XPC_WN_Helper_SetProperty;
     else if (mFlags.UseJSStubForSetProperty())
         setProperty = nullptr;
     else if (mFlags.AllowPropModsDuringResolve())
         setProperty = XPC_WN_MaybeResolvingSetPropertyStub;
     else
         setProperty = XPC_WN_CannotModifySetPropertyStub;
-    mJSClass.base.setProperty = setProperty;
+    mJSClass.setProperty = setProperty;
 
     MOZ_ASSERT_IF(mFlags.WantEnumerate(), !mFlags.WantNewEnumerate());
     MOZ_ASSERT_IF(mFlags.WantNewEnumerate(), !mFlags.WantEnumerate());
 
     // We will use ops->enumerate set below for NewEnumerate
     if (mFlags.WantNewEnumerate())
-        mJSClass.base.enumerate = nullptr;
+        mJSClass.enumerate = nullptr;
     else if (mFlags.WantEnumerate())
-        mJSClass.base.enumerate = XPC_WN_Helper_Enumerate;
+        mJSClass.enumerate = XPC_WN_Helper_Enumerate;
     else
-        mJSClass.base.enumerate = XPC_WN_Shared_Enumerate;
+        mJSClass.enumerate = XPC_WN_Shared_Enumerate;
 
     // We have to figure out resolve strategy at call time
-    mJSClass.base.resolve = XPC_WN_Helper_Resolve;
+    mJSClass.resolve = XPC_WN_Helper_Resolve;
 
     if (mFlags.WantFinalize())
-        mJSClass.base.finalize = XPC_WN_Helper_Finalize;
+        mJSClass.finalize = XPC_WN_Helper_Finalize;
     else
-        mJSClass.base.finalize = XPC_WN_NoHelper_Finalize;
+        mJSClass.finalize = XPC_WN_NoHelper_Finalize;
 
-    js::ObjectOps* ops = &mJSClass.base.ops;
+    js::ObjectOps* ops = &mJSClass.ops;
     if (mFlags.WantNewEnumerate())
         ops->enumerate = XPC_WN_JSOp_Enumerate;
 
     if (mFlags.WantCall())
-        mJSClass.base.call = XPC_WN_Helper_Call;
+        mJSClass.call = XPC_WN_Helper_Call;
     if (mFlags.WantConstruct())
-        mJSClass.base.construct = XPC_WN_Helper_Construct;
+        mJSClass.construct = XPC_WN_Helper_Construct;
 
     if (mFlags.WantHasInstance())
-        mJSClass.base.hasInstance = XPC_WN_Helper_HasInstance;
+        mJSClass.hasInstance = XPC_WN_Helper_HasInstance;
 
     if (mFlags.IsGlobalObject())
-        mJSClass.base.trace = JS_GlobalObjectTraceHook;
+        mJSClass.trace = JS_GlobalObjectTraceHook;
     else
-        mJSClass.base.trace = XPCWrappedNative::Trace;
+        mJSClass.trace = XPCWrappedNative::Trace;
 
-    mJSClass.base.ext.isWrappedNative = true;
-    mJSClass.base.ext.objectMovedOp = WrappedNativeObjectMoved;
+    mJSClass.ext.isWrappedNative = true;
+    mJSClass.ext.objectMovedOp = WrappedNativeObjectMoved;
 }
 
 /***************************************************************************/
 /***************************************************************************/
 
 // Compatibility hack.
 //
 // XPConnect used to do all sorts of funny tricks to find the "correct"
@@ -1064,17 +1061,17 @@ XPCNativeScriptableShared::PopulateJSCla
 // work on the derived object, which we really don't want to support. But we
 // handle it anyway, for now, to minimize regression risk on an already-risky
 // landing.
 //
 // This hack is mainly useful for the NoHelper JSClass. We also fix up
 // Components.utils because it implements nsIXPCScriptable (giving it a custom
 // JSClass) but not nsIClassInfo (which would put the methods on a prototype).
 
-#define IS_NOHELPER_CLASS(clasp) (clasp == &XPC_WN_NoHelper_JSClass.base)
+#define IS_NOHELPER_CLASS(clasp) (clasp == &XPC_WN_NoHelper_JSClass)
 #define IS_CU_CLASS(clasp) (clasp->name[0] == 'n' && !strcmp(clasp->name, "nsXPCComponents_Utils"))
 
 MOZ_ALWAYS_INLINE JSObject*
 FixUpThisIfBroken(JSObject* obj, JSObject* funobj)
 {
     if (funobj) {
         JSObject* parentObj =
             &js::GetFunctionNativeReserved(funobj,
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -920,18 +920,17 @@ private:
 * Core classes for wrapped native objects for use from JavaScript...
 *
 ****************************************************************************
 ***************************************************************************/
 
 // These are the various JSClasses and callbacks whose use that required
 // visibility from more than one .cpp file.
 
-struct XPCWrappedNativeJSClass;
-extern const XPCWrappedNativeJSClass XPC_WN_NoHelper_JSClass;
+extern const js::Class XPC_WN_NoHelper_JSClass;
 extern const js::Class XPC_WN_NoMods_WithCall_Proto_JSClass;
 extern const js::Class XPC_WN_NoMods_NoCall_Proto_JSClass;
 extern const js::Class XPC_WN_ModsAllowed_WithCall_Proto_JSClass;
 extern const js::Class XPC_WN_ModsAllowed_NoCall_Proto_JSClass;
 extern const js::Class XPC_WN_Tearoff_JSClass;
 #define XPC_WN_TEAROFF_RESERVED_SLOTS 1
 #define XPC_WN_TEAROFF_FLAT_OBJECT_SLOT 0
 extern const js::Class XPC_WN_NoHelper_Proto_JSClass;
@@ -1661,56 +1660,52 @@ public:
 // XPCNativeScriptableShared is used to hold the JSClass and the
 // associated scriptable flags for XPCWrappedNatives. These are shared across
 // the runtime and are garbage collected by xpconnect. We *used* to just store
 // this inside the XPCNativeScriptableInfo (usually owned by instances of
 // XPCWrappedNativeProto. This had two problems... It was wasteful, and it
 // was a big problem when wrappers are reparented to different scopes (and
 // thus different protos (the DOM does this).
 
-// We maintain the invariant that every JSClass for which ext.isWrappedNative
-// is true is a contained in an instance of this struct, and can thus be cast
-// to it.
-//
-// XXXbz Do we still need this struct at all?
-struct XPCWrappedNativeJSClass
-{
-    js::Class base;
-};
-
 class XPCNativeScriptableShared
 {
 public:
-    const XPCNativeScriptableFlags& GetFlags() const {return mFlags;}
-    const JSClass*                  GetJSClass()
-        {return Jsvalify(&mJSClass.base);}
+    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.base.name = aName;  // take ownership
-         MOZ_COUNT_CTOR(XPCNativeScriptableShared);}
-
-    ~XPCNativeScriptableShared()
-        {if (mJSClass.base.name)free((void*)mJSClass.base.name);
-         MOZ_COUNT_DTOR(XPCNativeScriptableShared);}
-
-    char* TransferNameOwnership()
-        {char* name=(char*)mJSClass.base.name; mJSClass.base.name = nullptr;
-        return name;}
+    {
+        memset(&mJSClass, 0, sizeof(mJSClass));
+        mJSClass.name = aName;  // take ownership
+        MOZ_COUNT_CTOR(XPCNativeScriptableShared);
+    }
+
+    ~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();}
+    void Mark()   { mFlags.Mark(); }
+    void Unmark() { mFlags.Unmark(); }
+    bool IsMarked() const { return mFlags.IsMarked(); }
 
 private:
     XPCNativeScriptableFlags mFlags;
-    XPCWrappedNativeJSClass  mJSClass;
+    js::Class mJSClass;
 };
 
 /***************************************************************************/
 // XPCNativeScriptableInfo is used to hold the nsIXPCScriptable state for a
 // given class or instance.
 
 class XPCNativeScriptableInfo
 {