From 66ee33a25170fa965d297c512a3bac70071019ae Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 23 Sep 2011 14:50:27 -0700 Subject: [PATCH] Bug 683802 - Separate reindentation from previous patch for easier review. No other changes. r=mrbkap --- js/src/xpconnect/src/xpcwrappednative.cpp | 242 +++++++++++----------- 1 file changed, 121 insertions(+), 121 deletions(-) diff --git a/js/src/xpconnect/src/xpcwrappednative.cpp b/js/src/xpconnect/src/xpcwrappednative.cpp index 2bb3f9ac8b58..df91dec2bd8c 100644 --- a/js/src/xpconnect/src/xpcwrappednative.cpp +++ b/js/src/xpconnect/src/xpcwrappednative.cpp @@ -2816,147 +2816,147 @@ CallMethodHelper::ConvertIndependentParams(JSBool* foundDependentParam) JSBool CallMethodHelper::ConvertIndependentParam(uint8 i) { - JSBool useAllocator = JS_FALSE; - const nsXPTParamInfo& paramInfo = mMethodInfo->GetParam(i); - const nsXPTType& type = paramInfo.GetType(); - uint8 type_tag = type.TagPart(); - nsXPTCVariant* dp = GetDispatchParam(i); - dp->type = type; + JSBool useAllocator = JS_FALSE; + const nsXPTParamInfo& paramInfo = mMethodInfo->GetParam(i); + const nsXPTType& type = paramInfo.GetType(); + uint8 type_tag = type.TagPart(); + nsXPTCVariant* dp = GetDispatchParam(i); + dp->type = type; - if(type_tag == nsXPTType::T_INTERFACE) + if(type_tag == nsXPTType::T_INTERFACE) + { + dp->SetValIsInterface(); + } + + jsval src; + + if (!GetOutParamSource(i, &src)) + return JS_FALSE; + + if(paramInfo.IsOut()) + { + dp->SetPtrIsData(); + dp->ptr = &dp->val; + + if (type_tag == nsXPTType::T_JSVAL) { - dp->SetValIsInterface(); + JS_STATIC_ASSERT(sizeof(jsval) <= sizeof(uint64)); + jsval *rootp = (jsval *)&dp->val.u64; + dp->ptr = rootp; + *rootp = JSVAL_VOID; + if (!JS_AddValueRoot(mCallContext, rootp)) + return JS_FALSE; + dp->SetValIsJSRoot(); } - jsval src; - - if (!GetOutParamSource(i, &src)) - return JS_FALSE; - - if(paramInfo.IsOut()) + if(type.IsPointer() && + type_tag != nsXPTType::T_INTERFACE && + !paramInfo.IsShared()) { - dp->SetPtrIsData(); - dp->ptr = &dp->val; + useAllocator = JS_TRUE; + dp->SetValIsAllocated(); + } - if (type_tag == nsXPTType::T_JSVAL) + if(!paramInfo.IsIn()) + return JS_TRUE; + } + else + { + if(type.IsPointer()) + { + switch(type_tag) { - JS_STATIC_ASSERT(sizeof(jsval) <= sizeof(uint64)); - jsval *rootp = (jsval *)&dp->val.u64; - dp->ptr = rootp; - *rootp = JSVAL_VOID; - if (!JS_AddValueRoot(mCallContext, rootp)) - return JS_FALSE; - dp->SetValIsJSRoot(); - } - - if(type.IsPointer() && - type_tag != nsXPTType::T_INTERFACE && - !paramInfo.IsShared()) - { - useAllocator = JS_TRUE; + case nsXPTType::T_IID: dp->SetValIsAllocated(); - } + useAllocator = JS_TRUE; + break; + case nsXPTType::T_CHAR_STR: + dp->SetValIsAllocated(); + useAllocator = JS_TRUE; + break; + case nsXPTType::T_ASTRING: + // Fall through to the T_DOMSTRING case - if(!paramInfo.IsIn()) - return JS_TRUE; - } - else - { - if(type.IsPointer()) - { - switch(type_tag) + case nsXPTType::T_DOMSTRING: + if(paramInfo.IsDipper()) { - case nsXPTType::T_IID: - dp->SetValIsAllocated(); - useAllocator = JS_TRUE; - break; - case nsXPTType::T_CHAR_STR: - dp->SetValIsAllocated(); - useAllocator = JS_TRUE; - break; - case nsXPTType::T_ASTRING: - // Fall through to the T_DOMSTRING case + // Is an 'out' DOMString. Make a new nsAString + // now and then continue in order to skip the call to + // JSData2Native - case nsXPTType::T_DOMSTRING: - if(paramInfo.IsDipper()) - { - // Is an 'out' DOMString. Make a new nsAString - // now and then continue in order to skip the call to - // JSData2Native - - dp->SetValIsDOMString(); - if(!(dp->val.p = new nsAutoString())) - { - JS_ReportOutOfMemory(mCallContext); - return JS_FALSE; - } - return JS_TRUE; - } - // else... - - // Is an 'in' DOMString. Set 'useAllocator' to indicate - // that JSData2Native should allocate a new - // nsAString. dp->SetValIsDOMString(); - useAllocator = JS_TRUE; - break; - - case nsXPTType::T_UTF8STRING: - // Fall through to the C string case for now... - case nsXPTType::T_CSTRING: - dp->SetValIsCString(); - if(paramInfo.IsDipper()) + if(!(dp->val.p = new nsAutoString())) { - // Is an 'out' CString. - if(!(dp->val.p = new nsCString())) - { - JS_ReportOutOfMemory(mCallContext); - return JS_FALSE; - } - return JS_TRUE; + JS_ReportOutOfMemory(mCallContext); + return JS_FALSE; } - // else ... - // Is an 'in' CString. - useAllocator = JS_TRUE; - break; + return JS_TRUE; } - } - else { - if(type_tag == nsXPTType::T_JSVAL) { - dp->SetValIsAllocated(); - useAllocator = JS_TRUE; + // else... + + // Is an 'in' DOMString. Set 'useAllocator' to indicate + // that JSData2Native should allocate a new + // nsAString. + dp->SetValIsDOMString(); + useAllocator = JS_TRUE; + break; + + case nsXPTType::T_UTF8STRING: + // Fall through to the C string case for now... + case nsXPTType::T_CSTRING: + dp->SetValIsCString(); + if(paramInfo.IsDipper()) + { + // Is an 'out' CString. + if(!(dp->val.p = new nsCString())) + { + JS_ReportOutOfMemory(mCallContext); + return JS_FALSE; + } + return JS_TRUE; } + // else ... + // Is an 'in' CString. + useAllocator = JS_TRUE; + break; + } + } + else { + if(type_tag == nsXPTType::T_JSVAL) { + dp->SetValIsAllocated(); + useAllocator = JS_TRUE; } - - // Do this *after* the above because in the case where we have a - // "T_DOMSTRING && IsDipper()" then arg might be null since this - // is really an 'out' param masquerading as an 'in' param. - NS_ASSERTION(i < mArgc || paramInfo.IsOptional(), - "Expected either enough arguments or an optional argument"); - if(i < mArgc) - src = mArgv[i]; - else if(type_tag == nsXPTType::T_JSVAL) - src = JSVAL_VOID; - else - src = JSVAL_NULL; } - nsID param_iid; - if(type_tag == nsXPTType::T_INTERFACE && - NS_FAILED(mIFaceInfo->GetIIDForParamNoAlloc(mVTableIndex, ¶mInfo, - ¶m_iid))) - { - ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, i, mCallContext); - return JS_FALSE; - } + // Do this *after* the above because in the case where we have a + // "T_DOMSTRING && IsDipper()" then arg might be null since this + // is really an 'out' param masquerading as an 'in' param. + NS_ASSERTION(i < mArgc || paramInfo.IsOptional(), + "Expected either enough arguments or an optional argument"); + if(i < mArgc) + src = mArgv[i]; + else if(type_tag == nsXPTType::T_JSVAL) + src = JSVAL_VOID; + else + src = JSVAL_NULL; + } - uintN err; - if(!XPCConvert::JSData2Native(mCallContext, &dp->val, src, type, - useAllocator, ¶m_iid, &err)) - { - ThrowBadParam(err, i, mCallContext); - return JS_FALSE; - } + nsID param_iid; + if(type_tag == nsXPTType::T_INTERFACE && + NS_FAILED(mIFaceInfo->GetIIDForParamNoAlloc(mVTableIndex, ¶mInfo, + ¶m_iid))) + { + ThrowBadParam(NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO, i, mCallContext); + return JS_FALSE; + } + + uintN err; + if(!XPCConvert::JSData2Native(mCallContext, &dp->val, src, type, + useAllocator, ¶m_iid, &err)) + { + ThrowBadParam(err, i, mCallContext); + return JS_FALSE; + } return JS_TRUE; }