Bug 1495820 - Inline do_QueryWrappedNative() r=bzbarsky
authorAndrew McCreight <continuation@gmail.com>
Wed, 03 Oct 2018 21:40:26 +0000
changeset 487867 9c6662e31204379c3e6f8dc4b0909f95b573664f
parent 487866 ff773ba8e86997a8b7bb049ee6baf70b25ec013d
child 487868 8b1f1ebed0f0d6c8abc7e201d70d999f92f2817e
child 487887 e1b7e9c180815febe1ac11baaa3e2de677624e92
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersbzbarsky
bugs1495820
milestone64.0a1
Bug 1495820 - Inline do_QueryWrappedNative() r=bzbarsky This method does very little, and is called in only a few places, so just inline it. The error variant is not called at all. Simplifying this makes it easier for me to change do_QueryInterface. Differential Revision: https://phabricator.services.mozilla.com/D7527
js/xpconnect/idl/nsIXPConnect.idl
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCRuntimeService.cpp
toolkit/components/places/History.cpp
--- a/js/xpconnect/idl/nsIXPConnect.idl
+++ b/js/xpconnect/idl/nsIXPConnect.idl
@@ -59,36 +59,16 @@ interface nsIXPConnectWrappedNative : ns
     nsISupports* Native() const { return mIdentity; }
 
 protected:
     nsCOMPtr<nsISupports> mIdentity;
 public:
 %}
 };
 
-%{C++
-
-inline
-const nsQueryInterface
-do_QueryWrappedNative(nsIXPConnectWrappedNative *aWrappedNative)
-{
-    return nsQueryInterface(aWrappedNative->Native());
-}
-
-inline
-const nsQueryInterfaceWithError
-do_QueryWrappedNative(nsIXPConnectWrappedNative *aWrappedNative,
-                      nsresult *aError)
-
-{
-    return nsQueryInterfaceWithError(aWrappedNative->Native(), aError);
-}
-
-%}
-
 [builtinclass, uuid(3a01b0d6-074b-49ed-bac3-08c76366cae4)]
 interface nsIXPConnectWrappedJS : nsIXPConnectJSObjectHolder
 {
     /* attribute 'JSObject' inherited from nsIXPConnectJSObjectHolder */
     readonly attribute InterfaceInfoPtr InterfaceInfo;
     readonly attribute nsIIDPtr         InterfaceIID;
 
     // Match the GetJSObject() signature.
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -1965,17 +1965,17 @@ nsXPCComponents_Constructor::CallOrConst
         RootedValue val(cx);
         if (!JS_GetPropertyById(cx, ifacesObj, id, &val) || val.isPrimitive()) {
             return ThrowAndFail(NS_ERROR_XPC_BAD_IID, cx, _retval);
         }
 
         nsCOMPtr<nsIXPConnectWrappedNative> wn;
         if (NS_FAILED(xpc->GetWrappedNativeOfJSObject(cx, &val.toObject(),
                                                       getter_AddRefs(wn))) || !wn ||
-            !(cInterfaceID = do_QueryWrappedNative(wn))) {
+            !(cInterfaceID = do_QueryInterface(wn->Native()))) {
             return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
         }
     } else {
         const nsXPTInterfaceInfo* info =
             nsXPTInterfaceInfo::ByIID(NS_GET_IID(nsISupports));
 
         if (info) {
             cInterfaceID = nsJSIID::NewID(info);
@@ -2013,17 +2013,17 @@ nsXPCComponents_Constructor::CallOrConst
         RootedValue val(cx);
         if (!JS_GetPropertyById(cx, classesObj, id, &val) || val.isPrimitive()) {
             return ThrowAndFail(NS_ERROR_XPC_BAD_CID, cx, _retval);
         }
 
         nsCOMPtr<nsIXPConnectWrappedNative> wn;
         if (NS_FAILED(xpc->GetWrappedNativeOfJSObject(cx, val.toObjectOrNull(),
                                                       getter_AddRefs(wn))) || !wn ||
-            !(cClassID = do_QueryWrappedNative(wn))) {
+            !(cClassID = do_QueryInterface(wn->Native()))) {
             return ThrowAndFail(NS_ERROR_XPC_UNEXPECTED, cx, _retval);
         }
     }
 
     nsCOMPtr<nsIXPCConstructor> ctor = new nsXPCConstructor(cClassID, cInterfaceID, cInitializer);
     RootedObject newObj(cx);
 
     if (NS_FAILED(xpc->WrapNative(cx, obj, ctor, NS_GET_IID(nsIXPCConstructor), newObj.address())) || !newObj) {
--- a/js/xpconnect/src/XPCRuntimeService.cpp
+++ b/js/xpconnect/src/XPCRuntimeService.cpp
@@ -124,17 +124,17 @@ NS_IMETHODIMP
 BackstagePass::GetClassIDNoAlloc(nsCID* aClassIDNoAlloc)
 {
     return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
 BackstagePass::Finalize(nsIXPConnectWrappedNative* wrapper, JSFreeOp * fop, JSObject * obj)
 {
-    nsCOMPtr<nsIGlobalObject> bsp(do_QueryWrappedNative(wrapper));
+    nsCOMPtr<nsIGlobalObject> bsp(do_QueryInterface(wrapper->Native()));
     MOZ_ASSERT(bsp);
     static_cast<BackstagePass*>(bsp.get())->ForgetGlobalObject();
     return NS_OK;
 }
 
 NS_IMETHODIMP
 BackstagePass::PreCreate(nsISupports* nativeObj, JSContext* cx,
                          JSObject* globalObj, JSObject** parentObj)
--- a/toolkit/components/places/History.cpp
+++ b/toolkit/components/places/History.cpp
@@ -229,17 +229,17 @@ GetJSValueAsURI(JSContext* aCtx,
                 const JS::Value& aValue) {
   if (!aValue.isPrimitive()) {
     nsCOMPtr<nsIXPConnect> xpc = nsIXPConnect::XPConnect();
 
     nsCOMPtr<nsIXPConnectWrappedNative> wrappedObj;
     nsresult rv = xpc->GetWrappedNativeOfJSObject(aCtx, aValue.toObjectOrNull(),
                                                   getter_AddRefs(wrappedObj));
     NS_ENSURE_SUCCESS(rv, nullptr);
-    nsCOMPtr<nsIURI> uri = do_QueryWrappedNative(wrappedObj);
+    nsCOMPtr<nsIURI> uri = do_QueryInterface(wrappedObj->Native());
     return uri.forget();
   }
   return nullptr;
 }
 
 /**
  * Obtains an nsIURI from the "uri" property of a JSObject.
  *