Bug 911258: Part 1 - Remove nsIExceptionService/Manager usage. r=bholley

This commit is contained in:
Kyle Huey 2013-09-08 20:28:49 -07:00
parent cf498d852b
commit 61aeeecde4
3 changed files with 47 additions and 63 deletions

View File

@ -2898,8 +2898,7 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
mObjectHolderRoots(nullptr),
mWatchdogManager(new WatchdogManager(this)),
mJunkScope(nullptr),
mAsyncSnowWhiteFreer(new AsyncFreeSnowWhite()),
mExceptionManagerNotAvailable(false)
mAsyncSnowWhiteFreer(new AsyncFreeSnowWhite())
{
#ifdef XPC_CHECK_WRAPPERS_AT_SHUTDOWN
DEBUG_WrappedNativeHashtable =

View File

@ -10,6 +10,7 @@
#include "xpcpublic.h"
#include "XPCWrapper.h"
#include "jsprf.h"
#include "nsDOMException.h"
bool XPCThrower::sVerbose = true;
@ -45,8 +46,7 @@ Throw(JSContext *cx, nsresult rv)
bool
XPCThrower::CheckForPendingException(nsresult result, JSContext *cx)
{
nsCOMPtr<nsIException> e;
XPCJSRuntime::Get()->GetPendingException(getter_AddRefs(e));
nsCOMPtr<nsIException> e = XPCJSRuntime::Get()->GetPendingException();
if (!e)
return false;
XPCJSRuntime::Get()->SetPendingException(nullptr);
@ -178,32 +178,52 @@ XPCThrower::BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz)
/* no need to set an expection if the security manager already has */
if (rv == NS_ERROR_XPC_SECURITY_MANAGER_VETO && JS_IsExceptionPending(cx))
return;
nsCOMPtr<nsIException> finalException;
nsCOMPtr<nsIException> defaultException;
nsXPCException::NewException(sz, rv, nullptr, nullptr, getter_AddRefs(defaultException));
nsIExceptionManager * exceptionManager = XPCJSRuntime::Get()->GetExceptionManager();
if (exceptionManager) {
// Ask the provider for the exception, if there is no provider
// we expect it to set e to null
exceptionManager->GetExceptionFromProvider(rv,
defaultException,
getter_AddRefs(finalException));
// We should get at least the defaultException back,
// but just in case
if (finalException == nullptr) {
finalException = defaultException;
XPCJSRuntime* runtime = XPCJSRuntime::Get();
nsCOMPtr<nsIException> existingException = runtime->GetPendingException();
if (existingException) {
nsresult nr;
if (NS_SUCCEEDED(existingException->GetResult(&nr)) &&
rv == nr) {
// Just reuse the existing exception.
return;
}
}
// XXX Should we put the following test and call to JS_ReportOutOfMemory
// inside this test?
if (finalException)
success = ThrowExceptionObject(cx, finalException);
// If we weren't able to build or throw an exception we're
nsCOMPtr<nsIException> finalException;
nsCOMPtr<nsIException> defaultException;
nsXPCException::NewException(sz, rv, nullptr, nullptr,
getter_AddRefs(defaultException));
// Do we use DOM exceptions for this error code?
switch (NS_ERROR_GET_MODULE(rv)) {
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()) {
NS_NewDOMException(rv, defaultException,
getter_AddRefs(finalException));
}
break;
default:
break;
}
// If not, use the default.
if (finalException == nullptr) {
finalException = defaultException;
}
MOZ_ASSERT(finalException);
success = ThrowExceptionObject(cx, finalException);
// If we weren't able to throw an exception we're
// most likely out of memory
if (!success)
if (!success) {
JS_ReportOutOfMemory(cx);
}
}
static bool

View File

@ -132,7 +132,7 @@
#include "nsIConsoleService.h"
#include "nsIScriptError.h"
#include "nsIExceptionService.h"
#include "nsIException.h"
#include "nsVariant.h"
#include "nsIPropertyBag.h"
@ -739,48 +739,15 @@ public:
~XPCJSRuntime();
nsresult GetPendingException(nsIException** aException)
already_AddRefed<nsIException> GetPendingException()
{
if (EnsureExceptionManager())
return mExceptionManager->GetCurrentException(aException);
nsCOMPtr<nsIException> out = mPendingException;
out.forget(aException);
return NS_OK;
return out.forget();
}
nsresult SetPendingException(nsIException* aException)
void SetPendingException(nsIException* aException)
{
if (EnsureExceptionManager())
return mExceptionManager->SetCurrentException(aException);
mPendingException = aException;
return NS_OK;
}
nsIExceptionManager* GetExceptionManager()
{
if (EnsureExceptionManager())
return mExceptionManager;
return nullptr;
}
bool EnsureExceptionManager()
{
if (mExceptionManager)
return true;
if (mExceptionManagerNotAvailable)
return false;
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
if (xs)
xs->GetCurrentExceptionManager(getter_AddRefs(mExceptionManager));
if (mExceptionManager)
return true;
mExceptionManagerNotAvailable = true;
return false;
}
XPCReadableJSStringWrapper *NewStringWrapper(const PRUnichar *str, uint32_t len);
@ -865,8 +832,6 @@ private:
mozilla::TimeStamp mSlowScriptCheckpoint;
nsCOMPtr<nsIException> mPendingException;
nsCOMPtr<nsIExceptionManager> mExceptionManager;
bool mExceptionManagerNotAvailable;
#define XPCCCX_STRING_CACHE_SIZE 2