Bug 1452981 - Remove qsObjectHelper. r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Wed, 02 May 2018 11:47:02 +0200
changeset 475085 078000699e1c8bd1ae4cd30cc0580f835a618e2c
parent 475084 f4d5d3d50fb5c9798f24cdad517844dff6f926b3
child 475086 04afbcd4a5940eef731b6363679a59390e1d0616
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1452981
milestone62.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 1452981 - Remove qsObjectHelper. r=bz.
dom/base/nsINode.h
dom/base/nsRange.h
dom/bindings/BindingUtils.h
dom/bindings/ToJSValue.h
dom/html/nsGenericHTMLElement.h
js/xpconnect/src/XPCWrappedNative.cpp
js/xpconnect/src/moz.build
js/xpconnect/src/qsObjectHelper.h
js/xpconnect/src/xpcObjectHelper.h
xpcom/base/nsISupportsImpl.h
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -2135,22 +2135,16 @@ inline nsINode* NODE_FROM(C& aContent, D
 NS_DEFINE_STATIC_IID_ACCESSOR(nsINode, NS_INODE_IID)
 
 inline nsISupports*
 ToSupports(nsINode* aPointer)
 {
   return aPointer;
 }
 
-inline nsISupports*
-ToCanonicalSupports(nsINode* aPointer)
-{
-  return aPointer;
-}
-
 // Some checks are faster to do on nsIContent or Element than on
 // nsINode, so spit out FromNode versions taking those types too.
 #define NS_IMPL_FROMNODE_GENERIC(_class, _check, _const)                 \
   template<typename T>                                                   \
   static auto FromNode(_const T& aNode)                                  \
     -> decltype(static_cast<_const _class*>(&aNode))                     \
   {                                                                      \
     return aNode._check ? static_cast<_const _class*>(&aNode) : nullptr; \
--- a/dom/base/nsRange.h
+++ b/dom/base/nsRange.h
@@ -582,20 +582,14 @@ protected:
 
   bool mIsPositioned : 1;
   bool mMaySpanAnonymousSubtrees : 1;
   bool mIsGenerated : 1;
   bool mCalledByJS : 1;
 };
 
 inline nsISupports*
-ToCanonicalSupports(nsRange* aRange)
-{
-  return static_cast<nsIDOMRange*>(aRange);
-}
-
-inline nsISupports*
 ToSupports(nsRange* aRange)
 {
   return static_cast<nsIDOMRange*>(aRange);
 }
 
 #endif /* nsRange_h___ */
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -30,17 +30,17 @@
 #include "mozilla/Likely.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsAutoPtr.h"
 #include "nsIDocument.h"
 #include "nsIGlobalObject.h"
 #include "nsIXPConnect.h"
 #include "nsJSUtils.h"
 #include "nsISupportsImpl.h"
-#include "qsObjectHelper.h"
+#include "xpcObjectHelper.h"
 #include "xpcpublic.h"
 #include "nsIVariant.h"
 #include "mozilla/dom/FakeString.h"
 
 #include "nsWrapperCacheInlines.h"
 
 class nsGenericHTMLElement;
 class nsIJSID;
@@ -1319,17 +1319,17 @@ template <class T>
 MOZ_ALWAYS_INLINE bool
 HandleNewBindingWrappingFailure(JSContext* cx, JS::Handle<JSObject*> scope,
                                 T* value, JS::MutableHandle<JS::Value> rval)
 {
   if (JS_IsExceptionPending(cx)) {
     return false;
   }
 
-  qsObjectHelper helper(value, GetWrapperCache(value));
+  xpcObjectHelper helper(value, GetWrapperCache(value));
   return NativeInterface2JSObjectAndThrowIfFailed(cx, scope, rval,
                                                   helper, nullptr, true);
 }
 
 // Helper for calling HandleNewBindingWrappingFailure with smart pointers
 // (nsAutoPtr/nsRefPtr/nsCOMPtr) or references.
 
 template <class T, bool isSmartPtr=IsSmartPtr<T>::value>
@@ -1553,17 +1553,17 @@ VariantToJsval(JSContext* aCx, nsIVarian
 // the nsWrapperCache for "p".
 template<class T>
 inline bool
 WrapObject(JSContext* cx, T* p, nsWrapperCache* cache, const nsIID* iid,
            JS::MutableHandle<JS::Value> rval)
 {
   if (xpc_FastGetCachedWrapper(cx, cache, rval))
     return true;
-  qsObjectHelper helper(p, cache);
+  xpcObjectHelper helper(ToSupports(p), cache);
   JS::Rooted<JSObject*> scope(cx, JS::CurrentGlobalOrNull(cx));
   return XPCOMObjectToJsval(cx, scope, helper, iid, true, rval);
 }
 
 // A specialization of the above for nsIVariant, because that needs to
 // do something different.
 template<>
 inline bool
@@ -1653,17 +1653,17 @@ WrapObject(JSContext* cx, JSObject& p, J
 // Given an object "p" that inherits from nsISupports, wrap it and return the
 // result.  Null is returned on wrapping failure.  This is somewhat similar to
 // WrapObject() above, but does NOT allow Xrays around the result, since we
 // don't want those for our parent object.
 template<typename T>
 static inline JSObject*
 WrapNativeISupports(JSContext* cx, T* p, nsWrapperCache* cache)
 {
-  qsObjectHelper helper(ToSupports(p), cache);
+  xpcObjectHelper helper(ToSupports(p), cache);
   JS::Rooted<JSObject*> scope(cx, JS::CurrentGlobalOrNull(cx));
   JS::Rooted<JS::Value> v(cx);
   return XPCOMObjectToJsval(cx, scope, helper, nullptr, false, &v) ?
          v.toObjectOrNull() :
          nullptr;
 }
 
 
--- a/dom/bindings/ToJSValue.h
+++ b/dom/bindings/ToJSValue.h
@@ -182,17 +182,17 @@ typename EnableIf<!IsBaseOf<nsWrapperCac
                   IsBaseOf<nsISupports, T>::value, bool>::Type
 ToJSValue(JSContext* aCx,
           T& aArgument,
           JS::MutableHandle<JS::Value> aValue)
 {
   // Make sure we're called in a compartment
   MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx));
 
-  qsObjectHelper helper(ToSupports(&aArgument), nullptr);
+  xpcObjectHelper helper(ToSupports(&aArgument));
   JS::Rooted<JSObject*> scope(aCx, JS::CurrentGlobalOrNull(aCx));
   return XPCOMObjectToJsval(aCx, scope, helper, nullptr, true, aValue);
 }
 
 // Accept nsRefPtr/nsCOMPtr
 template <typename T>
 MOZ_MUST_USE bool
 ToJSValue(JSContext* aCx,
--- a/dom/html/nsGenericHTMLElement.h
+++ b/dom/html/nsGenericHTMLElement.h
@@ -1341,21 +1341,9 @@ NS_DECLARE_NS_NEW_HTML_ELEMENT(TextArea)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Tfoot)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Thead)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Time)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Title)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Track)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Unknown)
 NS_DECLARE_NS_NEW_HTML_ELEMENT(Video)
 
