summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authornpm <npm@chromium.org>2016-11-28 12:31:13 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-28 12:31:13 -0800
commiteb9625c04876c45862fb30e48a4fd6d5998db0e9 (patch)
tree67725226cdf317ff35213da6761dfc0455ec69fb /xfa
parentc92e26defaa636b0d2ec9b9de0f88c6153ad7ed3 (diff)
downloadpdfium-eb9625c04876c45862fb30e48a4fd6d5998db0e9.tar.xz
Use unique pointers in CXFA_FMParse
Replaced CXFA_FMParse's returns to be unique pointers to prevent leaks. Review-Url: https://codereview.chromium.org/2530933002
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fxfa/fm2js/xfa_expression.cpp82
-rw-r--r--xfa/fxfa/fm2js/xfa_expression.h9
-rw-r--r--xfa/fxfa/fm2js/xfa_fmparse.cpp580
-rw-r--r--xfa/fxfa/fm2js/xfa_fmparse.h50
-rw-r--r--xfa/fxfa/fm2js/xfa_program.cpp23
-rw-r--r--xfa/fxfa/fm2js/xfa_simpleexpression.cpp95
-rw-r--r--xfa/fxfa/fm2js/xfa_simpleexpression.h12
-rw-r--r--xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp12
8 files changed, 412 insertions, 451 deletions
diff --git a/xfa/fxfa/fm2js/xfa_expression.cpp b/xfa/fxfa/fm2js/xfa_expression.cpp
index 5734593ff8..8d1888a797 100644
--- a/xfa/fxfa/fm2js/xfa_expression.cpp
+++ b/xfa/fxfa/fm2js/xfa_expression.cpp
@@ -35,24 +35,17 @@ CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition(
bool isGlobal,
const CFX_WideStringC& wsName,
std::unique_ptr<CFX_WideStringCArray> pArguments,
- CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressions)
+ std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressions)
: CXFA_FMExpression(line, XFA_FM_EXPTYPE_FUNC),
m_wsName(wsName),
m_pArguments(std::move(pArguments)),
- m_pExpressions(pExpressions),
+ m_pExpressions(std::move(pExpressions)),
m_isGlobal(isGlobal) {}
-CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() {
- if (m_pExpressions) {
- for (int i = 0; i < m_pExpressions->GetSize(); ++i)
- delete m_pExpressions->GetAt(i);
-
- delete m_pExpressions;
- }
-}
+CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() {}
void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) {
- if (m_isGlobal && (!m_pExpressions || m_pExpressions->GetSize() == 0)) {
+ if (m_isGlobal && m_pExpressions.empty()) {
javascript << FX_WSTRC(L"// comments only");
return;
}
@@ -87,15 +80,11 @@ void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << FX_WSTRC(L"var ");
javascript << RUNTIMEFUNCTIONRETURNVALUE;
javascript << FX_WSTRC(L" = null;\n");
- if (m_pExpressions) {
- for (int i = 0; i < m_pExpressions->GetSize(); ++i) {
- CXFA_FMExpression* e = m_pExpressions->GetAt(i);
- if (i + 1 < m_pExpressions->GetSize()) {
- e->ToJavaScript(javascript);
- } else {
- e->ToImpliedReturnJS(javascript);
- }
- }
+ for (const auto& expr : m_pExpressions) {
+ if (expr == m_pExpressions.back())
+ expr->ToImpliedReturnJS(javascript);
+ else
+ expr->ToJavaScript(javascript);
}
javascript << FX_WSTRC(L"return ");
if (m_isGlobal) {
@@ -210,39 +199,26 @@ void CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
CXFA_FMBlockExpression::CXFA_FMBlockExpression(
uint32_t line,
- CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressionList)
+ std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressionList)
: CXFA_FMExpression(line, XFA_FM_EXPTYPE_BLOCK),
- m_pExpressionList(pExpressionList) {}
+ m_ExpressionList(std::move(pExpressionList)) {}
-CXFA_FMBlockExpression::~CXFA_FMBlockExpression() {
- if (m_pExpressionList) {
- for (int i = 0; i < m_pExpressionList->GetSize(); ++i)
- delete m_pExpressionList->GetAt(i);
-
- delete m_pExpressionList;
- }
-}
+CXFA_FMBlockExpression::~CXFA_FMBlockExpression() {}
void CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << FX_WSTRC(L"{\n");
- if (m_pExpressionList) {
- for (int i = 0; i < m_pExpressionList->GetSize(); ++i)
- m_pExpressionList->GetAt(i)->ToJavaScript(javascript);
- }
+ for (const auto& expr : m_ExpressionList)
+ expr->ToJavaScript(javascript);
javascript << FX_WSTRC(L"}\n");
}
void CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
javascript << FX_WSTRC(L"{\n");
- if (m_pExpressionList) {
- for (int i = 0; i < m_pExpressionList->GetSize(); ++i) {
- CXFA_FMExpression* e = m_pExpressionList->GetAt(i);
- if (i + 1 == m_pExpressionList->GetSize()) {
- e->ToImpliedReturnJS(javascript);
- } else {
- e->ToJavaScript(javascript);
- }
- }
+ for (const auto& expr : m_ExpressionList) {
+ if (expr == m_ExpressionList.back())
+ expr->ToImpliedReturnJS(javascript);
+ else
+ expr->ToJavaScript(javascript);
}
javascript << FX_WSTRC(L"}\n");
}
@@ -536,12 +512,10 @@ void CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
javascript << FX_WSTRC(L"(");
- for (size_t i = 0; i < m_pAccessors.size(); ++i) {
- CXFA_FMSimpleExpression* s = m_pAccessors.at(i).get();
- s->ToJavaScript(javascript);
- if (i + 1 < m_pAccessors.size()) {
- javascript << FX_WSTRC(L", ");
- }
+ for (const auto& expr : m_pAccessors) {
+ expr->ToJavaScript(javascript);
+ if (expr != m_pAccessors.back())
+ javascript << L", ";
}
javascript << FX_WSTRC(L");\n");
javascript << FX_WSTRC(L"var ");
@@ -587,12 +561,10 @@ void CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
javascript << FX_WSTRC(L" = ");
javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
javascript << FX_WSTRC(L"(");
- for (size_t i = 0; i < m_pAccessors.size(); ++i) {
- CXFA_FMSimpleExpression* s = m_pAccessors.at(i).get();
- s->ToJavaScript(javascript);
- if (i + 1 < m_pAccessors.size()) {
- javascript << FX_WSTRC(L", ");
- }
+ for (const auto& expr : m_pAccessors) {
+ expr->ToJavaScript(javascript);
+ if (expr != m_pAccessors.back())
+ javascript << L", ";
}
javascript << FX_WSTRC(L");\n");
javascript << FX_WSTRC(L"var ");
diff --git a/xfa/fxfa/fm2js/xfa_expression.h b/xfa/fxfa/fm2js/xfa_expression.h
index 236b51a6b0..f89a923565 100644
--- a/xfa/fxfa/fm2js/xfa_expression.h
+++ b/xfa/fxfa/fm2js/xfa_expression.h
@@ -46,7 +46,7 @@ class CXFA_FMFunctionDefinition : public CXFA_FMExpression {
bool isGlobal,
const CFX_WideStringC& wsName,
std::unique_ptr<CFX_WideStringCArray> pArguments,
- CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressions);
+ std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressions);
~CXFA_FMFunctionDefinition() override;
void ToJavaScript(CFX_WideTextBuf& javascript) override;
@@ -55,7 +55,7 @@ class CXFA_FMFunctionDefinition : public CXFA_FMExpression {
private:
CFX_WideStringC m_wsName;
std::unique_ptr<CFX_WideStringCArray> m_pArguments;
- CFX_ArrayTemplate<CXFA_FMExpression*>* m_pExpressions;
+ std::vector<std::unique_ptr<CXFA_FMExpression>> m_pExpressions;
bool m_isGlobal;
};
@@ -88,17 +88,16 @@ class CXFA_FMExpExpression : public CXFA_FMExpression {
class CXFA_FMBlockExpression : public CXFA_FMExpression {
public:
- // Takes ownership of |pExpressionList|.
CXFA_FMBlockExpression(
uint32_t line,
- CFX_ArrayTemplate<CXFA_FMExpression*>* pExpressionList);
+ std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressionList);
~CXFA_FMBlockExpression() override;
void ToJavaScript(CFX_WideTextBuf& javascript) override;
void ToImpliedReturnJS(CFX_WideTextBuf&) override;
private:
- CFX_ArrayTemplate<CXFA_FMExpression*>* m_pExpressionList;
+ std::vector<std::unique_ptr<CXFA_FMExpression>> m_ExpressionList;
};
class CXFA_FMDoExpression : public CXFA_FMExpression {
diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp
index 36663fce2d..07edc32c3d 100644
--- a/xfa/fxfa/fm2js/xfa_fmparse.cpp
+++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp
@@ -19,7 +19,7 @@ CXFA_FMParse::~CXFA_FMParse() {}
int32_t CXFA_FMParse::Init(const CFX_WideStringC& wsFormcalc,
CXFA_FMErrorInfo* pErrorInfo) {
m_pErrorInfo = pErrorInfo;
- m_lexer.reset(new CXFA_FMLexer(wsFormcalc, m_pErrorInfo));
+ m_lexer = pdfium::MakeUnique<CXFA_FMLexer>(wsFormcalc, m_pErrorInfo);
return 0;
}
@@ -50,41 +50,41 @@ void CXFA_FMParse::Error(uint32_t lineNum, const FX_WCHAR* msg, ...) {
va_end(ap);
}
-CFX_ArrayTemplate<CXFA_FMExpression*>* CXFA_FMParse::ParseTopExpression() {
- std::unique_ptr<CXFA_FMExpression> e;
- CFX_ArrayTemplate<CXFA_FMExpression*>* expression =
- new CFX_ArrayTemplate<CXFA_FMExpression*>();
+std::vector<std::unique_ptr<CXFA_FMExpression>>
+CXFA_FMParse::ParseTopExpression() {
+ std::unique_ptr<CXFA_FMExpression> expr;
+ std::vector<std::unique_ptr<CXFA_FMExpression>> expressions;
while (1) {
if (m_pToken->m_type == TOKeof || m_pToken->m_type == TOKendfunc ||
m_pToken->m_type == TOKendif || m_pToken->m_type == TOKelseif ||
m_pToken->m_type == TOKelse || m_pToken->m_type == TOKreserver) {
- return expression;
+ return expressions;
}
if (m_pToken->m_type == TOKfunc) {
- e.reset(ParseFunction());
- if (e) {
- expression->Add(e.release());
+ expr = ParseFunction();
+ if (expr) {
+ expressions.push_back(std::move(expr));
} else {
break;
}
} else {
- e.reset(ParseExpression());
- if (e) {
- expression->Add(e.release());
+ expr = ParseExpression();
+ if (expr) {
+ expressions.push_back(std::move(expr));
} else {
break;
}
}
}
- return expression;
+ return expressions;
}
-CXFA_FMExpression* CXFA_FMParse::ParseFunction() {
- std::unique_ptr<CXFA_FMExpression> e;
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseFunction() {
+ std::unique_ptr<CXFA_FMExpression> expr;
CFX_WideStringC ident;
std::unique_ptr<CFX_WideStringCArray> pArguments;
- std::unique_ptr<CFX_ArrayTemplate<CXFA_FMExpression*>> pExpressions;
+ std::vector<std::unique_ptr<CXFA_FMExpression>> expressions;
uint32_t line = m_pToken->m_uLinenum;
NextToken();
if (m_pToken->m_type != TOKidentifier) {
@@ -99,7 +99,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseFunction() {
if (m_pToken->m_type == TOKrparen) {
NextToken();
} else {
- pArguments.reset(new CFX_WideStringCArray());
+ pArguments = pdfium::MakeUnique<CFX_WideStringCArray>();
CFX_WideStringC p;
while (1) {
if (m_pToken->m_type == TOKidentifier) {
@@ -129,29 +129,24 @@ CXFA_FMExpression* CXFA_FMParse::ParseFunction() {
if (m_pToken->m_type == TOKendfunc) {
NextToken();
} else {
- pExpressions.reset(ParseTopExpression());
+ expressions = ParseTopExpression();
Check(TOKendfunc);
}
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMFunctionDefinition(line, 0, ident, std::move(pArguments),
- pExpressions.release()));
- } else {
- if (pArguments)
- pArguments->RemoveAll();
- if (pExpressions) {
- for (int i = 0; i < pExpressions->GetSize(); ++i)
- delete pExpressions->GetAt(i);
- }
+ expr = pdfium::MakeUnique<CXFA_FMFunctionDefinition>(
+ line, false, ident, std::move(pArguments), std::move(expressions));
+ } else if (pArguments) {
+ pArguments->RemoveAll();
}
- return e.release();
+ return expr;
}
-CXFA_FMExpression* CXFA_FMParse::ParseExpression() {
- std::unique_ptr<CXFA_FMExpression> e;
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpression() {
+ std::unique_ptr<CXFA_FMExpression> expr;
uint32_t line = m_pToken->m_uLinenum;
switch (m_pToken->m_type) {
case TOKvar:
- e.reset(ParseVarExpression());
+ expr = ParseVarExpression();
break;
case TOKnull:
case TOKnumber:
@@ -161,29 +156,29 @@ CXFA_FMExpression* CXFA_FMParse::ParseExpression() {
case TOKksnot:
case TOKidentifier:
case TOKlparen:
- e.reset(ParseExpExpression());
+ expr = ParseExpExpression();
break;
case TOKif:
- e.reset(ParseIfExpression());
+ expr = ParseIfExpression();
break;
case TOKwhile:
- e.reset(ParseWhileExpression());
+ expr = ParseWhileExpression();
break;
case TOKfor:
- e.reset(ParseForExpression());
+ expr = ParseForExpression();
break;
case TOKforeach:
- e.reset(ParseForeachExpression());
+ expr = ParseForeachExpression();
break;
case TOKdo:
- e.reset(ParseDoExpression());
+ expr = ParseDoExpression();
break;
case TOKbreak:
- e.reset(new CXFA_FMBreakExpression(line));
+ expr = pdfium::MakeUnique<CXFA_FMBreakExpression>(line);
NextToken();
break;
case TOKcontinue:
- e.reset(new CXFA_FMContinueExpression(line));
+ expr = pdfium::MakeUnique<CXFA_FMContinueExpression>(line);
NextToken();
break;
default:
@@ -193,11 +188,11 @@ CXFA_FMExpression* CXFA_FMParse::ParseExpression() {
NextToken();
break;
}
- return e.release();
+ return expr;
}
-CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() {
- std::unique_ptr<CXFA_FMExpression> e;
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseVarExpression() {
+ std::unique_ptr<CXFA_FMExpression> expr;
CFX_WideStringC ident;
uint32_t line = m_pToken->m_uLinenum;
NextToken();
@@ -211,47 +206,49 @@ CXFA_FMExpression* CXFA_FMParse::ParseVarExpression() {
}
if (m_pToken->m_type == TOKassign) {
NextToken();
- e.reset(ParseExpExpression());
+ expr = ParseExpExpression();
}
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMVarExpression(line, ident, e.release()));
+ expr =
+ pdfium::MakeUnique<CXFA_FMVarExpression>(line, ident, expr.release());
} else {
- e.reset();
+ expr.reset();
}
- return e.release();
+ return expr;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseSimpleExpression() {
+std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseSimpleExpression() {
uint32_t line = m_pToken->m_uLinenum;
- std::unique_ptr<CXFA_FMSimpleExpression> pExp1(ParseLogicalOrExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression();
while (m_pToken->m_type == TOKassign) {
NextToken();
- std::unique_ptr<CXFA_FMSimpleExpression> pExp2(ParseLogicalOrExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> pExp2 = ParseLogicalOrExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- pExp1.reset(new CXFA_FMAssignExpression(line, TOKassign, pExp1.release(),
- pExp2.release()));
+ pExp1 = pdfium::MakeUnique<CXFA_FMAssignExpression>(
+ line, TOKassign, pExp1.release(), pExp2.release());
} else {
pExp1.reset();
}
}
- return pExp1.release();
+ return pExp1;
}
-CXFA_FMExpression* CXFA_FMParse::ParseExpExpression() {
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpExpression() {
uint32_t line = m_pToken->m_uLinenum;
- std::unique_ptr<CXFA_FMSimpleExpression> pExp1(ParseSimpleExpression());
- std::unique_ptr<CXFA_FMExpression> e;
+ std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseSimpleExpression();
+ std::unique_ptr<CXFA_FMExpression> expr;
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMExpExpression(line, pExp1.release()));
+ expr = pdfium::MakeUnique<CXFA_FMExpExpression>(line, pExp1.release());
} else {
- e.reset();
+ expr.reset();
}
- return e.release();
+ return expr;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() {
+std::unique_ptr<CXFA_FMSimpleExpression>
+CXFA_FMParse::ParseLogicalOrExpression() {
uint32_t line = m_pToken->m_uLinenum;
- std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseLogicalAndExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseLogicalAndExpression();
for (;;) {
switch (m_pToken->m_type) {
case TOKor:
@@ -260,8 +257,8 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() {
std::unique_ptr<CXFA_FMSimpleExpression> e2(
ParseLogicalAndExpression());
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMLogicalOrExpression(line, TOKor, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMLogicalOrExpression>(
+ line, TOKor, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -272,21 +269,22 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalOrExpression() {
}
break;
}
- return e1.release();
+ return e1;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalAndExpression() {
+std::unique_ptr<CXFA_FMSimpleExpression>
+CXFA_FMParse::ParseLogicalAndExpression() {
uint32_t line = m_pToken->m_uLinenum;
- std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseEqualityExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseEqualityExpression();
for (;;) {
switch (m_pToken->m_type) {
case TOKand:
case TOKksand: {
NextToken();
- std::unique_ptr<CXFA_FMSimpleExpression> e2(ParseEqualityExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> e2 = ParseEqualityExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMLogicalAndExpression(line, TOKand, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMLogicalAndExpression>(
+ line, TOKand, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -297,22 +295,23 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseLogicalAndExpression() {
}
break;
}
- return e1.release();
+ return e1;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() {
+std::unique_ptr<CXFA_FMSimpleExpression>
+CXFA_FMParse::ParseEqualityExpression() {
uint32_t line = m_pToken->m_uLinenum;
- std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseRelationalExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseRelationalExpression();
for (;;) {
std::unique_ptr<CXFA_FMSimpleExpression> e2;
switch (m_pToken->m_type) {
case TOKeq:
case TOKkseq:
NextToken();
- e2.reset(ParseRelationalExpression());
+ e2 = ParseRelationalExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMEqualityExpression(line, TOKeq, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMEqualityExpression>(
+ line, TOKeq, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -320,10 +319,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() {
case TOKne:
case TOKksne:
NextToken();
- e2.reset(ParseRelationalExpression());
+ e2 = ParseRelationalExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMEqualityExpression(line, TOKne, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMEqualityExpression>(
+ line, TOKne, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -333,22 +332,23 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseEqualityExpression() {
}
break;
}
- return e1.release();
+ return e1;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() {
+std::unique_ptr<CXFA_FMSimpleExpression>
+CXFA_FMParse::ParseRelationalExpression() {
uint32_t line = m_pToken->m_uLinenum;
- std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseAddtiveExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseAddtiveExpression();
for (;;) {
std::unique_ptr<CXFA_FMSimpleExpression> e2;
switch (m_pToken->m_type) {
case TOKlt:
case TOKkslt:
NextToken();
- e2.reset(ParseAddtiveExpression());
+ e2 = ParseAddtiveExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMRelationalExpression(line, TOKlt, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>(
+ line, TOKlt, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -356,10 +356,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() {
case TOKgt:
case TOKksgt:
NextToken();
- e2.reset(ParseAddtiveExpression());
+ e2 = ParseAddtiveExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMRelationalExpression(line, TOKgt, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>(
+ line, TOKgt, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -367,10 +367,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() {
case TOKle:
case TOKksle:
NextToken();
- e2.reset(ParseAddtiveExpression());
+ e2 = ParseAddtiveExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMRelationalExpression(line, TOKle, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>(
+ line, TOKle, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -378,10 +378,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() {
case TOKge:
case TOKksge:
NextToken();
- e2.reset(ParseAddtiveExpression());
+ e2 = ParseAddtiveExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMRelationalExpression(line, TOKge, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMRelationalExpression>(
+ line, TOKge, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -391,31 +391,32 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseRelationalExpression() {
}
break;
}
- return e1.release();
+ return e1;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseAddtiveExpression() {
+std::unique_ptr<CXFA_FMSimpleExpression>
+CXFA_FMParse::ParseAddtiveExpression() {
uint32_t line = m_pToken->m_uLinenum;
- std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseMultiplicativeExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseMultiplicativeExpression();
for (;;) {
std::unique_ptr<CXFA_FMSimpleExpression> e2;
switch (m_pToken->m_type) {
case TOKplus:
NextToken();
- e2.reset(ParseMultiplicativeExpression());
+ e2 = ParseMultiplicativeExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMAdditiveExpression(line, TOKplus, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMAdditiveExpression>(
+ line, TOKplus, e1.release(), e2.release());
} else {
e1.reset();
}
continue;
case TOKminus:
NextToken();
- e2.reset(ParseMultiplicativeExpression());
+ e2 = ParseMultiplicativeExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMAdditiveExpression(line, TOKminus, e1.release(),
- e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMAdditiveExpression>(
+ line, TOKminus, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -425,31 +426,32 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseAddtiveExpression() {
}
break;
}
- return e1.release();
+ return e1;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseMultiplicativeExpression() {
+std::unique_ptr<CXFA_FMSimpleExpression>
+CXFA_FMParse::ParseMultiplicativeExpression() {
uint32_t line = m_pToken->m_uLinenum;
- std::unique_ptr<CXFA_FMSimpleExpression> e1(ParseUnaryExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> e1 = ParseUnaryExpression();
for (;;) {
std::unique_ptr<CXFA_FMSimpleExpression> e2;
switch (m_pToken->m_type) {
case TOKmul:
NextToken();
- e2.reset(ParseUnaryExpression());
+ e2 = ParseUnaryExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMMultiplicativeExpression(
- line, TOKmul, e1.release(), e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMMultiplicativeExpression>(
+ line, TOKmul, e1.release(), e2.release());
} else {
e1.reset();
}
continue;
case TOKdiv:
NextToken();
- e2.reset(ParseUnaryExpression());
+ e2 = ParseUnaryExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e1.reset(new CXFA_FMMultiplicativeExpression(
- line, TOKdiv, e1.release(), e2.release()));
+ e1 = pdfium::MakeUnique<CXFA_FMMultiplicativeExpression>(
+ line, TOKdiv, e1.release(), e2.release());
} else {
e1.reset();
}
@@ -459,83 +461,88 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseMultiplicativeExpression() {
}
break;
}
- return e1.release();
+ return e1;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseUnaryExpression() {
- std::unique_ptr<CXFA_FMSimpleExpression> e;
+std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseUnaryExpression() {
+ std::unique_ptr<CXFA_FMSimpleExpression> expr;
uint32_t line = m_pToken->m_uLinenum;
switch (m_pToken->m_type) {
case TOKplus:
NextToken();
- e.reset(ParseUnaryExpression());
+ expr = ParseUnaryExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMPosExpression(line, e.release()));
+ expr = pdfium::MakeUnique<CXFA_FMPosExpression>(line, expr.release());
} else {
- e.reset();
+ expr.reset();
}
break;
case TOKminus:
NextToken();
- e.reset(ParseUnaryExpression());
+ expr = ParseUnaryExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMNegExpression(line, e.release()));
+ expr = pdfium::MakeUnique<CXFA_FMNegExpression>(line, expr.release());
} else {
- e.reset();
+ expr.reset();
}
break;
case TOKksnot:
NextToken();
- e.reset(ParseUnaryExpression());
+ expr = ParseUnaryExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMNotExpression(line, e.release()));
+ expr = pdfium::MakeUnique<CXFA_FMNotExpression>(line, expr.release());
} else {
- e.reset();
+ expr.reset();
}
break;
default:
- e.reset(ParsePrimaryExpression());
+ expr = ParsePrimaryExpression();
break;
}
- return e.release();
+ return expr;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() {
- std::unique_ptr<CXFA_FMSimpleExpression> e;
+std::unique_ptr<CXFA_FMSimpleExpression>
+CXFA_FMParse::ParsePrimaryExpression() {
+ std::unique_ptr<CXFA_FMSimpleExpression> expr;
uint32_t line = m_pToken->m_uLinenum;
switch (m_pToken->m_type) {
case TOKnumber:
- e.reset(new CXFA_FMNumberExpression(line, m_pToken->m_wstring));
+ expr = pdfium::MakeUnique<CXFA_FMNumberExpression>(line,
+ m_pToken->m_wstring);
NextToken();
break;
case TOKstring:
- e.reset(new CXFA_FMStringExpression(line, m_pToken->m_wstring));
+ expr = pdfium::MakeUnique<CXFA_FMStringExpression>(line,
+ m_pToken->m_wstring);
NextToken();
break;
case TOKidentifier: {
CFX_WideStringC wsIdentifier(m_pToken->m_wstring);
NextToken();
if (m_pToken->m_type == TOKlbracket) {
- CXFA_FMSimpleExpression* s = ParseIndexExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression();
if (s) {
- e.reset(new CXFA_FMDotAccessorExpression(line, nullptr, TOKdot,
- wsIdentifier, s));
+ expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>(
+ line, nullptr, TOKdot, wsIdentifier, s.release());
}
NextToken();
} else {
- e.reset(new CXFA_FMIdentifierExpression(line, wsIdentifier));
+ expr =
+ pdfium::MakeUnique<CXFA_FMIdentifierExpression>(line, wsIdentifier);
}
} break;
case TOKif:
- e.reset(new CXFA_FMIdentifierExpression(line, m_pToken->m_wstring));
+ expr = pdfium::MakeUnique<CXFA_FMIdentifierExpression>(
+ line, m_pToken->m_wstring);
NextToken();
break;
case TOKnull:
- e.reset(new CXFA_FMNullExpression(line));
+ expr = pdfium::MakeUnique<CXFA_FMNullExpression>(line);
NextToken();
break;
case TOKlparen:
- e.reset(ParseParenExpression());
+ expr = ParseParenExpression();
break;
default:
CFX_WideString ws_TempString(m_pToken->m_wstring);
@@ -544,25 +551,25 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePrimaryExpression() {
NextToken();
break;
}
- e.reset(ParsePostExpression(e.release()));
+ expr = ParsePostExpression(std::move(expr));
if (!(m_pErrorInfo->message.IsEmpty()))
- e.reset();
- return e.release();
+ expr.reset();
+ return expr;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
- CXFA_FMSimpleExpression* e) {
+std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression(
+ std::unique_ptr<CXFA_FMSimpleExpression> expr) {
uint32_t line = m_pToken->m_uLinenum;
while (1) {
switch (m_pToken->m_type) {
case TOKlparen: {
NextToken();
- std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pArray;
+ std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> expressions;
if (m_pToken->m_type != TOKrparen) {
- pArray.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>());
while (m_pToken->m_type != TOKrparen) {
- if (CXFA_FMSimpleExpression* expr = ParseSimpleExpression())
- pArray->Add(expr);
+ if (std::unique_ptr<CXFA_FMSimpleExpression> expr =
+ ParseSimpleExpression())
+ expressions.push_back(std::move(expr));
if (m_pToken->m_type == TOKcomma) {
NextToken();
} else if (m_pToken->m_type == TOKeof ||
@@ -577,26 +584,21 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
}
}
if (m_pErrorInfo->message.IsEmpty()) {
- e = new CXFA_FMCallExpression(line, e, pArray.release(), false);
+ expr = pdfium::MakeUnique<CXFA_FMCallExpression>(
+ line, expr.release(), std::move(expressions), false);
NextToken();
- if (m_pToken->m_type != TOKlbracket) {
+ if (m_pToken->m_type != TOKlbracket)
continue;
- }
- CXFA_FMSimpleExpression* s = ParseIndexExpression();
+
+ std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression();
if (s) {
- e = new CXFA_FMDotAccessorExpression(line, e, TOKcall,
- FX_WSTRC(L""), s);
+ expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>(
+ line, expr.release(), TOKcall, FX_WSTRC(L""), s.release());
} else {
- delete e;
- e = nullptr;
+ expr.reset();
}
} else {
- if (pArray) {
- for (int32_t i = 0; i < pArray->GetSize(); ++i)
- delete pArray->GetAt(i);
- }
- delete e;
- e = nullptr;
+ expr.reset();
}
} break;
case TOKdot:
@@ -606,16 +608,14 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
uint32_t tempLine = m_pToken->m_uLinenum;
NextToken();
if (m_pToken->m_type == TOKlparen) {
- CXFA_FMSimpleExpression* pExpAccessor;
- CXFA_FMSimpleExpression* pExpCall;
- pExpAccessor = e;
+ std::unique_ptr<CXFA_FMSimpleExpression> pExpCall;
NextToken();
- std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pArray;
+ std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> expressions;
if (m_pToken->m_type != TOKrparen) {
- pArray.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>());
while (m_pToken->m_type != TOKrparen) {
- CXFA_FMSimpleExpression* exp = ParseSimpleExpression();
- pArray->Add(exp);
+ std::unique_ptr<CXFA_FMSimpleExpression> exp =
+ ParseSimpleExpression();
+ expressions.push_back(std::move(exp));
if (m_pToken->m_type == TOKcomma) {
NextToken();
} else if (m_pToken->m_type == TOKeof ||
@@ -630,50 +630,48 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
}
}
if (m_pErrorInfo->message.IsEmpty()) {
- CXFA_FMSimpleExpression* pIdentifier =
- new CXFA_FMIdentifierExpression(tempLine, tempStr);
- pExpCall = new CXFA_FMCallExpression(line, pIdentifier,
- pArray.release(), true);
- e = new CXFA_FMMethodCallExpression(line, pExpAccessor, pExpCall);
+ std::unique_ptr<CXFA_FMSimpleExpression> pIdentifier =
+ pdfium::MakeUnique<CXFA_FMIdentifierExpression>(tempLine,
+ tempStr);
+ pExpCall = pdfium::MakeUnique<CXFA_FMCallExpression>(
+ line, pIdentifier.release(), std::move(expressions), true);
+ expr = pdfium::MakeUnique<CXFA_FMMethodCallExpression>(
+ line, expr.release(), pExpCall.release());
NextToken();
- if (m_pToken->m_type != TOKlbracket) {
+ if (m_pToken->m_type != TOKlbracket)
continue;
- }
- CXFA_FMSimpleExpression* s = ParseIndexExpression();
+
+ std::unique_ptr<CXFA_FMSimpleExpression> s =
+ ParseIndexExpression();
if (s) {
- e = new CXFA_FMDotAccessorExpression(line, e, TOKcall,
- FX_WSTRC(L""), s);
+ expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>(
+ line, expr.release(), TOKcall, FX_WSTRC(L""), s.release());
} else {
- delete e;
- e = nullptr;
+ expr.reset();
}
} else {
- if (pArray) {
- for (int32_t i = 0; i < pArray->GetSize(); ++i)
- delete pArray->GetAt(i);
- }
- delete e;
- e = nullptr;
+ expr.reset();
}
} else if (m_pToken->m_type == TOKlbracket) {
- std::unique_ptr<CXFA_FMSimpleExpression> s(ParseIndexExpression());
- if (!(m_pErrorInfo->message.IsEmpty())) {
- delete e;
+ std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression();
+ if (!(m_pErrorInfo->message.IsEmpty()))
return nullptr;
- }
- e = new CXFA_FMDotAccessorExpression(tempLine, e, TOKdot, tempStr,
- s.release());
+
+ expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>(
+ tempLine, expr.release(), TOKdot, tempStr, s.release());
} else {
- CXFA_FMSimpleExpression* s = new CXFA_FMIndexExpression(
- tempLine, ACCESSOR_NO_INDEX, nullptr, false);
- e = new CXFA_FMDotAccessorExpression(line, e, TOKdot, tempStr, s);
+ std::unique_ptr<CXFA_FMSimpleExpression> s =
+ pdfium::MakeUnique<CXFA_FMIndexExpression>(
+ tempLine, ACCESSOR_NO_INDEX, nullptr, false);
+ expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>(
+ line, expr.release(), TOKdot, tempStr, s.release());
continue;
}
} else {
CFX_WideString ws_TempString(m_pToken->m_wstring);
Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier,
ws_TempString.c_str());
- return e;
+ return expr;
}
break;
case TOKdotdot:
@@ -683,25 +681,25 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
uint32_t tempLine = m_pToken->m_uLinenum;
NextToken();
if (m_pToken->m_type == TOKlbracket) {
- std::unique_ptr<CXFA_FMSimpleExpression> s(ParseIndexExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression();
if (!(m_pErrorInfo->message.IsEmpty())) {
- delete e;
return nullptr;
}
- e = new CXFA_FMDotDotAccessorExpression(tempLine, e, TOKdotdot,
- tempStr, s.release());
+ expr = pdfium::MakeUnique<CXFA_FMDotDotAccessorExpression>(
+ tempLine, expr.release(), TOKdotdot, tempStr, s.release());
} else {
- CXFA_FMSimpleExpression* s = new CXFA_FMIndexExpression(
- tempLine, ACCESSOR_NO_INDEX, nullptr, false);
- e = new CXFA_FMDotDotAccessorExpression(line, e, TOKdotdot, tempStr,
- s);
+ std::unique_ptr<CXFA_FMSimpleExpression> s =
+ pdfium::MakeUnique<CXFA_FMIndexExpression>(
+ tempLine, ACCESSOR_NO_INDEX, nullptr, false);
+ expr = pdfium::MakeUnique<CXFA_FMDotDotAccessorExpression>(
+ line, expr.release(), TOKdotdot, tempStr, s.release());
continue;
}
} else {
CFX_WideString ws_TempString(m_pToken->m_wstring);
Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier,
ws_TempString.c_str());
- return e;
+ return expr;
}
break;
case TOKdotscream:
@@ -711,50 +709,51 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParsePostExpression(
uint32_t tempLine = m_pToken->m_uLinenum;
NextToken();
if (m_pToken->m_type == TOKlbracket) {
- std::unique_ptr<CXFA_FMSimpleExpression> s(ParseIndexExpression());
- if (!(m_pErrorInfo->message.IsEmpty())) {
- delete e;
+ std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression();
+ if (!(m_pErrorInfo->message.IsEmpty()))
return nullptr;
- }
- e = new CXFA_FMDotAccessorExpression(tempLine, e, TOKdotscream,
- tempStr, s.release());
+
+ expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>(
+ tempLine, expr.release(), TOKdotscream, tempStr, s.release());
} else {
- CXFA_FMSimpleExpression* s = new CXFA_FMIndexExpression(
- tempLine, ACCESSOR_NO_INDEX, nullptr, false);
- e = new CXFA_FMDotAccessorExpression(line, e, TOKdotscream, tempStr,
- s);
+ std::unique_ptr<CXFA_FMSimpleExpression> s =
+ pdfium::MakeUnique<CXFA_FMIndexExpression>(
+ tempLine, ACCESSOR_NO_INDEX, nullptr, false);
+ expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>(
+ line, expr.release(), TOKdotscream, tempStr, s.release());
continue;
}
} else {
CFX_WideString ws_TempString(m_pToken->m_wstring);
Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier,
ws_TempString.c_str());
- return e;
+ return expr;
}
break;
case TOKdotstar: {
- CXFA_FMSimpleExpression* s =
- new CXFA_FMIndexExpression(line, ACCESSOR_NO_INDEX, nullptr, false);
- e = new CXFA_FMDotAccessorExpression(line, e, TOKdotstar,
- FX_WSTRC(L"*"), s);
+ std::unique_ptr<CXFA_FMSimpleExpression> s =
+ pdfium::MakeUnique<CXFA_FMIndexExpression>(line, ACCESSOR_NO_INDEX,
+ nullptr, false);
+ expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>(
+ line, expr.release(), TOKdotstar, FX_WSTRC(L"*"), s.release());
} break;
default:
- return e;
+ return expr;
}
NextToken();
}
- return e;
+ return expr;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() {
+std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseIndexExpression() {
std::unique_ptr<CXFA_FMSimpleExpression> pExp;
uint32_t line = m_pToken->m_uLinenum;
NextToken();
std::unique_ptr<CXFA_FMSimpleExpression> s;
XFA_FM_AccessorIndex accessorIndex = ACCESSOR_NO_RELATIVEINDEX;
if (m_pToken->m_type == TOKmul) {
- pExp.reset(
- new CXFA_FMIndexExpression(line, accessorIndex, s.release(), true));
+ pExp = pdfium::MakeUnique<CXFA_FMIndexExpression>(line, accessorIndex,
+ s.release(), true);
NextToken();
if (m_pToken->m_type != TOKrbracket) {
CFX_WideString ws_TempString(m_pToken->m_wstring);
@@ -762,7 +761,7 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() {
XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
pExp.reset();
}
- return pExp.release();
+ return pExp;
}
if (m_pToken->m_type == TOKplus) {
accessorIndex = ACCESSOR_POSITIVE_INDEX;
@@ -771,19 +770,19 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseIndexExpression() {
accessorIndex = ACCESSOR_NEGATIVE_INDEX;
NextToken();
}
- s.reset(ParseSimpleExpression());
+ s = ParseSimpleExpression();
if (m_pToken->m_type != TOKrbracket) {
CFX_WideString ws_TempString(m_pToken->m_wstring);
Error(m_pToken->m_uLinenum, kFMErrExpectedToken,
XFA_FM_KeywordToString(TOKrparen), ws_TempString.c_str());
} else {
- pExp.reset(
- new CXFA_FMIndexExpression(line, accessorIndex, s.release(), false));
+ pExp = pdfium::MakeUnique<CXFA_FMIndexExpression>(line, accessorIndex,
+ s.release(), false);
}
- return pExp.release();
+ return pExp;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() {
+std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseParenExpression() {
Check(TOKlparen);
if (m_pToken->m_type == TOKrparen) {
@@ -793,27 +792,26 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseParenExpression() {
}
uint32_t line = m_pToken->m_uLinenum;
- std::unique_ptr<CXFA_FMSimpleExpression> pExp1(ParseLogicalOrExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseLogicalOrExpression();
while (m_pToken->m_type == TOKassign) {
NextToken();
- std::unique_ptr<CXFA_FMSimpleExpression> pExp2(ParseLogicalOrExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> pExp2 = ParseLogicalOrExpression();
if (m_pErrorInfo->message.IsEmpty()) {
- pExp1.reset(new CXFA_FMAssignExpression(line, TOKassign, pExp1.release(),
- pExp2.release()));
+ pExp1 = pdfium::MakeUnique<CXFA_FMAssignExpression>(
+ line, TOKassign, pExp1.release(), pExp2.release());
} else {
pExp1.reset();
}
}
Check(TOKrparen);
- return pExp1.release();
+ return pExp1;
}
-CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() {
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseBlockExpression() {
uint32_t line = m_pToken->m_uLinenum;
- CXFA_FMExpression* e = nullptr;
- std::unique_ptr<CFX_ArrayTemplate<CXFA_FMExpression*>> expression(
- new CFX_ArrayTemplate<CXFA_FMExpression*>());
+ std::unique_ptr<CXFA_FMExpression> expr;
+ std::vector<std::unique_ptr<CXFA_FMExpression>> expressions;
while (1) {
switch (m_pToken->m_type) {
@@ -828,15 +826,15 @@ CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() {
case TOKreserver:
break;
case TOKfunc:
- e = ParseFunction();
- if (e) {
- expression->Add(e);
+ expr = ParseFunction();
+ if (expr) {
+ expressions.push_back(std::move(expr));
}
continue;
default:
- e = ParseExpression();
- if (e) {
- expression->Add(e);
+ expr = ParseExpression();
+ if (expr) {
+ expressions.push_back(std::move(expr));
}
continue;
}
@@ -844,22 +842,20 @@ CXFA_FMExpression* CXFA_FMParse::ParseBlockExpression() {
}
std::unique_ptr<CXFA_FMBlockExpression> pExp;
if (m_pErrorInfo->message.IsEmpty()) {
- pExp.reset(new CXFA_FMBlockExpression(line, expression.release()));
- } else {
- for (int i = 0; i < expression->GetSize(); ++i)
- delete static_cast<CXFA_FMExpression*>(expression->GetAt(i));
+ pExp = pdfium::MakeUnique<CXFA_FMBlockExpression>(line,
+ std::move(expressions));
}
- return pExp.release();
+ return pExp;
}
-CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() {
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseIfExpression() {
uint32_t line = m_pToken->m_uLinenum;
const FX_WCHAR* pStartPos = m_lexer->SavePos();
NextToken();
Check(TOKlparen);
std::unique_ptr<CXFA_FMSimpleExpression> pExpression;
while (m_pToken->m_type != TOKrparen) {
- pExpression.reset(ParseSimpleExpression());
+ pExpression = ParseSimpleExpression();
if (m_pToken->m_type != TOKcomma)
break;
NextToken();
@@ -875,7 +871,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() {
return ParseExpExpression();
}
Check(TOKthen);
- std::unique_ptr<CXFA_FMExpression> pIfExpression(ParseBlockExpression());
+ std::unique_ptr<CXFA_FMExpression> pIfExpression = ParseBlockExpression();
std::unique_ptr<CXFA_FMExpression> pElseExpression;
switch (m_pToken->m_type) {
case TOKeof:
@@ -883,15 +879,15 @@ CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() {
Check(TOKendif);
break;
case TOKif:
- pElseExpression.reset(ParseIfExpression());
+ pElseExpression = ParseIfExpression();
Check(TOKendif);
break;
case TOKelseif:
- pElseExpression.reset(ParseIfExpression());
+ pElseExpression = ParseIfExpression();
break;
case TOKelse:
NextToken();
- pElseExpression.reset(ParseBlockExpression());
+ pElseExpression = ParseBlockExpression();
Check(TOKendif);
break;
default:
@@ -902,33 +898,34 @@ CXFA_FMExpression* CXFA_FMParse::ParseIfExpression() {
}
std::unique_ptr<CXFA_FMIfExpression> pExp;
if (m_pErrorInfo->message.IsEmpty()) {
- pExp.reset(new CXFA_FMIfExpression(line, pExpression.release(),
- pIfExpression.release(),
- pElseExpression.release()));
+ pExp = pdfium::MakeUnique<CXFA_FMIfExpression>(line, pExpression.release(),
+ pIfExpression.release(),
+ pElseExpression.release());
}
- return pExp.release();
+ return pExp;
}
-CXFA_FMExpression* CXFA_FMParse::ParseWhileExpression() {
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseWhileExpression() {
uint32_t line = m_pToken->m_uLinenum;
NextToken();
- std::unique_ptr<CXFA_FMSimpleExpression> pCondition(ParseParenExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> pCondition = ParseParenExpression();
Check(TOKdo);
- std::unique_ptr<CXFA_FMExpression> pExpression(ParseBlockExpression());
+ std::unique_ptr<CXFA_FMExpression> pExpression = ParseBlockExpression();
Check(TOKendwhile);
- std::unique_ptr<CXFA_FMExpression> e;
+ std::unique_ptr<CXFA_FMExpression> expr;
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMWhileExpression(line, pCondition.release(),
- pExpression.release()));
+ expr = pdfium::MakeUnique<CXFA_FMWhileExpression>(
+ line, pCondition.release(), pExpression.release());
}
- return e.release();
+ return expr;
}
-CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() {
- std::unique_ptr<CXFA_FMSimpleExpression> e;
+std::unique_ptr<CXFA_FMSimpleExpression>
+CXFA_FMParse::ParseSubassignmentInForExpression() {
+ std::unique_ptr<CXFA_FMSimpleExpression> expr;
switch (m_pToken->m_type) {
case TOKidentifier:
- e.reset(ParseSimpleExpression());
+ expr = ParseSimpleExpression();
break;
default:
CFX_WideString ws_TempString(m_pToken->m_wstring);
@@ -937,10 +934,10 @@ CXFA_FMSimpleExpression* CXFA_FMParse::ParseSubassignmentInForExpression() {
NextToken();
break;
}
- return e.release();
+ return expr;
}
-CXFA_FMExpression* CXFA_FMParse::ParseForExpression() {
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseForExpression() {
CFX_WideStringC wsVariant;
uint32_t line = m_pToken->m_uLinenum;
NextToken();
@@ -954,7 +951,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForExpression() {
std::unique_ptr<CXFA_FMSimpleExpression> pAssignment;
if (m_pToken->m_type == TOKassign) {
NextToken();
- pAssignment.reset(ParseSimpleExpression());
+ pAssignment = ParseSimpleExpression();
} else {
CFX_WideString ws_TempString(m_pToken->m_wstring);
Error(m_pToken->m_uLinenum, kFMErrExpectedToken,
@@ -971,26 +968,26 @@ CXFA_FMExpression* CXFA_FMParse::ParseForExpression() {
ws_TempString.c_str());
}
NextToken();
- std::unique_ptr<CXFA_FMSimpleExpression> pAccessor(ParseSimpleExpression());
+ std::unique_ptr<CXFA_FMSimpleExpression> pAccessor = ParseSimpleExpression();
std::unique_ptr<CXFA_FMSimpleExpression> pStep;
if (m_pToken->m_type == TOKstep) {
NextToken();
- pStep.reset(ParseSimpleExpression());
+ pStep = ParseSimpleExpression();
}
Check(TOKdo);
- std::unique_ptr<CXFA_FMExpression> pList(ParseBlockExpression());
+ std::unique_ptr<CXFA_FMExpression> pList = ParseBlockExpression();
Check(TOKendfor);
- std::unique_ptr<CXFA_FMExpression> e;
+ std::unique_ptr<CXFA_FMExpression> expr;
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMForExpression(line, wsVariant, pAssignment.release(),
- pAccessor.release(), iDirection,
- pStep.release(), pList.release()));
+ expr = pdfium::MakeUnique<CXFA_FMForExpression>(
+ line, wsVariant, pAssignment.release(), pAccessor.release(), iDirection,
+ pStep.release(), pList.release());
}
- return e.release();
+ return expr;
}
-CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
- std::unique_ptr<CXFA_FMExpression> e;
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseForeachExpression() {
+ std::unique_ptr<CXFA_FMExpression> expr;
CFX_WideStringC wsIdentifier;
std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> pAccessors;
std::unique_ptr<CXFA_FMExpression> pList;
@@ -1012,9 +1009,9 @@ CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
NextToken();
} else {
while (m_pToken->m_type != TOKrparen) {
- CXFA_FMSimpleExpression* s = ParseSimpleExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> s = ParseSimpleExpression();
if (s)
- pAccessors.push_back(pdfium::WrapUnique<CXFA_FMSimpleExpression>(s));
+ pAccessors.push_back(std::move(s));
if (m_pToken->m_type != TOKcomma)
break;
NextToken();
@@ -1022,25 +1019,24 @@ CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
Check(TOKrparen);
}
Check(TOKdo);
- pList.reset(ParseBlockExpression());
+ pList = ParseBlockExpression();
Check(TOKendfor);
if (m_pErrorInfo->message.IsEmpty()) {
- e = pdfium::MakeUnique<CXFA_FMForeachExpression>(
+ expr = pdfium::MakeUnique<CXFA_FMForeachExpression>(
line, wsIdentifier, std::move(pAccessors), pList.release());
}
- return e.release();
+ return expr;
}
-CXFA_FMExpression* CXFA_FMParse::ParseDoExpression() {
- std::unique_ptr<CXFA_FMExpression> e;
+std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseDoExpression() {
uint32_t line = m_pToken->m_uLinenum;
NextToken();
- e.reset(ParseBlockExpression());
+ std::unique_ptr<CXFA_FMExpression> expr = ParseBlockExpression();
Check(TOKend);
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMDoExpression(line, e.release()));
+ expr = pdfium::MakeUnique<CXFA_FMDoExpression>(line, expr.release());
} else {
- e.reset();
+ expr.reset();
}
- return e.release();
+ return expr;
}
diff --git a/xfa/fxfa/fm2js/xfa_fmparse.h b/xfa/fxfa/fm2js/xfa_fmparse.h
index 0283edaed0..5f8022f270 100644
--- a/xfa/fxfa/fm2js/xfa_fmparse.h
+++ b/xfa/fxfa/fm2js/xfa_fmparse.h
@@ -8,6 +8,7 @@
#define XFA_FXFA_FM2JS_XFA_FMPARSE_H_
#include <memory>
+#include <vector>
#include "xfa/fxfa/fm2js/xfa_expression.h"
#include "xfa/fxfa/fm2js/xfa_lexer.h"
@@ -21,30 +22,31 @@ class CXFA_FMParse {
void NextToken();
void Check(XFA_FM_TOKEN op);
void Error(uint32_t lineNum, const FX_WCHAR* msg, ...);
- CFX_ArrayTemplate<CXFA_FMExpression*>* ParseTopExpression();
- CXFA_FMExpression* ParseFunction();
- CXFA_FMExpression* ParseExpression();
- CXFA_FMExpression* ParseVarExpression();
- CXFA_FMExpression* ParseExpExpression();
- CXFA_FMExpression* ParseBlockExpression();
- CXFA_FMExpression* ParseIfExpression();
- CXFA_FMExpression* ParseWhileExpression();
- CXFA_FMExpression* ParseForExpression();
- CXFA_FMExpression* ParseForeachExpression();
- CXFA_FMExpression* ParseDoExpression();
- CXFA_FMSimpleExpression* ParseParenExpression();
- CXFA_FMSimpleExpression* ParseSimpleExpression();
- CXFA_FMSimpleExpression* ParseSubassignmentInForExpression();
- CXFA_FMSimpleExpression* ParseLogicalOrExpression();
- CXFA_FMSimpleExpression* ParseLogicalAndExpression();
- CXFA_FMSimpleExpression* ParseEqualityExpression();
- CXFA_FMSimpleExpression* ParseRelationalExpression();
- CXFA_FMSimpleExpression* ParseAddtiveExpression();
- CXFA_FMSimpleExpression* ParseMultiplicativeExpression();
- CXFA_FMSimpleExpression* ParseUnaryExpression();
- CXFA_FMSimpleExpression* ParsePrimaryExpression();
- CXFA_FMSimpleExpression* ParsePostExpression(CXFA_FMSimpleExpression* e);
- CXFA_FMSimpleExpression* ParseIndexExpression();
+ std::vector<std::unique_ptr<CXFA_FMExpression>> ParseTopExpression();
+ std::unique_ptr<CXFA_FMExpression> ParseFunction();
+ std::unique_ptr<CXFA_FMExpression> ParseExpression();
+ std::unique_ptr<CXFA_FMExpression> ParseVarExpression();
+ std::unique_ptr<CXFA_FMExpression> ParseExpExpression();
+ std::unique_ptr<CXFA_FMExpression> ParseBlockExpression();
+ std::unique_ptr<CXFA_FMExpression> ParseIfExpression();
+ std::unique_ptr<CXFA_FMExpression> ParseWhileExpression();
+ std::unique_ptr<CXFA_FMExpression> ParseForExpression();
+ std::unique_ptr<CXFA_FMExpression> ParseForeachExpression();
+ std::unique_ptr<CXFA_FMExpression> ParseDoExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseParenExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseSimpleExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseSubassignmentInForExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseLogicalOrExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseLogicalAndExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseEqualityExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseRelationalExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseAddtiveExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseMultiplicativeExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseUnaryExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParsePrimaryExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParsePostExpression(
+ std::unique_ptr<CXFA_FMSimpleExpression> e);
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseIndexExpression();
private:
std::unique_ptr<CXFA_FMLexer> m_lexer;
diff --git a/xfa/fxfa/fm2js/xfa_program.cpp b/xfa/fxfa/fm2js/xfa_program.cpp
index 5146a5e129..ac18c15e6d 100644
--- a/xfa/fxfa/fm2js/xfa_program.cpp
+++ b/xfa/fxfa/fm2js/xfa_program.cpp
@@ -6,6 +6,11 @@
#include "xfa/fxfa/fm2js/xfa_program.h"
+#include <utility>
+#include <vector>
+
+#include "third_party/base/ptr_util.h"
+
CXFA_FMProgram::CXFA_FMProgram() {}
CXFA_FMProgram::~CXFA_FMProgram() {}
@@ -15,21 +20,17 @@ int32_t CXFA_FMProgram::Init(const CFX_WideStringC& wsFormcalc) {
}
int32_t CXFA_FMProgram::ParseProgram() {
- CFX_ArrayTemplate<CXFA_FMExpression*>* expressions = nullptr;
m_parse.NextToken();
- if (!m_pErrorInfo.message.IsEmpty()) {
+ if (!m_pErrorInfo.message.IsEmpty())
return -1;
- }
- expressions = m_parse.ParseTopExpression();
- if (!m_pErrorInfo.message.IsEmpty()) {
- for (int32_t u = 0; u < expressions->GetSize(); ++u)
- delete expressions->GetAt(u);
- delete expressions;
+ std::vector<std::unique_ptr<CXFA_FMExpression>> expressions =
+ m_parse.ParseTopExpression();
+ if (!m_pErrorInfo.message.IsEmpty())
return -1;
- }
- m_globalFunction.reset(
- new CXFA_FMFunctionDefinition(1, 1, FX_WSTRC(L""), nullptr, expressions));
+
+ m_globalFunction = pdfium::MakeUnique<CXFA_FMFunctionDefinition>(
+ 1, true, L"", nullptr, std::move(expressions));
return 0;
}
diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp
index be02e51ec4..e52cd88979 100644
--- a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp
+++ b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp
@@ -6,6 +6,8 @@
#include "xfa/fxfa/fm2js/xfa_simpleexpression.h"
+#include <utility>
+
#include "core/fxcrt/fx_ext.h"
namespace {
@@ -477,20 +479,13 @@ void CXFA_FMNotExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
CXFA_FMCallExpression::CXFA_FMCallExpression(
uint32_t line,
CXFA_FMSimpleExpression* pExp,
- CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* pArguments,
+ std::vector<std::unique_ptr<CXFA_FMSimpleExpression>>&& pArguments,
bool bIsSomMethod)
: CXFA_FMUnaryExpression(line, TOKcall, pExp),
m_bIsSomMethod(bIsSomMethod),
- m_pArguments(pArguments) {}
-
-CXFA_FMCallExpression::~CXFA_FMCallExpression() {
- if (m_pArguments) {
- for (int i = 0; i < m_pArguments->GetSize(); ++i)
- delete m_pArguments->GetAt(i);
+ m_Arguments(std::move(pArguments)) {}
- delete m_pArguments;
- }
-}
+CXFA_FMCallExpression::~CXFA_FMCallExpression() {}
bool CXFA_FMCallExpression::IsBuildInFunc(CFX_WideTextBuf* funcName) {
uint32_t uHash = FX_HashCode_GetW(funcName->AsStringC(), true);
@@ -536,41 +531,37 @@ void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
m_pExp->ToJavaScript(funcName);
if (m_bIsSomMethod) {
javascript << funcName;
- javascript << FX_WSTRC(L"(");
- if (m_pArguments) {
- uint32_t methodPara = IsMethodWithObjParam(funcName.AsStringC());
- if (methodPara > 0) {
- for (int i = 0; i < m_pArguments->GetSize(); ++i) {
- // Currently none of our expressions use objects for a parameter over
- // the 6th. Make sure we don't overflow the shift when doing this
- // check. If we ever need more the 32 object params we can revisit.
- if (i < 32 && (methodPara & (0x01 << i)) > 0) {
- javascript << gs_lpStrExpFuncName[GETFMJSOBJ];
- } else {
- javascript << gs_lpStrExpFuncName[GETFMVALUE];
- }
- javascript << FX_WSTRC(L"(");
- CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i);
- e->ToJavaScript(javascript);
- javascript << FX_WSTRC(L")");
- if (i + 1 < m_pArguments->GetSize()) {
- javascript << FX_WSTRC(L", ");
- }
- }
- } else {
- for (int i = 0; i < m_pArguments->GetSize(); ++i) {
+ javascript << L"(";
+ uint32_t methodPara = IsMethodWithObjParam(funcName.AsStringC());
+ if (methodPara > 0) {
+ for (size_t i = 0; i < m_Arguments.size(); ++i) {
+ // Currently none of our expressions use objects for a parameter over
+ // the 6th. Make sure we don't overflow the shift when doing this
+ // check. If we ever need more the 32 object params we can revisit.
+ if (i < 32 && (methodPara & (0x01 << i)) > 0) {
+ javascript << gs_lpStrExpFuncName[GETFMJSOBJ];
+ } else {
javascript << gs_lpStrExpFuncName[GETFMVALUE];
- javascript << FX_WSTRC(L"(");
- CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i);
- e->ToJavaScript(javascript);
- javascript << FX_WSTRC(L")");
- if (i + 1 < m_pArguments->GetSize()) {
- javascript << FX_WSTRC(L", ");
- }
}
+ javascript << L"(";
+ const auto& expr = m_Arguments[i];
+ expr->ToJavaScript(javascript);
+ javascript << L")";
+ if (i + 1 < m_Arguments.size()) {
+ javascript << L", ";
+ }
+ }
+ } else {
+ for (const auto& expr : m_Arguments) {
+ javascript << gs_lpStrExpFuncName[GETFMVALUE];
+ javascript << L"(";
+ expr->ToJavaScript(javascript);
+ javascript << L")";
+ if (expr != m_Arguments.back())
+ javascript << L", ";
}
}
- javascript << FX_WSTRC(L")");
+ javascript << L")";
} else {
bool isEvalFunc = false;
bool isExistsFunc = false;
@@ -594,28 +585,26 @@ void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << FX_WSTRC(L"(");
if (isExistsFunc) {
javascript << FX_WSTRC(L"\n(\nfunction ()\n{\ntry\n{\n");
- if (m_pArguments && m_pArguments->GetSize() > 0) {
- CXFA_FMSimpleExpression* e = m_pArguments->GetAt(0);
+ if (!m_Arguments.empty()) {
+ const auto& expr = m_Arguments[0];
javascript << FX_WSTRC(L"return ");
- e->ToJavaScript(javascript);
+ expr->ToJavaScript(javascript);
javascript << FX_WSTRC(L";\n}\n");
} else {
javascript << FX_WSTRC(L"return 0;\n}\n");
}
javascript << FX_WSTRC(
L"catch(accessExceptions)\n{\nreturn 0;\n}\n}\n).call(this)\n");
- } else if (m_pArguments) {
- for (int i = 0; i < m_pArguments->GetSize(); ++i) {
- CXFA_FMSimpleExpression* e = m_pArguments->GetAt(i);
- e->ToJavaScript(javascript);
- if (i + 1 < m_pArguments->GetSize()) {
- javascript << FX_WSTRC(L", ");
- }
+ } else {
+ for (const auto& expr : m_Arguments) {
+ expr->ToJavaScript(javascript);
+ if (expr != m_Arguments.back())
+ javascript << L", ";
}
}
- javascript << FX_WSTRC(L")");
+ javascript << L")";
if (isEvalFunc) {
- javascript << FX_WSTRC(L")");
+ javascript << L")";
}
}
}
diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression.h b/xfa/fxfa/fm2js/xfa_simpleexpression.h
index 6c1e6257bd..c96d990b08 100644
--- a/xfa/fxfa/fm2js/xfa_simpleexpression.h
+++ b/xfa/fxfa/fm2js/xfa_simpleexpression.h
@@ -8,6 +8,7 @@
#define XFA_FXFA_FM2JS_XFA_SIMPLEEXPRESSION_H_
#include <memory>
+#include <vector>
#include "core/fxcrt/fx_basic.h"
#include "xfa/fxfa/fm2js/xfa_lexer.h"
@@ -228,10 +229,11 @@ class CXFA_FMNotExpression : public CXFA_FMUnaryExpression {
class CXFA_FMCallExpression : public CXFA_FMUnaryExpression {
public:
- CXFA_FMCallExpression(uint32_t line,
- CXFA_FMSimpleExpression* pExp,
- CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* pArguments,
- bool bIsSomMethod);
+ CXFA_FMCallExpression(
+ uint32_t line,
+ CXFA_FMSimpleExpression* pExp,
+ std::vector<std::unique_ptr<CXFA_FMSimpleExpression>>&& pArguments,
+ bool bIsSomMethod);
~CXFA_FMCallExpression() override;
bool IsBuildInFunc(CFX_WideTextBuf* funcName);
@@ -240,7 +242,7 @@ class CXFA_FMCallExpression : public CXFA_FMUnaryExpression {
private:
bool m_bIsSomMethod;
- CFX_ArrayTemplate<CXFA_FMSimpleExpression*>* m_pArguments;
+ std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> m_Arguments;
};
class CXFA_FMDotAccessorExpression : public CXFA_FMBinExpression {
diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp b/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp
index 534fc18a6f..d54921f99a 100644
--- a/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp
+++ b/xfa/fxfa/fm2js/xfa_simpleexpression_unittest.cpp
@@ -5,21 +5,21 @@
#include "xfa/fxfa/fm2js/xfa_simpleexpression.h"
#include <memory>
+#include <utility>
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fxfa/fm2js/xfa_lexer.h"
TEST(FMCallExpression, more_than_32_arguments) {
// Use sign as it has 3 object parameters at positions 0, 5, and 6.
- std::unique_ptr<CXFA_FMIdentifierExpression> exp(
- new CXFA_FMIdentifierExpression(0, CFX_WideStringC(L"sign")));
+ auto exp = pdfium::MakeUnique<CXFA_FMIdentifierExpression>(0, L"sign");
- std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> args(
- new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>());
+ std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> args;
for (size_t i = 0; i < 50; i++)
- args->Add(new CXFA_FMSimpleExpression(0, TOKnan));
+ args.push_back(pdfium::MakeUnique<CXFA_FMSimpleExpression>(0, TOKnan));
- CXFA_FMCallExpression callExp(0, exp.release(), args.release(), true);
+ CXFA_FMCallExpression callExp(0, exp.release(), std::move(args), true);
CFX_WideTextBuf js;
callExp.ToJavaScript(js);