diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-04 18:20:07 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-04 18:20:07 +0000 |
commit | 9256ad5784fc437f60fbeb836fe2ecd18e028a5d (patch) | |
tree | 484d9e9c4697d50800c574b58d5db4cfa349b27c /fxjs | |
parent | 76e336d26e78f6c6b5cdede6bb4b94ebddf3a2b1 (diff) | |
download | pdfium-9256ad5784fc437f60fbeb836fe2ecd18e028a5d.tar.xz |
Cleanup ResolveObjects params and return
The return value of ResolveObjects is always used as a boolean, so
change from int32_t. The XFA_RESOLVENODE_RS object was made a pointer
from a ref.
Change-Id: I030036c01101680e36f4ddf524b468354a2e6850
Reviewed-on: https://pdfium-review.googlesource.com/20331
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cfxjse_engine.cpp | 29 | ||||
-rw-r--r-- | fxjs/cfxjse_engine.h | 10 | ||||
-rw-r--r-- | fxjs/cfxjse_formcalc_context.cpp | 45 | ||||
-rw-r--r-- | fxjs/cfxjse_formcalc_context.h | 12 | ||||
-rw-r--r-- | fxjs/cfxjse_resolveprocessor.cpp | 12 | ||||
-rw-r--r-- | fxjs/cfxjse_resolveprocessor.h | 2 | ||||
-rw-r--r-- | fxjs/cjx_hostpseudomodel.cpp | 22 | ||||
-rw-r--r-- | fxjs/cjx_node.cpp | 19 |
8 files changed, 75 insertions, 76 deletions
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index 3bebec7e5b..a2bebdb7f9 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -173,7 +173,7 @@ bool CFXJSE_Engine::QueryNodeByFlag(CXFA_Node* refNode, return false; XFA_RESOLVENODE_RS resolveRs; - if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0) + if (!ResolveObjects(refNode, propname, &resolveRs, dwFlag, nullptr)) return false; if (resolveRs.dwFlags == XFA_RESOLVENODE_RSTYPE_Nodes) { pValue->Assign(GetJSValueFromMap(resolveRs.objects.front())); @@ -553,13 +553,13 @@ CFXJSE_Class* CFXJSE_Engine::GetJseNormalClass() { return m_pJsClass; } -int32_t CFXJSE_Engine::ResolveObjects(CXFA_Object* refObject, - const WideStringView& wsExpression, - XFA_RESOLVENODE_RS& resolveNodeRS, - uint32_t dwStyles, - CXFA_Node* bindNode) { +bool CFXJSE_Engine::ResolveObjects(CXFA_Object* refObject, + const WideStringView& wsExpression, + XFA_RESOLVENODE_RS* resolveNodeRS, + uint32_t dwStyles, + CXFA_Node* bindNode) { if (wsExpression.IsEmpty()) - return 0; + return false; if (m_eScriptType != CXFA_ScriptData::Type::Formcalc || (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { @@ -624,6 +624,7 @@ int32_t CFXJSE_Engine::ResolveObjects(CXFA_Object* refObject, this); if (bCreate) continue; + break; } @@ -695,13 +696,13 @@ int32_t CFXJSE_Engine::ResolveObjects(CXFA_Object* refObject, } if (!bNextCreate) { - resolveNodeRS.dwFlags = rndFind.m_dwFlag; + resolveNodeRS->dwFlags = rndFind.m_dwFlag; if (nNodes > 0) { - resolveNodeRS.objects.insert(resolveNodeRS.objects.end(), - findObjects.begin(), findObjects.end()); + resolveNodeRS->objects.insert(resolveNodeRS->objects.end(), + findObjects.begin(), findObjects.end()); } if (rndFind.m_dwFlag == XFA_RESOLVENODE_RSTYPE_Attribute) { - resolveNodeRS.pScriptAttribute = rndFind.m_pScriptAttribute; + resolveNodeRS->pScriptAttribute = rndFind.m_pScriptAttribute; return 1; } } @@ -710,11 +711,11 @@ int32_t CFXJSE_Engine::ResolveObjects(CXFA_Object* refObject, m_ResolveProcessor->SetResultCreateNode(resolveNodeRS, rndFind.m_wsCondition); if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) - resolveNodeRS.dwFlags = XFA_RESOLVENODE_RSTYPE_ExistNodes; + resolveNodeRS->dwFlags = XFA_RESOLVENODE_RSTYPE_ExistNodes; - return pdfium::CollectionSize<int32_t>(resolveNodeRS.objects); + return !resolveNodeRS->objects.empty(); } - return nNodes; + return nNodes > 0; } void CFXJSE_Engine::AddToCacheList(std::unique_ptr<CXFA_NodeList> pList) { diff --git a/fxjs/cfxjse_engine.h b/fxjs/cfxjse_engine.h index 66fe7a53e8..a675a390da 100644 --- a/fxjs/cfxjse_engine.h +++ b/fxjs/cfxjse_engine.h @@ -56,11 +56,11 @@ class CFXJSE_Engine { CFXJSE_Value* pRetValue, CXFA_Object* pThisObject); - int32_t ResolveObjects(CXFA_Object* refObject, - const WideStringView& wsExpression, - XFA_RESOLVENODE_RS& resolveNodeRS, - uint32_t dwStyles = XFA_RESOLVENODE_Children, - CXFA_Node* bindNode = nullptr); + bool ResolveObjects(CXFA_Object* refObject, + const WideStringView& wsExpression, + XFA_RESOLVENODE_RS* resolveNodeRS, + uint32_t dwStyles, + CXFA_Node* bindNode); CFXJSE_Value* GetJSValueFromMap(CXFA_Object* pObject); void AddToCacheList(std::unique_ptr<CXFA_NodeList> pList); CXFA_Object* GetThisObject() const { return m_pThisObject; } diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index b396db39b1..4bfe7d8b8b 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -5263,7 +5263,7 @@ void CFXJSE_FormCalcContext::dot_accessor(CFXJSE_Value* pThis, XFA_RESOLVENODE_RS resolveNodeRS; if (ResolveObjects(pThis, hJSObjValue.get(), szSomExp.AsStringView(), - resolveNodeRS, true, szName.IsEmpty()) > 0) { + &resolveNodeRS, true, szName.IsEmpty())) { ParseResolveResult(pThis, resolveNodeRS, hJSObjValue.get(), &resolveValues[i - 2], &bAttribute); iCounter += resolveValues[i - 2].size(); @@ -5298,19 +5298,19 @@ void CFXJSE_FormCalcContext::dot_accessor(CFXJSE_Value* pThis, } XFA_RESOLVENODE_RS resolveNodeRS; - int32_t iRet = 0; + bool iRet = false; ByteString bsAccessorName = args.GetUTF8String(1); if (argAccessor->IsObject() || (argAccessor->IsNull() && bsAccessorName.IsEmpty())) { iRet = ResolveObjects(pThis, argAccessor.get(), szSomExp.AsStringView(), - resolveNodeRS, true, szName.IsEmpty()); + &resolveNodeRS, true, szName.IsEmpty()); } else if (!argAccessor->IsObject() && !bsAccessorName.IsEmpty() && GetObjectForName(pThis, argAccessor.get(), bsAccessorName.AsStringView())) { iRet = ResolveObjects(pThis, argAccessor.get(), szSomExp.AsStringView(), - resolveNodeRS, true, szName.IsEmpty()); + &resolveNodeRS, true, szName.IsEmpty()); } - if (iRet < 1) { + if (!iRet) { pContext->ThrowPropertyNotInObjectException( WideString::FromUTF8(szName.AsStringView()), WideString::FromUTF8(szSomExp.AsStringView())); @@ -5381,7 +5381,7 @@ void CFXJSE_FormCalcContext::dotdot_accessor(CFXJSE_Value* pThis, argAccessor->GetObjectPropertyByIdx(i, hJSObjValue.get()); XFA_RESOLVENODE_RS resolveNodeRS; if (ResolveObjects(pThis, hJSObjValue.get(), szSomExp.AsStringView(), - resolveNodeRS, false) > 0) { + &resolveNodeRS, false, false)) { ParseResolveResult(pThis, resolveNodeRS, hJSObjValue.get(), &resolveValues[i - 2], &bAttribute); iCounter += resolveValues[i - 2].size(); @@ -5416,19 +5416,19 @@ void CFXJSE_FormCalcContext::dotdot_accessor(CFXJSE_Value* pThis, } XFA_RESOLVENODE_RS resolveNodeRS; - int32_t iRet = 0; + bool iRet = false; ByteString bsAccessorName = args.GetUTF8String(1); if (argAccessor->IsObject() || (argAccessor->IsNull() && bsAccessorName.IsEmpty())) { iRet = ResolveObjects(pThis, argAccessor.get(), szSomExp.AsStringView(), - resolveNodeRS, false); + &resolveNodeRS, false, false); } else if (!argAccessor->IsObject() && !bsAccessorName.IsEmpty() && GetObjectForName(pThis, argAccessor.get(), bsAccessorName.AsStringView())) { iRet = ResolveObjects(pThis, argAccessor.get(), szSomExp.AsStringView(), - resolveNodeRS, false); + &resolveNodeRS, false, false); } - if (iRet < 1) { + if (!iRet) { pContext->ThrowPropertyNotInObjectException( WideString::FromUTF8(szName.AsStringView()), WideString::FromUTF8(szSomExp.AsStringView())); @@ -5913,11 +5913,11 @@ bool CFXJSE_FormCalcContext::GetObjectForName( XFA_RESOLVENODE_RS resolveNodeRS; uint32_t dwFlags = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent; - int32_t iRet = pScriptContext->ResolveObjects( + bool iRet = pScriptContext->ResolveObjects( pScriptContext->GetThisObject(), - WideString::FromUTF8(szAccessorName).AsStringView(), resolveNodeRS, - dwFlags); - if (iRet >= 1 && resolveNodeRS.dwFlags == XFA_RESOLVENODE_RSTYPE_Nodes) { + WideString::FromUTF8(szAccessorName).AsStringView(), &resolveNodeRS, + dwFlags, nullptr); + if (iRet && resolveNodeRS.dwFlags == XFA_RESOLVENODE_RSTYPE_Nodes) { accessorValue->Assign( pScriptContext->GetJSValueFromMap(resolveNodeRS.objects.front())); return true; @@ -5926,16 +5926,15 @@ bool CFXJSE_FormCalcContext::GetObjectForName( } // static -int32_t CFXJSE_FormCalcContext::ResolveObjects( - CFXJSE_Value* pThis, - CFXJSE_Value* pRefValue, - const ByteStringView& bsSomExp, - XFA_RESOLVENODE_RS& resolveNodeRS, - bool bdotAccessor, - bool bHasNoResolveName) { +bool CFXJSE_FormCalcContext::ResolveObjects(CFXJSE_Value* pThis, + CFXJSE_Value* pRefValue, + const ByteStringView& bsSomExp, + XFA_RESOLVENODE_RS* resolveNodeRS, + bool bdotAccessor, + bool bHasNoResolveName) { CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); if (!pDoc) - return -1; + return false; WideString wsSomExpression = WideString::FromUTF8(bsSomExp); CFXJSE_Engine* pScriptContext = pDoc->GetScriptContext(); @@ -5973,7 +5972,7 @@ int32_t CFXJSE_FormCalcContext::ResolveObjects( dFlags = XFA_RESOLVENODE_AnyChild; } return pScriptContext->ResolveObjects(pNode, wsSomExpression.AsStringView(), - resolveNodeRS, dFlags); + resolveNodeRS, dFlags, nullptr); } // static diff --git a/fxjs/cfxjse_formcalc_context.h b/fxjs/cfxjse_formcalc_context.h index ba331426df..51e3178c13 100644 --- a/fxjs/cfxjse_formcalc_context.h +++ b/fxjs/cfxjse_formcalc_context.h @@ -392,12 +392,12 @@ class CFXJSE_FormCalcContext : public CFXJSE_HostObject { static bool GetObjectForName(CFXJSE_Value* pThis, CFXJSE_Value* accessorValue, const ByteStringView& szAccessorName); - static int32_t ResolveObjects(CFXJSE_Value* pThis, - CFXJSE_Value* pParentValue, - const ByteStringView& bsSomExp, - XFA_RESOLVENODE_RS& resolveNodeRS, - bool bdotAccessor = true, - bool bHasNoResolveName = false); + static bool ResolveObjects(CFXJSE_Value* pThis, + CFXJSE_Value* pParentValue, + const ByteStringView& bsSomExp, + XFA_RESOLVENODE_RS* resolveNodeRS, + bool bdotAccessor, + bool bHasNoResolveName); static void ParseResolveResult( CFXJSE_Value* pThis, const XFA_RESOLVENODE_RS& resolveNodeRS, diff --git a/fxjs/cfxjse_resolveprocessor.cpp b/fxjs/cfxjse_resolveprocessor.cpp index fb7bc555c6..eeeeefcf08 100644 --- a/fxjs/cfxjse_resolveprocessor.cpp +++ b/fxjs/cfxjse_resolveprocessor.cpp @@ -714,19 +714,19 @@ void CFXJSE_ResolveProcessor::SetStylesForChild(uint32_t dwParentStyles, } int32_t CFXJSE_ResolveProcessor::SetResultCreateNode( - XFA_RESOLVENODE_RS& resolveNodeRS, + XFA_RESOLVENODE_RS* resolveNodeRS, WideString& wsLastCondition) { if (m_pNodeHelper->m_pCreateParent) - resolveNodeRS.objects.push_back(m_pNodeHelper->m_pCreateParent); + resolveNodeRS->objects.push_back(m_pNodeHelper->m_pCreateParent); else m_pNodeHelper->CreateNode_ForCondition(wsLastCondition); - resolveNodeRS.dwFlags = m_pNodeHelper->m_iCreateFlag; - if (resolveNodeRS.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeOne) { + resolveNodeRS->dwFlags = m_pNodeHelper->m_iCreateFlag; + if (resolveNodeRS->dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeOne) { if (m_pNodeHelper->m_iCurAllStart != -1) - resolveNodeRS.dwFlags = XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll; + resolveNodeRS->dwFlags = XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll; } - return pdfium::CollectionSize<int32_t>(resolveNodeRS.objects); + return pdfium::CollectionSize<int32_t>(resolveNodeRS->objects); } void CFXJSE_ResolveProcessor::SetIndexDataBind(WideString& wsNextCondition, diff --git a/fxjs/cfxjse_resolveprocessor.h b/fxjs/cfxjse_resolveprocessor.h index dc6b9cc6b9..23ecd52d1a 100644 --- a/fxjs/cfxjse_resolveprocessor.h +++ b/fxjs/cfxjse_resolveprocessor.h @@ -41,7 +41,7 @@ class CFXJSE_ResolveProcessor { int32_t GetFilter(const WideStringView& wsExpression, int32_t nStart, CFXJSE_ResolveNodeData& rnd); - int32_t SetResultCreateNode(XFA_RESOLVENODE_RS& resolveNodeRS, + int32_t SetResultCreateNode(XFA_RESOLVENODE_RS* resolveNodeRS, WideString& wsLastCondition); void SetIndexDataBind(WideString& wsNextCondition, int32_t& iIndex, diff --git a/fxjs/cjx_hostpseudomodel.cpp b/fxjs/cjx_hostpseudomodel.cpp index 0e26a19048..8838c891d9 100644 --- a/fxjs/cjx_hostpseudomodel.cpp +++ b/fxjs/cjx_hostpseudomodel.cpp @@ -283,10 +283,10 @@ void CJX_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) { uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; XFA_RESOLVENODE_RS resolveNodeRS; - int32_t iRet = pScriptContext->ResolveObjects( - pObject, pValue->ToWideString().AsStringView(), resolveNodeRS, - dwFlag); - if (iRet < 1 || !resolveNodeRS.objects.front()->IsNode()) + bool iRet = pScriptContext->ResolveObjects( + pObject, pValue->ToWideString().AsStringView(), &resolveNodeRS, + dwFlag, nullptr); + if (!iRet || !resolveNodeRS.objects.front()->IsNode()) return; pNode = resolveNodeRS.objects.front()->AsNode(); @@ -387,9 +387,9 @@ void CJX_HostPseudoModel::ResetData(CFXJSE_Arguments* pArguments) { uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; XFA_RESOLVENODE_RS resolveNodeRS; - int32_t iRet = pScriptContext->ResolveObjects( - pObject, wsName.AsStringView(), resolveNodeRS, dwFlag); - if (iRet < 1 || !resolveNodeRS.objects.front()->IsNode()) + bool iRet = pScriptContext->ResolveObjects(pObject, wsName.AsStringView(), + &resolveNodeRS, dwFlag, nullptr); + if (!iRet || !resolveNodeRS.objects.front()->IsNode()) continue; pNode = resolveNodeRS.objects.front()->AsNode(); @@ -451,10 +451,10 @@ void CJX_HostPseudoModel::SetFocus(CFXJSE_Arguments* pArguments) { uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; XFA_RESOLVENODE_RS resolveNodeRS; - int32_t iRet = pScriptContext->ResolveObjects( - pObject, pValue->ToWideString().AsStringView(), resolveNodeRS, - dwFlag); - if (iRet < 1 || !resolveNodeRS.objects.front()->IsNode()) + bool iRet = pScriptContext->ResolveObjects( + pObject, pValue->ToWideString().AsStringView(), &resolveNodeRS, + dwFlag, nullptr); + if (!iRet || !resolveNodeRS.objects.front()->IsNode()) return; pNode = resolveNodeRS.objects.front()->AsNode(); diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index 2865ba4fbf..8bf00f585f 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -411,9 +411,8 @@ void CJX_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; XFA_RESOLVENODE_RS resolveNodeRS; - int32_t iRet = pScriptContext->ResolveObjects( - refNode, wsExpression.AsStringView(), resolveNodeRS, dwFlag); - if (iRet < 1) { + if (!pScriptContext->ResolveObjects(refNode, wsExpression.AsStringView(), + &resolveNodeRS, dwFlag, nullptr)) { pArguments->GetReturnValue()->SetNull(); return; } @@ -469,13 +468,12 @@ void CJX_Node::ResolveNodeList(CFXJSE_Value* pValue, CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext(); if (!pScriptContext) return; - - XFA_RESOLVENODE_RS resolveNodeRS; if (!refNode) refNode = GetXFANode(); + XFA_RESOLVENODE_RS resolveNodeRS; pScriptContext->ResolveObjects(refNode, wsExpression.AsStringView(), - resolveNodeRS, dwFlag); + &resolveNodeRS, dwFlag, nullptr); CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(GetDocument()); if (resolveNodeRS.dwFlags == XFA_RESOLVENODE_RSTYPE_Nodes) { for (CXFA_Object* pObject : resolveNodeRS.objects) { @@ -1236,12 +1234,13 @@ void CJX_Node::Script_Attribute_String(CFXJSE_Value* pValue, CXFA_Node* pProtoNode = nullptr; if (!wsSOM.IsEmpty()) { XFA_RESOLVENODE_RS resolveNodeRS; - int32_t iRet = GetDocument()->GetScriptContext()->ResolveObjects( - pProtoRoot, wsSOM.AsStringView(), resolveNodeRS, + bool iRet = GetDocument()->GetScriptContext()->ResolveObjects( + pProtoRoot, wsSOM.AsStringView(), &resolveNodeRS, XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | - XFA_RESOLVENODE_Siblings); - if (iRet > 0 && resolveNodeRS.objects.front()->IsNode()) + XFA_RESOLVENODE_Siblings, + nullptr); + if (iRet && resolveNodeRS.objects.front()->IsNode()) pProtoNode = resolveNodeRS.objects.front()->AsNode(); } else if (!wsID.IsEmpty()) { |