-inline nsISupports*
-ToSupports(nsGenericHTMLElement* aHTMLElement)
-{
-  return static_cast<nsIContent*>(aHTMLElement);
-}
-
-inline nsISupports*
-ToCanonicalSupports(nsGenericHTMLElement* aHTMLElement)
-{
-  return static_cast<nsIContent*>(aHTMLElement);
-}
-
 #endif /* nsGenericHTMLElement_h___ */
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -151,17 +151,17 @@ FinishCreate(XPCWrappedNativeScope* Scop
 nsresult
 XPCWrappedNative::WrapNewGlobal(xpcObjectHelper& nativeHelper,
                                 nsIPrincipal* principal,
                                 bool initStandardClasses,
                                 JS::CompartmentOptions& aOptions,
                                 XPCWrappedNative** wrappedGlobal)
 {
     AutoJSContext cx;
-    nsISupports* identity = nativeHelper.GetCanonical();
+    nsCOMPtr<nsISupports> identity = do_QueryInterface(nativeHelper.Object());
 
     // The object should specify that it's meant to be global.
     MOZ_ASSERT(nativeHelper.GetScriptableFlags() & XPC_SCRIPTABLE_IS_GLOBAL_OBJECT);
 
     // We shouldn't be reusing globals.
     MOZ_ASSERT(!nativeHelper.GetWrapperCache() ||
                !nativeHelper.GetWrapperCache()->GetWrapperPreserveColor());
 
@@ -207,18 +207,17 @@ XPCWrappedNative::WrapNewGlobal(xpcObjec
     MOZ_ASSERT(proto->GetJSProtoObject());
     RootedObject protoObj(cx, proto->GetJSProtoObject());
     bool success = JS_SplicePrototype(cx, global, protoObj);
     if (!success)
         return NS_ERROR_FAILURE;
 
     // Construct the wrapper, which takes over the strong reference to the
     // native object.
-    RefPtr<XPCWrappedNative> wrapper =
-        new XPCWrappedNative(nativeHelper.forgetCanonical(), proto);
+    RefPtr<XPCWrappedNative> wrapper = new XPCWrappedNative(identity.forget(), proto);
 
     //
     // We don't call ::Init() on this wrapper, because our setup requirements
     // are different for globals. We do our setup inline here, instead.
     //
 
     wrapper->mScriptable = scrWrapper;
 
@@ -279,17 +278,17 @@ XPCWrappedNative::GetNewOrUsed(xpcObject
                "We assume the caller already checked if it could get the "
                "wrapper from the cache.");
 
     nsresult rv;
 
     MOZ_ASSERT(!Scope->GetRuntime()->GCIsRunning(),
                "XPCWrappedNative::GetNewOrUsed called during GC");
 
-    nsISupports* identity = helper.GetCanonical();
+    nsCOMPtr<nsISupports> identity = do_QueryInterface(helper.Object());
 
     if (!identity) {
         NS_ERROR("This XPCOM object fails in QueryInterface to nsISupports!");
         return NS_ERROR_FAILURE;
     }
 
     RefPtr<XPCWrappedNative> wrapper;
 
@@ -401,31 +400,30 @@ XPCWrappedNative::GetNewOrUsed(xpcObject
     // Note that the security check happens inside FindTearOff - after the
     // wrapper is actually created, but before JS code can see it.
 
     if (info && !isClassInfoSingleton) {
         proto = XPCWrappedNativeProto::GetNewOrUsed(Scope, info, scrProto);
         if (!proto)
             return NS_ERROR_FAILURE;
 
-        wrapper = new XPCWrappedNative(helper.forgetCanonical(), proto);
+        wrapper = new XPCWrappedNative(identity.forget(), proto);
     } else {
         RefPtr<XPCNativeInterface> iface = Interface;
         if (!iface)
             iface = XPCNativeInterface::GetISupports();
 
         XPCNativeSetKey key(iface);
         RefPtr<XPCNativeSet> set =
             XPCNativeSet::GetNewOrUsed(&key);
 
         if (!set)
             return NS_ERROR_FAILURE;
 
-        wrapper = new XPCWrappedNative(helper.forgetCanonical(), Scope,
-                                       set.forget());
+        wrapper = new XPCWrappedNative(identity.forget(), Scope, set.forget());
     }
 
     MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(parent),
                "Xray wrapper being used to parent XPCWrappedNative?");
 
     // We use an AutoMarkingPtr here because it is possible for JS gc to happen
     // after we have Init'd the wrapper but *before* we add it to the hashtable.
     // This would cause the mSet to get collected and we'd later crash. I've
--- a/js/xpconnect/src/moz.build
+++ b/js/xpconnect/src/moz.build
@@ -1,17 +1,16 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXPORTS += [
     'BackstagePass.h',
-    'qsObjectHelper.h',
     'XPCJSMemoryReporter.h',
     'xpcObjectHelper.h',
     'xpcpublic.h',
 ]
 
 UNIFIED_SOURCES += [
     'ExportHelpers.cpp',
     'nsXPConnect.cpp',
deleted file mode 100644
--- a/js/xpconnect/src/qsObjectHelper.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* vim: set ts=8 sts=4 et sw=4 tw=99: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef qsObjectHelper_h
-#define qsObjectHelper_h
-
-#include "xpcObjectHelper.h"
-
-#include "nsCOMPtr.h"
-#include "nsWrapperCache.h"
-#include "mozilla/TypeTraits.h"
-
-class qsObjectHelper : public xpcObjectHelper
-{
-public:
-    template <class T>
-    inline
-    qsObjectHelper(T* aObject, nsWrapperCache* aCache)
-        : xpcObjectHelper(ToSupports(aObject), ToCanonicalSupports(aObject),
-                          aCache)
-    {}
-
-    template <class T>
-    inline
-    qsObjectHelper(nsCOMPtr<T>& aObject, nsWrapperCache* aCache)
-        : xpcObjectHelper(ToSupports(aObject.get()),
-                          ToCanonicalSupports(aObject.get()), aCache)
-    {
-        if (mCanonical) {
-            // Transfer the strong reference.
-            mCanonicalStrong = dont_AddRef(mCanonical);
-            aObject.forget();
-        }
-    }
-
-    template <class T>
-    inline
-    qsObjectHelper(RefPtr<T>& aObject, nsWrapperCache* aCache)
-        : xpcObjectHelper(ToSupports(aObject.get()),
-                          ToCanonicalSupports(aObject.get()), aCache)
-    {
-        if (mCanonical) {
-            // Transfer the strong reference.
-            mCanonicalStrong = dont_AddRef(mCanonical);
-            aObject.forget();
-        }
-    }
-};
-
-#endif
--- a/js/xpconnect/src/xpcObjectHelper.h
+++ b/js/xpconnect/src/xpcObjectHelper.h
@@ -21,52 +21,29 @@
 #include "nsISupports.h"
 #include "nsIXPCScriptable.h"
 #include "nsWrapperCache.h"
 
 class xpcObjectHelper
 {
 public:
     explicit xpcObjectHelper(nsISupports* aObject, nsWrapperCache* aCache = nullptr)
-      : mCanonical(nullptr)
-      , mObject(aObject)
+      : mObject(aObject)
       , mCache(aCache)
     {
-        if (!mCache) {
-            if (aObject)
-                CallQueryInterface(aObject, &mCache);
-            else
-                mCache = nullptr;
+        if (!mCache && aObject) {
+            CallQueryInterface(aObject, &mCache);
         }
     }
 
     nsISupports* Object()
     {
         return mObject;
     }
 
-    nsISupports* GetCanonical()
-    {
-        if (!mCanonical) {
-            mCanonicalStrong = do_QueryInterface(mObject);
-            mCanonical = mCanonicalStrong;
-        }
-        return mCanonical;
-    }
-
-    already_AddRefed<nsISupports> forgetCanonical()
-    {
-        MOZ_ASSERT(mCanonical, "Huh, no canonical to forget?");
-
-        if (!mCanonicalStrong)
-            mCanonicalStrong = mCanonical;
-        mCanonical = nullptr;
-        return mCanonicalStrong.forget();
-    }
-
     nsIClassInfo* GetClassInfo()
     {
         if (mXPCClassInfo)
           return mXPCClassInfo;
         if (!mClassInfo)
             mClassInfo = do_QueryInterface(mObject);
         return mClassInfo;
     }
@@ -88,46 +65,30 @@ public:
     // We assert that we can reach an nsIXPCScriptable somehow.
     uint32_t GetScriptableFlags()
     {
         // Try getting an nsXPCClassInfo - this handles DOM scriptable helpers.
         nsCOMPtr<nsIXPCScriptable> sinfo = GetXPCClassInfo();
 
         // If that didn't work, try just QI-ing. This handles BackstagePass.
         if (!sinfo)
-            sinfo = do_QueryInterface(GetCanonical());
+            sinfo = do_QueryInterface(mObject);
 
         // We should have something by now.
         MOZ_ASSERT(sinfo);
 
         // Grab the flags.
         return sinfo->GetScriptableFlags();
     }
 
     nsWrapperCache* GetWrapperCache()
     {
         return mCache;
     }
 
-protected:
-    xpcObjectHelper(nsISupports* aObject, nsISupports* aCanonical,
-                    nsWrapperCache* aCache)
-      : mCanonical(aCanonical)
-      , mObject(aObject)
-      , mCache(aCache)
-    {
-        if (!mCache && aObject)
-            CallQueryInterface(aObject, &mCache);
-    }
-
-    nsCOMPtr<nsISupports>    mCanonicalStrong;
-    nsISupports* MOZ_UNSAFE_REF("xpcObjectHelper has been specifically optimized "
-                                "to avoid unnecessary AddRefs and Releases. "
-                                "(see bug 565742)") mCanonical;
-
 private:
     xpcObjectHelper(xpcObjectHelper& aOther) = delete;
 
     nsISupports* MOZ_UNSAFE_REF("xpcObjectHelper has been specifically optimized "
                                 "to avoid unnecessary AddRefs and Releases. "
                                 "(see bug 565742)") mObject;
     nsWrapperCache*          mCache;
     nsCOMPtr<nsIClassInfo>   mClassInfo;
--- a/xpcom/base/nsISupportsImpl.h
+++ b/xpcom/base/nsISupportsImpl.h
@@ -34,22 +34,16 @@
                 "Make this class's destructor non-public");
 
 inline nsISupports*
 ToSupports(nsISupports* aSupports)
 {
   return aSupports;
 }
 
-inline nsISupports*
-ToCanonicalSupports(nsISupports* aSupports)
-{
-  return nullptr;
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 // Macros to help detect thread-safety:
 
 #ifdef MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED
 
 #include "prthread.h" /* needed for thread-safety checks */
 
 class nsAutoOwningThread