diff options
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cfxjse_engine.cpp | 61 | ||||
-rw-r--r-- | fxjs/cfxjse_resolveprocessor.cpp | 280 | ||||
-rw-r--r-- | fxjs/cfxjse_resolveprocessor.h | 21 | ||||
-rw-r--r-- | fxjs/cjx_node.cpp | 9 |
4 files changed, 169 insertions, 202 deletions
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index cc4f85554b..3bebec7e5b 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -196,16 +196,17 @@ void CFXJSE_Engine::GlobalPropertySetter(CFXJSE_Value* pObject, CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr); CXFA_Document* pDoc = lpOrginalNode->GetDocument(); CFXJSE_Engine* lpScriptContext = pDoc->GetScriptContext(); - CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); - WideString wsPropName = WideString::FromUTF8(szPropName); - uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | - XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | - XFA_RESOLVENODE_Attributes; CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); if (lpOrginalNode->IsVariablesThis()) - pRefNode = ToNode(lpCurNode); - if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringView(), - pValue, dwFlag, true)) { + pRefNode = ToNode(lpScriptContext->GetVariablesThis(lpOrginalNode)); + + WideString wsPropName = WideString::FromUTF8(szPropName); + if (lpScriptContext->QueryNodeByFlag( + pRefNode, wsPropName.AsStringView(), pValue, + XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | + XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | + XFA_RESOLVENODE_Attributes, + true)) { return; } if (lpOrginalNode->IsVariablesThis()) { @@ -228,7 +229,6 @@ void CFXJSE_Engine::GlobalPropertyGetter(CFXJSE_Value* pObject, CXFA_Object* pOriginalObject = ToObject(pObject, nullptr); CXFA_Document* pDoc = pOriginalObject->GetDocument(); CFXJSE_Engine* lpScriptContext = pDoc->GetScriptContext(); - CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); WideString wsPropName = WideString::FromUTF8(szPropName); if (lpScriptContext->GetType() == CXFA_ScriptData::Type::Formcalc) { if (szPropName == kFormCalcRuntime) { @@ -247,20 +247,21 @@ void CFXJSE_Engine::GlobalPropertyGetter(CFXJSE_Value* pObject, } } - uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | - XFA_RESOLVENODE_Attributes; CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); if (pOriginalObject->IsVariablesThis()) - pRefNode = ToNode(lpCurNode); + pRefNode = ToNode(lpScriptContext->GetVariablesThis(pOriginalObject)); - if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringView(), - pValue, dwFlag, false)) { + if (lpScriptContext->QueryNodeByFlag( + pRefNode, wsPropName.AsStringView(), pValue, + XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | + XFA_RESOLVENODE_Attributes, + false)) { return; } - dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; - if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringView(), - pValue, dwFlag, false)) { + if (lpScriptContext->QueryNodeByFlag( + pRefNode, wsPropName.AsStringView(), pValue, + XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings, false)) { return; } @@ -316,20 +317,20 @@ void CFXJSE_Engine::NormalPropertyGetter(CFXJSE_Value* pOriginalValue, return; } - uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | - XFA_RESOLVENODE_Attributes; bool bRet = lpScriptContext->QueryNodeByFlag( - ToNode(pObject), wsPropName.AsStringView(), pReturnValue, dwFlag, false); + ToNode(pObject), wsPropName.AsStringView(), pReturnValue, + XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | + XFA_RESOLVENODE_Attributes, + false); if (bRet) return; if (pObject == lpScriptContext->GetThisObject() || (lpScriptContext->GetType() == CXFA_ScriptData::Type::Javascript && !lpScriptContext->IsStrictScopeInJavaScript())) { - dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; - bRet = lpScriptContext->QueryNodeByFlag(ToNode(pObject), - wsPropName.AsStringView(), - pReturnValue, dwFlag, false); + bRet = lpScriptContext->QueryNodeByFlag( + ToNode(pObject), wsPropName.AsStringView(), pReturnValue, + XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings, false); } if (bRet) return; @@ -377,13 +378,11 @@ void CFXJSE_Engine::NormalPropertySetter(CFXJSE_Value* pOriginalValue, pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringView()); if (pPropOrChild) { - WideString wsDefaultName(L"{default}"); const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = XFA_GetScriptAttributeByName( - pPropOrChild->GetElementType(), wsDefaultName.AsStringView()); + pPropOrChild->GetElementType(), L"{default}"); if (lpAttrInfo) { - CJX_Node* jsObject = pPropOrChild->JSNode(); - (jsObject->*(lpAttrInfo->callback))(pReturnValue, true, - lpAttrInfo->attribute); + pPropOrChild->JSNode()->Script_Som_DefaultValue(pReturnValue, true, + XFA_Attribute::Unknown); return; } } @@ -581,7 +580,6 @@ int32_t CFXJSE_Engine::ResolveObjects(CXFA_Object* refObject, CFXJSE_ResolveNodeData rndFind(this); int32_t nStart = 0; int32_t nLevel = 0; - int32_t nRet = -1; std::vector<CXFA_Object*> findObjects; findObjects.push_back(refObject ? refObject : m_pDocument->GetRoot()); @@ -643,8 +641,7 @@ int32_t CFXJSE_Engine::ResolveObjects(CXFA_Object* refObject, rndFind.m_CurObject = findObjects[i++]; rndFind.m_nLevel = nLevel; rndFind.m_dwFlag = XFA_RESOLVENODE_RSTYPE_Nodes; - nRet = m_ResolveProcessor->Resolve(rndFind); - if (nRet < 1) + if (!m_ResolveProcessor->Resolve(rndFind)) continue; if (rndFind.m_dwFlag == XFA_RESOLVENODE_RSTYPE_Attribute && diff --git a/fxjs/cfxjse_resolveprocessor.cpp b/fxjs/cfxjse_resolveprocessor.cpp index 5dba39b25d..fb7bc555c6 100644 --- a/fxjs/cfxjse_resolveprocessor.cpp +++ b/fxjs/cfxjse_resolveprocessor.cpp @@ -27,20 +27,20 @@ CFXJSE_ResolveProcessor::CFXJSE_ResolveProcessor() CFXJSE_ResolveProcessor::~CFXJSE_ResolveProcessor() {} -int32_t CFXJSE_ResolveProcessor::Resolve(CFXJSE_ResolveNodeData& rnd) { +bool CFXJSE_ResolveProcessor::Resolve(CFXJSE_ResolveNodeData& rnd) { if (!rnd.m_CurObject) - return -1; + return false; if (!rnd.m_CurObject->IsNode()) { if (rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) { return ResolveForAttributeRs(rnd.m_CurObject, rnd, rnd.m_wsName.AsStringView()); } - return 0; + return false; } - if (rnd.m_dwStyles & XFA_RESOLVENODE_AnyChild) { + if (rnd.m_dwStyles & XFA_RESOLVENODE_AnyChild) return ResolveAnyChild(rnd); - } + if (rnd.m_wsName.GetLength()) { wchar_t wch = rnd.m_wsName[0]; switch (wch) { @@ -61,7 +61,7 @@ int32_t CFXJSE_ResolveProcessor::Resolve(CFXJSE_ResolveNodeData& rnd) { } if (rnd.m_uHashName == XFA_HASHCODE_This && rnd.m_nLevel == 0) { rnd.m_Objects.push_back(rnd.m_pSC->GetThisObject()); - return 1; + return true; } if (rnd.m_CurObject->GetElementType() == XFA_Element::Xfa) { CXFA_Object* pObjNode = @@ -73,20 +73,20 @@ int32_t CFXJSE_ResolveProcessor::Resolve(CFXJSE_ResolveNodeData& rnd) { } else if ((rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) && ResolveForAttributeRs(rnd.m_CurObject, rnd, rnd.m_wsName.AsStringView())) { - return 1; + return true; } if (!rnd.m_Objects.empty()) FilterCondition(rnd, rnd.m_wsCondition); - return pdfium::CollectionSize<int32_t>(rnd.m_Objects); + return !rnd.m_Objects.empty(); } - if (ResolveNormal(rnd) < 1 && rnd.m_uHashName == XFA_HASHCODE_Xfa) + if (!ResolveNormal(rnd) && rnd.m_uHashName == XFA_HASHCODE_Xfa) rnd.m_Objects.push_back(rnd.m_pSC->GetDocument()->GetRoot()); - return pdfium::CollectionSize<int32_t>(rnd.m_Objects); + return !rnd.m_Objects.empty(); } -int32_t CFXJSE_ResolveProcessor::ResolveAnyChild(CFXJSE_ResolveNodeData& rnd) { +bool CFXJSE_ResolveProcessor::ResolveAnyChild(CFXJSE_ResolveNodeData& rnd) { WideString wsName = rnd.m_wsName; WideString wsCondition = rnd.m_wsCondition; CXFA_Node* findNode = nullptr; @@ -97,13 +97,14 @@ int32_t CFXJSE_ResolveProcessor::ResolveAnyChild(CFXJSE_ResolveNodeData& rnd) { } findNode = m_pNodeHelper->ResolveNodes_GetOneChild( ToNode(rnd.m_CurObject), wsName.c_str(), bClassName); - if (!findNode) { - return 0; - } + if (!findNode) + return false; + if (wsCondition.IsEmpty()) { rnd.m_Objects.push_back(findNode); - return pdfium::CollectionSize<int32_t>(rnd.m_Objects); + return !rnd.m_Objects.empty(); } + std::vector<CXFA_Node*> tempNodes; for (auto* pObject : rnd.m_Objects) tempNodes.push_back(pObject->AsNode()); @@ -111,20 +112,20 @@ int32_t CFXJSE_ResolveProcessor::ResolveAnyChild(CFXJSE_ResolveNodeData& rnd) { bClassName); rnd.m_Objects = std::vector<CXFA_Object*>(tempNodes.begin(), tempNodes.end()); FilterCondition(rnd, wsCondition); - return pdfium::CollectionSize<int32_t>(rnd.m_Objects); + return !rnd.m_Objects.empty(); } -int32_t CFXJSE_ResolveProcessor::ResolveDollar(CFXJSE_ResolveNodeData& rnd) { +bool CFXJSE_ResolveProcessor::ResolveDollar(CFXJSE_ResolveNodeData& rnd) { WideString wsName = rnd.m_wsName; WideString wsCondition = rnd.m_wsCondition; int32_t iNameLen = wsName.GetLength(); if (iNameLen == 1) { rnd.m_Objects.push_back(rnd.m_CurObject); - return 1; - } - if (rnd.m_nLevel > 0) { - return -1; + return true; } + if (rnd.m_nLevel > 0) + return false; + XFA_HashCode dwNameHash = static_cast<XFA_HashCode>(FX_HashCode_GetW( WideStringView(wsName.c_str() + 1, iNameLen - 1), false)); if (dwNameHash == XFA_HASHCODE_Xfa) { @@ -137,18 +138,17 @@ int32_t CFXJSE_ResolveProcessor::ResolveDollar(CFXJSE_ResolveNodeData& rnd) { if (!rnd.m_Objects.empty()) FilterCondition(rnd, wsCondition); - return pdfium::CollectionSize<int32_t>(rnd.m_Objects); + return !rnd.m_Objects.empty(); } -int32_t CFXJSE_ResolveProcessor::ResolveExcalmatory( - CFXJSE_ResolveNodeData& rnd) { +bool CFXJSE_ResolveProcessor::ResolveExcalmatory(CFXJSE_ResolveNodeData& rnd) { if (rnd.m_nLevel > 0) - return 0; + return false; CXFA_Node* datasets = ToNode(rnd.m_pSC->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); if (!datasets) - return 0; + return false; CFXJSE_ResolveNodeData rndFind(rnd.m_pSC); rndFind.m_CurObject = datasets; @@ -159,18 +159,18 @@ int32_t CFXJSE_ResolveProcessor::ResolveExcalmatory( rndFind.m_dwStyles = XFA_RESOLVENODE_Children; rndFind.m_wsCondition = rnd.m_wsCondition; Resolve(rndFind); + rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), rndFind.m_Objects.end()); - return pdfium::CollectionSize<int32_t>(rnd.m_Objects); + return !rnd.m_Objects.empty(); } -int32_t CFXJSE_ResolveProcessor::ResolveNumberSign( - CFXJSE_ResolveNodeData& rnd) { +bool CFXJSE_ResolveProcessor::ResolveNumberSign(CFXJSE_ResolveNodeData& rnd) { WideString wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); WideString wsCondition = rnd.m_wsCondition; CXFA_Node* curNode = ToNode(rnd.m_CurObject); if (ResolveForAttributeRs(curNode, rnd, wsName.AsStringView())) - return 1; + return true; CFXJSE_ResolveNodeData rndFind(rnd.m_pSC); rndFind.m_nLevel = rnd.m_nLevel + 1; @@ -184,7 +184,7 @@ int32_t CFXJSE_ResolveProcessor::ResolveNumberSign( rndFind.m_CurObject = curNode; ResolveNormal(rndFind); if (rndFind.m_Objects.empty()) - return 0; + return false; if (wsCondition.GetLength() == 0 && pdfium::ContainsValue(rndFind.m_Objects, curNode)) { @@ -193,27 +193,27 @@ int32_t CFXJSE_ResolveProcessor::ResolveNumberSign( rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), rndFind.m_Objects.end()); } - return pdfium::CollectionSize<int32_t>(rnd.m_Objects); + return !rnd.m_Objects.empty(); } -int32_t CFXJSE_ResolveProcessor::ResolveForAttributeRs( +bool CFXJSE_ResolveProcessor::ResolveForAttributeRs( CXFA_Object* curNode, CFXJSE_ResolveNodeData& rnd, const WideStringView& strAttr) { const XFA_SCRIPTATTRIBUTEINFO* lpScriptAttribute = XFA_GetScriptAttributeByName(curNode->GetElementType(), strAttr); if (!lpScriptAttribute) - return 0; + return false; rnd.m_pScriptAttribute = lpScriptAttribute; rnd.m_Objects.push_back(curNode); rnd.m_dwFlag = XFA_RESOLVENODE_RSTYPE_Attribute; - return 1; + return true; } -int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { +bool CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { if (rnd.m_nLevel > 32 || !rnd.m_CurObject->IsNode()) - return 0; + return false; CXFA_Node* curNode = rnd.m_CurObject->AsNode(); size_t nNum = rnd.m_Objects.size(); @@ -248,8 +248,7 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { children.push_back(pChild); } if ((dwStyles & XFA_RESOLVENODE_Properties) && pVariablesNode) { - uint32_t uPropHash = pVariablesNode->GetClassHashCode(); - if (uPropHash == uNameHash) { + if (pVariablesNode->GetClassHashCode() == uNameHash) { rnd.m_Objects.push_back(pVariablesNode); } else { rndFind.m_CurObject = pVariablesNode; @@ -264,9 +263,10 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { } if (rnd.m_Objects.size() > nNum) { FilterCondition(rnd, wsCondition); - return !rnd.m_Objects.empty() ? 1 : 0; + return !rnd.m_Objects.empty(); } } + if (dwStyles & XFA_RESOLVENODE_Children) { bool bSetFlag = false; if (pPageSetNode && (dwStyles & XFA_RESOLVENODE_Properties)) @@ -279,6 +279,7 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { } else if (child->GetNameHash() == uNameHash) { rnd.m_Objects.push_back(child); } + if (m_pNodeHelper->NodeIsTransparent(child) && child->GetElementType() != XFA_Element::PageSet) { if (!bSetFlag) { @@ -286,9 +287,11 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { bSetFlag = true; } rndFind.m_CurObject = child; + WideString wsSaveCondition = rndFind.m_wsCondition; rndFind.m_wsCondition.clear(); ResolveNormal(rndFind); + rndFind.m_wsCondition = wsSaveCondition; rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), rndFind.m_Objects.end()); @@ -311,7 +314,7 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { } } FilterCondition(rnd, wsCondition); - return !rnd.m_Objects.empty() ? 1 : 0; + return !rnd.m_Objects.empty(); } } if (dwStyles & XFA_RESOLVENODE_Attributes) { @@ -333,8 +336,9 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { } if (rnd.m_Objects.size() > nNum) { FilterCondition(rnd, wsCondition); - return !rnd.m_Objects.empty() ? 1 : 0; + return !rnd.m_Objects.empty(); } + CXFA_Node* pProp = nullptr; if (XFA_Element::Subform == curNode->GetElementType() && XFA_HASHCODE_Occur == uNameHash) { @@ -353,9 +357,10 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { } if (pProp) { rnd.m_Objects.push_back(pProp); - return pdfium::CollectionSize<int32_t>(rnd.m_Objects); + return !rnd.m_Objects.empty(); } } + CXFA_Node* parentNode = m_pNodeHelper->ResolveNodes_GetParent( curNode->AsNode(), XFA_LOGIC_NoTransparent); uint32_t uCurClassHash = curNode->GetClassHashCode(); @@ -364,10 +369,11 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { rnd.m_Objects.push_back(curNode->AsNode()); FilterCondition(rnd, wsCondition); if (!rnd.m_Objects.empty()) - return 1; + return true; } - return 0; + return false; } + if (dwStyles & XFA_RESOLVENODE_Siblings) { CXFA_Node* child = parentNode->GetNodeItem(XFA_NODEITEM_FirstChild); uint32_t dwSubStyles = @@ -376,26 +382,27 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { dwSubStyles |= XFA_RESOLVENODE_TagName; if (dwStyles & XFA_RESOLVENODE_ALL) dwSubStyles |= XFA_RESOLVENODE_ALL; + rndFind.m_dwStyles = dwSubStyles; while (child) { if (child == curNode) { if (dwStyles & XFA_RESOLVENODE_TagName) { - if (uCurClassHash == uNameHash) { + if (uCurClassHash == uNameHash) rnd.m_Objects.push_back(curNode); - } } else { if (child->GetNameHash() == uNameHash) { rnd.m_Objects.push_back(curNode); if (rnd.m_nLevel == 0 && wsCondition.GetLength() == 0) { rnd.m_Objects.clear(); rnd.m_Objects.push_back(curNode); - return 1; + return true; } } } child = child->GetNodeItem(XFA_NODEITEM_NextSibling); continue; } + if (dwStyles & XFA_RESOLVENODE_TagName) { if (child->GetClassHashCode() == uNameHash) rnd.m_Objects.push_back(child); @@ -409,18 +416,18 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { child->GetElementType() == XFA_Element::PageSet)) { bInnerSearch = true; } - } else { - if (m_pNodeHelper->NodeIsTransparent(child)) { - bInnerSearch = true; - } + } else if (m_pNodeHelper->NodeIsTransparent(child)) { + bInnerSearch = true; } if (bInnerSearch) { rndFind.m_CurObject = child; WideString wsOriginCondition = rndFind.m_wsCondition; rndFind.m_wsCondition.clear(); + uint32_t dwOriginStyle = rndFind.m_dwStyles; rndFind.m_dwStyles = dwOriginStyle | XFA_RESOLVENODE_ALL; ResolveNormal(rndFind); + rndFind.m_dwStyles = dwOriginStyle; rndFind.m_wsCondition = wsOriginCondition; rnd.m_Objects.insert(rnd.m_Objects.end(), rndFind.m_Objects.begin(), @@ -443,18 +450,18 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { } } FilterCondition(rnd, wsCondition); - return !rnd.m_Objects.empty() ? 1 : 0; + return !rnd.m_Objects.empty(); } } + if (dwStyles & XFA_RESOLVENODE_Parent) { uint32_t dwSubStyles = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Properties; - if (dwStyles & XFA_RESOLVENODE_TagName) { + if (dwStyles & XFA_RESOLVENODE_TagName) dwSubStyles |= XFA_RESOLVENODE_TagName; - } - if (dwStyles & XFA_RESOLVENODE_ALL) { + if (dwStyles & XFA_RESOLVENODE_ALL) dwSubStyles |= XFA_RESOLVENODE_ALL; - } + rndFind.m_dwStyles = dwSubStyles; rndFind.m_CurObject = parentNode; rnd.m_pSC->GetUpObjectArray()->push_back(parentNode); @@ -463,37 +470,29 @@ int32_t CFXJSE_ResolveProcessor::ResolveNormal(CFXJSE_ResolveNodeData& rnd) { rndFind.m_Objects.end()); rndFind.m_Objects.clear(); if (rnd.m_Objects.size() > nNum) - return 1; + return true; } - return 0; + return false; } -int32_t CFXJSE_ResolveProcessor::ResolveAsterisk(CFXJSE_ResolveNodeData& rnd) { +bool CFXJSE_ResolveProcessor::ResolveAsterisk(CFXJSE_ResolveNodeData& rnd) { CXFA_Node* curNode = ToNode(rnd.m_CurObject); std::vector<CXFA_Node*> array = curNode->GetNodeList(XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties, XFA_Element::Unknown); rnd.m_Objects.insert(rnd.m_Objects.end(), array.begin(), array.end()); - return pdfium::CollectionSize<int32_t>(rnd.m_Objects); -} - -int32_t CFXJSE_ResolveProcessor::ResolvePopStack(std::vector<int32_t>* stack) { - if (stack->empty()) - return -1; - - int32_t nType = stack->back(); - stack->pop_back(); - return nType; + return !rnd.m_Objects.empty(); } int32_t CFXJSE_ResolveProcessor::GetFilter(const WideStringView& wsExpression, int32_t nStart, CFXJSE_ResolveNodeData& rnd) { ASSERT(nStart > -1); + int32_t iLength = wsExpression.GetLength(); - if (nStart >= iLength) { + if (nStart >= iLength) return 0; - } + WideString& wsName = rnd.m_wsName; WideString& wsCondition = rnd.m_wsCondition; wchar_t* pNameBuf = wsName.GetBuffer(iLength - nStart); @@ -503,7 +502,8 @@ int32_t CFXJSE_ResolveProcessor::GetFilter(const WideStringView& wsExpression, std::vector<int32_t> stack; int32_t nType = -1; const wchar_t* pSrc = wsExpression.unterminated_c_str(); - wchar_t wPrev = 0, wCur; + wchar_t wPrev = 0; + wchar_t wCur; bool bIsCondition = false; while (nStart < iLength) { wCur = pSrc[nStart++]; @@ -516,12 +516,10 @@ int32_t CFXJSE_ResolveProcessor::GetFilter(const WideStringView& wsExpression, rnd.m_dwStyles |= XFA_RESOLVENODE_AnyChild; continue; } + wchar_t wLookahead = nStart < iLength ? pSrc[nStart] : 0; - if (wLookahead != '[' && wLookahead != '(') { - if (nType < 0) { - break; - } - } + if (wLookahead != '[' && wLookahead != '(' && nType < 0) + break; } if (wCur == '[' || wCur == '(') { bIsCondition = true; @@ -529,47 +527,25 @@ int32_t CFXJSE_ResolveProcessor::GetFilter(const WideStringView& wsExpression, (pSrc[nStart] == '[' || pSrc[nStart] == '(')) { bIsCondition = true; } - if (bIsCondition) { + if (bIsCondition) pConditionBuf[nConditionCount++] = wCur; - } else { + else pNameBuf[nNameCount++] = wCur; - } - bool bRecursive = true; - switch (nType) { - case 0: - if (wCur == ']') { - nType = ResolvePopStack(&stack); - bRecursive = false; - } - break; - case 1: - if (wCur == ')') { - nType = ResolvePopStack(&stack); - bRecursive = false; - } - break; - case 2: - if (wCur == '"') { - nType = ResolvePopStack(&stack); - bRecursive = false; - } - break; - } - if (bRecursive) { - switch (wCur) { - case '[': - stack.push_back(nType); - nType = 0; - break; - case '(': - stack.push_back(nType); - nType = 1; - break; - case '"': - stack.push_back(nType); - nType = 2; - break; - } + + if ((nType == 0 && wCur == ']') || (nType == 1 && wCur == ')') || + (nType == 2 && wCur == '"')) { + nType = stack.empty() ? -1 : stack.back(); + if (!stack.empty()) + stack.pop_back(); + } else if (wCur == '[') { + stack.push_back(nType); + nType = 0; + } else if (wCur == '(') { + stack.push_back(nType); + nType = 1; + } else if (wCur == '"') { + stack.push_back(nType); + nType = 2; } wPrev = wCur; } @@ -597,11 +573,11 @@ void CFXJSE_ResolveProcessor::ConditionArray(int32_t iCurIndex, wchar_t ch = wsCondition[i]; if (ch == ' ') continue; - if (ch == '+' || ch == '-') { + if (ch == '+' || ch == '-') bRelative = true; - } else if (ch == '*') { + else if (ch == '*') bAll = true; - } + break; } if (bAll) { @@ -612,28 +588,23 @@ void CFXJSE_ResolveProcessor::ConditionArray(int32_t iCurIndex, rnd.m_Objects.clear(); m_pNodeHelper->m_iCurAllStart = -1; m_pNodeHelper->m_pAllStartParent = nullptr; - } else { - if (m_pNodeHelper->m_iCurAllStart == -1) { - m_pNodeHelper->m_iCurAllStart = m_iCurStart; - m_pNodeHelper->m_pAllStartParent = ToNode(rnd.m_CurObject); - } + } else if (m_pNodeHelper->m_iCurAllStart == -1) { + m_pNodeHelper->m_iCurAllStart = m_iCurStart; + m_pNodeHelper->m_pAllStartParent = ToNode(rnd.m_CurObject); } } else if (rnd.m_dwStyles & XFA_RESOLVENODE_BindNew) { - if (m_pNodeHelper->m_iCurAllStart == -1) { + if (m_pNodeHelper->m_iCurAllStart == -1) m_pNodeHelper->m_iCurAllStart = m_iCurStart; - } } return; } - if (iFoundCount == 1 && !iLen) { + if (iFoundCount == 1 && !iLen) return; - } - WideString wsIndex; - wsIndex = wsCondition.Mid(i, iLen - 1 - i); - int32_t iIndex = wsIndex.GetInteger(); - if (bRelative) { + + int32_t iIndex = wsCondition.Mid(i, iLen - 1 - i).GetInteger(); + if (bRelative) iIndex += iCurIndex; - } + if (iFoundCount <= iIndex || iIndex < 0) { if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurObject); @@ -654,13 +625,12 @@ void CFXJSE_ResolveProcessor::DoPredicateFilter(int32_t iCurIndex, ASSERT(iFoundCount == pdfium::CollectionSize<int32_t>(rnd.m_Objects)); WideString wsExpression; CXFA_ScriptData::Type eLangType = CXFA_ScriptData::Type::Unknown; - if (wsCondition.Left(2) == L".[" && wsCondition.Last() == L']') { + if (wsCondition.Left(2) == L".[" && wsCondition.Last() == L']') eLangType = CXFA_ScriptData::Type::Formcalc; - } else if (wsCondition.Left(2) == L".(" && wsCondition.Last() == L')') { + else if (wsCondition.Left(2) == L".(" && wsCondition.Last() == L')') eLangType = CXFA_ScriptData::Type::Javascript; - } else { + else return; - } CFXJSE_Engine* pContext = rnd.m_pSC; wsExpression = wsCondition.Mid(2, wsCondition.GetLength() - 3); @@ -689,16 +659,17 @@ void CFXJSE_ResolveProcessor::FilterCondition(CFXJSE_ResolveNodeData& rnd, bIsProperty, false); } } + int32_t iFoundCount = pdfium::CollectionSize<int32_t>(rnd.m_Objects); wsCondition.Trim(); + int32_t iLen = wsCondition.GetLength(); if (!iLen) { - if (rnd.m_dwStyles & XFA_RESOLVENODE_ALL) { + if (rnd.m_dwStyles & XFA_RESOLVENODE_ALL) return; - } - if (iFoundCount == 1) { + if (iFoundCount == 1) return; - } + if (iFoundCount <= iCurrIndex) { if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurObject); @@ -706,26 +677,25 @@ void CFXJSE_ResolveProcessor::FilterCondition(CFXJSE_ResolveNodeData& rnd, } rnd.m_Objects.clear(); return; - } else { - CXFA_Object* ret = rnd.m_Objects[iCurrIndex]; - rnd.m_Objects.clear(); - rnd.m_Objects.push_back(ret); - return; } + + CXFA_Object* ret = rnd.m_Objects[iCurrIndex]; + rnd.m_Objects.clear(); + rnd.m_Objects.push_back(ret); + return; } + wchar_t wTypeChar = wsCondition[0]; switch (wTypeChar) { case '[': ConditionArray(iCurrIndex, wsCondition, iFoundCount, rnd); return; - case '(': - return; - case '"': - return; case '.': - if (iLen > 1 && (wsCondition[1] == '[' || wsCondition[1] == '(')) { + if (iLen > 1 && (wsCondition[1] == '[' || wsCondition[1] == '(')) DoPredicateFilter(iCurrIndex, wsCondition, iFoundCount, rnd); - } + return; + case '(': + case '"': default: return; } @@ -733,9 +703,9 @@ void CFXJSE_ResolveProcessor::FilterCondition(CFXJSE_ResolveNodeData& rnd, void CFXJSE_ResolveProcessor::SetStylesForChild(uint32_t dwParentStyles, CFXJSE_ResolveNodeData& rnd) { uint32_t dwSubStyles = XFA_RESOLVENODE_Children; - if (dwParentStyles & XFA_RESOLVENODE_TagName) { + if (dwParentStyles & XFA_RESOLVENODE_TagName) dwSubStyles |= XFA_RESOLVENODE_TagName; - } + dwSubStyles &= ~XFA_RESOLVENODE_Parent; dwSubStyles &= ~XFA_RESOLVENODE_Siblings; dwSubStyles &= ~XFA_RESOLVENODE_Properties; diff --git a/fxjs/cfxjse_resolveprocessor.h b/fxjs/cfxjse_resolveprocessor.h index 2961d21727..dc6b9cc6b9 100644 --- a/fxjs/cfxjse_resolveprocessor.h +++ b/fxjs/cfxjse_resolveprocessor.h @@ -37,7 +37,7 @@ class CFXJSE_ResolveProcessor { CFXJSE_ResolveProcessor(); ~CFXJSE_ResolveProcessor(); - int32_t Resolve(CFXJSE_ResolveNodeData& rnd); + bool Resolve(CFXJSE_ResolveNodeData& rnd); int32_t GetFilter(const WideStringView& wsExpression, int32_t nStart, CFXJSE_ResolveNodeData& rnd); @@ -51,16 +51,15 @@ class CFXJSE_ResolveProcessor { CXFA_NodeHelper* GetNodeHelper() const { return m_pNodeHelper.get(); } private: - int32_t ResolveForAttributeRs(CXFA_Object* curNode, - CFXJSE_ResolveNodeData& rnd, - const WideStringView& strAttr); - int32_t ResolveAnyChild(CFXJSE_ResolveNodeData& rnd); - int32_t ResolveDollar(CFXJSE_ResolveNodeData& rnd); - int32_t ResolveExcalmatory(CFXJSE_ResolveNodeData& rnd); - int32_t ResolveNumberSign(CFXJSE_ResolveNodeData& rnd); - int32_t ResolveAsterisk(CFXJSE_ResolveNodeData& rnd); - int32_t ResolveNormal(CFXJSE_ResolveNodeData& rnd); - int32_t ResolvePopStack(std::vector<int32_t>* stack); + bool ResolveForAttributeRs(CXFA_Object* curNode, + CFXJSE_ResolveNodeData& rnd, + const WideStringView& strAttr); + bool ResolveAnyChild(CFXJSE_ResolveNodeData& rnd); + bool ResolveDollar(CFXJSE_ResolveNodeData& rnd); + bool ResolveExcalmatory(CFXJSE_ResolveNodeData& rnd); + bool ResolveNumberSign(CFXJSE_ResolveNodeData& rnd); + bool ResolveAsterisk(CFXJSE_ResolveNodeData& rnd); + bool ResolveNormal(CFXJSE_ResolveNodeData& rnd); void SetStylesForChild(uint32_t dwParentStyles, CFXJSE_ResolveNodeData& rnd); void ConditionArray(int32_t iCurIndex, diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index 58e2cdeb7c..2865ba4fbf 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -1384,20 +1384,21 @@ void CJX_Node::Script_Field_Length(CFXJSE_Value* pValue, void CJX_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, bool bSetting, - XFA_Attribute eAttribute) { + XFA_Attribute /* unused */) { XFA_Element eType = GetXFANode()->GetElementType(); if (eType == XFA_Element::Field) { - Script_Field_DefaultValue(pValue, bSetting, eAttribute); + Script_Field_DefaultValue(pValue, bSetting, XFA_Attribute::Unknown); return; } if (eType == XFA_Element::Draw) { - Script_Draw_DefaultValue(pValue, bSetting, eAttribute); + Script_Draw_DefaultValue(pValue, bSetting, XFA_Attribute::Unknown); return; } if (eType == XFA_Element::Boolean) { - Script_Boolean_Value(pValue, bSetting, eAttribute); + Script_Boolean_Value(pValue, bSetting, XFA_Attribute::Unknown); return; } + if (bSetting) { WideString wsNewValue; if (pValue && !(pValue->IsNull() || pValue->IsUndefined())) |