From 656bc99a3ef2f366dc8f0d8074709d074ba43f7a Mon Sep 17 00:00:00 2001 From: "jband%netscape.com" Date: Tue, 17 Apr 2001 07:22:52 +0000 Subject: [PATCH] fix bug 76102. Only vend weak references from the root of a wrappedJS wrapper chain. r=dbaron sr=brendan git-svn-id: svn://10.0.0.236/trunk@92531 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/xpconnect/src/xpcprivate.h | 1 + mozilla/js/src/xpconnect/src/xpcwrappedjs.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mozilla/js/src/xpconnect/src/xpcprivate.h b/mozilla/js/src/xpconnect/src/xpcprivate.h index 6ce9ba3e79d..0eda2553a12 100644 --- a/mozilla/js/src/xpconnect/src/xpcprivate.h +++ b/mozilla/js/src/xpconnect/src/xpcprivate.h @@ -772,6 +772,7 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIXPCONNECTJSOBJECTHOLDER NS_DECL_NSIXPCONNECTWRAPPEDJS + NS_DECL_NSISUPPORTSWEAKREFERENCE // Note that both nsXPTCStubBase and nsIXPConnectWrappedJS declare // GetInterfaceInfo methods with the same sig. So, the declaration diff --git a/mozilla/js/src/xpconnect/src/xpcwrappedjs.cpp b/mozilla/js/src/xpconnect/src/xpcwrappedjs.cpp index b9124a03a6b..2f5ca750cd8 100644 --- a/mozilla/js/src/xpconnect/src/xpcwrappedjs.cpp +++ b/mozilla/js/src/xpconnect/src/xpcwrappedjs.cpp @@ -161,14 +161,25 @@ do_decrement: JS_RemoveRootRT(rt->GetJSRuntime(), &mJSObj); } - // If we are not being used from a weak reference, then this extra - // ref is not needed and we can let ourself be deleted. - if(!mRoot->HasWeakReferences()) + // If we are not the root wrapper or if we are not being used from a + // weak reference, then this extra ref is not needed and we can let + // ourself be deleted. + // Note: HasWeakReferences() could only return true for the root. + if(!HasWeakReferences()) goto do_decrement; } return cnt; } +NS_IMETHODIMP +nsXPCWrappedJS::GetWeakReference(nsIWeakReference** aInstancePtr) +{ + if(mRoot != this) + return mRoot->GetWeakReference(aInstancePtr); + + return nsSupportsWeakReference::GetWeakReference(aInstancePtr); +} + NS_IMETHODIMP nsXPCWrappedJS::GetJSObject(JSObject** aJSObj) {