From 45c744033deabd31ec360b0566f0f02e21aa5fb6 Mon Sep 17 00:00:00 2001 From: "pedemont%us.ibm.com" Date: Wed, 27 Sep 2006 15:18:35 +0000 Subject: [PATCH] Implement IID for nsJavaXPTCStub. Return associated Java object if returning nsJavaXPTCStub. Original committer: pedemont%us.ibm.com Original revision: 1.10 Original date: 2004/10/18 17:04:29 --- .../xpcom/src/nsJavaXPCOMBindingUtils.cpp | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp b/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp index 347b76fe43f..b9c733d53df 100644 --- a/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp +++ b/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp @@ -257,18 +257,34 @@ GetMatchingXPCOMObject(JNIEnv* env, jobject aJavaObject) jobject GetMatchingJavaObject(JNIEnv* env, void* aXPCOMObject) { - JavaXPCOMBindingEntry *entry = - NS_STATIC_CAST(JavaXPCOMBindingEntry*, - PL_DHashTableOperate(gXPCOMtoJAVABindings, aXPCOMObject, - PL_DHASH_LOOKUP)); + jobject java_obj = nsnull; + nsISupports* xpcom_obj = NS_STATIC_CAST(nsISupports*, aXPCOMObject); - if (PL_DHASH_ENTRY_IS_BUSY(entry)) { - LOG("< Get Java<->XPCOM binding (Java=0x%08x | XPCOM=0x%08x)\n", - env->CallIntMethod(entry->mJavaObject, hashCodeMID), (int) aXPCOMObject); - return entry->mJavaObject; + nsJavaXPTCStub* stub = nsnull; + xpcom_obj->QueryInterface(NS_GET_IID(nsJavaXPTCStub), (void**) &stub); + if (stub) { + java_obj = stub->GetJavaObject(); + NS_ASSERTION(java_obj != nsnull, "nsJavaXPTCStub w/o matching Java object"); + NS_RELEASE(stub); } - return nsnull; + if (java_obj == nsnull) { + JavaXPCOMBindingEntry *entry = + NS_STATIC_CAST(JavaXPCOMBindingEntry*, + PL_DHashTableOperate(gXPCOMtoJAVABindings, aXPCOMObject, + PL_DHASH_LOOKUP)); + + if (PL_DHASH_ENTRY_IS_BUSY(entry)) { + java_obj = entry->mJavaObject; + } + } + + if (java_obj) { + LOG("< Get Java<->XPCOM binding (Java=0x%08x | XPCOM=0x%08x)\n", + env->CallIntMethod(java_obj, hashCodeMID), (int) aXPCOMObject); + } + + return java_obj; } @@ -364,13 +380,13 @@ InitializeJavaGlobals(JNIEnv *env) { return PR_FALSE; } - + if (!(clazz = env->FindClass("org/mozilla/xpcom/XPCOMException")) || !(xpcomExceptionClass = (jclass) env->NewGlobalRef(clazz))) { return PR_FALSE; } - + if (!(hashCodeMID = env->GetMethodID(objectClass, "hashCode","()I"))) { return PR_FALSE; }