Bug 755255 - Hoist mJSContextStack into XPCJSRuntime. r=mrbkap

This commit is contained in:
Bobby Holley 2012-06-21 16:14:48 +02:00
parent 172742cebc
commit 742b686e2e
4 changed files with 27 additions and 29 deletions

View File

@ -987,6 +987,12 @@ DetachedWrappedNativeProtoShutdownMarker(JSDHashTable *table, JSDHashEntryHdr *h
return JS_DHASH_NEXT;
}
void XPCJSRuntime::DestroyJSContextStack()
{
delete mJSContextStack;
mJSContextStack = nsnull;
}
void XPCJSRuntime::SystemIsBeingShutDown()
{
DOM_ClearInterfaces();
@ -1936,6 +1942,7 @@ bool PreserveWrapper(JSContext *cx, JSObject *obj)
XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
: mXPConnect(aXPConnect),
mJSRuntime(nsnull),
mJSContextStack(new XPCJSContextStack()),
mJSCycleCollectionContext(nsnull),
mWrappedJSMap(JSObject2WrappedJSMap::newMap(XPC_JS_MAP_SIZE)),
mWrappedJSClassMap(IID2WrappedJSClassMap::newMap(XPC_JS_CLASS_MAP_SIZE)),

View File

@ -240,8 +240,7 @@ XPCPerThreadData* XPCPerThreadData::gThreads = nsnull;
XPCPerThreadData *XPCPerThreadData::sMainThreadData = nsnull;
void * XPCPerThreadData::sMainJSThread = nsnull;
XPCPerThreadData::XPCPerThreadData()
: mJSContextStack(new XPCJSContextStack()),
XPCPerThreadData::XPCPerThreadData() :
mNextThread(nsnull),
mCallContext(nsnull),
mResolveName(JSID_VOID),
@ -268,8 +267,6 @@ XPCPerThreadData::Cleanup()
MOZ_ASSERT(!mAutoRoots);
NS_IF_RELEASE(mExceptionManager);
NS_IF_RELEASE(mException);
delete mJSContextStack;
mJSContextStack = nsnull;
if (mCallContext)
mCallContext->SystemIsBeingShutDown();
@ -402,33 +399,14 @@ XPCPerThreadData::CleanupAllThreads()
// to copy out the data that needs to be cleaned up *outside* of
// the lock. Yuk!
XPCJSContextStack** stacks = nsnull;
int count = 0;
int i;
if (gLock) {
MutexAutoLock lock(*gLock);
for (XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread)
count++;
stacks = (XPCJSContextStack**) new XPCJSContextStack*[count] ;
if (stacks) {
i = 0;
for (XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread) {
stacks[i++] = cur->mJSContextStack;
cur->mJSContextStack = nsnull;
cur->Cleanup();
}
for (XPCPerThreadData* cur = gThreads; cur; cur = cur->mNextThread) {
cur->Cleanup();
}
}
if (stacks) {
for (i = 0; i < count; i++)
delete stacks[i];
delete [] stacks;
}
if (gTLSIndex != BAD_TLS_INDEX)
PR_SetThreadPrivate(gTLSIndex, nsnull);
}

View File

@ -105,6 +105,11 @@ nsXPConnect::~nsXPConnect()
}
XPCPerThreadData::CleanupAllThreads();
// This needs to happen exactly here, otherwise we leak at shutdown. I don't
// know why. :-(
mRuntime->DestroyJSContextStack();
mShuttingDown = true;
if (cx) {
// XXX Call even if |mRuntime| null?

View File

@ -647,6 +647,7 @@ private:
// So, xpconnect can only be used on one JSRuntime within the process.
// no virtuals. no refcounting.
class XPCJSContextStack;
class XPCJSRuntime
{
public:
@ -654,6 +655,10 @@ public:
JSRuntime* GetJSRuntime() const {return mJSRuntime;}
nsXPConnect* GetXPConnect() const {return mXPConnect;}
XPCJSContextStack* GetJSContextStack() {return mJSContextStack;}
void DestroyJSContextStack();
JSContext* GetJSCycleCollectionContext();
JSObject2WrappedJSMap* GetWrappedJSMap() const
@ -818,6 +823,7 @@ private:
nsXPConnect* mXPConnect;
JSRuntime* mJSRuntime;
XPCJSContextStack* mJSContextStack;
JSContext* mJSCycleCollectionContext;
JSObject2WrappedJSMap* mWrappedJSMap;
IID2WrappedJSClassMap* mWrappedJSClassMap;
@ -3722,8 +3728,6 @@ public:
return false;
}
XPCJSContextStack* GetJSContextStack() {return mJSContextStack;}
XPCCallContext* GetCallContext() const {return mCallContext;}
XPCCallContext* SetCallContext(XPCCallContext* ccx)
{XPCCallContext* old = mCallContext; mCallContext = ccx; return old;}
@ -3737,10 +3741,15 @@ public:
{XPCWrappedNative* old = mResolvingWrapper;
mResolvingWrapper = w; return old;}
// Forward to the runtime for now. This will go away entirely soon.
XPCJSContextStack* GetJSContextStack() {
return nsXPConnect::GetXPConnect()->GetRuntime()->GetJSContextStack();
}
void Cleanup();
void ReleaseNatives();
bool IsValid() const {return mJSContextStack != nsnull;}
bool IsValid() const { return true; }
static Mutex* GetLock() {return gLock;}
// Must be called with the threads locked.
@ -3772,7 +3781,6 @@ private:
static XPCPerThreadData* GetDataImpl(JSContext *cx);
private:
XPCJSContextStack* mJSContextStack;
XPCPerThreadData* mNextThread;
XPCCallContext* mCallContext;
jsid mResolveName;