Make CXFA_NodeHelper::GetNameExpression() a member of CXFA_Node. Also remove CFXJSE_Engine::GetSomExpression(), which is just a pass-through method. Change-Id: Ice1812db040ccb21e7e5460579bb53552a019ab5 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52374 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/xfa/cfxjse_engine.cpp b/fxjs/xfa/cfxjse_engine.cpp index c7e2645..719b74c 100644 --- a/fxjs/xfa/cfxjse_engine.cpp +++ b/fxjs/xfa/cfxjse_engine.cpp
@@ -771,10 +771,6 @@ refNode->IsProperty(), true); } -WideString CFXJSE_Engine::GetSomExpression(CXFA_Node* refNode) { - return CXFA_NodeHelper::GetNameExpression(refNode); -} - void CFXJSE_Engine::SetNodesOfRunScript(std::vector<CXFA_Node*>* pArray) { m_pScriptNodeArray = pArray; }
diff --git a/fxjs/xfa/cfxjse_engine.h b/fxjs/xfa/cfxjse_engine.h index 524e10b..cacf09f 100644 --- a/fxjs/xfa/cfxjse_engine.h +++ b/fxjs/xfa/cfxjse_engine.h
@@ -86,7 +86,6 @@ size_t GetIndexByName(CXFA_Node* refNode); size_t GetIndexByClassName(CXFA_Node* refNode); - WideString GetSomExpression(CXFA_Node* refNode); void SetNodesOfRunScript(std::vector<CXFA_Node*>* pArray); void AddNodesOfRunScript(CXFA_Node* pNode);
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 8d5f313..f750034 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -218,6 +218,7 @@ #include "xfa/fxfa/parser/cxfa_msgid.h" #include "xfa/fxfa/parser/cxfa_nameattr.h" #include "xfa/fxfa/parser/cxfa_neverembed.h" +#include "xfa/fxfa/parser/cxfa_nodehelper.h" #include "xfa/fxfa/parser/cxfa_nodeiteratortemplate.h" #include "xfa/fxfa/parser/cxfa_numberofcopies.h" #include "xfa/fxfa/parser/cxfa_numberpattern.h" @@ -750,6 +751,28 @@ return nullptr; } +WideString GetNameExpressionSinglePath(CXFA_Node* pNode) { + const bool bIsProperty = pNode->IsProperty(); + const bool bIsClassIndex = + pNode->IsUnnamed() || + (bIsProperty && pNode->GetElementType() != XFA_Element::PageSet); + const wchar_t* pszFormat; + WideString ws; + if (bIsClassIndex) { + pszFormat = L"#%ls[%zu]"; + ws = WideString::FromASCII(pNode->GetClassName()); + } else { + pszFormat = L"%ls[%zu]"; + ws = pNode->JSObject()->GetCData(XFA_Attribute::Name); + ws.Replace(L".", L"\\."); + } + + return WideString::Format( + pszFormat, ws.c_str(), + CXFA_NodeHelper::GetIndex(pNode, XFA_LOGIC_Transparent, bIsProperty, + bIsClassIndex)); +} + } // namespace class CXFA_WidgetLayoutData { @@ -1366,6 +1389,19 @@ } } +WideString CXFA_Node::GetNameExpression() { + WideString wsName = GetNameExpressionSinglePath(this); + CXFA_Node* parent = GetParent(); + while (parent) { + WideString wsParent = GetNameExpressionSinglePath(parent); + wsParent += L"."; + wsParent += wsName; + wsName = std::move(wsParent); + parent = parent->GetParent(); + } + return wsName; +} + CXFA_Node* CXFA_Node::GetDataDescriptionNode() { if (m_ePacket == XFA_PacketType::Datasets) return m_pAuxNode;
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index f8e60fa..106050f 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h
@@ -197,6 +197,7 @@ LocaleIface* GetLocale(); Optional<WideString> GetLocaleName(); XFA_AttributeValue GetIntact(); + WideString GetNameExpression(); CXFA_Node* GetFirstChildByName(WideStringView wsNodeName) const; CXFA_Node* GetFirstChildByName(uint32_t dwNodeNameHash) const;
diff --git a/xfa/fxfa/parser/cxfa_nodehelper.cpp b/xfa/fxfa/parser/cxfa_nodehelper.cpp index 9d0305c..978595d 100644 --- a/xfa/fxfa/parser/cxfa_nodehelper.cpp +++ b/xfa/fxfa/parser/cxfa_nodehelper.cpp
@@ -74,26 +74,6 @@ false); } } - return; -} - -WideString GetNameExpressionSinglePath(CXFA_Node* refNode) { - WideString ws; - bool bIsProperty = refNode->IsProperty(); - if (refNode->IsUnnamed() || - (bIsProperty && refNode->GetElementType() != XFA_Element::PageSet)) { - ws = WideString::FromASCII(refNode->GetClassName()); - return WideString::Format( - L"#%ls[%zu]", ws.c_str(), - CXFA_NodeHelper::GetIndex(refNode, XFA_LOGIC_Transparent, bIsProperty, - true)); - } - ws = refNode->JSObject()->GetCData(XFA_Attribute::Name); - ws.Replace(L".", L"\\."); - return WideString::Format( - L"%ls[%zu]", ws.c_str(), - CXFA_NodeHelper::GetIndex(refNode, XFA_LOGIC_Transparent, bIsProperty, - false)); } CXFA_Node* GetTransparentParent(CXFA_Node* pNode) { @@ -163,20 +143,6 @@ return 0; } -// static -WideString CXFA_NodeHelper::GetNameExpression(CXFA_Node* refNode) { - WideString wsName = GetNameExpressionSinglePath(refNode); - CXFA_Node* parent = refNode ? refNode->GetParent() : nullptr; - while (parent) { - WideString wsParent = GetNameExpressionSinglePath(parent); - wsParent += L"."; - wsParent += wsName; - wsName = std::move(wsParent); - parent = parent->GetParent(); - } - return wsName; -} - bool CXFA_NodeHelper::CreateNodeForCondition(const WideString& wsCondition) { size_t szLen = wsCondition.GetLength(); WideString wsIndex(L"0");
diff --git a/xfa/fxfa/parser/cxfa_nodehelper.h b/xfa/fxfa/parser/cxfa_nodehelper.h index 90b9c72..6e0f280 100644 --- a/xfa/fxfa/parser/cxfa_nodehelper.h +++ b/xfa/fxfa/parser/cxfa_nodehelper.h
@@ -33,7 +33,6 @@ XFA_LOGIC_TYPE eLogicType, bool bIsProperty, bool bIsClassIndex); - static WideString GetNameExpression(CXFA_Node* refNode); bool CreateNode(const WideString& wsName, const WideString& wsCondition,
diff --git a/xfa/fxfa/parser/cxfa_object.cpp b/xfa/fxfa/parser/cxfa_object.cpp index e69d060..a541991 100644 --- a/xfa/fxfa/parser/cxfa_object.cpp +++ b/xfa/fxfa/parser/cxfa_object.cpp
@@ -37,8 +37,8 @@ } WideString CXFA_Object::GetSOMExpression() { - CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext(); - return pScriptContext->GetSomExpression(ToNode(this)); + CXFA_Node* pNode = AsNode(); + return pNode ? pNode->GetNameExpression() : WideString(); } CXFA_List* CXFA_Object::AsList() {