Use UnownedPtr<> in xfa_resolvenode_rs.h

Change-Id: I4420fbf7402a8b08e33ca525e98690643d59efdf
Reviewed-on: https://pdfium-review.googlesource.com/40930
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp
index 5d2ee25..3b60989 100644
--- a/fxjs/cfxjse_engine.cpp
+++ b/fxjs/cfxjse_engine.cpp
@@ -163,11 +163,12 @@
   if (!ResolveObjects(refNode, propname, &resolveRs, dwFlag, nullptr))
     return false;
   if (resolveRs.dwFlags == XFA_ResolveNode_RSType_Nodes) {
-    pValue->Assign(GetJSValueFromMap(resolveRs.objects.front()));
+    pValue->Assign(GetJSValueFromMap(resolveRs.objects.front().Get()));
     return true;
   }
   if (resolveRs.dwFlags == XFA_ResolveNode_RSType_Attribute) {
-    const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute;
+    const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
+        resolveRs.pScriptAttribute.Get();
     if (lpAttributeInfo) {
       CJX_Object* jsObject = resolveRs.objects.front()->JSObject();
       (jsObject->*(lpAttributeInfo->callback))(pValue, bSetting,
@@ -600,8 +601,8 @@
   int32_t nStart = 0;
   int32_t nLevel = 0;
 
-  std::vector<CXFA_Object*> findObjects;
-  findObjects.push_back(refObject ? refObject : m_pDocument->GetRoot());
+  std::vector<UnownedPtr<CXFA_Object>> findObjects;
+  findObjects.emplace_back(refObject ? refObject : m_pDocument->GetRoot());
   int32_t nNodes = 0;
   while (true) {
     nNodes = pdfium::CollectionSize<int32_t>(findObjects);
@@ -617,18 +618,18 @@
           pDataNode = m_pDocument->GetNotBindNode(findObjects);
           if (pDataNode) {
             findObjects.clear();
-            findObjects.push_back(pDataNode);
+            findObjects.emplace_back(pDataNode);
             break;
           }
         } else {
           pDataNode = findObjects.front()->AsNode();
           findObjects.clear();
-          findObjects.push_back(pDataNode);
+          findObjects.emplace_back(pDataNode);
           break;
         }
         dwStyles |= XFA_RESOLVENODE_Bind;
         findObjects.clear();
-        findObjects.push_back(
+        findObjects.emplace_back(
             m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent.Get());
         continue;
       }
@@ -658,7 +659,7 @@
         m_ResolveProcessor->SetIndexDataBind(rndBind.m_wsCondition, i, nNodes);
         bDataBind = true;
       }
-      rndFind.m_CurObject = findObjects[i++];
+      rndFind.m_CurObject = findObjects[i++].Get();
       rndFind.m_nLevel = nLevel;
       rndFind.m_dwFlag = XFA_ResolveNode_RSType_Nodes;
       if (!m_ResolveProcessor->Resolve(rndFind))
@@ -705,8 +706,8 @@
       break;
     }
 
-    findObjects =
-        std::vector<CXFA_Object*>(retObjects.begin(), retObjects.end());
+    findObjects = std::vector<UnownedPtr<CXFA_Object>>(retObjects.begin(),
+                                                       retObjects.end());
     rndFind.m_Objects.clear();
     if (nLevel == 0)
       dwStyles &= ~(XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings);
@@ -729,7 +730,7 @@
                   XFA_RESOLVENODE_BindNew)) {
     CXFA_NodeHelper* helper = m_ResolveProcessor->GetNodeHelper();
     if (helper->m_pCreateParent)
-      resolveNodeRS->objects.push_back(helper->m_pCreateParent.Get());
+      resolveNodeRS->objects.emplace_back(helper->m_pCreateParent.Get());
     else
       helper->CreateNode_ForCondition(rndFind.m_wsCondition);
 
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp
index 0eee3d4..34f5642 100644
--- a/fxjs/cfxjse_formcalc_context.cpp
+++ b/fxjs/cfxjse_formcalc_context.cpp
@@ -5904,7 +5904,7 @@
       dwFlags, nullptr);
   if (iRet && resolveNodeRS.dwFlags == XFA_ResolveNode_RSType_Nodes) {
     accessorValue->Assign(
-        pScriptContext->GetJSValueFromMap(resolveNodeRS.objects.front()));
+        pScriptContext->GetJSValueFromMap(resolveNodeRS.objects.front().Get()));
     return true;
   }
   return false;
