From ceff10a2d428dabdad2823e109a3000d87dd15c3 Mon Sep 17 00:00:00 2001 From: "pedemont%us.ibm.com" Date: Wed, 27 Sep 2006 15:13:54 +0000 Subject: [PATCH] A weak reference implementation. Not part of default build. Original committer: pedemont%us.ibm.com Original revision: 1.4 Original date: 2004/09/15 21:50:41 git-svn-id: svn://10.0.0.236/trunk@212539 18797224-902f-48f8-a5cc-f745e15eee43 --- .../java/xpcom/src/nsJavaWrapper.cpp | 53 +++++++------------ 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/mozilla/extensions/java/xpcom/src/nsJavaWrapper.cpp b/mozilla/extensions/java/xpcom/src/nsJavaWrapper.cpp index 8cb816158b6..df97ba1bb0a 100644 --- a/mozilla/extensions/java/xpcom/src/nsJavaWrapper.cpp +++ b/mozilla/extensions/java/xpcom/src/nsJavaWrapper.cpp @@ -320,19 +320,22 @@ SetupParams(JNIEnv *env, const jobject aParam, // Check if we already have a corresponding XPCOM object void* inst = GetMatchingXPCOMObject(env, data); - if (inst == nsnull) { + // Get IID for this param + nsID iid; + rv = GetIIDForMethodParam(aIInfo, aMethodInfo, aParamInfo, + aMethodIndex, aDispatchParams, PR_TRUE, + iid); + if (NS_FAILED(rv)) + return rv; + + PRBool isWeakRef = iid.Equals(NS_GET_IID(nsIWeakReference)); + + if (inst == nsnull && !isWeakRef) { // If there is not corresponding XPCOM object, then that means that the // parameter is non-generated class (that is, it is not one of our // Java stubs that represent an exising XPCOM object). So we need to // create an XPCOM stub, that can route any method calls to the class. - // Get IID for this param - nsID iid; - rv = GetIIDForMethodParam(aIInfo, aMethodInfo, aParamInfo, - aMethodIndex, aDispatchParams, PR_TRUE, iid); - if (NS_FAILED(rv)) - return rv; - // Get interface info for class nsCOMPtr iim = XPTI_GetInterfaceInfoManager(); nsCOMPtr iinfo; @@ -343,34 +346,14 @@ SetupParams(JNIEnv *env, const jobject aParam, inst = SetAsXPTCStub(xpcomStub); AddJavaXPCOMBinding(env, data, inst); } -#if 1 - // XXX This code is here to make sure that the nsJavaXPTCStub that is - // used has the correct (asked for) interface info. For example, in - // the Java code, the nsIWeakReference functions return the current - // Java object ('this'); so when we call GetMatchingXPCOMObject on - // that Java object, we get back a nsJavaXPTCStub that has the interface - // info for something other than nsIWeakReference. This will cause - // problems later when we try to call one of the nsIWeakReference - // functions on that Java object, but the nsJavaXPTCStub object doesn't - // know anything about nsIWeakReference. - else { - if (IsXPTCStub(inst)) { - // Get IID for this param - nsID iid; - rv = GetIIDForMethodParam(aIInfo, aMethodInfo, aParamInfo, - aMethodIndex, aDispatchParams, PR_TRUE, iid); - if (NS_FAILED(rv)) - return rv; - void* temp; - rv = GetXPTCStubAddr(inst)->QueryInterface(iid, &temp); - if (NS_SUCCEEDED(rv) && temp != GetXPTCStubAddr(inst)) - inst = SetAsXPTCStub((nsJavaXPTCStub*) temp); - } - } -#endif - - if (IsXPTCStub(inst)) { + if (isWeakRef) { + // If the function expects an weak reference, then we need to + // create it here. + nsJavaXPTCStubWeakRef* weakref = new nsJavaXPTCStubWeakRef(env, data); + NS_ADDREF(weakref); + aVariant.val.p = aVariant.ptr = (void*) weakref; + } else if (IsXPTCStub(inst)) { nsJavaXPTCStub* xpcomStub = GetXPTCStubAddr(inst); NS_ADDREF(xpcomStub); aVariant.val.p = aVariant.ptr = (void*) xpcomStub;