Backing out changeset dc1aff36a411 (bug 462389) to try to fix bustage

This commit is contained in:
Robert O'Callahan 2008-11-05 12:36:19 +13:00
parent 6ee62d9200
commit 2e6de46ff1
10 changed files with 89 additions and 91 deletions

View File

@ -672,7 +672,7 @@ nsDOMWorkerScriptLoader::
ScriptCompiler::ScriptCompiler(nsDOMWorkerScriptLoader* aLoader,
const nsString& aScriptText,
const nsCString& aFilename,
nsAutoJSValHolder& aScriptObj)
nsAutoJSObjectHolder& aScriptObj)
: ScriptLoaderRunnable(aLoader),
mScriptText(aScriptText),
mFilename(aFilename),

View File

@ -50,7 +50,7 @@
// Other includes
#include "jsapi.h"
#include "nsAutoPtr.h"
#include "nsAutoJSValHolder.h"
#include "nsAutoJSObjectHolder.h"
#include "nsCOMPtr.h"
#include "nsStringGlue.h"
#include "nsTArray.h"
@ -162,12 +162,12 @@ private:
ScriptCompiler(nsDOMWorkerScriptLoader* aLoader,
const nsString& aScriptText,
const nsCString& aFilename,
nsAutoJSValHolder& aScriptObj);
nsAutoJSObjectHolder& aScriptObj);
private:
nsString mScriptText;
nsCString mFilename;
nsAutoJSValHolder& mScriptObj;
nsAutoJSObjectHolder& mScriptObj;
};
class ScriptLoaderDone : public ScriptLoaderRunnable
@ -202,7 +202,7 @@ private:
nsresult result;
nsCOMPtr<nsIURI> finalURI;
nsCOMPtr<nsIChannel> channel;
nsAutoJSValHolder scriptObj;
nsAutoJSObjectHolder scriptObj;
};
nsIThread* mTarget;

View File

