Bug 337675 - improper automatic nsISupportsWeakReference handling for java-based xpcom objects. XULRunner only. r=bsmedberg

Original committer: pedemont%us.ibm.com
Original revision: 1.41
Original date: 2006/06/09 13:30:24
This commit is contained in:
pedemont%us.ibm.com 2006-09-27 15:17:37 +00:00
parent a7b69855a9
commit 386dc0348e

View File

@ -1510,40 +1510,23 @@ nsJavaXPTCStub::FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
isWeakRef = PR_FALSE;
}
PRBool isXPTCStub;
rv = GetNewOrUsedXPCOMObject(env, java_obj, iid, &xpcom_obj,
&isXPTCStub);
rv = GetNewOrUsedXPCOMObject(env, java_obj, iid, &xpcom_obj);
if (NS_FAILED(rv))
break;
// If the function expects a weak reference, then we need to
// create it here.
if (isWeakRef) {
if (isXPTCStub) {
nsJavaXPTCStub* stub = NS_STATIC_CAST(nsJavaXPTCStub*,
NS_STATIC_CAST(nsXPTCStubBase*,
xpcom_obj));
nsJavaXPTCStubWeakRef* weakref;
weakref = new nsJavaXPTCStubWeakRef(java_obj, stub);
if (!weakref) {
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
nsCOMPtr<nsISupportsWeakReference> supportsweak =
do_QueryInterface(xpcom_obj);
if (supportsweak) {
nsWeakPtr weakref;
supportsweak->GetWeakReference(getter_AddRefs(weakref));
NS_RELEASE(xpcom_obj);
xpcom_obj = weakref;
NS_ADDREF(xpcom_obj);
} else { // if is native XPCOM object
nsCOMPtr<nsISupportsWeakReference> supportsweak =
do_QueryInterface(xpcom_obj);
if (supportsweak) {
nsWeakPtr weakref;
supportsweak->GetWeakReference(getter_AddRefs(weakref));
NS_RELEASE(xpcom_obj);
xpcom_obj = weakref;
NS_ADDREF(xpcom_obj);
} else {
xpcom_obj = nsnull;
}
} else {
xpcom_obj = nsnull;
}
}
}