diff --git a/dom/base/moz.build b/dom/base/moz.build index f28260dd7fc2..4829577bbf75 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -22,6 +22,7 @@ EXPORTS += [ 'nsDOMCID.h', 'nsDOMClassInfoClasses.h', 'nsDOMClassInfoID.h', + 'nsDOMException.h', 'nsDOMJSUtils.h', 'nsDOMNavigationTiming.h', 'nsDOMString.h', diff --git a/dom/base/nsDOMScriptObjectFactory.cpp b/dom/base/nsDOMScriptObjectFactory.cpp index c73f476f2bf4..c270975ef000 100644 --- a/dom/base/nsDOMScriptObjectFactory.cpp +++ b/dom/base/nsDOMScriptObjectFactory.cpp @@ -33,8 +33,6 @@ using mozilla::dom::GetNameSpaceManager; -nsIExceptionProvider* gExceptionProvider = nullptr; - nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() { nsCOMPtr observerService = @@ -43,20 +41,6 @@ nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); } - nsCOMPtr provider = new nsDOMExceptionProvider(); - nsCOMPtr xs = - do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID); - - if (xs) { - xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM); - xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_SVG); - xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_XPATH); - xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_INDEXEDDB); - xs->RegisterExceptionProvider(provider, NS_ERROR_MODULE_DOM_FILEHANDLE); - } - - NS_ASSERTION(!gExceptionProvider, "Registered twice?!"); - provider.swap(gExceptionProvider); } NS_INTERFACE_MAP_BEGIN(nsDOMScriptObjectFactory) @@ -121,26 +105,6 @@ nsDOMScriptObjectFactory::Observe(nsISupports *aSubject, nsGlobalWindow::ShutDown(); nsDOMClassInfo::ShutDown(); - - if (gExceptionProvider) { - nsCOMPtr xs = - do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID); - - if (xs) { - xs->UnregisterExceptionProvider(gExceptionProvider, - NS_ERROR_MODULE_DOM); - xs->UnregisterExceptionProvider(gExceptionProvider, - NS_ERROR_MODULE_SVG); - xs->UnregisterExceptionProvider(gExceptionProvider, - NS_ERROR_MODULE_DOM_XPATH); - xs->UnregisterExceptionProvider(gExceptionProvider, - NS_ERROR_MODULE_DOM_INDEXEDDB); - xs->UnregisterExceptionProvider(gExceptionProvider, - NS_ERROR_MODULE_DOM_FILEHANDLE); - } - - NS_RELEASE(gExceptionProvider); - } } return NS_OK; @@ -166,31 +130,3 @@ nsDOMScriptObjectFactory::RegisterDOMClassInfo(const char *aName, aHasClassInterface, aConstructorCID); } - -NS_IMPL_ISUPPORTS1(nsDOMExceptionProvider, nsIExceptionProvider) - -NS_IMETHODIMP -nsDOMExceptionProvider::GetException(nsresult result, - nsIException *aDefaultException, - nsIException **_retval) -{ - if (!NS_IsMainThread()) { - return NS_ERROR_NOT_IMPLEMENTED; - } - - switch (NS_ERROR_GET_MODULE(result)) - { - case NS_ERROR_MODULE_DOM: - case NS_ERROR_MODULE_SVG: - case NS_ERROR_MODULE_DOM_XPATH: - case NS_ERROR_MODULE_DOM_FILE: - case NS_ERROR_MODULE_DOM_INDEXEDDB: - case NS_ERROR_MODULE_DOM_FILEHANDLE: - return NS_NewDOMException(result, aDefaultException, _retval); - default: - NS_WARNING("Trying to create an exception for the wrong error module."); - return NS_ERROR_FAILURE; - } - NS_NOTREACHED("Not reached"); - return NS_ERROR_UNEXPECTED; -} diff --git a/dom/base/nsDOMScriptObjectFactory.h b/dom/base/nsDOMScriptObjectFactory.h index e86c34132fd9..110e7d8ef266 100644 --- a/dom/base/nsDOMScriptObjectFactory.h +++ b/dom/base/nsDOMScriptObjectFactory.h @@ -20,7 +20,6 @@ #include "nsIDOMScriptObjectFactory.h" #include "nsIObserver.h" -#include "nsIExceptionService.h" #include "mozilla/Attributes.h" class nsDOMScriptObjectFactory MOZ_FINAL : public nsIDOMScriptObjectFactory, @@ -47,9 +46,3 @@ public: const nsCID *aConstructorCID) MOZ_OVERRIDE; }; -class nsDOMExceptionProvider MOZ_FINAL : public nsIExceptionProvider -{ -public: - NS_DECL_THREADSAFE_ISUPPORTS - NS_DECL_NSIEXCEPTIONPROVIDER -}; diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 9691d128e22c..cefe79c494de 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -2853,10 +2853,10 @@ nsJSContext::EnsureStatics() obs->AddObserver(observer, "memory-pressure", false); obs->AddObserver(observer, "quit-application", false); - // We need to explicitly get the nsIDOMScriptObjectFactory service in order - // to force its constructor to run, which registers various exceptions - // providers and other things. It would be nice to make this more explicit - // and less side-effect-y. + // Bug 907848 - We need to explicitly get the nsIDOMScriptObjectFactory + // service in order to force its constructor to run, which registers a + // shutdown observer. It would be nice to make this more explicit and less + // side-effect-y. nsCOMPtr factory = do_GetService(kDOMScriptObjectFactoryCID); if (!factory) { MOZ_CRASH(); diff --git a/xpcom/base/nsExceptionService.cpp b/xpcom/base/nsExceptionService.cpp index ab3cf4d66b85..430eccd08575 100644 --- a/xpcom/base/nsExceptionService.cpp +++ b/xpcom/base/nsExceptionService.cpp @@ -3,16 +3,18 @@ * 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/. */ +#include "nsExceptionService.h" + #include "mozilla/Attributes.h" #include "mozilla/DebugOnly.h" - -#include "nsISupports.h" -#include "nsExceptionService.h" -#include "nsIServiceManager.h" +#include "mozilla/Services.h" #include "nsCOMPtr.h" +#include "nsDOMException.h" +#include "nsIServiceManager.h" +#include "nsISupports.h" +#include "nsThreadUtils.h" #include "pratom.h" #include "prthread.h" -#include "mozilla/Services.h" using namespace mozilla; @@ -21,24 +23,6 @@ static const unsigned BAD_TLS_INDEX = (unsigned) -1; #define CHECK_SERVICE_USE_OK() if (!sLock) return NS_ERROR_NOT_INITIALIZED #define CHECK_MANAGER_USE_OK() if (!mService || !nsExceptionService::sLock) return NS_ERROR_NOT_INITIALIZED -// A key for our registered module providers hashtable -class nsProviderKey : public nsHashKey { -protected: - uint32_t mKey; -public: - nsProviderKey(uint32_t key) : mKey(key) {} - uint32_t HashCode(void) const { - return mKey; - } - bool Equals(const nsHashKey *aKey) const { - return mKey == ((const nsProviderKey *) aKey)->mKey; - } - nsHashKey *Clone() const { - return new nsProviderKey(mKey); - } - uint32_t GetValue() { return mKey; } -}; - /** Exception Manager definition **/ class nsExceptionManager MOZ_FINAL : public nsIExceptionManager { @@ -129,7 +113,6 @@ NS_IMPL_ISUPPORTS3(nsExceptionService, nsIObserver) nsExceptionService::nsExceptionService() - : mProviders(4, true) /* small, thread-safe hashtable */ { #ifdef DEBUG if (PR_ATOMIC_INCREMENT(&totalInstances)!=1) { @@ -174,7 +157,6 @@ void nsExceptionService::ThreadDestruct( void *data ) void nsExceptionService::Shutdown() { - mProviders.Reset(); if (sLock) { DropAllThreads(); delete sLock; @@ -230,30 +212,6 @@ NS_IMETHODIMP nsExceptionService::GetCurrentExceptionManager(nsIExceptionManager return NS_OK; } -/* void registerErrorProvider (in nsIExceptionProvider provider, in uint32_t moduleCode); */ -NS_IMETHODIMP nsExceptionService::RegisterExceptionProvider(nsIExceptionProvider *provider, uint32_t errorModule) -{ - CHECK_SERVICE_USE_OK(); - - nsProviderKey key(errorModule); - if (mProviders.Put(&key, provider)) { - NS_WARNING("Registration of exception provider overwrote another provider with the same module code!"); - } - return NS_OK; -} - -/* void unregisterErrorProvider (in nsIExceptionProvider provider, in uint32_t errorModule); */ -NS_IMETHODIMP nsExceptionService::UnregisterExceptionProvider(nsIExceptionProvider *provider, uint32_t errorModule) -{ - CHECK_SERVICE_USE_OK(); - nsProviderKey key(errorModule); - if (!mProviders.Remove(&key)) { - NS_WARNING("Attempt to unregister an unregistered exception provider!"); - return NS_ERROR_UNEXPECTED; - } - return NS_OK; -} - // nsIObserver NS_IMETHODIMP nsExceptionService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData) { @@ -275,18 +233,26 @@ nsExceptionService::DoGetExceptionFromProvider(nsresult errCode, return NS_OK; NS_RELEASE(*_exc); } - nsProviderKey key(NS_ERROR_GET_MODULE(errCode)); - nsCOMPtr provider = - dont_AddRef((nsIExceptionProvider *)mProviders.Get(&key)); - // No provider so we'll return the default exception - if (!provider) { - *_exc = defaultException; - NS_IF_ADDREF(*_exc); - return NS_OK; + switch (NS_ERROR_GET_MODULE(errCode)) { + case NS_ERROR_MODULE_DOM: + case NS_ERROR_MODULE_SVG: + case NS_ERROR_MODULE_DOM_XPATH: + case NS_ERROR_MODULE_DOM_INDEXEDDB: + case NS_ERROR_MODULE_DOM_FILEHANDLE: + if (NS_IsMainThread()) { + return NS_NewDOMException(errCode, defaultException, _exc); + } + break; + + default: + break; } - return provider->GetException(errCode, defaultException, _exc); + // No provider so we'll return the default exception + *_exc = defaultException; + NS_IF_ADDREF(*_exc); + return NS_OK; } // thread management diff --git a/xpcom/base/nsExceptionService.h b/xpcom/base/nsExceptionService.h index ee86f9a42854..b4a2c52d3067 100644 --- a/xpcom/base/nsExceptionService.h +++ b/xpcom/base/nsExceptionService.h @@ -43,10 +43,7 @@ public: static void DropAllThreads(); static nsExceptionManager *firstThread; - nsSupportsHashtable mProviders; - - /* single lock protects both providers hashtable - and thread list */ + /* Protects the thread list. */ static mozilla::Mutex* sLock; static unsigned tlsIndex; diff --git a/xpcom/base/nsIExceptionService.idl b/xpcom/base/nsIExceptionService.idl index 1a9d75d8d53f..fcc816af3882 100644 --- a/xpcom/base/nsIExceptionService.idl +++ b/xpcom/base/nsIExceptionService.idl @@ -6,16 +6,6 @@ #include "nsISupports.idl" #include "nsIException.idl" -// An exception provider. These can turn special nsresult codes -// into nsIExceptions - -[scriptable, uuid(0577744c-c1d2-47f2-8bcc-ce7a9e5a88fc)] -interface nsIExceptionProvider : nsISupports -{ - /** Gets an nsIException or returns NULL if not possible. **/ - nsIException getException(in nsresult result, in nsIException defaultException); -}; - // A ScriptErrorManager for a single thread. These objects // are _not_ thread-safe. Use the ScriptErrorService // to get a script error manager for your current thread. @@ -36,22 +26,11 @@ interface nsIExceptionManager : nsISupports // The Exception Service. Allows you to get an set exceptions in a thread // safe manner, or to get an ExceptionManager for your specific thread. -[scriptable, uuid(35A88F54-F267-4414-92A7-191F6454AB52)] +[scriptable, uuid(8f9ccabb-a68b-43e3-b570-dd8c3179d2fb)] interface nsIExceptionService : nsIExceptionManager { /** Obtains an exception manager for the current thread. */ readonly attribute nsIExceptionManager currentExceptionManager; - - /** Installs an "exception provider" which is capable of - translating an nsresult into an exception. This enables - error providers to return simple nsresults and only provide - rich errors when specifically requested. It also has the - advantage of allowing code like the DOM to handle all errors - in a single function rather than at each XPCOM entry point. - NOTE: This interface must be thread-safe - it will be called - on whatever thread needs the error translation performed.*/ - void registerExceptionProvider( in nsIExceptionProvider provider, in uint32_t moduleCode ); - void unregisterExceptionProvider( in nsIExceptionProvider provider, in uint32_t moduleCode ); };