Use vector of cppgc::Member in XFA_ResolveNodeRS.
Make XFA_ResolveNodeRS a stack-only object, and consequently its
members (little m) will be stack-allocated. This includes a vector
of UnownedPtr to the GC'd CXFA_Object, which should be Member (big M)
for future correctness when cppgc-approved containers become available.
-- Pass span by value rather than vector by const-ref, assuming that
future types will convert to span the same way as std::vector.
Bug: pdfium:1563
Change-Id: Ibcd5d158789999772a0023bc4884ca0be6a58850
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/74270
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/xfa/cfxjse_engine.cpp b/fxjs/xfa/cfxjse_engine.cpp
index 284b940..bd6f912 100644
--- a/fxjs/xfa/cfxjse_engine.cpp
+++ b/fxjs/xfa/cfxjse_engine.cpp
@@ -628,7 +628,7 @@
int32_t nStart = 0;
int32_t nLevel = 0;
- std::vector<UnownedPtr<CXFA_Object>> findObjects;
+ std::vector<cppgc::Member<CXFA_Object>> findObjects;
findObjects.emplace_back(refObject ? refObject : m_pDocument->GetRoot());
int32_t nNodes = 0;
while (true) {
@@ -670,7 +670,7 @@
}
break;
}
- std::vector<UnownedPtr<CXFA_Object>> retObjects;
+ std::vector<cppgc::Member<CXFA_Object>> retObjects;
while (i < nNodes) {
bool bDataBind = false;
if (((dwStyles & XFA_RESOLVENODE_Bind) ||
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index 5bb1cf5..c41fc42 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -1628,7 +1628,7 @@
}
CXFA_Node* CXFA_Document::GetNotBindNode(
- const std::vector<UnownedPtr<CXFA_Object>>& arrayObjects) const {
+ pdfium::span<cppgc::Member<CXFA_Object>> arrayObjects) const {
for (auto& pObject : arrayObjects) {
CXFA_Node* pNode = pObject->AsNode();
if (pNode && !pNode->HasBindItem())
diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h
index c6e6b2d..ca8d8fc 100644
--- a/xfa/fxfa/parser/cxfa_document.h
+++ b/xfa/fxfa/parser/cxfa_document.h
@@ -14,6 +14,7 @@
#include "core/fxcrt/unowned_ptr.h"
#include "fxjs/gc/heap.h"
#include "third_party/base/optional.h"
+#include "third_party/base/span.h"
#include "v8/include/cppgc/garbage-collected.h"
#include "v8/include/cppgc/member.h"
#include "v8/include/cppgc/persistent.h"
@@ -96,7 +97,7 @@
CXFA_Object* GetXFAObject(XFA_HashCode wsNodeNameHash);
CXFA_Node* GetNodeByID(CXFA_Node* pRoot, WideStringView wsID) const;
CXFA_Node* GetNotBindNode(
- const std::vector<UnownedPtr<CXFA_Object>>& arrayNodes) const;
+ pdfium::span<cppgc::Member<CXFA_Object>> arrayNodes) const;
LayoutProcessorIface* GetLayoutProcessor() const {
return m_pLayoutProcessor;
diff --git a/xfa/fxfa/parser/xfa_resolvenode_rs.h b/xfa/fxfa/parser/xfa_resolvenode_rs.h
index a7a3200..851c94b 100644
--- a/xfa/fxfa/parser/xfa_resolvenode_rs.h
+++ b/xfa/fxfa/parser/xfa_resolvenode_rs.h
@@ -9,12 +9,15 @@
#include <vector>
-#include "core/fxcrt/unowned_ptr.h"
+#include "v8/include/cppgc/macros.h"
+#include "v8/include/cppgc/member.h"
#include "xfa/fxfa/parser/xfa_basic_data.h"
class CXFA_Object;
class XFA_ResolveNodeRS {
+ CPPGC_STACK_ALLOCATED(); // Allow raw/unowned pointers.
+
public:
enum class Type {
kNodes,
@@ -30,7 +33,10 @@
Type dwFlags = Type::kNodes;
XFA_SCRIPTATTRIBUTEINFO script_attribute;
- std::vector<UnownedPtr<CXFA_Object>> objects;
+
+ // Vector of Member would be correct for stack-based vectors, if
+ // STL worked with cppgc.
+ std::vector<cppgc::Member<CXFA_Object>> objects;
};
#endif // XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_