summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-09 10:33:10 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-09 10:33:10 -0700
commit16fccc51456dbab7e392c3952cc367723f9694f6 (patch)
tree0bd44bec6b81213db9d1dc487237164cdcaa43a4 /xfa/fxfa/fm2js
parentaf7ab33c73f58f18d0db0c90d93fa0aab0bc83f3 (diff)
downloadpdfium-16fccc51456dbab7e392c3952cc367723f9694f6.tar.xz
Use smart pointers for class owned pointers
For classes under xfa/fxfa/fm2js, and xfa/fxgraphics, use smart pointers instead of raw pointer to make memory management easier. Also fix some styling issues along the changes. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2222203002
Diffstat (limited to 'xfa/fxfa/fm2js')
-rw-r--r--xfa/fxfa/fm2js/xfa_expression.cpp5
-rw-r--r--xfa/fxfa/fm2js/xfa_expression.h4
-rw-r--r--xfa/fxfa/fm2js/xfa_fmparse.cpp2
-rw-r--r--xfa/fxfa/fm2js/xfa_program.cpp17
-rw-r--r--xfa/fxfa/fm2js/xfa_program.h8
5 files changed, 19 insertions, 17 deletions
diff --git a/xfa/fxfa/fm2js/xfa_expression.cpp b/xfa/fxfa/fm2js/xfa_expression.cpp
index ad6acafd48..22e627d72d 100644
--- a/xfa/fxfa/fm2js/xfa_expression.cpp
+++ b/xfa/fxfa/fm2js/xfa_expression.cpp
@@ -32,16 +32,15 @@ CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition(
uint32_t line,
FX_BOOL isGlobal,
const CFX_WideStringC& wsName,
- CFX_WideStringCArray* pArguments,
+ std::unique_ptr<CFX_WideStringCArray> pArguments,
CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressions)
: CXFA_FMExpression(line, XFA_FM_EXPTYPE_FUNC),
m_wsName(wsName),
- m_pArguments(pArguments),
+ m_pArguments(std::move(pArguments)),
m_pExpressions(pExpressions),
m_isGlobal(isGlobal) {}
CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() {
- delete m_pArguments;
if (m_pExpressions) {
for (int i = 0; i < m_pExpressions->GetSize(); ++i)
delete m_pExpressions->GetAt(i);
diff --git a/xfa/fxfa/fm2js/xfa_expression.h b/xfa/fxfa/fm2js/xfa_expression.h
index 8134988f4e..88cebdf036 100644
--- a/xfa/fxfa/fm2js/xfa_expression.h
+++ b/xfa/fxfa/fm2js/xfa_expression.h
@@ -44,7 +44,7 @@ class CXFA_FMFunctionDefinition : public CXFA_FMExpression {
uint32_t line,
FX_BOOL isGlobal,
const CFX_WideStringC& wsName,
- CFX_WideStringCArray* pArguments,
+ std::unique_ptr<CFX_WideStringCArray> pArguments,
CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressions);
~CXFA_FMFunctionDefinition() override;
@@ -53,7 +53,7 @@ class CXFA_FMFunctionDefinition : public CXFA_FMExpression {
private:
CFX_WideStringC m_wsName;
- CFX_WideStringCArray* m_pArguments;
+ std::unique_ptr<CFX_WideStringCArray> m_pArguments;
CFX_ArrayTemplate<CXFA_FMExpression*>* m_pExpressions;
FX_BOOL m_isGlobal;
};
diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp
index 5c17bbc723..3223df64dc 100644
--- a/xfa/fxfa/fm2js/xfa_fmparse.cpp
+++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp
@@ -129,7 +129,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseFunction() {
Check(TOKendfunc);
}
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMFunctionDefinition(line, 0, ident, pArguments.release(),
+ e.reset(new CXFA_FMFunctionDefinition(line, 0, ident, std::move(pArguments),
pExpressions.release()));
} else {
if (pArguments)
diff --git a/xfa/fxfa/fm2js/xfa_program.cpp b/xfa/fxfa/fm2js/xfa_program.cpp
index a5c429765f..5146a5e129 100644
--- a/xfa/fxfa/fm2js/xfa_program.cpp
+++ b/xfa/fxfa/fm2js/xfa_program.cpp
@@ -6,16 +6,14 @@
#include "xfa/fxfa/fm2js/xfa_program.h"
-CXFA_FMProgram::CXFA_FMProgram() : m_globalFunction(0) {}
-CXFA_FMProgram::~CXFA_FMProgram() {
- if (m_globalFunction != 0) {
- delete m_globalFunction;
- m_globalFunction = 0;
- }
-}
+CXFA_FMProgram::CXFA_FMProgram() {}
+
+CXFA_FMProgram::~CXFA_FMProgram() {}
+
int32_t CXFA_FMProgram::Init(const CFX_WideStringC& wsFormcalc) {
return m_parse.Init(wsFormcalc, &m_pErrorInfo);
}
+
int32_t CXFA_FMProgram::ParseProgram() {
CFX_ArrayTemplate<CXFA_FMExpression*>* expressions = nullptr;
m_parse.NextToken();
@@ -30,10 +28,11 @@ int32_t CXFA_FMProgram::ParseProgram() {
delete expressions;
return -1;
}
- m_globalFunction =
- new CXFA_FMFunctionDefinition(1, 1, FX_WSTRC(L""), 0, expressions);
+ m_globalFunction.reset(
+ new CXFA_FMFunctionDefinition(1, 1, FX_WSTRC(L""), nullptr, expressions));
return 0;
}
+
int32_t CXFA_FMProgram::TranslateProgram(CFX_WideTextBuf& wsJavaScript) {
m_globalFunction->ToJavaScript(wsJavaScript);
wsJavaScript.AppendChar(0);
diff --git a/xfa/fxfa/fm2js/xfa_program.h b/xfa/fxfa/fm2js/xfa_program.h
index 2f6de5e3a8..aa29bba87b 100644
--- a/xfa/fxfa/fm2js/xfa_program.h
+++ b/xfa/fxfa/fm2js/xfa_program.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXFA_FM2JS_XFA_PROGRAM_H_
#define XFA_FXFA_FM2JS_XFA_PROGRAM_H_
+#include <memory>
+
#include "xfa/fxfa/fm2js/xfa_error.h"
#include "xfa/fxfa/fm2js/xfa_fmparse.h"
@@ -14,15 +16,17 @@ class CXFA_FMProgram {
public:
CXFA_FMProgram();
~CXFA_FMProgram();
+
int32_t Init(const CFX_WideStringC& wsFormcalc);
int32_t ParseProgram();
int32_t TranslateProgram(CFX_WideTextBuf& wsJavaScript);
- CXFA_FMErrorInfo& GetError() { return m_pErrorInfo; }
+
+ const CXFA_FMErrorInfo& GetError() const { return m_pErrorInfo; }
private:
CXFA_FMErrorInfo m_pErrorInfo;
CXFA_FMParse m_parse;
- CXFA_FMFunctionDefinition* m_globalFunction;
+ std::unique_ptr<CXFA_FMFunctionDefinition> m_globalFunction;
};
#endif // XFA_FXFA_FM2JS_XFA_PROGRAM_H_