Bug 770840 - Add Runtime aborts when using XPCWrappedJS off-main-thread. v2

This commit is contained in:
Bobby Holley 2013-04-12 15:35:00 -04:00
parent 94b63dfc74
commit e11b57da96

View File

@ -11,6 +11,7 @@
#include "nsProxyRelease.h"
#include "nsThreadUtils.h"
#include "nsTextFormatter.h"
#include "nsCycleCollectorUtils.h"
// NOTE: much of the fancy footwork is done in xpcstubs.cpp
@ -150,6 +151,8 @@ nsXPCWrappedJS::QueryInterface(REFNSIID aIID, void** aInstancePtr)
nsrefcnt
nsXPCWrappedJS::AddRef(void)
{
if (!MOZ_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
MOZ_CRASH();
nsrefcnt cnt = NS_AtomicIncrementRefcnt(mRefCnt);
NS_LOG_ADDREF(this, cnt, "nsXPCWrappedJS", sizeof(*this));
@ -164,6 +167,8 @@ nsXPCWrappedJS::AddRef(void)
nsrefcnt
nsXPCWrappedJS::Release(void)
{
if (!MOZ_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
MOZ_CRASH();
NS_PRECONDITION(0 != mRefCnt, "dup release");
if (mMainThreadOnly && !NS_IsMainThread()) {
@ -277,6 +282,10 @@ nsXPCWrappedJS::GetNewOrUsed(JSContext* cx,
nsISupports* aOuter,
nsXPCWrappedJS** wrapperResult)
{
// Do a release-mode assert against accessing nsXPCWrappedJS off-main-thread.
if (!MOZ_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
MOZ_CRASH();
JS::RootedObject jsObj(cx, aJSObj);
JSObject2WrappedJSMap* map;
nsXPCWrappedJS* root = nullptr;
@ -559,6 +568,10 @@ nsXPCWrappedJS::CallMethod(uint16_t methodIndex,
const XPTMethodDescriptor* info,
nsXPTCMiniVariant* params)
{
// Do a release-mode assert against accessing nsXPCWrappedJS off-main-thread.
if (!MOZ_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
MOZ_CRASH();
if (!IsValid())
return NS_ERROR_UNEXPECTED;
if (NS_IsMainThread() != mMainThread) {