@ -48,7 +48,6 @@ MODULE = xpconnect
EXPORTS = \
nsAXPCNativeCallContext.h \
xpc_map_end.h \
nsAutoJSValHolder.h \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -21,7 +21,6 @@
*
* Contributor(s):
* Ben Turner <bent.mozilla@gmail.com> (Original Author)
* Ben Newman <b{enjamn,newman}@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -37,33 +36,55 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NSAUTOJSVALHOLDER_H__
#define __NSAUTOJSVALHOLDER_H__
#ifndef __NSAUTOJSOBJECTHOLDER_H__
#define __NSAUTOJSOBJECTHOLDER_H__
#include "jsapi.h"
/**
* Simple class that looks and acts like a jsval except that it unroots
* Simple class that looks and acts like a JSObject* except that it unroots
* itself automatically if Root() is ever called. Designed to be rooted on the
* context or runtime (but not both!).
* context or runtime (but not both!). Also automatically nulls its JSObject*
* on Unroot and asserts that Root has been called prior to assigning an object.
*/
class nsAutoJSValHolder
class nsAutoJSObjectHolder
{
public:
/**
* Default constructor, no holding.
*/
nsAutoJSObjectHolder()
: mRt(NULL), mObj(NULL), mHeld(PR_FALSE) { }
nsAutoJSValHolder()
: mRt(NULL)
, mVal(JSVAL_NULL)
, mGCThing(NULL)
, mHeld(JS_FALSE)
{
// nothing to do
/**
* Hold by rooting on the context's runtime in the constructor, passing the
* result out.
*/
nsAutoJSObjectHolder(JSContext* aCx, JSBool* aRv = NULL,
JSObject* aObj = NULL)
: mRt(NULL), mObj(aObj), mHeld(JS_FALSE) {
JSBool rv = Hold(aCx);
if (aRv) {
*aRv = rv;
}
}
/**
* Hold by rooting on the runtime in the constructor, passing the result out.
*/
nsAutoJSObjectHolder(JSRuntime* aRt, JSBool* aRv = NULL,
JSObject* aObj = NULL)
: mRt(aRt), mObj(aObj), mHeld(JS_FALSE) {
JSBool rv = Hold(aRt);
if (aRv) {
*aRv = rv;
}
}
/**
* Always release on destruction.
*/
virtual ~nsAutoJSValHolder() {
~nsAutoJSObjectHolder() {
Release();
}
@ -76,39 +97,29 @@ public:
/**
* Hold by rooting on the runtime.
* Note that mGCThing may be JSVAL_NULL, which is not a problem.
*/
JSBool Hold(JSRuntime* aRt) {
if (!mHeld) {
if (JS_AddNamedRootRT(aRt, &mGCThing, "nsAutoJSValHolder")) {
mHeld = JS_AddNamedRootRT(aRt, &mObj, "nsAutoRootedJSObject");
if (mHeld) {
mRt = aRt;
mHeld = JS_TRUE;
} else {
Release(); // out of memory
}
}
return mHeld;
}
/**
* Manually release, nullifying mVal, mGCThing, and mRt, but returning
* the original jsval.
* Manually release.
*/
jsval Release() {
void Release() {
NS_ASSERTION(!mHeld || mRt, "Bad!");
jsval oldval = mVal;
if (mHeld) {
JS_RemoveRootRT(mRt, &mGCThing); // infallible
mHeld = JS_FALSE;
mHeld = !JS_RemoveRootRT(mRt, &mObj);
if (!mHeld) {
mRt = NULL;
}
mObj = NULL;
}
mVal = JSVAL_NULL;
mGCThing = NULL;
mRt = NULL;
return oldval;
}
/**
@ -121,44 +132,33 @@ public:
/**
* Pretend to be a JSObject*.
*/
operator JSObject*() const {
return JSVAL_IS_OBJECT(mVal)
? JSVAL_TO_OBJECT(mVal)
: JSVAL_NULL;
JSObject* get() const {
return mObj;
}
/**
* Pretend to be a jsval.
* Pretend to be a JSObject*.
*/
operator jsval() const { return mVal; }
nsAutoJSValHolder &operator=(JSObject* aOther) {
#ifdef DEBUG
if (aOther) {
NS_ASSERTION(mHeld, "Not rooted!");
}
#endif
return *this = OBJECT_TO_JSVAL(aOther);
operator JSObject*() const {
return get();
}
nsAutoJSValHolder &operator=(jsval aOther) {
/**
* Pretend to be a JSObject*. Assert if not held.
*/
JSObject* operator=(JSObject* aOther) {
#ifdef DEBUG
if (aOther) {
NS_ASSERTION(mHeld, "Not rooted!");
}
#endif
mVal = aOther;
mGCThing = JSVAL_IS_GCTHING(aOther)
? JSVAL_TO_GCTHING(aOther)
: NULL;
return *this;
return mObj = aOther;
}
private:
JSRuntime* mRt;
jsval mVal;
void* mGCThing;
JSObject* mObj;
JSBool mHeld;
};
#endif /* __NSAUTOJSVALHOLDER_H__ */
#endif /* __NSAUTOJSOBJECTHOLDER_H__ */

View File

@ -465,7 +465,7 @@ pre_call_clean_up:
nsCOMPtr<nsIException> e;
XPCConvert::ConstructException(code, sz, "IDispatch", name.get(),
nsnull, getter_AddRefs(e), nsnull, nsnull);
nsnull, getter_AddRefs(e), nsnull);
xpcc->SetException(e);
if(sz)
JS_smprintf_free(sz);

View File

@ -1384,11 +1384,8 @@ XPCConvert::ConstructException(nsresult rv, const char* message,
const char* ifaceName, const char* methodName,
nsISupports* data,
nsIException** exceptn,
JSContext* cx,
jsval* jsExceptionPtr)
const jsval *jsExceptionPtr)
{
NS_ASSERTION(!cx == !jsExceptionPtr, "Expected cx and jsExceptionPtr to cooccur.");
static const char format[] = "\'%s\' when calling method: [%s::%s]";
const char * msg = message;
char* sz = nsnull;
@ -1410,11 +1407,11 @@ XPCConvert::ConstructException(nsresult rv, const char* message,
nsresult res = nsXPCException::NewException(msg, rv, nsnull, data, exceptn);
if(NS_SUCCEEDED(res) && cx && jsExceptionPtr && *exceptn)
if(NS_SUCCEEDED(res) && jsExceptionPtr && *exceptn)
{
nsCOMPtr<nsXPCException> xpcEx = do_QueryInterface(*exceptn);
if(xpcEx)
xpcEx->StowThrownJSVal(cx, *jsExceptionPtr);
xpcEx->SetThrownJSVal(*jsExceptionPtr);
}
if(sz)
@ -1485,7 +1482,7 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx,
// it is a wrapped native, but not an exception!
return ConstructException(NS_ERROR_XPC_JS_THREW_NATIVE_OBJECT,
nsnull, ifaceName, methodName, supports,
exceptn, nsnull, nsnull);
exceptn, nsnull);
}
}
else
@ -1543,7 +1540,7 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx,
return ConstructException(NS_ERROR_XPC_JS_THREW_JS_OBJECT,
JS_GetStringBytes(str),
ifaceName, methodName, nsnull,
exceptn, cx, &s);
exceptn, &s);
}
}
@ -1551,7 +1548,7 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx,
{
return ConstructException(NS_ERROR_XPC_JS_THREW_NULL,
nsnull, ifaceName, methodName, nsnull,
exceptn, cx, &s);
exceptn, &s);
}
if(JSVAL_IS_NUMBER(s))
@ -1584,7 +1581,7 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx,
if(isResult)
return ConstructException(rv, nsnull, ifaceName, methodName,
nsnull, exceptn, cx, &s);
nsnull, exceptn, &s);
else
{
// XXX all this nsISupportsDouble code seems a little redundant
@ -1600,7 +1597,7 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx,
return NS_ERROR_FAILURE;
data->SetData(number);
rv = ConstructException(NS_ERROR_XPC_JS_THREW_NUMBER, nsnull,
ifaceName, methodName, data, exceptn, cx, &s);
ifaceName, methodName, data, exceptn, &s);
NS_RELEASE(data);
return rv;
}
@ -1614,7 +1611,7 @@ XPCConvert::JSValToXPCException(XPCCallContext& ccx,
return ConstructException(NS_ERROR_XPC_JS_THREW_STRING,
JS_GetStringBytes(str),
ifaceName, methodName, nsnull,
exceptn, cx, &s);
exceptn, &s);
return NS_ERROR_FAILURE;
}
@ -1668,7 +1665,7 @@ XPCConvert::JSErrorToXPCException(XPCCallContext& ccx,
rv = ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS,
formattedMsg.get(), ifaceName, methodName, data,
exceptn, nsnull, nsnull);
exceptn, nsnull);
NS_RELEASE(data);
}
@ -1676,7 +1673,7 @@ XPCConvert::JSErrorToXPCException(XPCCallContext& ccx,
{
rv = ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR,
nsnull, ifaceName, methodName, nsnull,
exceptn, nsnull, nsnull);
exceptn, nsnull);
}
return rv;
}

