diff --git a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp index c9e15b794fd..b98987e4f99 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp @@ -403,20 +403,42 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi if (methodInfo->IsNotXPCOM()) return NS_ERROR_PROXY_INVALID_IN_PARAMETER; - - PLEvent *event = PR_NEW(PLEvent); - - if (event == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - nsXPTCVariant *fullParam; uint8 paramCount; rv = convertMiniVariantToVariant(methodInfo, params, &fullParam, ¶mCount); if (NS_FAILED(rv)) - { - PR_DELETE(event); return rv; + + if (!fullParam) + return NS_ERROR_FAILURE; + + PRBool callDirectly; + + // see if we should call into the method directly. Either it is a QI function call + // (methodIndex == 0), or it is a sync proxy and this code is running on the same thread + // as the destination event queue. + if ( (methodIndex == 0) || + (mProxyType & PROXY_SYNC && + NS_SUCCEEDED(mDestQueue->IsQueueOnCurrentThread(&callDirectly)) && + callDirectly)) + { + + // invoke the magic of xptc... + nsresult rv = XPTC_InvokeByIndex( mRealObject, + methodIndex, + paramCount, + fullParam); + + free(fullParam); // allocated with malloc + return rv; + } + + PLEvent *event = PR_NEW(PLEvent); + + if (event == nsnull) { + free(fullParam); + return NS_ERROR_OUT_OF_MEMORY; } nsProxyObjectCallInfo *proxyInfo = new nsProxyObjectCallInfo(this, @@ -427,12 +449,7 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi event); // will be deleted by ~() if (proxyInfo == nsnull) - { - PR_DELETE(event); - if (fullParam) - free(fullParam); // allocated with malloc - return NS_ERROR_OUT_OF_MEMORY; - } + return NS_ERROR_OUT_OF_MEMORY; PL_InitEvent(event, proxyInfo, @@ -441,24 +458,11 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi if (mProxyType & PROXY_SYNC) { - PRBool callDirectly; - mDestQueue->IsQueueOnCurrentThread(&callDirectly); - - if (callDirectly) - { - EventHandler(event); - PL_DestroyEvent(event); - // there is no need to call the DestroyHandler() because - // there is no need to wake up the nested event loop. - } - else - { - rv = PostAndWait(proxyInfo); - - if (NS_FAILED(rv)) - return rv; - } + rv = PostAndWait(proxyInfo); + if (NS_FAILED(rv)) + return rv; + rv = proxyInfo->GetResult(); delete proxyInfo; return rv;