From 1c669214fe9de34505a4cf3d4cf5e2371e038114 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 21 Apr 2009 16:09:29 -0700 Subject: [PATCH] Bug 467865 - [@ js_RemoveRoot - ... - XPCThrower::ThrowExceptionObject] xpconnect is misusing nsCOMPtr. r=jonas+sr=jst --- js/src/xpconnect/idl/xpcexception.idl | 13 ++++++++++++- js/src/xpconnect/src/xpcconvert.cpp | 4 ++-- js/src/xpconnect/src/xpcexception.cpp | 20 +++++++++++++------- js/src/xpconnect/src/xpcprivate.h | 3 --- js/src/xpconnect/src/xpcthrower.cpp | 4 ++-- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/js/src/xpconnect/idl/xpcexception.idl b/js/src/xpconnect/idl/xpcexception.idl index 62eca10a148..5db9bf9903d 100644 --- a/js/src/xpconnect/idl/xpcexception.idl +++ b/js/src/xpconnect/idl/xpcexception.idl @@ -42,7 +42,14 @@ #include "nsISupports.idl" #include "nsIException.idl" -[scriptable, uuid(b2a34010-3983-11d3-9888-006008962422)] +%{ C++ +#include "jspubtd.h" +%} + +[ptr] native xpcexJSContextPtr(JSContext); + native xpcexJSVal(jsval); + +[scriptable, uuid(cac29630-7bf2-4e22-811b-46855a7d5af0)] interface nsIXPCException : nsIException { // inherits methods from nsIException @@ -53,6 +60,10 @@ interface nsIXPCException : nsIException in nsIStackFrame aLocation, in nsISupports aData, in nsIException aInner); + + [noscript] xpcexJSVal stealJSVal(); + [noscript] void stowJSVal(in xpcexJSContextPtr cx, + in xpcexJSVal val); }; /* this goes into the C++ header verbatim. */ diff --git a/js/src/xpconnect/src/xpcconvert.cpp b/js/src/xpconnect/src/xpcconvert.cpp index 6c847602832..f2ca6cdf680 100644 --- a/js/src/xpconnect/src/xpcconvert.cpp +++ b/js/src/xpconnect/src/xpcconvert.cpp @@ -1428,9 +1428,9 @@ XPCConvert::ConstructException(nsresult rv, const char* message, if(NS_SUCCEEDED(res) && cx && jsExceptionPtr && *exceptn) { - nsCOMPtr xpcEx = do_QueryInterface(*exceptn); + nsCOMPtr xpcEx = do_QueryInterface(*exceptn); if(xpcEx) - xpcEx->StowThrownJSVal(cx, *jsExceptionPtr); + xpcEx->StowJSVal(cx, *jsExceptionPtr); } if(sz) diff --git a/js/src/xpconnect/src/xpcexception.cpp b/js/src/xpconnect/src/xpcexception.cpp index 513e85622cd..d2096e194c9 100644 --- a/js/src/xpconnect/src/xpcexception.cpp +++ b/js/src/xpconnect/src/xpcexception.cpp @@ -151,22 +151,28 @@ nsXPCException::~nsXPCException() Reset(); } -PRBool -nsXPCException::StealThrownJSVal(jsval *vp) +/* [noscript] xpcexJSVal stealJSVal (); */ +NS_IMETHODIMP +nsXPCException::StealJSVal(jsval *vp NS_OUTPARAM) { if(mThrownJSVal.IsHeld()) { *vp = mThrownJSVal.Release(); - return PR_TRUE; + return NS_OK; } - return PR_FALSE; + return NS_ERROR_FAILURE; } -void -nsXPCException::StowThrownJSVal(JSContext *cx, jsval v) +/* [noscript] void stowJSVal (in xpcexJSContextPtr cx, in xpcexJSVal val); */ +NS_IMETHODIMP +nsXPCException::StowJSVal(JSContext* cx, jsval v) { - if (mThrownJSVal.Hold(cx)) + if(mThrownJSVal.Hold(cx)) + { mThrownJSVal = v; + return NS_OK; + } + return NS_ERROR_FAILURE; } void diff --git a/js/src/xpconnect/src/xpcprivate.h b/js/src/xpconnect/src/xpcprivate.h index c528c2365e2..cbc3b9afa0c 100644 --- a/js/src/xpconnect/src/xpcprivate.h +++ b/js/src/xpconnect/src/xpcprivate.h @@ -2982,9 +2982,6 @@ public: static void InitStatics() { sEverMadeOneFromFactory = JS_FALSE; } - PRBool StealThrownJSVal(jsval* vp); - void StowThrownJSVal(JSContext* cx, jsval v); - protected: void Reset(); private: diff --git a/js/src/xpconnect/src/xpcthrower.cpp b/js/src/xpconnect/src/xpcthrower.cpp index 88457576b43..5c8d25375b3 100644 --- a/js/src/xpconnect/src/xpcthrower.cpp +++ b/js/src/xpconnect/src/xpcthrower.cpp @@ -301,7 +301,7 @@ XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e) JSBool success = JS_FALSE; if(e) { - nsCOMPtr xpcEx; + nsCOMPtr xpcEx; jsval thrown; nsXPConnect* xpc; @@ -310,7 +310,7 @@ XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e) // context (i.e., not chrome), rethrow the original value. if(!IsCallerChrome(cx) && (xpcEx = do_QueryInterface(e)) && - xpcEx->StealThrownJSVal(&thrown)) + NS_SUCCEEDED(xpcEx->StealJSVal(&thrown))) { JS_SetPendingException(cx, thrown); success = JS_TRUE;