@@ -5979,9 +5979,10 @@
   if (resolveNodeRS.dwFlags == XFA_ResolveNode_RSType_Nodes) {
     *bAttribute = false;
     CFXJSE_Engine* pScriptContext = pContext->GetDocument()->GetScriptContext();
-    for (CXFA_Object* pObject : resolveNodeRS.objects) {
+    for (auto& pObject : resolveNodeRS.objects) {
       resultValues->push_back(pdfium::MakeUnique<CFXJSE_Value>(pIsolate));
-      resultValues->back()->Assign(pScriptContext->GetJSValueFromMap(pObject));
+      resultValues->back()->Assign(
+          pScriptContext->GetJSValueFromMap(pObject.Get()));
     }
     return;
   }
@@ -5989,7 +5990,7 @@
   *bAttribute = true;
   if (resolveNodeRS.pScriptAttribute &&
       resolveNodeRS.pScriptAttribute->eValueType == XFA_ScriptType::Object) {
-    for (CXFA_Object* pObject : resolveNodeRS.objects) {
+    for (auto& pObject : resolveNodeRS.objects) {
       auto pValue = pdfium::MakeUnique<CFXJSE_Value>(pIsolate);
       CJX_Object* jsObject = pObject->JSObject();
       (jsObject->*(resolveNodeRS.pScriptAttribute->callback))(
diff --git a/fxjs/cfxjse_resolveprocessor.cpp b/fxjs/cfxjse_resolveprocessor.cpp
index 0419b79..917f78c 100644
--- a/fxjs/cfxjse_resolveprocessor.cpp
+++ b/fxjs/cfxjse_resolveprocessor.cpp
@@ -12,6 +12,7 @@
 
 #include "core/fxcrt/fx_extension.h"
 #include "fxjs/cfxjse_engine.h"
+#include "fxjs/cfxjse_value.h"
 #include "fxjs/xfa/cjx_object.h"
 #include "third_party/base/ptr_util.h"
 #include "third_party/base/stl_util.h"
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index fed9409..8876628 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -13,6 +13,7 @@
 #include "core/fxcrt/cfx_memorystream.h"
 #include "core/fxcrt/fx_codepage.h"
 #include "fxjs/cfxjse_engine.h"
+#include "fxjs/cfxjse_value.h"
 #include "fxjs/js_resources.h"
 #include "third_party/base/ptr_util.h"
 #include "xfa/fxfa/cxfa_eventparam.h"
diff --git a/fxjs/xfa/cjx_tree.cpp b/fxjs/xfa/cjx_tree.cpp
index 9787b9b..23f7658 100644
--- a/fxjs/xfa/cjx_tree.cpp
+++ b/fxjs/xfa/cjx_tree.cpp
@@ -55,7 +55,7 @@
   }
 
   if (resolveNodeRS.dwFlags == XFA_ResolveNode_RSType_Nodes) {
-    CXFA_Object* pObject = resolveNodeRS.objects.front();
+    CXFA_Object* pObject = resolveNodeRS.objects.front().Get();
     CFXJSE_Value* value =
         GetDocument()->GetScriptContext()->GetJSValueFromMap(pObject);
     if (!value)
@@ -66,7 +66,7 @@
   }
 
   const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
-      resolveNodeRS.pScriptAttribute;
+      resolveNodeRS.pScriptAttribute.Get();
   if (!lpAttributeInfo ||
       lpAttributeInfo->eValueType != XFA_ScriptType::Object) {
     return CJS_Result::Success(runtime->NewNull());
@@ -231,14 +231,14 @@
                                  &resolveNodeRS, dwFlag, nullptr);
   CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(GetDocument());
   if (resolveNodeRS.dwFlags == XFA_ResolveNode_RSType_Nodes) {
-    for (CXFA_Object* pObject : resolveNodeRS.objects) {
+    for (auto& pObject : resolveNodeRS.objects) {
       if (pObject->IsNode())
         pNodeList->Append(pObject->AsNode());
     }
   } else {
     if (resolveNodeRS.pScriptAttribute &&
         resolveNodeRS.pScriptAttribute->eValueType == XFA_ScriptType::Object) {
-      for (CXFA_Object* pObject : resolveNodeRS.objects) {
+      for (auto& pObject : resolveNodeRS.objects) {
         auto pValue =
             pdfium::MakeUnique<CFXJSE_Value>(pScriptContext->GetIsolate());
         CJX_Object* jsObject = pObject->JSObject();
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index 46b5710..affdca2 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -622,7 +622,7 @@
     WideString wsValue;
     WideString wsLabel;
     uint32_t uValueHash = FX_HashCode_GetW(wsValueRef.AsStringView(), false);
-    for (CXFA_Object* refObject : rs.objects) {
+    for (auto& refObject : rs.objects) {
       CXFA_Node* refNode = refObject->AsNode();
       if (!refNode)
         continue;
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index d42bfb5..72bba2a 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -360,7 +360,8 @@
   }
 
   if (rs.dwFlags == XFA_ResolveNode_RSType_CreateNodeOne) {
-    CXFA_Object* pObject = !rs.objects.empty() ? rs.objects.front() : nullptr;
+    CXFA_Object* pObject =
+        !rs.objects.empty() ? rs.objects.front().Get() : nullptr;
     CXFA_Node* pNode = ToNode(pObject);
     return (bForceBind || !pNode || !pNode->HasBindItem()) ? pNode : nullptr;
   }
@@ -1200,7 +1201,7 @@
           pDocument->GetScriptContext()->ResolveObjects(
               pDataScope, wsRef.AsStringView(), &rs, dFlags, pTemplateNode);
           CXFA_Object* pObject =
-              !rs.objects.empty() ? rs.objects.front() : nullptr;
+              !rs.objects.empty() ? rs.objects.front().Get() : nullptr;
           pDataNode = ToNode(pObject);
           if (pDataNode) {
             CreateDataBinding(pFormNode, pDataNode,
@@ -1618,8 +1619,8 @@
 }
 
 CXFA_Node* CXFA_Document::GetNotBindNode(
-    const std::vector<CXFA_Object*>& arrayObjects) const {
-  for (CXFA_Object* pObject : arrayObjects) {
+    const std::vector<UnownedPtr<CXFA_Object>>& arrayObjects) const {
+  for (auto& pObject : arrayObjects) {
     CXFA_Node* pNode = pObject->AsNode();
     if (pNode && !pNode->HasBindItem())
       return pNode;
diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h
index 5260b18..590a4cf 100644
--- a/xfa/fxfa/parser/cxfa_document.h
+++ b/xfa/fxfa/parser/cxfa_document.h
@@ -11,6 +11,7 @@
 #include <memory>
 #include <vector>
 
+#include "core/fxcrt/unowned_ptr.h"
 #include "xfa/fxfa/fxfa.h"
 #include "xfa/fxfa/parser/cxfa_localemgr.h"
 #include "xfa/fxfa/parser/cxfa_nodeowner.h"
@@ -65,7 +66,8 @@
   CXFA_LocaleMgr* GetLocaleMgr();
   CXFA_Object* GetXFAObject(XFA_HashCode wsNodeNameHash);
   CXFA_Node* GetNodeByID(CXFA_Node* pRoot, const WideStringView& wsID) const;
-  CXFA_Node* GetNotBindNode(const std::vector<CXFA_Object*>& arrayNodes) const;
+  CXFA_Node* GetNotBindNode(
+      const std::vector<UnownedPtr<CXFA_Object>>& arrayNodes) const;
   CXFA_LayoutProcessor* GetLayoutProcessor();
   CFXJSE_Engine* GetScriptContext() const;
 
diff --git a/xfa/fxfa/parser/xfa_resolvenode_rs.h b/xfa/fxfa/parser/xfa_resolvenode_rs.h
index 86960ab..7039c61 100644
--- a/xfa/fxfa/parser/xfa_resolvenode_rs.h
+++ b/xfa/fxfa/parser/xfa_resolvenode_rs.h
@@ -7,13 +7,10 @@
 #ifndef XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_
 #define XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_
 
-#include <memory>
-#include <utility>
 #include <vector>
 
-#include "fxjs/cfxjse_value.h"
-#include "third_party/base/ptr_util.h"
-#include "xfa/fxfa/fxfa.h"
+#include "core/fxcrt/unowned_ptr.h"
+#include "fxjs/xfa/cjx_object.h"
 #include "xfa/fxfa/parser/cxfa_object.h"
 
 #define XFA_RESOLVENODE_Children 0x0001
@@ -40,14 +37,13 @@
   XFA_RESOLVENODE_RS();
   ~XFA_RESOLVENODE_RS();
 
-  std::vector<CXFA_Object*> objects;  // Not owned.
-  XFA_ResolveNode_RSType dwFlags;
-  const XFA_SCRIPTATTRIBUTEINFO* pScriptAttribute;
+  XFA_ResolveNode_RSType dwFlags = XFA_ResolveNode_RSType_Nodes;
+  std::vector<UnownedPtr<CXFA_Object>> objects;
+  UnownedPtr<const XFA_SCRIPTATTRIBUTEINFO> pScriptAttribute;
 };
 
-inline XFA_RESOLVENODE_RS::XFA_RESOLVENODE_RS()
-    : dwFlags(XFA_ResolveNode_RSType_Nodes), pScriptAttribute(nullptr) {}
+inline XFA_RESOLVENODE_RS::XFA_RESOLVENODE_RS() = default;
 
-inline XFA_RESOLVENODE_RS::~XFA_RESOLVENODE_RS() {}
+inline XFA_RESOLVENODE_RS::~XFA_RESOLVENODE_RS() = default;
 
 #endif  // XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_