Fixing part of bug 241157. Making it valid for an nsIVariant to hold a interface pointer pointing to null. r=ben@bengoodger.com, sr=darin@meer.net.

This commit is contained in:
jst%mozilla.jstenback.com 2004-05-21 21:19:13 +00:00
parent e51273889b
commit d7c3908a90

View File

@ -1168,8 +1168,13 @@ nsVariant::ConvertToISupports(const nsDiscriminatedUnion& data,
{
case nsIDataType::VTYPE_INTERFACE:
case nsIDataType::VTYPE_INTERFACE_IS:
return data.u.iface.mInterfaceValue->
QueryInterface(NS_GET_IID(nsISupports), (void**)_retval);
if (data.u.iface.mInterfaceValue) {
return data.u.iface.mInterfaceValue->
QueryInterface(NS_GET_IID(nsISupports), (void**)_retval);
} else {
*_retval = nsnull;
return NS_OK;
}
default:
return NS_ERROR_CANNOT_CONVERT_DATA;
}
@ -1196,7 +1201,13 @@ nsVariant::ConvertToInterface(const nsDiscriminatedUnion& data, nsIID * *iid,
*iid = (nsIID*) nsMemory::Clone(piid, sizeof(nsIID));
if(!*iid)
return NS_ERROR_OUT_OF_MEMORY;
return data.u.iface.mInterfaceValue->QueryInterface(*piid, iface);
if (data.u.iface.mInterfaceValue) {
return data.u.iface.mInterfaceValue->QueryInterface(*piid, iface);
}
*iface = nsnull;
return NS_OK;
}
/* static */ nsresult
@ -1498,9 +1509,7 @@ nsVariant::SetFromInterface(nsDiscriminatedUnion* data, const nsIID& iid,
nsISupports *aValue)
{
DATA_SETTER_PROLOGUE(data);
if(!aValue)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(aValue);
NS_IF_ADDREF(aValue);
data->u.iface.mInterfaceValue = aValue;
data->u.iface.mInterfaceID = iid;
DATA_SETTER_EPILOGUE(data, VTYPE_INTERFACE_IS);