7#include "fxjs/xfa/cfxjse_resolveprocessor.h"
13#include "core/fxcrt/fx_extension.h"
14#include "fxjs/xfa/cfxjse_engine.h"
15#include "fxjs/xfa/cfxjse_nodehelper.h"
16#include "fxjs/xfa/cfxjse_value.h"
17#include "fxjs/xfa/cjx_object.h"
18#include "third_party/base/check.h"
19#include "third_party/base/check_op.h"
20#include "third_party/base/containers/contains.h"
21#include "xfa/fxfa/parser/cxfa_document.h"
22#include "xfa/fxfa/parser/cxfa_localemgr.h"
23#include "xfa/fxfa/parser/cxfa_node.h"
24#include "xfa/fxfa/parser/cxfa_object.h"
25#include "xfa/fxfa/parser/cxfa_occur.h"
26#include "xfa/fxfa/parser/xfa_utils.h"
38 if (!rnd.m_CurObject->IsNode()) {
40 return ResolveForAttributeRs(rnd.m_CurObject, &rnd
.m_Result,
41 rnd.m_wsName.AsStringView());
46 return ResolveAnyChild(pIsolate, rnd);
48 if (rnd.m_wsName.GetLength()) {
49 wchar_t wch = rnd.m_wsName[0];
52 return ResolveDollar(pIsolate, rnd);
54 return ResolveExcalmatory(pIsolate, rnd);
56 return ResolveNumberSign(pIsolate, rnd);
58 return ResolveAsterisk(rnd);
61 return ResolveAnyChild(pIsolate, rnd);
67 rnd.m_Result.objects.emplace_back(m_pEngine->GetThisObject());
70 if (rnd.m_CurObject->GetElementType() ==
XFA_Element::Xfa) {
72 m_pEngine->GetDocument()->GetXFAObject(rnd.m_uHashName);
74 rnd
.m_Result.objects.emplace_back(pObjNode);
76 rnd
.m_Result.objects.emplace_back(rnd.m_CurObject);
78 ResolveForAttributeRs(rnd.m_CurObject, &rnd
.m_Result,
79 rnd.m_wsName.AsStringView())) {
83 FilterCondition(pIsolate, rnd.m_wsCondition, &rnd);
87 if (!ResolveNormal(pIsolate, rnd) && rnd.m_uHashName == XFA_HASHCODE_Xfa)
88 rnd.m_Result.objects.emplace_back(m_pEngine->GetDocument()->GetRoot());
95 CXFA_Node* pParent = ToNode(rnd.m_CurObject);
99 WideStringView wsName = rnd.m_wsName.AsStringView();
100 WideString wsCondition = rnd.m_wsCondition;
101 const bool bClassName = !wsName.IsEmpty() && wsName[0] ==
'#';
110 rnd
.m_Result.objects.emplace_back(pChild);
114 std::vector<CXFA_Node*> nodes;
115 for (
const auto& pObject : rnd.m_Result.objects)
116 nodes.push_back(pObject->AsNode());
118 std::vector<CXFA_Node*> siblings = pChild->GetSiblings(bClassName);
119 nodes.insert(nodes.end(), siblings.begin(), siblings.end());
120 rnd.m_Result.objects =
121 std::vector<cppgc::Member<CXFA_Object>>(nodes.begin(), nodes.end());
122 FilterCondition(pIsolate, wsCondition, &rnd);
128 WideString wsName = rnd.m_wsName;
129 WideString wsCondition = rnd.m_wsCondition;
130 size_t nNameLen = wsName.GetLength();
132 rnd
.m_Result.objects.emplace_back(rnd.m_CurObject);
138 CXFA_Document* pDocument = m_pEngine->GetDocument();
140 FX_HashCode_GetW(wsName.AsStringView().Last(nNameLen - 1)));
146 rnd
.m_Result.objects.emplace_back(pObjNode);
149 FilterCondition(pIsolate, wsCondition, &rnd);
159 ToNode(m_pEngine->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets));
164 rndFind.m_CurObject = datasets;
165 rndFind.m_wsName = rnd.m_wsName.Last(rnd.m_wsName.GetLength() - 1);
167 FX_HashCode_GetW(rndFind.m_wsName.AsStringView()));
170 rndFind.m_wsCondition = rnd.m_wsCondition;
181 WideString wsName = rnd.m_wsName.Last(rnd.m_wsName.GetLength() - 1);
182 WideString wsCondition = rnd.m_wsCondition;
183 CXFA_Node* curNode = ToNode(rnd.m_CurObject);
184 if (ResolveForAttributeRs(curNode, &rnd
.m_Result, wsName.AsStringView()))
189 rndFind.m_dwStyles = rnd.m_dwStyles;
192 rndFind.m_wsName =
std::move(wsName);
194 FX_HashCode_GetW(rndFind.m_wsName.AsStringView()));
195 rndFind.m_wsCondition = wsCondition;
196 rndFind.m_CurObject = curNode;
197 ResolveNormal(pIsolate, rndFind);
202 pdfium::Contains(rndFind
.m_Result.objects, curNode)) {
203 rnd
.m_Result.objects.emplace_back(curNode);
215 WideStringView strAttr) {
216 absl::optional<XFA_SCRIPTATTRIBUTEINFO> info =
217 XFA_GetScriptAttributeByName(curNode->GetElementType(), strAttr);
218 if (!info.has_value())
222 rnd->script_attribute = info.value();
223 rnd->objects.emplace_back(curNode);
229 if (rnd
.m_nLevel > 32 || !rnd.m_CurObject->IsNode())
232 CXFA_Node* curNode = rnd.m_CurObject->AsNode();
233 size_t nNum = rnd.m_Result.objects.size();
235 WideString& wsName = rnd.m_wsName;
237 WideString& wsCondition = rnd.m_wsCondition;
240 rndFind.m_wsName = rnd.m_wsName;
241 rndFind.m_wsCondition = rnd.m_wsCondition;
245 std::vector<CXFA_Node*> children;
246 std::vector<CXFA_Node*> properties;
249 for (
CXFA_Node* pChild = curNode->GetFirstChild(); pChild;
250 pChild = pChild->GetNextSibling()) {
252 pVariablesNode = pChild;
256 pPageSetNode = pChild;
260 properties.push_back(pChild);
262 children.push_back(pChild);
266 rnd
.m_Result.objects.emplace_back(pVariablesNode);
268 rndFind.m_CurObject = pVariablesNode;
269 SetStylesForChild(dwStyles, rndFind);
270 WideString wsSaveCondition =
std::move(rndFind.m_wsCondition);
271 ResolveNormal(pIsolate, rndFind);
272 rndFind.m_wsCondition =
std::move(wsSaveCondition);
278 if (rnd
.m_Result.objects.size() > nNum) {
279 FilterCondition(pIsolate, wsCondition, &rnd);
285 bool bSetFlag =
false;
287 children.push_back(pPageSetNode);
289 for (CXFA_Node* child : children) {
290 if (dwStyles & XFA_ResolveFlag::kTagName) {
291 if (child->GetClassHashCode() == uNameHash)
292 rnd.m_Result.objects.emplace_back(child);
293 }
else if (child->GetNameHash() == uNameHash) {
294 rnd.m_Result.objects.emplace_back(child);
297 if (child->GetElementType() != XFA_Element::PageSet &&
298 child->IsTransparent()) {
300 SetStylesForChild(dwStyles, rndFind);
303 rndFind.m_CurObject = child;
305 WideString wsSaveCondition = std::move(rndFind.m_wsCondition);
306 ResolveNormal(pIsolate, rndFind);
307 rndFind.m_wsCondition = std::move(wsSaveCondition);
308 rnd.m_Result.objects.insert(rnd.m_Result.objects.end(),
309 rndFind.m_Result.objects.begin(),
310 rndFind.m_Result.objects.end());
311 rndFind.m_Result.objects.clear();
314 if (rnd
.m_Result.objects.size() > nNum) {
316 std::vector<CXFA_Node*> upArrayNodes;
324 if (upArrayNodes.size() > rnd
.m_Result.objects.size()) {
326 rnd.m_Result.objects = std::vector<cppgc::Member<CXFA_Object>>(
327 upArrayNodes.begin(), upArrayNodes.end());
328 rnd
.m_Result.objects.front() = pSaveObject;
331 FilterCondition(pIsolate, wsCondition, &rnd);
336 if (ResolveForAttributeRs(curNode, &rnd
.m_Result, wsName.AsStringView()))
340 for (CXFA_Node* pChildProperty : properties) {
341 if (pChildProperty->IsUnnamed()) {
342 if (pChildProperty->GetClassHashCode() == uNameHash)
343 rnd.m_Result.objects.emplace_back(pChildProperty);
346 if (pChildProperty->GetNameHash() == uNameHash &&
347 pChildProperty->GetElementType() != XFA_Element::Extras &&
348 pChildProperty->GetElementType() != XFA_Element::Items) {
349 rnd.m_Result.objects.emplace_back(pChildProperty);
352 if (rnd
.m_Result.objects.size() > nNum) {
353 FilterCondition(pIsolate, wsCondition, &rnd);
361 if (pInstanceManager) {
362 pProp = pInstanceManager->JSObject()->GetOrCreateProperty<CXFA_Occur>(
366 XFA_Element eType = XFA_GetElementByName(wsName.AsStringView());
368 pProp = curNode->JSObject()->GetProperty<
CXFA_Node>(0, eType);
370 pProp = curNode->JSObject()->GetOrCreateProperty<
CXFA_Node>(0, eType);
374 rnd
.m_Result.objects.emplace_back(pProp);
379 CXFA_Node*
const parentNode = curNode->GetParent();
382 if (uCurClassHash == uNameHash) {
383 rnd
.m_Result.objects.emplace_back(curNode);
384 FilterCondition(pIsolate, wsCondition, &rnd);
392 CXFA_Node* child = parentNode->GetFirstChild();
394 XFA_ResolveFlag::kProperties};
400 rndFind.m_dwStyles = dwSubStyles;
402 if (child == curNode) {
404 if (uCurClassHash == uNameHash)
405 rnd
.m_Result.objects.emplace_back(curNode);
408 rnd
.m_Result.objects.emplace_back(curNode);
411 rnd
.m_Result.objects.emplace_back(curNode);
416 child = child->GetNextSibling();
422 rnd
.m_Result.objects.emplace_back(child);
424 rnd
.m_Result.objects.emplace_back(child);
427 bool bInnerSearch =
false;
437 rndFind.m_CurObject = child;
438 WideString wsOriginCondition =
std::move(rndFind.m_wsCondition);
441 ResolveNormal(pIsolate, rndFind);
442 rndFind.m_dwStyles = dwOriginStyle;
443 rndFind.m_wsCondition =
std::move(wsOriginCondition);
449 child = child->GetNextSibling();
451 if (rnd
.m_Result.objects.size() > nNum) {
453 std::vector<CXFA_Node*> upArrayNodes;
459 if (upArrayNodes.size() > rnd
.m_Result.objects.size()) {
461 rnd.m_Result.objects = std::vector<cppgc::Member<CXFA_Object>>(
462 upArrayNodes.begin(), upArrayNodes.end());
463 rnd
.m_Result.objects.front() = pSaveObject;
466 FilterCondition(pIsolate, wsCondition, &rnd);
473 XFA_ResolveFlag::kParent,
474 XFA_ResolveFlag::kProperties};
480 m_pEngine->AddObjectToUpArray(parentNode);
481 rndFind.m_dwStyles = dwSubStyles;
482 rndFind.m_CurObject = parentNode;
483 ResolveNormal(pIsolate, rndFind);
495 CXFA_Node* curNode = ToNode(rnd.m_CurObject);
496 std::vector<CXFA_Node*> array = curNode->GetNodeListWithFilter(
497 {XFA_NodeFilter::kChildren, XFA_NodeFilter::kProperties});
508 int32_t iLength = wsExpression.GetLength();
509 if (nStart >= iLength)
512 WideString& wsName = rnd.m_wsName;
513 WideString& wsCondition = rnd.m_wsCondition;
514 int32_t nNameCount = 0;
515 int32_t nConditionCount = 0;
518 pdfium::span<
wchar_t> pNameBuf = wsName.GetBuffer(iLength - nStart);
519 pdfium::span<
wchar_t> pConditionBuf =
520 wsCondition.GetBuffer(iLength - nStart);
521 pdfium::span<
const wchar_t> pSrc = wsExpression.span();
522 std::vector<int32_t> stack;
526 bool bIsCondition =
false;
527 while (nStart < iLength) {
528 wCur = pSrc[nStart++];
530 if (nNameCount == 0) {
535 pNameBuf[nNameCount - 1] = wPrev =
'.';
539 wchar_t wLookahead = nStart < iLength ? pSrc[nStart] : 0;
540 if (wLookahead !=
'[' && wLookahead !=
'(' && nType < 0)
543 if (wCur ==
'[' || wCur ==
'(') {
545 }
else if (wCur ==
'.' && nStart < iLength &&
546 (pSrc[nStart] ==
'[' || pSrc[nStart] ==
'(')) {
550 pConditionBuf[nConditionCount++] = wCur;
552 pNameBuf[nNameCount++] = wCur;
554 if ((nType == 0 && wCur ==
']') || (nType == 1 && wCur ==
')') ||
555 (nType == 2 && wCur ==
'"')) {
556 nType = stack.empty() ? -1 : stack.back();
559 }
else if (wCur ==
'[') {
560 stack.push_back(nType);
562 }
else if (wCur ==
'(') {
563 stack.push_back(nType);
565 }
else if (wCur ==
'"') {
566 stack.push_back(nType);
574 wsName.ReleaseBuffer(nNameCount);
575 wsCondition.ReleaseBuffer(nConditionCount);
579 static_cast<
XFA_HashCode>(FX_HashCode_GetW(wsName.AsStringView()));
584 WideString wsCondition,
587 size_t iLen = wsCondition.GetLength();
588 bool bRelative =
false;
591 for (; i < iLen; ++i) {
592 wchar_t ch = wsCondition[i];
595 if (ch ==
'+' || ch ==
'-')
605 m_pNodeHelper->m_pCreateParent = ToNode(pRnd->m_CurObject);
606 m_pNodeHelper->m_iCreateCount = 1;
608 m_pNodeHelper->m_iCurAllStart = -1;
609 m_pNodeHelper->m_pAllStartParent =
nullptr;
610 }
else if (m_pNodeHelper->m_iCurAllStart == -1) {
611 m_pNodeHelper->m_iCurAllStart = m_iCurStart;
612 m_pNodeHelper->m_pAllStartParent = ToNode(pRnd->m_CurObject);
615 if (m_pNodeHelper->m_iCurAllStart == -1)
616 m_pNodeHelper->m_iCurAllStart = m_iCurStart;
620 if (iFoundCount == 1 && !iLen)
623 int32_t iIndex = wsCondition.Substr(i, iLen - 1 - i).GetInteger();
627 if (iIndex < 0 ||
static_cast<size_t>(iIndex) >= iFoundCount) {
629 m_pNodeHelper->m_pCreateParent = ToNode(pRnd->m_CurObject);
630 m_pNodeHelper->m_iCreateCount = iIndex - iFoundCount + 1;
634 pRnd->m_Result.objects = std::vector<cppgc::Member<CXFA_Object>>(
635 1, pRnd->m_Result.objects[iIndex]);
640 WideString wsCondition,
642 size_t iCurIndex = 0;
643 CXFA_Node* pNode = m_pEngine->LastObjectFromUpArray();
646 const bool bIsClassIndex =
649 iCurIndex = pNode->GetIndex(bIsProperty, bIsClassIndex);
652 size_t iFoundCount = pRnd->m_Result.objects.size();
655 const size_t nLen = wsCondition.GetLength();
659 if (iFoundCount == 1)
662 if (iFoundCount <= iCurIndex) {
664 m_pNodeHelper->m_pCreateParent = ToNode(pRnd->m_CurObject);
665 m_pNodeHelper->m_iCreateCount = iCurIndex - iFoundCount + 1;
671 pRnd->m_Result.objects = std::vector<cppgc::Member<CXFA_Object>>(
672 1, pRnd->m_Result.objects[iCurIndex]);
676 wchar_t wTypeChar = wsCondition
[0
];
679 ConditionArray(iCurIndex, wsCondition, iFoundCount, pRnd);
682 if (nLen > 1 && (wsCondition[1] ==
'[' || wsCondition[1] ==
'('))
683 DoPredicateFilter(pIsolate, wsCondition, iFoundCount, pRnd);
696 XFA_ResolveFlag::kALL};
699 rnd.m_dwStyles = dwSubStyles;
703 const WideString& wsNextCondition,
705 if (m_pNodeHelper->CreateNodeForCondition(wsNextCondition) &&
706 m_pNodeHelper->m_eLastCreateType == XFA_Element::DataGroup) {
713 WideString wsCondition,
716 DCHECK_EQ(iFoundCount, pRnd
->m_Result.objects.size());
718 if (wsCondition.First(2).EqualsASCII(
".[") && wsCondition
.Back() == L']')
720 else if (wsCondition.First(2).EqualsASCII(
".(") && wsCondition
.Back() == L')')
725 WideString wsExpression = wsCondition.Substr(2, wsCondition.GetLength() - 3);
726 for (size_t i = iFoundCount; i > 0; --i) {
728 m_pEngine->RunScript(eLangType, wsExpression.AsStringView(),
729 pRnd->m_Result.objects[i - 1].Get());
730 if (!exec_result
.status || !exec_result.value->ToBoolean(pIsolate)) {
friend class EventParamScope
CFXJSE_Engine::ResolveResult m_Result
bool Resolve(v8::Isolate *pIsolate, NodeData &rnd)
~CFXJSE_ResolveProcessor()
int32_t GetFilter(WideStringView wsExpression, int32_t nStart, NodeData &rnd)
int32_t IndexForDataBind(const WideString &wsNextCondition, int32_t iCount)
CFXJSE_ResolveProcessor(CFXJSE_Engine *pEngine, CFXJSE_NodeHelper *pHelper)
CXFA_Object * GetXFAObject(XFA_HashCode wsNodeNameHash)
CXFA_Node * GetRoot() const
bool HasProperty(XFA_Element property) const
CXFA_Node * GetInstanceMgrOfSubform()
CXFA_Node * GetOneChildOfClass(WideStringView wsClass)
CXFA_Node * GetOneChildNamed(WideStringView wsName)
uint32_t GetNameHash() const
bool IsTransparent() const
XFA_Element GetElementType() const
uint32_t GetClassHashCode() const
CharType operator[](const size_t index) const