| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/xfa_script_imp.h" | 7 #include "xfa/fxfa/parser/xfa_script_imp.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fxfa/app/xfa_ffnotify.h" | 10 #include "xfa/fxfa/app/xfa_ffnotify.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 m_mapXFAToValue.GetNextAssoc(ps, pXFAObj, pValue); | 100 m_mapXFAToValue.GetNextAssoc(ps, pXFAObj, pValue); |
| 101 delete pValue; | 101 delete pValue; |
| 102 } | 102 } |
| 103 m_mapXFAToValue.RemoveAll(); | 103 m_mapXFAToValue.RemoveAll(); |
| 104 ReleaseVariablesMap(); | 104 ReleaseVariablesMap(); |
| 105 | 105 |
| 106 delete m_hFM2JSContext; | 106 delete m_hFM2JSContext; |
| 107 | 107 |
| 108 if (m_pJsContext) { | 108 if (m_pJsContext) { |
| 109 FXJSE_Context_Release(m_pJsContext); | 109 FXJSE_Context_Release(m_pJsContext); |
| 110 m_pJsContext = NULL; | 110 m_pJsContext = nullptr; |
| 111 } | 111 } |
| 112 delete m_pResolveProcessor; | 112 delete m_pResolveProcessor; |
| 113 m_upObjectArray.RemoveAll(); | 113 m_upObjectArray.RemoveAll(); |
| 114 for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) | 114 for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) |
| 115 delete m_CacheListArray[i]; | 115 delete m_CacheListArray[i]; |
| 116 } | 116 } |
| 117 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { | 117 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { |
| 118 m_pIsolate = pIsolate; | 118 m_pIsolate = pIsolate; |
| 119 DefineJsContext(); | 119 DefineJsContext(); |
| 120 DefineJsClass(); | 120 DefineJsClass(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 140 FXJSE_Value_SetUndefined(hRetValue); | 140 FXJSE_Value_SetUndefined(hRetValue); |
| 141 return FALSE; | 141 return FALSE; |
| 142 } | 142 } |
| 143 btScript = | 143 btScript = |
| 144 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); | 144 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); |
| 145 } else { | 145 } else { |
| 146 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); | 146 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); |
| 147 } | 147 } |
| 148 CXFA_Object* pOriginalObject = m_pThisObject; | 148 CXFA_Object* pOriginalObject = m_pThisObject; |
| 149 m_pThisObject = pThisObject; | 149 m_pThisObject = pThisObject; |
| 150 CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : NULL; | 150 CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : nullptr; |
| 151 FX_BOOL bRet = | 151 FX_BOOL bRet = |
| 152 FXJSE_ExecuteScript(m_pJsContext, btScript.c_str(), hRetValue, pValue); | 152 FXJSE_ExecuteScript(m_pJsContext, btScript.c_str(), hRetValue, pValue); |
| 153 m_pThisObject = pOriginalObject; | 153 m_pThisObject = pOriginalObject; |
| 154 m_eScriptType = eSaveType; | 154 m_eScriptType = eSaveType; |
| 155 return bRet; | 155 return bRet; |
| 156 } | 156 } |
| 157 void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject, | 157 void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject, |
| 158 const CFX_ByteStringC& szPropName, | 158 const CFX_ByteStringC& szPropName, |
| 159 CFXJSE_Value* pValue) { | 159 CFXJSE_Value* pValue) { |
| 160 CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr); | 160 CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 pObject->GetClassID(), wsPropName.AsStringC()); | 324 pObject->GetClassID(), wsPropName.AsStringC()); |
| 325 if (lpAttributeInfo) { | 325 if (lpAttributeInfo) { |
| 326 (pObject->*(lpAttributeInfo->lpfnCallback))( | 326 (pObject->*(lpAttributeInfo->lpfnCallback))( |
| 327 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 327 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
| 328 } else { | 328 } else { |
| 329 if (pObject->IsNode()) { | 329 if (pObject->IsNode()) { |
| 330 if (wsPropName.GetAt(0) == '#') { | 330 if (wsPropName.GetAt(0) == '#') { |
| 331 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); | 331 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); |
| 332 } | 332 } |
| 333 CXFA_Node* pNode = ToNode(pObject); | 333 CXFA_Node* pNode = ToNode(pObject); |
| 334 CXFA_Node* pPropOrChild = NULL; | 334 CXFA_Node* pPropOrChild = nullptr; |
| 335 const XFA_ELEMENTINFO* lpElementInfo = | 335 const XFA_ELEMENTINFO* lpElementInfo = |
| 336 XFA_GetElementByName(wsPropName.AsStringC()); | 336 XFA_GetElementByName(wsPropName.AsStringC()); |
| 337 if (lpElementInfo) { | 337 if (lpElementInfo) { |
| 338 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); | 338 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); |
| 339 } else { | 339 } else { |
| 340 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); | 340 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); |
| 341 } | 341 } |
| 342 if (pPropOrChild) { | 342 if (pPropOrChild) { |
| 343 CFX_WideString wsDefaultName(L"{default}"); | 343 CFX_WideString wsDefaultName(L"{default}"); |
| 344 const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = | 344 const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 m_upObjectArray.RemoveAll(); | 569 m_upObjectArray.RemoveAll(); |
| 570 } | 570 } |
| 571 if (refNode && refNode->IsNode() && | 571 if (refNode && refNode->IsNode() && |
| 572 (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { | 572 (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { |
| 573 m_upObjectArray.Add(refNode->AsNode()); | 573 m_upObjectArray.Add(refNode->AsNode()); |
| 574 } | 574 } |
| 575 FX_BOOL bNextCreate = FALSE; | 575 FX_BOOL bNextCreate = FALSE; |
| 576 if (dwStyles & XFA_RESOLVENODE_CreateNode) { | 576 if (dwStyles & XFA_RESOLVENODE_CreateNode) { |
| 577 m_pResolveProcessor->GetNodeHelper()->XFA_SetCreateNodeType(bindNode); | 577 m_pResolveProcessor->GetNodeHelper()->XFA_SetCreateNodeType(bindNode); |
| 578 } | 578 } |
| 579 m_pResolveProcessor->GetNodeHelper()->m_pCreateParent = NULL; | 579 m_pResolveProcessor->GetNodeHelper()->m_pCreateParent = nullptr; |
| 580 m_pResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1; | 580 m_pResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1; |
| 581 CXFA_ResolveNodesData rndFind; | 581 CXFA_ResolveNodesData rndFind; |
| 582 int32_t nStart = 0; | 582 int32_t nStart = 0; |
| 583 int32_t nLevel = 0; | 583 int32_t nLevel = 0; |
| 584 int32_t nRet = -1; | 584 int32_t nRet = -1; |
| 585 rndFind.m_pSC = this; | 585 rndFind.m_pSC = this; |
| 586 CXFA_ObjArray findNodes; | 586 CXFA_ObjArray findNodes; |
| 587 findNodes.Add(refNode ? refNode : m_pDocument->GetRoot()); | 587 findNodes.Add(refNode ? refNode : m_pDocument->GetRoot()); |
| 588 int32_t nNodes = 0; | 588 int32_t nNodes = 0; |
| 589 while (TRUE) { | 589 while (TRUE) { |
| 590 nNodes = findNodes.GetSize(); | 590 nNodes = findNodes.GetSize(); |
| 591 int32_t i = 0; | 591 int32_t i = 0; |
| 592 rndFind.m_dwStyles = dwStyles; | 592 rndFind.m_dwStyles = dwStyles; |
| 593 m_pResolveProcessor->m_iCurStart = nStart; | 593 m_pResolveProcessor->m_iCurStart = nStart; |
| 594 nStart = m_pResolveProcessor->XFA_ResolveNodes_GetFilter(wsExpression, | 594 nStart = m_pResolveProcessor->XFA_ResolveNodes_GetFilter(wsExpression, |
| 595 nStart, rndFind); | 595 nStart, rndFind); |
| 596 if (nStart < 1) { | 596 if (nStart < 1) { |
| 597 if ((dwStyles & XFA_RESOLVENODE_CreateNode) && !bNextCreate) { | 597 if ((dwStyles & XFA_RESOLVENODE_CreateNode) && !bNextCreate) { |
| 598 CXFA_Node* pDataNode = NULL; | 598 CXFA_Node* pDataNode = nullptr; |
| 599 nStart = m_pResolveProcessor->GetNodeHelper()->m_iCurAllStart; | 599 nStart = m_pResolveProcessor->GetNodeHelper()->m_iCurAllStart; |
| 600 if (nStart != -1) { | 600 if (nStart != -1) { |
| 601 pDataNode = m_pDocument->GetNotBindNode(findNodes); | 601 pDataNode = m_pDocument->GetNotBindNode(findNodes); |
| 602 if (pDataNode) { | 602 if (pDataNode) { |
| 603 findNodes.RemoveAll(); | 603 findNodes.RemoveAll(); |
| 604 findNodes.Add(pDataNode); | 604 findNodes.Add(pDataNode); |
| 605 break; | 605 break; |
| 606 } | 606 } |
| 607 } else { | 607 } else { |
| 608 pDataNode = findNodes[0]->AsNode(); | 608 pDataNode = findNodes[0]->AsNode(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 rndFind.m_Nodes.RemoveAll(); | 665 rndFind.m_Nodes.RemoveAll(); |
| 666 if (bDataBind) { | 666 if (bDataBind) { |
| 667 break; | 667 break; |
| 668 } | 668 } |
| 669 } | 669 } |
| 670 findNodes.RemoveAll(); | 670 findNodes.RemoveAll(); |
| 671 nNodes = retNodes.GetSize(); | 671 nNodes = retNodes.GetSize(); |
| 672 if (nNodes < 1) { | 672 if (nNodes < 1) { |
| 673 if (dwStyles & XFA_RESOLVENODE_CreateNode) { | 673 if (dwStyles & XFA_RESOLVENODE_CreateNode) { |
| 674 bNextCreate = TRUE; | 674 bNextCreate = TRUE; |
| 675 if (m_pResolveProcessor->GetNodeHelper()->m_pCreateParent == NULL) { | 675 if (!m_pResolveProcessor->GetNodeHelper()->m_pCreateParent) { |
| 676 m_pResolveProcessor->GetNodeHelper()->m_pCreateParent = | 676 m_pResolveProcessor->GetNodeHelper()->m_pCreateParent = |
| 677 ToNode(rndFind.m_CurNode); | 677 ToNode(rndFind.m_CurNode); |
| 678 m_pResolveProcessor->GetNodeHelper()->m_iCreateCount = 1; | 678 m_pResolveProcessor->GetNodeHelper()->m_iCreateCount = 1; |
| 679 } | 679 } |
| 680 FX_BOOL bCreate = | 680 FX_BOOL bCreate = |
| 681 m_pResolveProcessor->GetNodeHelper()->XFA_ResolveNodes_CreateNode( | 681 m_pResolveProcessor->GetNodeHelper()->XFA_ResolveNodes_CreateNode( |
| 682 rndFind.m_wsName, rndFind.m_wsCondition, | 682 rndFind.m_wsName, rndFind.m_wsCondition, |
| 683 nStart == wsExpression.GetLength(), this); | 683 nStart == wsExpression.GetLength(), this); |
| 684 if (bCreate) { | 684 if (bCreate) { |
| 685 continue; | 685 continue; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 } | 763 } |
| 764 } | 764 } |
| 765 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 765 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
| 766 if (!m_pScriptNodeArray) { | 766 if (!m_pScriptNodeArray) { |
| 767 return; | 767 return; |
| 768 } | 768 } |
| 769 if (m_pScriptNodeArray->Find(pNode) == -1) { | 769 if (m_pScriptNodeArray->Find(pNode) == -1) { |
| 770 m_pScriptNodeArray->Add(pNode); | 770 m_pScriptNodeArray->Add(pNode); |
| 771 } | 771 } |
| 772 } | 772 } |
| OLD | NEW |