Bug 937152 - Remove XPCWrappedJS::mMainThread and mMainThreadOnly. r=bholley

This commit is contained in:
Andrew McCreight 2013-11-17 14:47:02 -08:00
parent e8941dde8b
commit b734ae8d6b
2 changed files with 1 additions and 76 deletions

View File

@ -175,20 +175,6 @@ nsXPCWrappedJS::Release(void)
MOZ_CRASH();
NS_PRECONDITION(0 != mRefCnt, "dup release");
if (mMainThreadOnly && !NS_IsMainThread()) {
// We'd like to abort here, but this can happen if someone uses a proxy
// for the nsXPCWrappedJS.
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
// If we can't get the main thread anymore we just leak, but this really
// shouldn't happen.
MOZ_ASSERT(mainThread, "Can't get main thread, leaking nsXPCWrappedJS!");
if (mainThread) {
NS_ProxyRelease(mainThread,
static_cast<nsIXPConnectWrappedJS*>(this));
}
return mRefCnt;
}
// need to take the map lock here to prevent GetNewOrUsed from trying
// to reuse a wrapper on one thread while it's being destroyed on another
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
@ -253,28 +239,6 @@ nsXPCWrappedJS::GetJSObject()
return mJSObj;
}
static bool
CheckMainThreadOnly(nsXPCWrappedJS *aWrapper)
{
if(aWrapper->IsMainThreadOnly())
return NS_IsMainThread();
nsCOMPtr<nsIClassInfo> ci;
CallQueryInterface(aWrapper, getter_AddRefs(ci));
if (ci) {
uint32_t flags;
if (NS_SUCCEEDED(ci->GetFlags(&flags)) && !(flags & nsIClassInfo::MAIN_THREAD_ONLY))
return true;
if (!NS_IsMainThread())
return false;
}
aWrapper->SetIsMainThreadOnly();
return true;
}
// static
nsresult
nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
@ -339,13 +303,6 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
map->Add(cx, root);
}
if (!CheckMainThreadOnly(root)) {
XPCAutoLock lock(rt->GetMapLock());
map->Remove(root);
wrapper = nullptr;
}
goto return_wrapper;
} else {
// just a root wrapper
@ -368,12 +325,6 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
map->Add(cx, root);
}
if (!CheckMainThreadOnly(root)) {
XPCAutoLock lock(rt->GetMapLock());
map->Remove(root);
goto return_wrapper;
}
}
}
@ -413,12 +364,8 @@ nsXPCWrappedJS::nsXPCWrappedJS(JSContext* cx,
mClass(aClass),
mRoot(root ? root : this),
mNext(nullptr),
mOuter(root ? nullptr : aOuter),
mMainThread(NS_IsMainThread()),
mMainThreadOnly(root && root->mMainThreadOnly)
mOuter(root ? nullptr : aOuter)
{
MOZ_ASSERT_IF(mMainThreadOnly, mMainThread);
InitStub(GetClass()->GetIID());
// intentionally do double addref - see Release().
@ -555,20 +502,6 @@ nsXPCWrappedJS::CallMethod(uint16_t methodIndex,
if (!IsValid())
return NS_ERROR_UNEXPECTED;
if (NS_IsMainThread() != mMainThread) {
NS_NAMED_LITERAL_STRING(kFmt, "Attempt to use JS function on a different thread calling %s.%s. JS objects may not be shared across threads.");
PRUnichar* msg =
nsTextFormatter::smprintf(kFmt.get(),
GetClass()->GetInterfaceName(),
info->name);
nsCOMPtr<nsIConsoleService> cs =
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
if (cs)
cs->LogStringMessage(msg);
NS_Free(msg);
return NS_ERROR_NOT_SAME_THREAD;
}
return GetClass()->CallMethod(this, methodIndex, info, params);
}

View File

@ -2660,12 +2660,6 @@ public:
bool IsAggregatedToNative() const {return mRoot->mOuter != nullptr;}
nsISupports* GetAggregatedNativeObject() const {return mRoot->mOuter;}
void SetIsMainThreadOnly() {
MOZ_ASSERT(mMainThread);
mMainThreadOnly = true;
}
bool IsMainThreadOnly() const {return mMainThreadOnly;}
void TraceJS(JSTracer* trc);
static void GetTraceName(JSTracer* trc, char *buf, size_t bufsize);
@ -2686,8 +2680,6 @@ private:
nsXPCWrappedJS* mRoot;
nsXPCWrappedJS* mNext;
nsISupports* mOuter; // only set in root
bool mMainThread;
bool mMainThreadOnly;
};
/***************************************************************************/