summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cjx_node.cpp48
-rw-r--r--fxjs/cjx_node.h22
2 files changed, 33 insertions, 37 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp
index e653795a4b..945b12f868 100644
--- a/fxjs/cjx_node.cpp
+++ b/fxjs/cjx_node.cpp
@@ -6,7 +6,7 @@
#include "fxjs/cjx_node.h"
-#include <memory>
+#include <map>
#include <vector>
#include "core/fxcrt/cfx_decimal.h"
@@ -172,12 +172,22 @@ static void XFA_DefaultFreeData(void* pData) {}
static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
XFA_DefaultFreeData, nullptr};
-XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
+struct XFA_MAPDATABLOCK {
+ uint8_t* GetData() const { return (uint8_t*)this + sizeof(XFA_MAPDATABLOCK); }
-XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
+ XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo;
+ int32_t iBytes;
+};
+
+struct XFA_MAPMODULEDATA {
+ XFA_MAPMODULEDATA() {}
+ ~XFA_MAPMODULEDATA() {}
+
+ std::map<void*, void*> m_ValueMap;
+ std::map<void*, XFA_MAPDATABLOCK*> m_BufferMap;
+};
-CJX_Node::CJX_Node(CXFA_Node* node)
- : CJX_Object(node), map_module_data_(nullptr) {}
+CJX_Node::CJX_Node(CXFA_Node* node) : CJX_Object(node) {}
CJX_Node::~CJX_Node() {
ClearMapModuleBuffer();
@@ -3663,17 +3673,16 @@ CXFA_Node* CJX_Node::GetProperty(int32_t index,
XFA_MAPMODULEDATA* CJX_Node::CreateMapModuleData() {
if (!map_module_data_)
- map_module_data_ = new XFA_MAPMODULEDATA;
- return map_module_data_;
+ map_module_data_ = pdfium::MakeUnique<XFA_MAPMODULEDATA>();
+ return map_module_data_.get();
}
XFA_MAPMODULEDATA* CJX_Node::GetMapModuleData() const {
- return map_module_data_;
+ return map_module_data_.get();
}
void CJX_Node::SetMapModuleValue(void* pKey, void* pValue) {
- XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
- pModule->m_ValueMap[pKey] = pValue;
+ CreateMapModuleData()->m_ValueMap[pKey] = pValue;
}
bool CJX_Node::GetMapModuleValue(void* pKey, void*& pValue) {
@@ -3713,19 +3722,19 @@ void CJX_Node::SetMapModuleBuffer(void* pKey,
void* pValue,
int32_t iBytes,
XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
- XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
- XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
+ XFA_MAPDATABLOCK*& pBuffer = CreateMapModuleData()->m_BufferMap[pKey];
if (!pBuffer) {
- pBuffer =
- (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
+ pBuffer = reinterpret_cast<XFA_MAPDATABLOCK*>(
+ FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes));
} else if (pBuffer->iBytes != iBytes) {
if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
}
- pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
- sizeof(XFA_MAPDATABLOCK) + iBytes);
+ pBuffer = reinterpret_cast<XFA_MAPDATABLOCK*>(
+ FX_Realloc(uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + iBytes));
} else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
- pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
+ pBuffer->pCallbackInfo->pFree(
+ *reinterpret_cast<void**>(pBuffer->GetData()));
}
if (!pBuffer)
return;
@@ -3782,7 +3791,6 @@ void CJX_Node::ClearMapModuleBuffer() {
}
pModule->m_BufferMap.clear();
pModule->m_ValueMap.clear();
- delete pModule;
}
void CJX_Node::RemoveMapModuleKey(void* pKey) {
@@ -3806,9 +3814,9 @@ void CJX_Node::RemoveMapModuleKey(void* pKey) {
return;
}
-void CJX_Node::MergeAllData(void* pDstModule) {
+void CJX_Node::MergeAllData(CXFA_Node* pDstModule) {
XFA_MAPMODULEDATA* pDstModuleData =
- static_cast<CXFA_Node*>(pDstModule)->JSNode()->CreateMapModuleData();
+ pDstModule->JSNode()->CreateMapModuleData();
XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
if (!pSrcModuleData)
return;
diff --git a/fxjs/cjx_node.h b/fxjs/cjx_node.h
index 80ee6ae4b2..a8b579c399 100644
--- a/fxjs/cjx_node.h
+++ b/fxjs/cjx_node.h
@@ -7,7 +7,7 @@
#ifndef FXJS_CJX_NODE_H_
#define FXJS_CJX_NODE_H_
-#include <map>
+#include <memory>
#include "core/fxcrt/unowned_ptr.h"
#include "fxjs/cjx_object.h"
@@ -21,20 +21,6 @@ struct XFA_MAPDATABLOCKCALLBACKINFO {
PD_CALLBACK_DUPLICATEDATA pCopy;
};
-struct XFA_MAPDATABLOCK {
- uint8_t* GetData() const { return (uint8_t*)this + sizeof(XFA_MAPDATABLOCK); }
- XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo;
- int32_t iBytes;
-};
-
-struct XFA_MAPMODULEDATA {
- XFA_MAPMODULEDATA();
- ~XFA_MAPMODULEDATA();
-
- std::map<void*, void*> m_ValueMap;
- std::map<void*, XFA_MAPDATABLOCK*> m_BufferMap;
-};
-
enum XFA_SOM_MESSAGETYPE {
XFA_SOM_ValidationMessage,
XFA_SOM_FormatMessage,
@@ -44,6 +30,8 @@ enum XFA_SOM_MESSAGETYPE {
class CFXJSE_Arguments;
class CXFA_Node;
+struct XFA_MAPMODULEDATA;
+
class CJX_Node : public CJX_Object {
public:
explicit CJX_Node(CXFA_Node* node);
@@ -123,7 +111,7 @@ class CJX_Node : public CJX_Object {
bool TryNamespace(WideString& wsNamespace);
- void MergeAllData(void* pDstModule);
+ void MergeAllData(CXFA_Node* pDstModule);
void ThrowMissingPropertyException(const WideString& obj,
const WideString& prop) const;
@@ -453,7 +441,7 @@ class CJX_Node : public CJX_Object {
int32_t execSingleEventByName(const WideStringView& wsEventName,
XFA_Element eType);
- XFA_MAPMODULEDATA* map_module_data_;
+ std::unique_ptr<XFA_MAPMODULEDATA> map_module_data_;
};
#endif // FXJS_CJX_NODE_H_