From 381a5bcaf39198f219c0544443fe5ccaa9c86c9b Mon Sep 17 00:00:00 2001 From: "graydon%mozilla.com" Date: Thu, 14 Jun 2007 19:42:59 +0000 Subject: [PATCH] Bug 368869, suspect all native wrappers for cycle collection. Nth attempt, slightly safer. r=brendan, sr=jst --- js/src/xpconnect/src/xpcwrappednative.cpp | 7 +++++++ js/src/xpconnect/src/xpcwrappednativescope.cpp | 18 +++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/js/src/xpconnect/src/xpcwrappednative.cpp b/js/src/xpconnect/src/xpcwrappednative.cpp index c522a3213f1..6a220c985da 100644 --- a/js/src/xpconnect/src/xpcwrappednative.cpp +++ b/js/src/xpconnect/src/xpcwrappednative.cpp @@ -633,6 +633,13 @@ XPCWrappedNative::~XPCWrappedNative() XPCWrappedNativeProto* proto = GetProto(); + if (proto && + proto->ClassIsMainThreadOnly() && + NS_IsMainThread()) + { + nsCycleCollector_forget(this); + } + if(mScriptableInfo && (!HasProto() || (proto && proto->GetScriptableInfo() != mScriptableInfo))) diff --git a/js/src/xpconnect/src/xpcwrappednativescope.cpp b/js/src/xpconnect/src/xpcwrappednativescope.cpp index 22b2b8cdf6b..59c279b5396 100644 --- a/js/src/xpconnect/src/xpcwrappednativescope.cpp +++ b/js/src/xpconnect/src/xpcwrappednativescope.cpp @@ -272,13 +272,17 @@ WrappedNativeJSGCThingTracer(JSDHashTable *table, JSDHashEntryHdr *hdr, JS_CALL_OBJECT_TRACER(trc, wrapper->GetFlatJSObject(), "XPCWrappedNative::mFlatJSObject"); - // FIXME: this call appears to do more harm than good, but - // there is reason to imagine it might clean up some cycles - // formed by a poor order between C++ and JS garbage cycle - // formations. See Bug 368869. - // - // if (JS_IsGCMarkingTracer(trc)) - // nsCycleCollector_suspectCurrent(wrapper); + if (JS_IsGCMarkingTracer(trc)) + { + XPCWrappedNativeProto* proto = wrapper->GetProto(); + if (proto && + proto->ClassIsMainThreadOnly()) + { + NS_ASSERTION(NS_IsMainThread(), + "Tracing wrapped natives from non-main thread"); + nsCycleCollector_suspectCurrent(wrapper); + } + } } return JS_DHASH_NEXT; }