fix bug 119387. Add a non-allocating IID version of the frequently used getIIDForParam method. r=dbradley sr=jst

This commit is contained in:
jband%netscape.com 2002-01-14 20:02:14 +00:00
parent 80007341d2
commit 66c9536fcc
6 changed files with 65 additions and 104 deletions

View File

@ -2015,8 +2015,7 @@ private:
uint16 methodIndex,
const nsXPTType& type,
nsXPTCMiniVariant* params,
JSBool* iidIsOwned,
nsID** result);
nsID* result);
void CleanupPointerArray(const nsXPTType& datum_type,
JSUint32 array_count,

View File

@ -713,20 +713,17 @@ nsXPCWrappedJSClass::GetInterfaceTypeFromParam(JSContext* cx,
uint16 methodIndex,
const nsXPTType& type,
nsXPTCMiniVariant* nativeParams,
JSBool* iidIsOwned,
nsID** result)
nsID* result)
{
uint8 type_tag = type.TagPart();
nsID* iid;
if(type_tag == nsXPTType::T_INTERFACE)
{
if(NS_FAILED(GetInterfaceInfo()->
GetIIDForParam(methodIndex, &param, &iid)))
if(NS_SUCCEEDED(GetInterfaceInfo()->
GetIIDForParamNoAlloc(methodIndex, &param, result)))
{
return JS_FALSE;
return JS_TRUE;
}
*iidIsOwned = JS_TRUE;
}
else if(type_tag == nsXPTType::T_INTERFACE_IS)
{
@ -743,15 +740,23 @@ nsXPCWrappedJSClass::GetInterfaceTypeFromParam(JSContext* cx,
arg_type.TagPart() == nsXPTType::T_IID)
{
if(arg_param.IsOut())
iid = *((nsID**)nativeParams[argnum].val.p);
{
nsID** p = (nsID**) nativeParams[argnum].val.p;
if(!p || !*p)
return JS_FALSE;
*result = **p;
}
else
iid = (nsID*) nativeParams[argnum].val.p;
*iidIsOwned = JS_FALSE;
{
nsID* p = (nsID*) nativeParams[argnum].val.p;
if(!p)
return JS_FALSE;
*result = *p;
}
return JS_TRUE;
}
}
*result = iid;
return iid ? JS_TRUE : JS_FALSE;
return JS_FALSE;
}
void
@ -813,8 +818,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
JSErrorReporter older;
JSBool success;
JSBool readyToDoTheCall = JS_FALSE;
nsID* conditional_iid = nsnull;
JSBool iidIsOwned = JS_FALSE;
nsID param_iid;
uint8 outConversionFailedIndex;
JSObject* obj;
const char* name = info->GetName();
@ -1055,7 +1059,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
if(datum_type.IsInterfacePointer() &&
!GetInterfaceTypeFromParam(cx, info, param, methodIndex,
datum_type, nativeParams,
&iidIsOwned, &conditional_iid))
&param_iid))
goto pre_call_clean_up;
if(isArray || isSizedString)
@ -1070,7 +1074,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
{
if(!XPCConvert::NativeArray2JS(ccx, &val, (const void**)&pv->val,
datum_type, conditional_iid,
datum_type, &param_iid,
array_count, obj, nsnull))
goto pre_call_clean_up;
}
@ -1085,18 +1089,9 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
else
{
if(!XPCConvert::NativeData2JS(ccx, &val, &pv->val, type,
conditional_iid, obj, nsnull))
&param_iid, obj, nsnull))
goto pre_call_clean_up;
}
if(conditional_iid)
{
if(iidIsOwned)
{
nsMemory::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = nsnull;
}
}
if(param.IsOut())
@ -1174,16 +1169,6 @@ pre_call_clean_up:
*((void**)p) = nsnull;
}
if(conditional_iid)
{
if(iidIsOwned)
{
nsMemory::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = nsnull;
}
if(!readyToDoTheCall)
goto done;
@ -1432,27 +1417,17 @@ pre_call_clean_up:
if(type_tag == nsXPTType::T_INTERFACE)
{
if(NS_FAILED(GetInterfaceInfo()->GetIIDForParam(methodIndex, &param,
&conditional_iid)))
if(NS_FAILED(GetInterfaceInfo()->
GetIIDForParamNoAlloc(methodIndex, &param,
&param_iid)))
HANDLE_OUT_CONVERSION_FAILURE
iidIsOwned = JS_TRUE;
}
else if(type.IsPointer() && !param.IsShared() && !param.IsDipper())
useAllocator = JS_TRUE;
if(!XPCConvert::JSData2Native(ccx, &pv->val, val, type,
useAllocator, conditional_iid, nsnull))
useAllocator, &param_iid, nsnull))
HANDLE_OUT_CONVERSION_FAILURE
if(conditional_iid)
{
if(iidIsOwned)
{
nsMemory::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = nsnull;
}
}
// if any params were dependent, then we must iterate again to convert them.
@ -1503,7 +1478,7 @@ pre_call_clean_up:
{
if(!GetInterfaceTypeFromParam(cx, info, param, methodIndex,
datum_type, nativeParams,
&iidIsOwned, &conditional_iid))
&param_iid))
HANDLE_OUT_CONVERSION_FAILURE
}
else if(type.IsPointer() && !param.IsShared())
@ -1522,7 +1497,7 @@ pre_call_clean_up:
if(!XPCConvert::JSArray2Native(ccx, (void**)&pv->val, val,
array_count, array_count,
datum_type,
useAllocator, conditional_iid,
useAllocator, &param_iid,
nsnull))
HANDLE_OUT_CONVERSION_FAILURE
}
@ -1538,20 +1513,10 @@ pre_call_clean_up:
else
{
if(!XPCConvert::JSData2Native(ccx, &pv->val, val, type,
useAllocator, conditional_iid,
useAllocator, &param_iid,
nsnull))
HANDLE_OUT_CONVERSION_FAILURE
}
if(conditional_iid)
{
if(iidIsOwned)
{
nsMemory::Free((void*)conditional_iid);
iidIsOwned = JS_FALSE;
}
conditional_iid = nsnull;
}
}
}
@ -1608,9 +1573,6 @@ done:
if(sp)
js_FreeStack(cx, mark);
if(conditional_iid && iidIsOwned)
nsMemory::Free((void*)conditional_iid);
if(cx)
{
JS_SetErrorReporter(cx, older);

View File

@ -1537,7 +1537,7 @@ GetInterfaceTypeFromParam(XPCCallContext& ccx,
uint8 paramIndex,
const nsXPTType& datum_type,
nsXPTCVariant* dispatchParams,
nsID** result)
nsID* result)
{
uint8 argnum;
nsresult rv;
@ -1547,7 +1547,7 @@ GetInterfaceTypeFromParam(XPCCallContext& ccx,
if(type_tag == nsXPTType::T_INTERFACE)
{
rv = ifaceInfo->GetIIDForParam(vtblIndex, &paramInfo, result);
rv = ifaceInfo->GetIIDForParamNoAlloc(vtblIndex, &paramInfo, result);
if(NS_FAILED(rv))
return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx);
}
@ -1564,9 +1564,10 @@ GetInterfaceTypeFromParam(XPCCallContext& ccx,
if(!arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_IID)
return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx);
if(!(*result = (nsID*) nsMemory::Clone(dispatchParams[argnum].val.p,
sizeof(nsID))))
return ReportOutOfMemory(ccx);
nsID* p = (nsID*) dispatchParams[argnum].val.p;
if(!p)
return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, paramIndex, ccx);
*result = *p;
}
return JS_TRUE;
}
@ -1621,7 +1622,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
uint8 paramCount;
jsval src;
nsresult invokeResult;
nsID* conditional_iid = nsnull;
nsID param_iid;
uintN err;
nsIXPCSecurityManager* sm;
JSBool foundDependentParam;
@ -1832,25 +1833,19 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
}
if(type_tag == nsXPTType::T_INTERFACE &&
NS_FAILED(ifaceInfo->GetIIDForParam(vtblIndex, &paramInfo,
&conditional_iid)))
NS_FAILED(ifaceInfo->GetIIDForParamNoAlloc(vtblIndex, &paramInfo,
&param_iid)))
{
ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, i, ccx);
goto done;
}
if(!XPCConvert::JSData2Native(ccx, &dp->val, src, type,
useAllocator, conditional_iid, &err))
useAllocator, &param_iid, &err))
{
ThrowBadParam(err, i, ccx);
goto done;
}
if(conditional_iid)
{
nsMemory::Free((void*)conditional_iid);
conditional_iid = nsnull;
}
}
// if any params were dependent, then we must iterate again to convert them.
@ -1940,7 +1935,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
if(datum_type.IsInterfacePointer() &&
!GetInterfaceTypeFromParam(ccx, ifaceInfo, methodInfo, paramInfo,
vtblIndex, i, datum_type,
dispatchParams, &conditional_iid))
dispatchParams, &param_iid))
goto done;
if(isArray || isSizedString)
@ -1959,7 +1954,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
array_count, array_capacity,
datum_type,
useAllocator,
conditional_iid, &err))
&param_iid, &err))
{
// XXX need exception scheme for arrays to indicate bad element
ThrowBadParam(err, i, ccx);
@ -1983,19 +1978,13 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
else
{
if(!XPCConvert::JSData2Native(ccx, &dp->val, src, type,
useAllocator, conditional_iid,
useAllocator, &param_iid,
&err))
{
ThrowBadParam(err, i, ccx);
goto done;
}
}
if(conditional_iid)
{
nsMemory::Free((void*)conditional_iid);
conditional_iid = nsnull;
}
}
}
@ -2065,13 +2054,13 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
if(datum_type.IsInterfacePointer() &&
!GetInterfaceTypeFromParam(ccx, ifaceInfo, methodInfo, paramInfo,
vtblIndex, i, datum_type, dispatchParams,
&conditional_iid))
&param_iid))
goto done;
if(isArray)
{
if(!XPCConvert::NativeArray2JS(ccx, &v, (const void**)&dp->val,
datum_type, conditional_iid,
datum_type, &param_iid,
array_count, ccx.GetCurrentJSObject(),
&err))
{
@ -2094,7 +2083,7 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
else
{
if(!XPCConvert::NativeData2JS(ccx, &v, &dp->val, datum_type,
conditional_iid,
&param_iid,
ccx.GetCurrentJSObject(), &err))
{
ThrowBadParam(err, i, ccx);
@ -2118,11 +2107,6 @@ XPCWrappedNative::CallMethod(XPCCallContext& ccx,
goto done;
}
}
if(conditional_iid)
{
nsMemory::Free((void*)conditional_iid);
conditional_iid = nsnull;
}
}
retval = JS_TRUE;
@ -2186,9 +2170,6 @@ done:
}
}
if(conditional_iid)
nsMemory::Free((void*)conditional_iid);
if(dispatchParams && dispatchParams != paramBuffer)
delete [] dispatchParams;

