Merge backout.

This commit is contained in:
Peter Van der Beken 2009-05-16 16:17:50 +02:00
commit 1dfd758d21
6 changed files with 21 additions and 45 deletions

View File

@ -1286,9 +1286,7 @@ nsJSContext::~nsJSContext()
#endif
NS_PRECONDITION(!mTerminations, "Shouldn't have termination funcs by now");
mGlobalWrapperRef = nsnull;
DestroyJSContext();
Unlink();
--sContextCount;
@ -1305,7 +1303,7 @@ nsJSContext::~nsJSContext()
}
void
nsJSContext::DestroyJSContext()
nsJSContext::Unlink()
{
if (!mContext)
return;
@ -1318,37 +1316,30 @@ nsJSContext::DestroyJSContext()
JSOptionChangedCallback,
this);
PRBool do_gc = mGCOnDestruction && !sGCTimer && sReadyForGC;
// Release mGlobalWrapperRef before the context is destroyed
mGlobalWrapperRef = nsnull;
// Let xpconnect destroy the JSContext when it thinks the time is right.
nsIXPConnect *xpc = nsContentUtils::XPConnect();
if (xpc) {
PRBool do_gc = mGCOnDestruction && !sGCTimer && sReadyForGC;
xpc->ReleaseJSContext(mContext, !do_gc);
} else if (do_gc) {
::JS_DestroyContext(mContext);
} else {
::JS_DestroyContextNoGC(mContext);
::JS_DestroyContext(mContext);
}
mContext = nsnull;
}
// QueryInterface implementation for nsJSContext
NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSContext)
NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(nsJSContext)
NS_ASSERTION(!tmp->mContext || tmp->mContext->outstandingRequests == 0,
"Trying to unlink a context with outstanding requests.");
tmp->mIsInitialized = PR_FALSE;
tmp->mGCOnDestruction = PR_FALSE;
tmp->DestroyJSContext();
NS_IMPL_CYCLE_COLLECTION_ROOT_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSContext)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSContext)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGlobalWrapperRef)
tmp->Unlink();
tmp->mIsInitialized = PR_FALSE;
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_REFCNT(nsJSContext, tmp->GetCCRefcnt())
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSContext)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGlobalWrapperRef)
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mContext");
nsContentUtils::XPConnect()->NoteJSContext(tmp->mContext, cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@ -1362,12 +1353,6 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsJSContext, nsIScriptContext)
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsJSContext, nsIScriptContext)
nsrefcnt
nsJSContext::GetCCRefcnt()
{
return mRefCnt.get() + mContext->outstandingRequests;
}
nsresult
nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
void *aScopeObject,

View File

@ -57,8 +57,7 @@ public:
virtual ~nsJSContext();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsJSContext,
nsIScriptContext)
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsJSContext, nsIScriptContext)
virtual PRUint32 GetScriptTypeID()
{ return nsIProgrammingLanguage::JAVASCRIPT; }
@ -219,9 +218,7 @@ protected:
// related to our exception.
void ReportPendingException(PRBool aSetAsideFrameChain);
private:
void DestroyJSContext();
nsrefcnt GetCCRefcnt();
void Unlink();
JSContext *mContext;
PRUint32 mNumEvaluations;

View File

@ -594,8 +594,6 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
#endif
rt = cx->runtime;
JS_ASSERT_IF(rt->gcRunning, cx->outstandingRequests == 0);
if (mode != JSDCM_NEW_FAILED) {
cxCallback = rt->cxCallback;
if (cxCallback) {
@ -631,8 +629,6 @@ js_DestroyContext(JSContext *cx, JSDestroyContextMode mode)
|| cx->requestDepth != 0
#endif
) {
JS_ASSERT(rt->gcLevel == 0);
JS_UNLOCK_GC(rt);
if (last) {

View File

@ -371,6 +371,7 @@ void XPCJSRuntime::TraceXPConnectRoots(JSTracer *trc, JSBool rootGlobals)
}
}
}
NS_ASSERTION(!rootGlobals || mUnrootedGlobalCount == 0, "bad state");
}
XPCWrappedNativeScope::TraceJS(trc, this);

View File

@ -309,7 +309,7 @@ _class::AggregatedQueryInterface(REFNSIID aIID, void** aInstancePtr) \
"not the nsISupports pointer we expect"); \
_class *tmp = static_cast<_class*>(Downcast(s)); \
if (!tmp->IsPartOfAggregated()) \
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, tmp->mRefCnt.get())
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class)
#define NS_GENERIC_AGGREGATED_CONSTRUCTOR(_InstanceClass) \
static NS_METHOD \

View File

@ -322,14 +322,14 @@ public:
///////////////////////////////////////////////////////////////////////////////
#ifdef DEBUG_CC
#define NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, _refcnt) \
cb.DescribeNode(RefCounted, _refcnt, sizeof(_class), #_class);
#define NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class) \
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(), sizeof(_class), #_class);
#else
#define NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, _refcnt) \
cb.DescribeNode(RefCounted, _refcnt);
#define NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class) \
cb.DescribeNode(RefCounted, tmp->mRefCnt.get());
#endif
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_REFCNT(_class, _refcnt) \
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_class) \
NS_IMETHODIMP \
NS_CYCLE_COLLECTION_CLASSNAME(_class)::Traverse \
(void *p, \
@ -339,10 +339,7 @@ public:
NS_ASSERTION(CheckForRightISupports(s), \
"not the nsISupports pointer we expect"); \
_class *tmp = Downcast(s); \
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, _refcnt)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_class) \
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_REFCNT(_class, tmp->mRefCnt.get())
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class)
// Base class' CC participant should return NS_SUCCESS_INTERRUPTED_TRAVERSE
// from Traverse if it wants derived classes to not traverse anything from
@ -372,7 +369,7 @@ public:
nsCycleCollectionTraversalCallback &cb) \
{ \
_class *tmp = static_cast<_class*>(p); \
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, tmp->mRefCnt.get())
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class)
#ifdef DEBUG_CC
#define NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(_cb, _name) \