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 3eee30d40b
commit c8413360d4

View File

@ -12,6 +12,7 @@
#include "nsProxyRelease.h"
#include "nsThreadUtils.h"
#include "nsTextFormatter.h"
#include "nsCycleCollectorUtils.h"
using namespace mozilla;
@ -153,6 +154,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));
@ -167,6 +170,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()) {
@ -274,6 +279,10 @@ nsXPCWrappedJS::GetNewOrUsed(JSObject* aJSObj,
nsISupports* aOuter,
nsXPCWrappedJS** wrapperResult)
{
// Do a release-mode assert against accessing nsXPCWrappedJS off-main-thread.
if (!MOZ_LIKELY(NS_IsMainThread() || NS_IsCycleCollectorThread()))
MOZ_CRASH();
AutoJSContext cx;
JS::RootedObject jsObj(cx, aJSObj);
JSObject2WrappedJSMap* map;
@ -557,6 +566,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) {