Bug 811206, Fix JSHolder drop handling, part 1 (base), r=mccr8

--HG--
extra : rebase_source : 0ea98d9e542ebade36653661fe4e941a03b87781
This commit is contained in:
Olli Pettay 2012-11-28 01:54:15 +02:00
parent a5cafc148a
commit 9ade992793
2 changed files with 10 additions and 16 deletions

View File

@ -4519,28 +4519,14 @@ nsContentUtils::HoldJSObjects(void* aScriptObjectHolder,
{
NS_ENSURE_TRUE(sXPConnect, NS_ERROR_UNEXPECTED);
nsresult rv = sXPConnect->AddJSHolder(aScriptObjectHolder, aTracer);
NS_ENSURE_SUCCESS(rv, rv);
if (sJSGCThingRootCount++ == 0) {
nsLayoutStatics::AddRef();
}
NS_LOG_ADDREF(sXPConnect, sJSGCThingRootCount, "HoldJSObjects",
sizeof(void*));
return NS_OK;
return sXPConnect->AddJSHolder(aScriptObjectHolder, aTracer);
}
/* static */
nsresult
nsContentUtils::DropJSObjects(void* aScriptObjectHolder)
{
NS_LOG_RELEASE(sXPConnect, sJSGCThingRootCount - 1, "HoldJSObjects");
nsresult rv = sXPConnect->RemoveJSHolder(aScriptObjectHolder);
if (--sJSGCThingRootCount == 0) {
nsLayoutStatics::Release();
}
return rv;
return sXPConnect->RemoveJSHolder(aScriptObjectHolder);
}
#ifdef DEBUG

View File

@ -250,7 +250,11 @@ nsresult
XPCJSRuntime::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
{
MOZ_ASSERT(aTracer->Trace, "AddJSHolder needs a non-null Trace function");
bool wasEmpty = mJSHolders.Count() == 0;
mJSHolders.Put(aHolder, aTracer);
if (wasEmpty && mJSHolders.Count() == 1) {
nsLayoutStatics::AddRef();
}
return NS_OK;
}
@ -258,7 +262,11 @@ XPCJSRuntime::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
nsresult
XPCJSRuntime::RemoveJSHolder(void* aHolder)
{
bool hadOne = mJSHolders.Count() == 1;
mJSHolders.Remove(aHolder);
if (hadOne && mJSHolders.Count() == 0) {
nsLayoutStatics::Release();
}
return NS_OK;
}