View File

@ -129,5 +129,9 @@ interface nsIInterfaceInfo : nsISupports
PRBool isFunction();
PRBool hasAncestor(in nsIIDPtr iid);
[notxpcom] nsresult getIIDForParamNoAlloc(in PRUint16 methodIndex,
[const] in nsXPTParamInfoPtr param,
out nsIID iid);
};

View File

@ -463,6 +463,19 @@ xptiInterfaceEntry::GetIIDForParam(uint16 methodIndex,
return entry->GetIID(iid);
}
nsresult
xptiInterfaceEntry::GetIIDForParamNoAlloc(PRUint16 methodIndex,
const nsXPTParamInfo * param,
nsIID *iid)
{
xptiInterfaceEntry* entry;
nsresult rv = GetEntryForParam(methodIndex, param, &entry);
if(NS_FAILED(rv))
return rv;
*iid = entry->mIID;
return NS_OK;
}
// this is a private helper
nsresult
xptiInterfaceEntry::GetTypeInArray(const nsXPTParamInfo* param,

View File

@ -629,6 +629,7 @@ public:
nsresult GetIIDShared(const nsIID * *iid);
nsresult IsFunction(PRBool *_retval);
nsresult HasAncestor(const nsIID * iid, PRBool *_retval);
nsresult GetIIDForParamNoAlloc(PRUint16 methodIndex, const nsXPTParamInfo * param, nsIID *iid);
//////////////////////
@ -721,6 +722,7 @@ public:
NS_IMETHOD GetIIDShared(const nsIID * *iid) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIIDShared(iid); }
NS_IMETHOD IsFunction(PRBool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->IsFunction(_retval); }
NS_IMETHOD HasAncestor(const nsIID * iid, PRBool *_retval) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->HasAncestor(iid, _retval); }
NS_IMETHOD GetIIDForParamNoAlloc(PRUint16 methodIndex, const nsXPTParamInfo * param, nsIID *iid) { return !mEntry ? NS_ERROR_UNEXPECTED : mEntry->GetIIDForParamNoAlloc(methodIndex, param, iid); }
public:
xptiInterfaceInfo(xptiInterfaceEntry* entry);