summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_scriptcontext.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-14 12:13:22 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-14 19:59:49 +0000
commitf8a943908a414836271a1b7d7e4a97635d941b7f (patch)
tree7f900d57e21c72a67a0347e4f25d0784bdad7c83 /xfa/fxfa/parser/cxfa_scriptcontext.cpp
parent05df075154a832fcb476e1dfcfb865722d0ea898 (diff)
downloadpdfium-f8a943908a414836271a1b7d7e4a97635d941b7f.tar.xz
Replace CXFA_{Object,Node}Array with std::vector
These two ought to happen at the same time as they are intertwined in spots. Remove blatant casts between the two along the way. Change-Id: I9ce5d2faadf1e38aba7cade316560d24a66d8669 Reviewed-on: https://pdfium-review.googlesource.com/2933 Commit-Queue: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_scriptcontext.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_scriptcontext.cpp119
1 files changed, 59 insertions, 60 deletions
diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
index 584cd76bed..03fd128332 100644
--- a/xfa/fxfa/parser/cxfa_scriptcontext.cpp
+++ b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
@@ -13,6 +13,7 @@
#include "fxjs/cfxjse_class.h"
#include "fxjs/cfxjse_value.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
#include "xfa/fxfa/app/xfa_ffnotify.h"
#include "xfa/fxfa/cxfa_eventparam.h"
#include "xfa/fxfa/parser/cxfa_document.h"
@@ -131,7 +132,6 @@ CXFA_ScriptContext::~CXFA_ScriptContext() {
delete pVariableContext;
}
m_mapVariableToContext.clear();
- m_upObjectArray.RemoveAll();
}
void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) {
@@ -146,7 +146,7 @@ bool CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType,
CFXJSE_Value* hRetValue,
CXFA_Object* pThisObject) {
CFX_ByteString btScript;
- XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType;
+ CFX_AutoRestorer<XFA_SCRIPTLANGTYPE> typeRestorer(&m_eScriptType);
m_eScriptType = eScriptType;
if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) {
if (!m_FM2JSContext) {
@@ -165,14 +165,12 @@ bool CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType,
} else {
btScript = FX_UTF8Encode(wsScript);
}
- CXFA_Object* pOriginalObject = m_pThisObject;
+ CFX_AutoRestorer<CXFA_Object*> nodeRestorer(&m_pThisObject);
m_pThisObject = pThisObject;
CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : nullptr;
- bool bRet = m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue);
- m_pThisObject = pOriginalObject;
- m_eScriptType = eSaveType;
- return bRet;
+ return m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue);
}
+
void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject,
const CFX_ByteStringC& szPropName,
CFXJSE_Value* pValue) {
@@ -215,13 +213,13 @@ bool CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode,
if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0)
return false;
if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
- pValue->Assign(GetJSValueFromMap(resolveRs.nodes[0]));
+ pValue->Assign(GetJSValueFromMap(resolveRs.objects.front()));
return true;
}
if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) {
const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute;
if (lpAttributeInfo) {
- (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
+ (resolveRs.objects.front()->*(lpAttributeInfo->lpfnCallback))(
pValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
}
}
@@ -495,12 +493,9 @@ bool CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) {
CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent);
CFXJSE_Context* pVariablesContext =
CreateVariablesContext(pScriptNode, pThisObject);
- CXFA_Object* pOriginalObject = m_pThisObject;
+ CFX_AutoRestorer<CXFA_Object*> nodeRestorer(&m_pThisObject);
m_pThisObject = pThisObject;
- bool bRet =
- pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get());
- m_pThisObject = pOriginalObject;
- return bRet;
+ return pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get());
}
bool CXFA_ScriptContext::QueryVariableValue(CXFA_Node* pScriptNode,
@@ -556,38 +551,41 @@ void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const {
CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() {
return m_pJsClass;
}
-int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
+
+int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refObject,
const CFX_WideStringC& wsExpression,
XFA_RESOLVENODE_RS& resolveNodeRS,
uint32_t dwStyles,
CXFA_Node* bindNode) {
- if (wsExpression.IsEmpty()) {
+ if (wsExpression.IsEmpty())
return 0;
- }
+
if (m_eScriptType != XFA_SCRIPTLANGTYPE_Formcalc ||
(dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) {
- m_upObjectArray.RemoveAll();
+ m_upObjectArray.clear();
}
- if (refNode && refNode->IsNode() &&
+ if (refObject && refObject->IsNode() &&
(dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) {
- m_upObjectArray.Add(refNode->AsNode());
+ m_upObjectArray.push_back(refObject->AsNode());
}
+
bool bNextCreate = false;
if (dwStyles & XFA_RESOLVENODE_CreateNode) {
m_ResolveProcessor->GetNodeHelper()->SetCreateNodeType(bindNode);
}
m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = nullptr;
m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1;
+
CXFA_ResolveNodesData rndFind;
int32_t nStart = 0;
int32_t nLevel = 0;
int32_t nRet = -1;
rndFind.m_pSC = this;
- CXFA_ObjArray findNodes;
- findNodes.Add(refNode ? refNode : m_pDocument->GetRoot());
+ std::vector<CXFA_Object*> findObjects;
+ findObjects.push_back(refObject ? refObject : m_pDocument->GetRoot());
int32_t nNodes = 0;
while (true) {
- nNodes = findNodes.GetSize();
+ nNodes = pdfium::CollectionSize<int32_t>(findObjects);
int32_t i = 0;
rndFind.m_dwStyles = dwStyles;
m_ResolveProcessor->SetCurStart(nStart);
@@ -597,21 +595,22 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
CXFA_Node* pDataNode = nullptr;
nStart = m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart;
if (nStart != -1) {
- pDataNode = m_pDocument->GetNotBindNode(findNodes);
+ pDataNode = m_pDocument->GetNotBindNode(findObjects);
if (pDataNode) {
- findNodes.RemoveAll();
- findNodes.Add(pDataNode);
+ findObjects.clear();
+ findObjects.push_back(pDataNode);
break;
}
} else {
- pDataNode = findNodes[0]->AsNode();
- findNodes.RemoveAll();
- findNodes.Add(pDataNode);
+ pDataNode = findObjects.front()->AsNode();
+ findObjects.clear();
+ findObjects.push_back(pDataNode);
break;
}
dwStyles |= XFA_RESOLVENODE_Bind;
- findNodes.RemoveAll();
- findNodes.Add(m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent);
+ findObjects.clear();
+ findObjects.push_back(
+ m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent);
continue;
} else {
break;
@@ -628,7 +627,7 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
break;
}
}
- CXFA_ObjArray retNodes;
+ std::vector<CXFA_Object*> retObjects;
while (i < nNodes) {
bool bDataBind = false;
if (((dwStyles & XFA_RESOLVENODE_Bind) ||
@@ -639,7 +638,7 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
m_ResolveProcessor->SetIndexDataBind(rndBind.m_wsCondition, i, nNodes);
bDataBind = true;
}
- rndFind.m_CurNode = findNodes[i++];
+ rndFind.m_CurObject = findObjects[i++];
rndFind.m_nLevel = nLevel;
rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes;
nRet = m_ResolveProcessor->Resolve(rndFind);
@@ -649,29 +648,28 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute &&
rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) {
std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(m_pIsolate));
- (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))(
+ (rndFind.m_Objects.front()
+ ->*(rndFind.m_pScriptAttribute->lpfnCallback))(
pValue.get(), false,
(XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute);
- rndFind.m_Nodes.SetAt(0, ToObject(pValue.get(), nullptr));
+ rndFind.m_Objects.front() = ToObject(pValue.get(), nullptr);
}
- int32_t iSize = m_upObjectArray.GetSize();
- if (iSize) {
- m_upObjectArray.RemoveAt(iSize - 1);
- }
- retNodes.Append(rndFind.m_Nodes);
- rndFind.m_Nodes.RemoveAll();
- if (bDataBind) {
+ if (!m_upObjectArray.empty())
+ m_upObjectArray.pop_back();
+ retObjects.insert(retObjects.end(), rndFind.m_Objects.begin(),
+ rndFind.m_Objects.end());
+ rndFind.m_Objects.clear();
+ if (bDataBind)
break;
- }
}
- findNodes.RemoveAll();
- nNodes = retNodes.GetSize();
+ findObjects.clear();
+ nNodes = pdfium::CollectionSize<int32_t>(retObjects);
if (nNodes < 1) {
if (dwStyles & XFA_RESOLVENODE_CreateNode) {
bNextCreate = true;
if (!m_ResolveProcessor->GetNodeHelper()->m_pCreateParent) {
m_ResolveProcessor->GetNodeHelper()->m_pCreateParent =
- ToNode(rndFind.m_CurNode);
+ ToNode(rndFind.m_CurObject);
m_ResolveProcessor->GetNodeHelper()->m_iCreateCount = 1;
}
bool bCreate =
@@ -687,8 +685,9 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
break;
}
}
- findNodes.Copy(retNodes);
- rndFind.m_Nodes.RemoveAll();
+ findObjects =
+ std::vector<CXFA_Object*>(retObjects.begin(), retObjects.end());
+ rndFind.m_Objects.clear();
if (nLevel == 0) {
dwStyles &= ~(XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings);
}
@@ -697,7 +696,8 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
if (!bNextCreate) {
resolveNodeRS.dwFlags = rndFind.m_dwFlag;
if (nNodes > 0) {
- resolveNodeRS.nodes.Append(findNodes);
+ resolveNodeRS.objects.insert(resolveNodeRS.objects.end(),
+ findObjects.begin(), findObjects.end());
}
if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute) {
resolveNodeRS.pScriptAttribute = rndFind.m_pScriptAttribute;
@@ -711,7 +711,7 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode,
if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) {
resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes;
}
- return resolveNodeRS.nodes.GetSize();
+ return pdfium::CollectionSize<int32_t>(resolveNodeRS.objects);
}
return nNodes;
}
@@ -752,18 +752,17 @@ void CXFA_ScriptContext::GetSomExpression(CXFA_Node* refNode,
lpNodeHelper->GetNameExpression(refNode, wsExpression, true,
XFA_LOGIC_Transparent);
}
-void CXFA_ScriptContext::SetNodesOfRunScript(CXFA_NodeArray* pArray) {
+void CXFA_ScriptContext::SetNodesOfRunScript(std::vector<CXFA_Node*>* pArray) {
m_pScriptNodeArray = pArray;
}
-void CXFA_ScriptContext::AddNodesOfRunScript(const CXFA_NodeArray& nodes) {
- if (!m_pScriptNodeArray)
- return;
- if (nodes.GetSize() > 0)
- m_pScriptNodeArray->Copy(nodes);
+
+void CXFA_ScriptContext::AddNodesOfRunScript(
+ const std::vector<CXFA_Node*>& nodes) {
+ if (m_pScriptNodeArray && !nodes.empty())
+ *m_pScriptNodeArray = nodes;
}
+
void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) {
- if (!m_pScriptNodeArray)
- return;
- if (m_pScriptNodeArray->Find(pNode) == -1)
- m_pScriptNodeArray->Add(pNode);
+ if (m_pScriptNodeArray && !pdfium::ContainsValue(*m_pScriptNodeArray, pNode))
+ m_pScriptNodeArray->push_back(pNode);
}