From 369fe1f7f9f3a424ee3cf8f992c3128db27fa479 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 27 Mar 2017 16:03:43 -0700 Subject: Remove CFX_ArrayTemplate in CXFA_ValueArray Change-Id: I68f317b9fb9b162a5d99cdacc619c85f96a5bf52 Reviewed-on: https://pdfium-review.googlesource.com/3239 Commit-Queue: dsinclair Reviewed-by: dsinclair --- xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 4 ++-- xfa/fxfa/parser/cxfa_node.cpp | 2 +- xfa/fxfa/parser/cxfa_valuearray.cpp | 18 +++++++++--------- xfa/fxfa/parser/cxfa_valuearray.h | 4 +++- xfa/fxfa/parser/xfa_resolvenode_rs.h | 12 +++++++----- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index e951716802..8a42c2619c 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -6169,13 +6169,13 @@ void CXFA_FM2JSContext::ParseResolveResult( } CXFA_ValueArray objectProperties(pIsolate); - int32_t iRet = resoveNodeRS.GetAttributeResult(objectProperties); + int32_t iRet = resoveNodeRS.GetAttributeResult(&objectProperties); *bAttribute = true; if (iRet != 0) { *bAttribute = false; for (int32_t i = 0; i < iRet; i++) { resultValues->push_back(pdfium::MakeUnique(pIsolate)); - resultValues->back()->Assign(objectProperties[i]); + resultValues->back()->Assign(objectProperties.m_Values[i].get()); } return; } diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 645f907525..509decd037 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -1055,7 +1055,7 @@ void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue, } } else { CXFA_ValueArray valueArray(pScriptContext->GetRuntime()); - if (resoveNodeRS.GetAttributeResult(valueArray) > 0) { + if (resoveNodeRS.GetAttributeResult(&valueArray) > 0) { for (CXFA_Object* pObject : valueArray.GetAttributeObject()) { if (pObject->IsNode()) pNodeList->Append(pObject->AsNode()); diff --git a/xfa/fxfa/parser/cxfa_valuearray.cpp b/xfa/fxfa/parser/cxfa_valuearray.cpp index 1170010139..eded624c36 100644 --- a/xfa/fxfa/parser/cxfa_valuearray.cpp +++ b/xfa/fxfa/parser/cxfa_valuearray.cpp @@ -6,20 +6,20 @@ #include "xfa/fxfa/parser/cxfa_valuearray.h" +#include + #include "xfa/fxfa/parser/cxfa_scriptcontext.h" CXFA_ValueArray::CXFA_ValueArray(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} -CXFA_ValueArray::~CXFA_ValueArray() { - for (int32_t i = 0; i < GetSize(); i++) - delete GetAt(i); -} +CXFA_ValueArray::~CXFA_ValueArray() {} std::vector CXFA_ValueArray::GetAttributeObject() { - std::vector objArray; - for (int32_t i = 0; i < GetSize(); i++) - objArray.push_back(CXFA_ScriptContext::ToObject(GetAt(i), nullptr)); - - return objArray; + std::vector result(m_Values.size()); + std::transform(m_Values.begin(), m_Values.end(), result.begin(), + [](const std::unique_ptr& value) { + return CXFA_ScriptContext::ToObject(value.get(), nullptr); + }); + return result; } diff --git a/xfa/fxfa/parser/cxfa_valuearray.h b/xfa/fxfa/parser/cxfa_valuearray.h index 48efae4774..f0c5d234c9 100644 --- a/xfa/fxfa/parser/cxfa_valuearray.h +++ b/xfa/fxfa/parser/cxfa_valuearray.h @@ -7,12 +7,13 @@ #ifndef XFA_FXFA_PARSER_CXFA_VALUEARRAY_H_ #define XFA_FXFA_PARSER_CXFA_VALUEARRAY_H_ +#include #include #include "fxjs/cfxjse_value.h" #include "xfa/fxfa/fxfa.h" -class CXFA_ValueArray : public CFX_ArrayTemplate { +class CXFA_ValueArray { public: explicit CXFA_ValueArray(v8::Isolate* pIsolate); ~CXFA_ValueArray(); @@ -20,6 +21,7 @@ class CXFA_ValueArray : public CFX_ArrayTemplate { std::vector GetAttributeObject(); v8::Isolate* const m_pIsolate; + std::vector> m_Values; }; #endif // XFA_FXFA_PARSER_CXFA_VALUEARRAY_H_ diff --git a/xfa/fxfa/parser/xfa_resolvenode_rs.h b/xfa/fxfa/parser/xfa_resolvenode_rs.h index a60ef9a3c6..a30d540ef0 100644 --- a/xfa/fxfa/parser/xfa_resolvenode_rs.h +++ b/xfa/fxfa/parser/xfa_resolvenode_rs.h @@ -8,6 +8,7 @@ #define XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_ #include +#include #include #include "fxjs/cfxjse_value.h" @@ -45,16 +46,17 @@ struct XFA_RESOLVENODE_RS { XFA_RESOLVENODE_RS(); ~XFA_RESOLVENODE_RS(); - int32_t GetAttributeResult(CXFA_ValueArray& valueArray) const { + size_t GetAttributeResult(CXFA_ValueArray* valueArray) const { if (pScriptAttribute && pScriptAttribute->eValueType == XFA_SCRIPT_Object) { for (CXFA_Object* pObject : objects) { - auto pValue = pdfium::MakeUnique(valueArray.m_pIsolate); + auto pValue = pdfium::MakeUnique(valueArray->m_pIsolate); (pObject->*(pScriptAttribute->lpfnCallback))( - pValue.get(), false, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute); - valueArray.Add(pValue.release()); + pValue.get(), false, + static_cast(pScriptAttribute->eAttribute)); + valueArray->m_Values.push_back(std::move(pValue)); } } - return valueArray.GetSize(); + return valueArray->m_Values.size(); } std::vector objects; // Not owned. -- cgit v1.2.3