Bug 692342 - Remove the obviously superfluous uses of IsPointer(). r=mrbkap

These are the easy cases, which all fall into one or more of the following categories:
* A check-and-throw, followed by a switch whose default case also throws
* A check of IsPointer() &&-ed with or tightly enclosing a check that implies IsPointer()
* A check of something clearly enforced by the XPIDL compiler
This commit is contained in:
Bobby Holley 2011-11-25 17:09:06 -08:00
parent 356768725f
commit d3ba9f6532
3 changed files with 29 additions and 53 deletions

View File

@ -316,10 +316,6 @@ XPCConvert::NativeData2JS(XPCLazyCallContext& lccx, jsval* d, const void* s,
}
default:
if (!type.IsPointer()) {
XPC_LOG_ERROR(("XPCConvert::NativeData2JS : unsupported type"));
return JS_FALSE;
}
// set the default result
*d = JSVAL_NULL;
@ -658,10 +654,6 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s,
*((jsval*)d) = s;
break;
default:
if (!type.IsPointer()) {
NS_ERROR("unsupported type");
return JS_FALSE;
}
switch (type.TagPart()) {
case nsXPTType::T_VOID:
@ -1907,10 +1899,6 @@ XPCConvert::NativeStringWithSize2JS(JSContext* cx,
if (pErr)
*pErr = NS_ERROR_XPC_BAD_CONVERT_NATIVE;
if (!type.IsPointer()) {
XPC_LOG_ERROR(("XPCConvert::NativeStringWithSize2JS : unsupported type"));
return JS_FALSE;
}
switch (type.TagPart()) {
case nsXPTType::T_PSTRING_SIZE_IS:
{
@ -1957,10 +1945,6 @@ XPCConvert::JSStringWithSize2Native(XPCCallContext& ccx, void* d, jsval s,
if (pErr)
*pErr = NS_ERROR_XPC_BAD_CONVERT_NATIVE;
if (!type.IsPointer()) {
XPC_LOG_ERROR(("XPCConvert::JSStringWithSize2Native : unsupported type"));
return JS_FALSE;
}
switch (type.TagPart()) {
case nsXPTType::T_PSTRING_SIZE_IS:
{

View File

@ -883,9 +883,10 @@ nsXPCWrappedJSClass::GetArraySizeFromParam(JSContext* cx,
const nsXPTParamInfo& arg_param = method->params[argnum];
const nsXPTType& arg_type = arg_param.GetType();
// The xpidl compiler ensures this. We reaffirm it for safety.
if (arg_type.IsPointer() || arg_type.TagPart() != nsXPTType::T_U32)
return JS_FALSE;
// This should be enforced by the xpidl compiler, but it's not.
// See bug 695235.
NS_ABORT_IF_FALSE(arg_type.TagPart() == nsXPTType::T_U32,
"size_is references parameter of invalid type.");
if (arg_param.IsIndirect())
*result = *(JSUint32*)nativeParams[argnum].val.p;
@ -921,8 +922,8 @@ nsXPCWrappedJSClass::GetInterfaceTypeFromParam(JSContext* cx,
const nsXPTParamInfo& arg_param = method->params[argnum];
const nsXPTType& arg_type = arg_param.GetType();
if (arg_type.IsPointer() &&
arg_type.TagPart() == nsXPTType::T_IID) {
if (arg_type.TagPart() == nsXPTType::T_IID) {
if (arg_param.IsIndirect()) {
nsID** p = (nsID**) nativeParams[argnum].val.p;
if (!p || !*p)
@ -1299,7 +1300,8 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16 methodIndex,
const nsXPTParamInfo& firstParam = info->params[0];
if (firstParam.IsIn()) {
const nsXPTType& firstType = firstParam.GetType();
if (firstType.IsPointer() && firstType.IsInterfacePointer()) {
if (firstType.IsInterfacePointer()) {
nsIXPCFunctionThisTranslator* translator;
IID2ThisTranslatorMap* map =

View File

@ -2325,9 +2325,6 @@ CallMethodHelper::GetArraySizeFromParam(uint8 paramIndex,
return Throw(NS_ERROR_XPC_CANT_GET_ARRAY_INFO, mCallContext);
const nsXPTType& type = mMethodInfo->GetParam(paramIndex).GetType();
// The xpidl compiler ensures this. We reaffirm it for safety.
if (type.IsPointer() || type.TagPart() != nsXPTType::T_U32)
return Throw(NS_ERROR_XPC_CANT_GET_ARRAY_INFO, mCallContext);
*result = GetDispatchParam(paramIndex)->val.u32;
@ -2357,10 +2354,6 @@ CallMethodHelper::GetInterfaceTypeFromParam(uint8 paramIndex,
return Throw(NS_ERROR_XPC_CANT_GET_ARRAY_INFO, mCallContext);
const nsXPTType& type = mMethodInfo->GetParam(paramIndex).GetType();
// The xpidl compiler ensures this. We reaffirm it for safety.
if (!type.IsPointer() || type.TagPart() != nsXPTType::T_IID)
return ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO,
paramIndex, mCallContext);
nsID* p = (nsID*) GetDispatchParam(paramIndex)->val.p;
if (!p)
@ -2671,8 +2664,8 @@ CallMethodHelper::ConvertIndependentParam(uint8 i)
if (!paramInfo.IsIn())
return JS_TRUE;
} else {
if (type.IsPointer()) {
switch (type_tag) {
case nsXPTType::T_IID:
dp->SetValNeedsCleanup();
@ -2682,7 +2675,6 @@ CallMethodHelper::ConvertIndependentParam(uint8 i)
break;
case nsXPTType::T_ASTRING:
// Fall through to the T_DOMSTRING case
case nsXPTType::T_DOMSTRING:
dp->SetValNeedsCleanup();
break;
@ -2693,7 +2685,6 @@ CallMethodHelper::ConvertIndependentParam(uint8 i)
dp->SetValNeedsCleanup();
break;
}
}
// Do this *after* the above because in the case where we have a
// "T_DOMSTRING && IsDipper()" then arg might be null since this
@ -2785,10 +2776,9 @@ CallMethodHelper::ConvertDependentParams()
"Expected either enough arguments or an optional argument");
src = i < mArgc ? mArgv[i] : JSVAL_NULL;
if ((datum_type.IsPointer() &&
(datum_type.TagPart() == nsXPTType::T_IID ||
if (datum_type.TagPart() == nsXPTType::T_IID ||
datum_type.TagPart() == nsXPTType::T_PSTRING_SIZE_IS ||
datum_type.TagPart() == nsXPTType::T_PWSTRING_SIZE_IS)) ||
datum_type.TagPart() == nsXPTType::T_PWSTRING_SIZE_IS ||
(isArray && datum_type.TagPart() == nsXPTType::T_CHAR_STR)) {
dp->SetValNeedsCleanup();
}