View File

@ -152,21 +152,23 @@ nsXPCException::~nsXPCException()
}
PRBool
nsXPCException::StealThrownJSVal(jsval *vp)
nsXPCException::GetThrownJSVal(jsval *vp) const
{
if(mThrownJSVal.IsHeld())
if(mThrownJSVal)
{
*vp = mThrownJSVal.Release();
if(vp)
*vp = mThrownJSVal->GetJSVal();
return PR_TRUE;
}
return PR_FALSE;
}
void
nsXPCException::StowThrownJSVal(JSContext *cx, jsval v)
nsXPCException::SetThrownJSVal(jsval v)
{
if (mThrownJSVal.Hold(cx))
mThrownJSVal = v;
mThrownJSVal = JSVAL_IS_TRACEABLE(v)
? new XPCTraceableVariant(nsXPConnect::GetRuntimeInstance(), v)
: new XPCVariant(v);
}
void

View File

@ -95,7 +95,6 @@
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsXPIDLString.h"
#include "nsAutoJSValHolder.h"
#include "nsThreadUtils.h"
#include "nsIJSContextStack.h"
@ -2835,8 +2834,7 @@ public:
const char* methodName,
nsISupports* data,
nsIException** exception,
JSContext* cx,
jsval *jsExceptionPtr);
const jsval *jsExceptionPtr);
static void RemoveXPCOMUCStringFinalizer();
@ -2922,6 +2920,8 @@ private:
/***************************************************************************/
class XPCVariant;
class nsXPCException :
public nsIXPCException
{
@ -2954,8 +2954,8 @@ public:
static void InitStatics() { sEverMadeOneFromFactory = JS_FALSE; }
PRBool StealThrownJSVal(jsval* vp);
void StowThrownJSVal(JSContext* cx, jsval v);
PRBool GetThrownJSVal(jsval *vp) const;
void SetThrownJSVal(jsval v);
protected:
void Reset();
@ -2970,7 +2970,7 @@ private:
nsIException* mInner;
PRBool mInitialized;
nsAutoJSValHolder mThrownJSVal;
nsCOMPtr<XPCVariant> mThrownJSVal;
static JSBool sEverMadeOneFromFactory;
};

View File

@ -284,7 +284,7 @@ XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e)
// (see XPCConvert::ConstructException) and we are in a web
// context (i.e., not chrome), rethrow the original value.
if((xpcEx = do_QueryInterface(e)) &&
xpcEx->StealThrownJSVal(&thrown) &&
xpcEx->GetThrownJSVal(&thrown) &&
!IsCallerChrome())
{
JS_SetPendingException(cx, thrown);

View File

@ -1566,7 +1566,7 @@ pre_call_clean_up:
nsCOMPtr<nsIException> e;
XPCConvert::ConstructException(code, sz, GetInterfaceName(), name,
nsnull, getter_AddRefs(e), nsnull, nsnull);
nsnull, getter_AddRefs(e), nsnull);
xpcc->SetException(e);
if(sz)
JS_smprintf_free(sz);