diff options
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r-- | xfa/fxfa/parser/xfa_document_imp.cpp | 55 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_document_layout_imp.cpp | 25 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_locale.cpp | 11 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_parser_imp.cpp | 8 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_script_imp.cpp | 156 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_script_resolveprocessor.cpp | 11 |
6 files changed, 121 insertions, 145 deletions
diff --git a/xfa/fxfa/parser/xfa_document_imp.cpp b/xfa/fxfa/parser/xfa_document_imp.cpp index ad3fd70e0d..083fe24a7e 100644 --- a/xfa/fxfa/parser/xfa_document_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_imp.cpp @@ -45,44 +45,31 @@ CXFA_Document::~CXFA_Document() { delete m_pRootNode; PurgeNodes(); } + void CXFA_Document::ClearLayoutData() { - if (m_pLayoutProcessor) { - delete m_pLayoutProcessor; - m_pLayoutProcessor = NULL; - } + delete m_pLayoutProcessor; + m_pLayoutProcessor = nullptr; + if (m_pScriptContext) { m_pScriptContext->Release(); - m_pScriptContext = NULL; - } - if (m_pLocalMgr) { - delete m_pLocalMgr; - m_pLocalMgr = NULL; - } - if (m_pScriptDataWindow) { - delete m_pScriptDataWindow; - m_pScriptDataWindow = NULL; - } - if (m_pScriptEvent) { - delete m_pScriptEvent; - m_pScriptEvent = NULL; - } - if (m_pScriptHost) { - delete m_pScriptHost; - m_pScriptHost = NULL; - } - if (m_pScriptLog) { - delete m_pScriptLog; - m_pScriptLog = NULL; - } - if (m_pScriptLayout) { - delete m_pScriptLayout; - m_pScriptLayout = NULL; - } - if (m_pScriptSignature) { - delete m_pScriptSignature; - m_pScriptSignature = NULL; - } + m_pScriptContext = nullptr; + } + delete m_pLocalMgr; + m_pLocalMgr = nullptr; + delete m_pScriptDataWindow; + m_pScriptDataWindow = nullptr; + delete m_pScriptEvent; + m_pScriptEvent = nullptr; + delete m_pScriptHost; + m_pScriptHost = nullptr; + delete m_pScriptLog; + m_pScriptLog = nullptr; + delete m_pScriptLayout; + m_pScriptLayout = nullptr; + delete m_pScriptSignature; + m_pScriptSignature = nullptr; } + void CXFA_Document::SetRoot(CXFA_Node* pNewRoot) { if (m_pRootNode) { AddPurgeNode(m_pRootNode); diff --git a/xfa/fxfa/parser/xfa_document_layout_imp.cpp b/xfa/fxfa/parser/xfa_document_layout_imp.cpp index 9b9a879d4d..44d053b8c2 100644 --- a/xfa/fxfa/parser/xfa_document_layout_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_layout_imp.cpp @@ -42,14 +42,13 @@ CXFA_LayoutProcessor::~CXFA_LayoutProcessor() { CXFA_Document* CXFA_LayoutProcessor::GetDocument() const { return m_pDocument; } + int32_t CXFA_LayoutProcessor::StartLayout(FX_BOOL bForceRestart) { - if (!bForceRestart && !IsNeedLayout()) { + if (!bForceRestart && !IsNeedLayout()) return 100; - } - if (m_pRootItemLayoutProcessor) { - delete m_pRootItemLayoutProcessor; - m_pRootItemLayoutProcessor = NULL; - } + + delete m_pRootItemLayoutProcessor; + m_pRootItemLayoutProcessor = nullptr; m_nProgressCounter = 0; CXFA_Node* pFormPacketNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); @@ -147,17 +146,15 @@ void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) { CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const { return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetRootLayoutItem() : NULL; } + void CXFA_LayoutProcessor::ClearLayoutData() { - if (m_pLayoutPageMgr) { - delete m_pLayoutPageMgr; - m_pLayoutPageMgr = NULL; - } - if (m_pRootItemLayoutProcessor) { - delete m_pRootItemLayoutProcessor; - m_pRootItemLayoutProcessor = NULL; - } + delete m_pLayoutPageMgr; + m_pLayoutPageMgr = nullptr; + delete m_pRootItemLayoutProcessor; + m_pRootItemLayoutProcessor = nullptr; m_nProgressCounter = 0; } + FX_BOOL CXFA_LayoutProcessor::IsNeedLayout() { return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0; } diff --git a/xfa/fxfa/parser/xfa_locale.cpp b/xfa/fxfa/parser/xfa_locale.cpp index ee6d289a25..ff0371bc88 100644 --- a/xfa/fxfa/parser/xfa_locale.cpp +++ b/xfa/fxfa/parser/xfa_locale.cpp @@ -21,14 +21,13 @@ static const FX_WCHAR g_FX_Currency[] = L"$z,zzz,zzz,zzz,zzz,zz9.99"; static const FX_WCHAR g_FX_Decimal[] = L"z,zzz,zzz,zzz,zzz,zz9.zzz"; static const FX_WCHAR g_FX_Integer[] = L"z,zzz,zzz,zzz,zzz,zzz"; -CXFA_XMLLocale::CXFA_XMLLocale(CXML_Element* pLocaleData) { - m_pLocaleData = pLocaleData; -} +CXFA_XMLLocale::CXFA_XMLLocale(CXML_Element* pLocaleData) + : m_pLocaleData(pLocaleData) {} + CXFA_XMLLocale::~CXFA_XMLLocale() { - if (m_pLocaleData) { - delete m_pLocaleData; - } + delete m_pLocaleData; } + void CXFA_XMLLocale::Release() { delete this; } diff --git a/xfa/fxfa/parser/xfa_parser_imp.cpp b/xfa/fxfa/parser/xfa_parser_imp.cpp index 7eef2bd403..23a8dbc925 100644 --- a/xfa/fxfa/parser/xfa_parser_imp.cpp +++ b/xfa/fxfa/parser/xfa_parser_imp.cpp @@ -1390,13 +1390,13 @@ void CXFA_DocumentParser::ConstructXFANode(CXFA_Node* pXFANode, m_pDocument->SetRoot(pRootNode); } } + void CXFA_DocumentParser::CloseParser() { - if (m_pDocument) { - delete m_pDocument; - m_pDocument = NULL; - } + delete m_pDocument; + m_pDocument = nullptr; m_nodeParser.CloseParser(); } + CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) : m_nElementStart(0), m_dwCheckStatus(0), diff --git a/xfa/fxfa/parser/xfa_script_imp.cpp b/xfa/fxfa/parser/xfa_script_imp.cpp index ea16fd1e7c..1cd5689045 100644 --- a/xfa/fxfa/parser/xfa_script_imp.cpp +++ b/xfa/fxfa/parser/xfa_script_imp.cpp @@ -53,10 +53,7 @@ CXFA_ScriptContext::~CXFA_ScriptContext() { FXJSE_Context_Release(m_hJsContext); m_hJsContext = NULL; } - if (m_pResolveProcessor) { - delete m_pResolveProcessor; - m_pResolveProcessor = NULL; - } + delete m_pResolveProcessor; m_upObjectArray.RemoveAll(); for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) delete m_CacheListArray[i]; @@ -398,29 +395,29 @@ void CXFA_ScriptContext::DefineJsContext() { FXJSE_HCONTEXT CXFA_ScriptContext::CreateVariablesContext( CXFA_Node* pScriptNode, CXFA_Node* pSubform) { - if (pScriptNode == NULL || pSubform == NULL) { - return NULL; - } + if (!pScriptNode || !pSubform) + return nullptr; + if (m_mapVariableToHValue.GetCount() == 0) { - m_JsGlobalVariablesClass.constructor = NULL; + m_JsGlobalVariablesClass.constructor = nullptr; m_JsGlobalVariablesClass.name = "XFAScriptObject"; m_JsGlobalVariablesClass.propNum = 0; - m_JsGlobalVariablesClass.properties = NULL; + m_JsGlobalVariablesClass.properties = nullptr; m_JsGlobalVariablesClass.methNum = 0; - m_JsGlobalVariablesClass.methods = NULL; + m_JsGlobalVariablesClass.methods = nullptr; m_JsGlobalVariablesClass.dynPropGetter = CXFA_ScriptContext::GlobalPropertyGetter; m_JsGlobalVariablesClass.dynPropSetter = CXFA_ScriptContext::GlobalPropertySetter; m_JsGlobalVariablesClass.dynPropTypeGetter = CXFA_ScriptContext::NormalPropTypeGetter; - m_JsGlobalVariablesClass.dynPropDeleter = NULL; + m_JsGlobalVariablesClass.dynPropDeleter = nullptr; m_JsGlobalVariablesClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; } - CXFA_ThisProxy* lpVariableNode = new CXFA_ThisProxy(pSubform, pScriptNode); - FXJSE_HCONTEXT hVariablesContext = FXJSE_Context_Create( - m_hJsRuntime, &m_JsGlobalVariablesClass, (CXFA_Object*)lpVariableNode); + FXJSE_HCONTEXT hVariablesContext = + FXJSE_Context_Create(m_hJsRuntime, &m_JsGlobalVariablesClass, + new CXFA_ThisProxy(pSubform, pScriptNode)); RemoveBuiltInObjs(hVariablesContext); FXJSE_Context_EnableCompatibleMode( hVariablesContext, FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS); @@ -435,97 +432,96 @@ CXFA_Object* CXFA_ScriptContext::GetVariablesThis(CXFA_Object* pObject, } return pObject; } + FX_BOOL CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { - if (pScriptNode == NULL) { + if (!pScriptNode) return FALSE; - } - if (pScriptNode->GetClassID() == XFA_ELEMENT_Script) { - CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); - if (!pParent || pParent->GetClassID() != XFA_ELEMENT_Variables) { - return FALSE; - } - if (m_mapVariableToHValue.GetValueAt(pScriptNode)) { - return TRUE; - } - CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); - if (!pTextNode) { - return FALSE; - } - CFX_WideStringC wsScript; - if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) { - return FALSE; - } - CFX_ByteString btScript = - FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); - FXJSE_HVALUE hRetValue = FXJSE_Value_Create(m_hJsRuntime); - CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); - FXJSE_HCONTEXT hVariablesContext = - CreateVariablesContext(pScriptNode, pThisObject); - CXFA_Object* pOriginalObject = m_pThisObject; - m_pThisObject = pThisObject; - FX_BOOL bRet = - FXJSE_ExecuteScript(hVariablesContext, btScript.c_str(), hRetValue); - m_pThisObject = pOriginalObject; - FXJSE_Value_Release(hRetValue); - return bRet; - } - return TRUE; + + if (pScriptNode->GetClassID() != XFA_ELEMENT_Script) + return TRUE; + + CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); + if (!pParent || pParent->GetClassID() != XFA_ELEMENT_Variables) + return FALSE; + + if (m_mapVariableToHValue.GetValueAt(pScriptNode)) + return TRUE; + + CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); + if (!pTextNode) + return FALSE; + + CFX_WideStringC wsScript; + if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) + return FALSE; + + CFX_ByteString btScript = + FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); + FXJSE_HVALUE hRetValue = FXJSE_Value_Create(m_hJsRuntime); + CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); + FXJSE_HCONTEXT hVariablesContext = + CreateVariablesContext(pScriptNode, pThisObject); + CXFA_Object* pOriginalObject = m_pThisObject; + m_pThisObject = pThisObject; + FX_BOOL bRet = + FXJSE_ExecuteScript(hVariablesContext, btScript.c_str(), hRetValue); + m_pThisObject = pOriginalObject; + FXJSE_Value_Release(hRetValue); + return bRet; } + FX_BOOL CXFA_ScriptContext::QueryVariableHValue( CXFA_Node* pScriptNode, const CFX_ByteStringC& szPropName, FXJSE_HVALUE hValue, FX_BOOL bGetter) { - if (!pScriptNode || pScriptNode->GetClassID() != XFA_ELEMENT_Script) { + if (!pScriptNode || pScriptNode->GetClassID() != XFA_ELEMENT_Script) return FALSE; - } + CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); - if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables) { + if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables) return FALSE; - } - FX_BOOL bRes = FALSE; + void* lpVariables = m_mapVariableToHValue.GetValueAt(pScriptNode); - if (lpVariables) { - FXJSE_HCONTEXT hVariableContext = (FXJSE_HCONTEXT)lpVariables; - FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(hVariableContext); - FXJSE_HVALUE hVariableValue = FXJSE_Value_Create(m_hJsRuntime); - if (!bGetter) { - FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); - bRes = TRUE; - } else if (FXJSE_Value_ObjectHasOwnProp(hObject, szPropName, FALSE)) { - FXJSE_Value_GetObjectProp(hObject, szPropName, hVariableValue); - if (FXJSE_Value_IsFunction(hVariableValue)) { - FXJSE_Value_SetFunctionBind(hValue, hVariableValue, hObject); - } else if (bGetter) { - FXJSE_Value_Set(hValue, hVariableValue); - } else { - FXJSE_Value_Set(hVariableValue, hValue); - } - bRes = TRUE; - } - FXJSE_Value_Release(hVariableValue); - FXJSE_Value_Release(hObject); - } + if (!lpVariables) + return FALSE; + + FX_BOOL bRes = FALSE; + FXJSE_HCONTEXT hVariableContext = (FXJSE_HCONTEXT)lpVariables; + FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(hVariableContext); + FXJSE_HVALUE hVariableValue = FXJSE_Value_Create(m_hJsRuntime); + if (!bGetter) { + FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); + bRes = TRUE; + } else if (FXJSE_Value_ObjectHasOwnProp(hObject, szPropName, FALSE)) { + FXJSE_Value_GetObjectProp(hObject, szPropName, hVariableValue); + if (FXJSE_Value_IsFunction(hVariableValue)) + FXJSE_Value_SetFunctionBind(hValue, hVariableValue, hObject); + else if (bGetter) + FXJSE_Value_Set(hValue, hVariableValue); + else + FXJSE_Value_Set(hVariableValue, hValue); + bRes = TRUE; + } + FXJSE_Value_Release(hVariableValue); + FXJSE_Value_Release(hObject); return bRes; } + void CXFA_ScriptContext::ReleaseVariablesMap() { FX_POSITION ps = m_mapVariableToHValue.GetStartPosition(); while (ps) { CXFA_Object* pScriptNode; - FXJSE_HCONTEXT hVariableContext; + FXJSE_HCONTEXT hVariableContext = nullptr; m_mapVariableToHValue.GetNextAssoc(ps, pScriptNode, hVariableContext); FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(hVariableContext); - CXFA_Object* lpCurNode = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); - if (lpCurNode) { - delete (CXFA_ThisProxy*)lpCurNode; - lpCurNode = NULL; - } + delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(hObject, nullptr)); FXJSE_Value_Release(hObject); FXJSE_Context_Release(hVariableContext); - hVariableContext = NULL; } m_mapVariableToHValue.RemoveAll(); } + void CXFA_ScriptContext::DefineJsClass() { m_JsNormalClass.constructor = NULL; m_JsNormalClass.name = "XFAObject"; diff --git a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp b/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp index 6ea1a331c1..fa21a50b3e 100644 --- a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp +++ b/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp @@ -19,15 +19,12 @@ #include "xfa/fxfa/parser/xfa_utils.h" CXFA_ResolveProcessor::CXFA_ResolveProcessor(void) - : m_pNodeHelper(NULL), m_iCurStart(0) { - m_pNodeHelper = new CXFA_NodeHelper; -} + : m_pNodeHelper(new CXFA_NodeHelper), m_iCurStart(0) {} + CXFA_ResolveProcessor::~CXFA_ResolveProcessor(void) { - if (m_pNodeHelper) { - delete m_pNodeHelper; - m_pNodeHelper = NULL; - } + delete m_pNodeHelper; } + int32_t CXFA_ResolveProcessor::XFA_ResolveNodes(CXFA_ResolveNodesData& rnd) { if (rnd.m_CurNode == NULL) { return -1; |