diff options
author | dsinclair <dsinclair@chromium.org> | 2016-05-31 11:34:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-31 11:34:04 -0700 |
commit | 86fad999ba59b1f8780582cc683b008880aab42e (patch) | |
tree | bc63f57e472a4aca6c2316eea4707d0aa415c122 /xfa/fxfa/parser | |
parent | 4dce6d4689d464c3a8825a5d6aa790adfc9228ee (diff) | |
download | pdfium-86fad999ba59b1f8780582cc683b008880aab42e.tar.xz |
Replace CFXJSE_Value create/destroy with new and delete.
In most cases, the destroy calls were removed and the object wrapped in a
unique_ptr.
Review-Url: https://codereview.chromium.org/2014323003
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r-- | xfa/fxfa/parser/xfa_object_imp.cpp | 13 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_script.h | 9 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp | 64 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_script_imp.cpp | 55 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_script_resolveprocessor.cpp | 11 |
5 files changed, 70 insertions, 82 deletions
diff --git a/xfa/fxfa/parser/xfa_object_imp.cpp b/xfa/fxfa/parser/xfa_object_imp.cpp index 53c8847be8..0b1209734f 100644 --- a/xfa/fxfa/parser/xfa_object_imp.cpp +++ b/xfa/fxfa/parser/xfa_object_imp.cpp @@ -654,20 +654,19 @@ void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { if (iRet < 1) { return FXJSE_Value_SetNull(pArguments->GetReturnValue()); } - CFXJSE_Value* pValue = nullptr; if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { CXFA_Object* pNode = resoveNodeRS.nodes[0]; - pValue = pScriptContext->GetJSValueFromMap(pNode); - FXJSE_Value_Set(pArguments->GetReturnValue(), pValue); + FXJSE_Value_Set(pArguments->GetReturnValue(), + pScriptContext->GetJSValueFromMap(pNode)); } else { const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resoveNodeRS.pScriptAttribute; if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) { - pValue = FXJSE_Value_Create(pScriptContext->GetRuntime()); + std::unique_ptr<CFXJSE_Value> pValue( + new CFXJSE_Value(pScriptContext->GetRuntime())); (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))( - pValue, FALSE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); - FXJSE_Value_Set(pArguments->GetReturnValue(), pValue); - FXJSE_Value_Release(pValue); + pValue.get(), FALSE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); + FXJSE_Value_Set(pArguments->GetReturnValue(), pValue.get()); } else { FXJSE_Value_SetNull(pArguments->GetReturnValue()); } diff --git a/xfa/fxfa/parser/xfa_script.h b/xfa/fxfa/parser/xfa_script.h index 42d3ddfa47..350588f8b5 100644 --- a/xfa/fxfa/parser/xfa_script.h +++ b/xfa/fxfa/parser/xfa_script.h @@ -8,6 +8,7 @@ #define XFA_FXFA_PARSER_XFA_SCRIPT_H_ #include "xfa/fxfa/include/fxfa.h" +#include "xfa/fxjse/value.h" #define XFA_RESOLVENODE_Children 0x0001 #define XFA_RESOLVENODE_Attributes 0x0004 @@ -41,7 +42,7 @@ class CXFA_ValueArray : public CFX_ArrayTemplate<CFXJSE_Value*> { ~CXFA_ValueArray() { for (int32_t i = 0; i < GetSize(); i++) { - FXJSE_Value_Release(GetAt(i)); + delete GetAt(i); } } @@ -65,10 +66,10 @@ struct XFA_RESOLVENODE_RS { if (pScriptAttribute && pScriptAttribute->eValueType == XFA_SCRIPT_Object) { v8::Isolate* pIsolate = valueArray.m_pIsolate; for (int32_t i = 0; i < nodes.GetSize(); i++) { - CFXJSE_Value* pValue = FXJSE_Value_Create(pIsolate); + std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(pIsolate)); (nodes[i]->*(pScriptAttribute->lpfnCallback))( - pValue, FALSE, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute); - valueArray.Add(pValue); + pValue.get(), FALSE, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute); + valueArray.Add(pValue.release()); } } return valueArray.GetSize(); diff --git a/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp b/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp index 2bff14c77f..2aa1de7580 100644 --- a/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp +++ b/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp @@ -308,36 +308,33 @@ void CScript_HostPseudoModel::Script_HostPseudoModel_OpenList( } CXFA_Node* pNode = NULL; if (iLength >= 1) { - CFXJSE_Value* pValue = pArguments->GetValue(0); - if (FXJSE_Value_IsObject(pValue)) { - pNode = static_cast<CXFA_Node*>(FXJSE_Value_ToObject(pValue, nullptr)); - } else if (FXJSE_Value_IsUTF8String(pValue)) { + std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0)); + if (FXJSE_Value_IsObject(pValue.get())) { + pNode = + static_cast<CXFA_Node*>(FXJSE_Value_ToObject(pValue.get(), nullptr)); + } else if (FXJSE_Value_IsUTF8String(pValue.get())) { CFX_ByteString bsString; - FXJSE_Value_ToUTF8String(pValue, bsString); + FXJSE_Value_ToUTF8String(pValue.get(), bsString); CFX_WideString wsExpression = CFX_WideString::FromUTF8(bsString.AsStringC()); CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); - if (!pScriptContext) { - FXJSE_Value_Release(pValue); + if (!pScriptContext) return; - } + CXFA_Object* pObject = pScriptContext->GetThisObject(); - if (!pObject) { - FXJSE_Value_Release(pValue); + if (!pObject) return; - } + uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects( pObject, wsExpression.AsStringC(), resoveNodeRS, dwFlag); - if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { - FXJSE_Value_Release(pValue); + if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) return; - } + pNode = resoveNodeRS.nodes[0]->AsNode(); } - FXJSE_Value_Release(pValue); } CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); if (!pDocLayout) { @@ -509,36 +506,33 @@ void CScript_HostPseudoModel::Script_HostPseudoModel_SetFocus( } CXFA_Node* pNode = NULL; if (iLength >= 1) { - CFXJSE_Value* pValue = pArguments->GetValue(0); - if (FXJSE_Value_IsObject(pValue)) { - pNode = static_cast<CXFA_Node*>(FXJSE_Value_ToObject(pValue, nullptr)); - } else if (FXJSE_Value_IsUTF8String(pValue)) { + std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0)); + if (FXJSE_Value_IsObject(pValue.get())) { + pNode = + static_cast<CXFA_Node*>(FXJSE_Value_ToObject(pValue.get(), nullptr)); + } else if (FXJSE_Value_IsUTF8String(pValue.get())) { CFX_ByteString bsString; - FXJSE_Value_ToUTF8String(pValue, bsString); + FXJSE_Value_ToUTF8String(pValue.get(), bsString); CFX_WideString wsExpression = CFX_WideString::FromUTF8(bsString.AsStringC()); CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); - if (!pScriptContext) { - FXJSE_Value_Release(pValue); + if (!pScriptContext) return; - } + CXFA_Object* pObject = pScriptContext->GetThisObject(); - if (!pObject) { - FXJSE_Value_Release(pValue); + if (!pObject) return; - } + uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects( pObject, wsExpression.AsStringC(), resoveNodeRS, dwFlag); - if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { - FXJSE_Value_Release(pValue); + if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) return; - } + pNode = resoveNodeRS.nodes[0]->AsNode(); } - FXJSE_Value_Release(pValue); } pNotify->SetFocusWidgetNode(pNode); } @@ -614,20 +608,18 @@ FX_BOOL CScript_HostPseudoModel::Script_HostPseudoModel_ValidateArgsForMsg( XFA_SCRIPTLANGTYPE_Javascript) { bIsJsType = TRUE; } - CFXJSE_Value* pValueArg = pArguments->GetValue(iArgIndex); - if (!FXJSE_Value_IsUTF8String(pValueArg) && bIsJsType) { + std::unique_ptr<CFXJSE_Value> pValueArg(pArguments->GetValue(iArgIndex)); + if (!FXJSE_Value_IsUTF8String(pValueArg.get()) && bIsJsType) { ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); - FXJSE_Value_Release(pValueArg); return FALSE; } - if (FXJSE_Value_IsNull(pValueArg)) { + if (FXJSE_Value_IsNull(pValueArg.get())) { wsValue = FX_WSTRC(L""); } else { CFX_ByteString byMessage; - FXJSE_Value_ToUTF8String(pValueArg, byMessage); + FXJSE_Value_ToUTF8String(pValueArg.get(), byMessage); wsValue = CFX_WideString::FromUTF8(byMessage.AsStringC()); } - FXJSE_Value_Release(pValueArg); return TRUE; } void CScript_HostPseudoModel::Script_HostPseudoModel_DocumentCountInBatch( diff --git a/xfa/fxfa/parser/xfa_script_imp.cpp b/xfa/fxfa/parser/xfa_script_imp.cpp index c77ec4889a..159a9eced3 100644 --- a/xfa/fxfa/parser/xfa_script_imp.cpp +++ b/xfa/fxfa/parser/xfa_script_imp.cpp @@ -86,7 +86,7 @@ CXFA_ScriptContext::~CXFA_ScriptContext() { CXFA_Object* pXFAObj; CFXJSE_Value* pValue; m_mapXFAToValue.GetNextAssoc(ps, pXFAObj, pValue); - FXJSE_Value_Release(pValue); + delete pValue; } m_mapXFAToValue.RemoveAll(); ReleaseVariablesMap(); @@ -473,16 +473,15 @@ FX_BOOL CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { CFX_ByteString btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); - CFXJSE_Value* hRetValue = FXJSE_Value_Create(m_pIsolate); + std::unique_ptr<CFXJSE_Value> hRetValue(new CFXJSE_Value(m_pIsolate)); CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); CFXJSE_Context* pVariablesContext = CreateVariablesContext(pScriptNode, pThisObject); CXFA_Object* pOriginalObject = m_pThisObject; m_pThisObject = pThisObject; FX_BOOL bRet = - FXJSE_ExecuteScript(pVariablesContext, btScript.c_str(), hRetValue); + FXJSE_ExecuteScript(pVariablesContext, btScript.c_str(), hRetValue.get()); m_pThisObject = pOriginalObject; - FXJSE_Value_Release(hRetValue); return bRet; } @@ -504,23 +503,22 @@ FX_BOOL CXFA_ScriptContext::QueryVariableValue( FX_BOOL bRes = FALSE; CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); - CFXJSE_Value* pObject = FXJSE_Context_GetGlobalObject(pVariableContext); - CFXJSE_Value* hVariableValue = FXJSE_Value_Create(m_pIsolate); + std::unique_ptr<CFXJSE_Value> pObject( + FXJSE_Context_GetGlobalObject(pVariableContext)); + std::unique_ptr<CFXJSE_Value> hVariableValue(new CFXJSE_Value(m_pIsolate)); if (!bGetter) { - FXJSE_Value_SetObjectOwnProp(pObject, szPropName, pValue); + FXJSE_Value_SetObjectOwnProp(pObject.get(), szPropName, pValue); bRes = TRUE; - } else if (FXJSE_Value_ObjectHasOwnProp(pObject, szPropName, FALSE)) { - FXJSE_Value_GetObjectProp(pObject, szPropName, hVariableValue); - if (FXJSE_Value_IsFunction(hVariableValue)) - FXJSE_Value_SetFunctionBind(pValue, hVariableValue, pObject); + } else if (FXJSE_Value_ObjectHasOwnProp(pObject.get(), szPropName, FALSE)) { + FXJSE_Value_GetObjectProp(pObject.get(), szPropName, hVariableValue.get()); + if (FXJSE_Value_IsFunction(hVariableValue.get())) + FXJSE_Value_SetFunctionBind(pValue, hVariableValue.get(), pObject.get()); else if (bGetter) - FXJSE_Value_Set(pValue, hVariableValue); + FXJSE_Value_Set(pValue, hVariableValue.get()); else - FXJSE_Value_Set(hVariableValue, pValue); + FXJSE_Value_Set(hVariableValue.get(), pValue); bRes = TRUE; } - FXJSE_Value_Release(hVariableValue); - FXJSE_Value_Release(pObject); return bRes; } @@ -530,9 +528,10 @@ void CXFA_ScriptContext::ReleaseVariablesMap() { CXFA_Object* pScriptNode; CFXJSE_Context* pVariableContext = nullptr; m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); - CFXJSE_Value* pObject = FXJSE_Context_GetGlobalObject(pVariableContext); - delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(pObject, nullptr)); - FXJSE_Value_Release(pObject); + std::unique_ptr<CFXJSE_Value> pObject( + FXJSE_Context_GetGlobalObject(pVariableContext)); + delete static_cast<CXFA_ThisProxy*>( + FXJSE_Value_ToObject(pObject.get(), nullptr)); FXJSE_Context_Release(pVariableContext); } m_mapVariableToContext.RemoveAll(); @@ -544,14 +543,13 @@ void CXFA_ScriptContext::DefineJsClass() { void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; - CFXJSE_Value* pObject = FXJSE_Context_GetGlobalObject(pContext); - CFXJSE_Value* hProp = FXJSE_Value_Create(m_pIsolate); + std::unique_ptr<CFXJSE_Value> pObject( + FXJSE_Context_GetGlobalObject(pContext)); + std::unique_ptr<CFXJSE_Value> hProp(new CFXJSE_Value(m_pIsolate)); for (int i = 0; i < 2; ++i) { - if (FXJSE_Value_GetObjectProp(pObject, OBJ_NAME[i], hProp)) - FXJSE_Value_DeleteObjectProp(pObject, OBJ_NAME[i]); + if (FXJSE_Value_GetObjectProp(pObject.get(), OBJ_NAME[i], hProp.get())) + FXJSE_Value_DeleteObjectProp(pObject.get(), OBJ_NAME[i]); } - FXJSE_Value_Release(hProp); - FXJSE_Value_Release(pObject); } CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { return m_pJsClass; @@ -651,13 +649,12 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, } if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { - CFXJSE_Value* pValue = FXJSE_Value_Create(m_pIsolate); + std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(m_pIsolate)); (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( - pValue, FALSE, + pValue.get(), FALSE, (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); rndFind.m_Nodes.SetAt( - 0, (CXFA_Object*)FXJSE_Value_ToObject(pValue, nullptr)); - FXJSE_Value_Release(pValue); + 0, (CXFA_Object*)FXJSE_Value_ToObject(pValue.get(), nullptr)); } int32_t iSize = m_upObjectArray.GetSize(); if (iSize) { @@ -728,7 +725,7 @@ CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { void* pValue = m_mapXFAToValue.GetValueAt(pObject); if (!pValue) { - CFXJSE_Value* jsValue = FXJSE_Value_Create(m_pIsolate); + CFXJSE_Value* jsValue = new CFXJSE_Value(m_pIsolate); FXJSE_Value_SetObject(jsValue, pObject, m_pJsClass); m_mapXFAToValue.SetAt(pObject, jsValue); pValue = jsValue; diff --git a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp b/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp index aa2fa87c4a..8471b802cc 100644 --- a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp +++ b/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp @@ -709,13 +709,12 @@ void CXFA_ResolveProcessor::XFA_ResolveNode_DoPredicateFilter( for (int32_t i = iFoundCount - 1; i >= 0; i--) { CXFA_Object* node = findNodes[i]; FX_BOOL bRet = FALSE; - CFXJSE_Value* pRetValue = FXJSE_Value_Create(rnd.m_pSC->GetRuntime()); - bRet = pContext->RunScript(eLangType, wsExpression.AsStringC(), pRetValue, - node); - if (!bRet || !FXJSE_Value_ToBoolean(pRetValue)) { + std::unique_ptr<CFXJSE_Value> pRetValue( + new CFXJSE_Value(rnd.m_pSC->GetRuntime())); + bRet = pContext->RunScript(eLangType, wsExpression.AsStringC(), + pRetValue.get(), node); + if (!bRet || !FXJSE_Value_ToBoolean(pRetValue.get())) findNodes.RemoveAt(i); - } - FXJSE_Value_Release(pRetValue); } } |