Bug 1389848: Make isServiceInstantiated*() return false rather than throw for uninstantiated services. r=ehsan
authorKris Maglione <maglione.k@gmail.com>
Sat, 12 Aug 2017 16:15:19 -0700
changeset 374749 e194530032089fd598a5645e95d2e3daa327c980
parent 374748 890e87283c5ddbf66388f5ecb3165b9bc6cfb64c
child 374750 3c160a8e90ad661e21ff032acc870e75d52115d1
push id32335
push usercbook@mozilla.com
push dateTue, 15 Aug 2017 09:42:31 +0000
treeherdermozilla-central@564e82f0f289 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1389848
milestone57.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 1389848: Make isServiceInstantiated*() return false rather than throw for uninstantiated services. r=ehsan MozReview-Commit-ID: J8w7eQ6R3eS
browser/components/tests/startupRecorder.js
xpcom/components/nsComponentManager.cpp
xpcom/components/nsIServiceManager.idl
--- a/browser/components/tests/startupRecorder.js
+++ b/browser/components/tests/startupRecorder.js
@@ -41,18 +41,17 @@ startupRecorder.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
 
   record(name) {
     this.data.code[name] = {
       components: this.loader.loadedComponents(),
       modules: this.loader.loadedModules(),
       services: Object.keys(Cc).filter(c => {
         try {
-          Cm.isServiceInstantiatedByContractID(c, Ci.nsISupports);
-          return true;
+          return Cm.isServiceInstantiatedByContractID(c, Ci.nsISupports);
         } catch (e) {
           return false;
         }
       })
     };
   },
 
   observe(subject, topic, data) {
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -1311,28 +1311,30 @@ nsComponentManagerImpl::IsServiceInstant
     aClass.ToProvidedString(cid);
     aIID.ToProvidedString(iid);
     fprintf(stderr, "Checking for service on shutdown. Denied.\n"
             "         CID: %s\n         IID: %s\n", cid, iid);
 #endif /* SHOW_DENIED_ON_SHUTDOWN */
     return NS_ERROR_UNEXPECTED;
   }
 
-  nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
+  nsresult rv = NS_OK;
   nsFactoryEntry* entry;
 
   {
     SafeMutexAutoLock lock(mLock);
     entry = mFactories.Get(aClass);
   }
 
   if (entry && entry->mServiceObject) {
     nsCOMPtr<nsISupports> service;
     rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
     *aResult = (service != nullptr);
+  } else {
+    *aResult = false;
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsComponentManagerImpl::IsServiceInstantiatedByContractID(
     const char* aContractID,
@@ -1351,27 +1353,29 @@ nsComponentManagerImpl::IsServiceInstant
     char iid[NSID_LENGTH];
     aIID.ToProvidedString(iid);
     fprintf(stderr, "Checking for service on shutdown. Denied.\n"
             "  ContractID: %s\n         IID: %s\n", aContractID, iid);
 #endif /* SHOW_DENIED_ON_SHUTDOWN */
     return NS_ERROR_UNEXPECTED;
   }
 
-  nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
+  nsresult rv = NS_OK;
   nsFactoryEntry* entry;
   {
     SafeMutexAutoLock lock(mLock);
     entry = mContractIDs.Get(nsDependentCString(aContractID));
   }
 
   if (entry && entry->mServiceObject) {
     nsCOMPtr<nsISupports> service;
     rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
     *aResult = (service != nullptr);
+  } else {
+    *aResult = false;
   }
   return rv;
 }
 
 
 NS_IMETHODIMP
 nsComponentManagerImpl::GetServiceByContractID(const char* aContractID,
                                                const nsIID& aIID,
--- a/xpcom/components/nsIServiceManager.idl
+++ b/xpcom/components/nsIServiceManager.idl
@@ -40,23 +40,22 @@ interface nsIServiceManager : nsISupport
     void getServiceByContractID(in string aContractID,
 				in nsIIDRef aIID, 
 				[iid_is(aIID),retval] out nsQIResult result);
 
     /**
      * isServiceInstantiated
      *
      * isServiceInstantiated will return a true if the service has already
-     * been created, or throw otherwise
+     * been created, or false otherwise. Throws if the service does not
+     * implement the given IID.
      *
      * @param aClass or aContractID : aClass or aContractID of object 
      *                                instance requested
      * @param aIID : IID of interface requested
-     * @throws NS_ERROR_SERVICE_NOT_AVAILABLE if the service hasn't been 
-     *         instantiated
      * @throws NS_NOINTERFACE if the IID given isn't supported by the object
      */
     boolean isServiceInstantiated(in nsCIDRef aClass, in nsIIDRef aIID);
     boolean isServiceInstantiatedByContractID(in string aContractID, in nsIIDRef aIID);
 };
 
 
 %{C++