summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2018-02-19 18:10:34 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-19 18:10:34 +0000
commit6a5b1c96e23bd684d9fec2c59e0d4bc5d883650c (patch)
treeb6ba4042b3e6ad51d240b69e3cec78891e3b583c /xfa/fxfa
parentc8785f736df57d7d20649d803818a30eb55b2ee8 (diff)
downloadpdfium-6a5b1c96e23bd684d9fec2c59e0d4bc5d883650c.tar.xz
Merge FormCalc to JavaScript methods
This CL merges the ToJavaScript and the ToImpliedJS methods in the FormCalc expressions. The type of return is passed as a paramter to ToJavaScript. Change-Id: Idff83677bc70b964d95aa6ff6b0e2c1bf8c603ea Reviewed-on: https://pdfium-review.googlesource.com/27210 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmexpression.cpp396
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmexpression.h42
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp8
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp177
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h66
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp16
6 files changed, 241 insertions, 464 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
index 759a875b8d..40827f8652 100644
--- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
@@ -31,12 +31,8 @@ CXFA_FMExpression::CXFA_FMExpression(uint32_t line)
CXFA_FMExpression::CXFA_FMExpression(uint32_t line, XFA_FM_EXPTYPE type)
: m_type(type), m_line(line) {}
-bool CXFA_FMExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
-}
-
-bool CXFA_FMExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
+bool CXFA_FMExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
}
@@ -55,8 +51,13 @@ CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition(
CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() {}
-bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
+ if (type == ReturnType::kImplied) {
+ return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
+ }
+
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -96,9 +97,9 @@ bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) {
for (const auto& expr : m_pExpressions) {
bool ret;
if (expr == m_pExpressions.back())
- ret = expr->ToImpliedReturnJS(javascript);
+ ret = expr->ToJavaScript(javascript, ReturnType::kImplied);
else
- ret = expr->ToJavaScript(javascript);
+ ret = expr->ToJavaScript(javascript, ReturnType::kInfered);
if (!ret)
return false;
@@ -119,11 +120,6 @@ bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) {
return !CXFA_IsTooBig(javascript);
}
-bool CXFA_FMFunctionDefinition::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
-}
-
CXFA_FMVarExpression::CXFA_FMVarExpression(
uint32_t line,
const WideStringView& wsName,
@@ -134,7 +130,8 @@ CXFA_FMVarExpression::CXFA_FMVarExpression(
CXFA_FMVarExpression::~CXFA_FMVarExpression() {}
-bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -148,7 +145,7 @@ bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << tempName;
javascript << L" = ";
if (m_pInit) {
- if (!m_pInit->ToJavaScript(javascript))
+ if (!m_pInit->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << tempName;
javascript << L" = ";
@@ -159,38 +156,13 @@ bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
} else {
javascript << L"\"\";\n";
}
- return !CXFA_IsTooBig(javascript);
-}
-
-bool CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
- javascript << L"var ";
- WideString tempName(m_wsName);
- if (m_wsName[0] == L'!') {
- tempName =
- EXCLAMATION_IN_IDENTIFIER + m_wsName.Right(m_wsName.GetLength() - 1);
- }
- javascript << tempName;
- javascript << L" = ";
- if (m_pInit) {
- if (!m_pInit->ToJavaScript(javascript))
- return false;
- javascript << tempName;
+ if (type == ReturnType::kImplied) {
+ javascript << RUNTIMEFUNCTIONRETURNVALUE;
javascript << L" = ";
- javascript << XFA_FM_EXPTypeToString(VARFILTER);
- javascript << L"(";
javascript << tempName;
- javascript << L");\n";
- } else {
- javascript << L"\"\";\n";
+ javascript << L";\n";
}
- javascript << RUNTIMEFUNCTIONRETURNVALUE;
- javascript << L" = ";
- javascript << tempName;
- javascript << L";\n";
return !CXFA_IsTooBig(javascript);
}
@@ -202,24 +174,21 @@ CXFA_FMExpExpression::CXFA_FMExpExpression(
CXFA_FMExpExpression::~CXFA_FMExpExpression() {}
-bool CXFA_FMExpExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMExpExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
- bool ret = m_pExpression->ToJavaScript(javascript);
- if (m_pExpression->GetOperatorToken() != TOKassign)
- javascript << L";\n";
- return ret;
-}
-
-bool CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
+ if (type == ReturnType::kInfered) {
+ bool ret = m_pExpression->ToJavaScript(javascript, ReturnType::kInfered);
+ if (m_pExpression->GetOperatorToken() != TOKassign)
+ javascript << L";\n";
+ return ret;
+ }
if (m_pExpression->GetOperatorToken() == TOKassign)
- return m_pExpression->ToImpliedReturnJS(javascript);
+ return m_pExpression->ToJavaScript(javascript, ReturnType::kImplied);
if (m_pExpression->GetOperatorToken() == TOKstar ||
m_pExpression->GetOperatorToken() == TOKdotstar ||
@@ -230,7 +199,7 @@ bool CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
javascript << L" = ";
javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
javascript << L"(";
- if (!m_pExpression->ToJavaScript(javascript))
+ if (!m_pExpression->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L");\n";
return !CXFA_IsTooBig(javascript);
@@ -238,7 +207,7 @@ bool CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
javascript << RUNTIMEFUNCTIONRETURNVALUE;
javascript << L" = ";
- if (!m_pExpression->ToJavaScript(javascript))
+ if (!m_pExpression->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L";\n";
return !CXFA_IsTooBig(javascript);
@@ -252,35 +221,27 @@ CXFA_FMBlockExpression::CXFA_FMBlockExpression(
CXFA_FMBlockExpression::~CXFA_FMBlockExpression() {}
-bool CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
javascript << L"{\n";
for (const auto& expr : m_ExpressionList) {
- if (!expr->ToJavaScript(javascript))
- return false;
- }
- javascript << L"}\n";
- return !CXFA_IsTooBig(javascript);
-}
-
-bool CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
-
- javascript << L"{\n";
- for (const auto& expr : m_ExpressionList) {
- bool ret;
- if (expr == m_ExpressionList.back())
- ret = expr->ToImpliedReturnJS(javascript);
- else
- ret = expr->ToJavaScript(javascript);
+ if (type == ReturnType::kInfered) {
+ if (!expr->ToJavaScript(javascript, ReturnType::kInfered))
+ return false;
+ } else {
+ bool ret;
+ if (expr == m_ExpressionList.back())
+ ret = expr->ToJavaScript(javascript, ReturnType::kImplied);
+ else
+ ret = expr->ToJavaScript(javascript, ReturnType::kInfered);
- if (!ret)
- return false;
+ if (!ret)
+ return false;
+ }
}
javascript << L"}\n";
return !CXFA_IsTooBig(javascript);
@@ -293,20 +254,13 @@ CXFA_FMDoExpression::CXFA_FMDoExpression(
CXFA_FMDoExpression::~CXFA_FMDoExpression() {}
-bool CXFA_FMDoExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMDoExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
- return m_pList->ToJavaScript(javascript);
-}
-
-bool CXFA_FMDoExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
-
- return m_pList->ToImpliedReturnJS(javascript);
+ return m_pList->ToJavaScript(javascript, type);
}
CXFA_FMIfExpression::CXFA_FMIfExpression(
@@ -321,58 +275,22 @@ CXFA_FMIfExpression::CXFA_FMIfExpression(
CXFA_FMIfExpression::~CXFA_FMIfExpression() {}
-bool CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
- javascript << L"if (";
- if (m_pExpression) {
- javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
- javascript << L"(";
- if (!m_pExpression->ToJavaScript(javascript))
- return false;
- javascript << L")";
- }
- javascript << L")\n";
- if (CXFA_IsTooBig(javascript))
- return false;
-
- if (m_pIfExpression) {
- if (!m_pIfExpression->ToJavaScript(javascript))
- return false;
- if (CXFA_IsTooBig(javascript))
- return false;
+ if (type == ReturnType::kImplied) {
+ javascript << RUNTIMEFUNCTIONRETURNVALUE;
+ javascript << L" = 0;\n";
}
- if (m_pElseExpression) {
- if (m_pElseExpression->GetExpType() == XFA_FM_EXPTYPE_IF) {
- javascript << L"else\n";
- javascript << L"{\n";
- if (!m_pElseExpression->ToJavaScript(javascript))
- return false;
- javascript << L"}\n";
- } else {
- javascript << L"else\n";
- if (!m_pElseExpression->ToJavaScript(javascript))
- return false;
- }
- }
- return !CXFA_IsTooBig(javascript);
-}
-
-bool CXFA_FMIfExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
-
- javascript << RUNTIMEFUNCTIONRETURNVALUE;
- javascript << L" = 0;\n";
javascript << L"if (";
if (m_pExpression) {
javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
javascript << L"(";
- if (!m_pExpression->ToJavaScript(javascript))
+ if (!m_pExpression->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
}
@@ -381,21 +299,22 @@ bool CXFA_FMIfExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
return false;
if (m_pIfExpression) {
- if (!m_pIfExpression->ToImpliedReturnJS(javascript))
+ if (!m_pIfExpression->ToJavaScript(javascript, type))
return false;
if (CXFA_IsTooBig(javascript))
return false;
}
+
if (m_pElseExpression) {
if (m_pElseExpression->GetExpType() == XFA_FM_EXPTYPE_IF) {
javascript << L"else\n";
javascript << L"{\n";
- if (!m_pElseExpression->ToImpliedReturnJS(javascript))
+ if (!m_pElseExpression->ToJavaScript(javascript, type))
return false;
javascript << L"}\n";
} else {
javascript << L"else\n";
- if (!m_pElseExpression->ToImpliedReturnJS(javascript))
+ if (!m_pElseExpression->ToJavaScript(javascript, type))
return false;
}
}
@@ -404,12 +323,8 @@ bool CXFA_FMIfExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
CXFA_FMLoopExpression::~CXFA_FMLoopExpression() {}
-bool CXFA_FMLoopExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
-}
-
-bool CXFA_FMLoopExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
+bool CXFA_FMLoopExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
}
@@ -424,38 +339,25 @@ CXFA_FMWhileExpression::CXFA_FMWhileExpression(
CXFA_FMWhileExpression::~CXFA_FMWhileExpression() {}
-bool CXFA_FMWhileExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMWhileExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
- javascript << L"while (";
- if (!m_pCondition->ToJavaScript(javascript))
- return false;
- javascript << L")\n";
- if (CXFA_IsTooBig(javascript))
- return false;
-
- if (!m_pExpression->ToJavaScript(javascript))
- return false;
- return !CXFA_IsTooBig(javascript);
-}
-
-bool CXFA_FMWhileExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
+ if (type == ReturnType::kImplied) {
+ javascript << RUNTIMEFUNCTIONRETURNVALUE;
+ javascript << L" = 0;\n";
+ }
- javascript << RUNTIMEFUNCTIONRETURNVALUE;
- javascript << L" = 0;\n";
javascript << L"while (";
- if (!m_pCondition->ToJavaScript(javascript))
+ if (!m_pCondition->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")\n";
if (CXFA_IsTooBig(javascript))
return false;
- if (!m_pExpression->ToImpliedReturnJS(javascript))
+ if (!m_pExpression->ToJavaScript(javascript, type))
return false;
return !CXFA_IsTooBig(javascript);
}
@@ -465,18 +367,8 @@ CXFA_FMBreakExpression::CXFA_FMBreakExpression(uint32_t line)
CXFA_FMBreakExpression::~CXFA_FMBreakExpression() {}
-bool CXFA_FMBreakExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
-
- javascript << RUNTIMEFUNCTIONRETURNVALUE;
- javascript << L" = 0;\n";
- javascript << L"break;\n";
- return !CXFA_IsTooBig(javascript);
-}
-
-bool CXFA_FMBreakExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
+bool CXFA_FMBreakExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -492,18 +384,8 @@ CXFA_FMContinueExpression::CXFA_FMContinueExpression(uint32_t line)
CXFA_FMContinueExpression::~CXFA_FMContinueExpression() {}
-bool CXFA_FMContinueExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
-
- javascript << RUNTIMEFUNCTIONRETURNVALUE;
- javascript << L" = 0;\n";
- javascript << L"continue;\n";
- return !CXFA_IsTooBig(javascript);
-}
-
-bool CXFA_FMContinueExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
+bool CXFA_FMContinueExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -532,66 +414,17 @@ CXFA_FMForExpression::CXFA_FMForExpression(
CXFA_FMForExpression::~CXFA_FMForExpression() {}
-bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
- javascript << L"{\nvar ";
- WideString tempVariant;
- if (m_wsVariant[0] == L'!') {
- tempVariant = EXCLAMATION_IN_IDENTIFIER +
- m_wsVariant.Right(m_wsVariant.GetLength() - 1);
- javascript << tempVariant;
- } else {
- tempVariant = m_wsVariant;
- javascript << m_wsVariant;
- }
- javascript << L" = null;\n";
- javascript << L"for (";
- javascript << tempVariant;
- javascript << L" = ";
- javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
- javascript << L"(";
- if (!m_pAssignment->ToJavaScript(javascript))
- return false;
- javascript << L"); ";
- javascript << tempVariant;
-
- javascript << (m_bDirection ? kLessEqual : kGreaterEqual);
- javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
- javascript << L"(";
- if (!m_pAccessor->ToJavaScript(javascript))
- return false;
- javascript << L"); ";
- javascript << tempVariant;
- javascript << (m_bDirection ? kPlusEqual : kMinusEqual);
- if (CXFA_IsTooBig(javascript))
- return false;
-
- if (m_pStep) {
- javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
- javascript << L"(";
- if (!m_pStep->ToJavaScript(javascript))
- return false;
- javascript << L")";
- } else {
- javascript << L"1";
+ if (type == ReturnType::kImplied) {
+ javascript << RUNTIMEFUNCTIONRETURNVALUE;
+ javascript << L" = 0;\n";
}
- javascript << L")\n";
- if (!m_pList->ToJavaScript(javascript))
- return false;
- javascript << L"}\n";
- return !CXFA_IsTooBig(javascript);
-}
-
-bool CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
- javascript << RUNTIMEFUNCTIONRETURNVALUE;
- javascript << L" = 0;\n";
javascript << L"{\nvar ";
WideString tempVariant;
if (m_wsVariant[0] == L'!') {
@@ -608,7 +441,7 @@ bool CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
javascript << L" = ";
javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
javascript << L"(";
- if (!m_pAssignment->ToJavaScript(javascript))
+ if (!m_pAssignment->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L"); ";
javascript << tempVariant;
@@ -616,7 +449,7 @@ bool CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
javascript << (m_bDirection ? kLessEqual : kGreaterEqual);
javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
javascript << L"(";
- if (!m_pAccessor->ToJavaScript(javascript))
+ if (!m_pAccessor->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L"); ";
javascript << tempVariant;
@@ -628,16 +461,17 @@ bool CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
if (m_pStep) {
javascript << XFA_FM_EXPTypeToString(GETFMVALUE);
javascript << L"(";
- if (!m_pStep->ToJavaScript(javascript))
+ if (!m_pStep->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
- if (CXFA_IsTooBig(javascript))
- return false;
} else {
javascript << L"1";
}
+ if (CXFA_IsTooBig(javascript))
+ return false;
+
javascript << L")\n";
- if (!m_pList->ToImpliedReturnJS(javascript))
+ if (!m_pList->ToJavaScript(javascript, type))
return false;
javascript << L"}\n";
return !CXFA_IsTooBig(javascript);
@@ -655,70 +489,17 @@ CXFA_FMForeachExpression::CXFA_FMForeachExpression(
CXFA_FMForeachExpression::~CXFA_FMForeachExpression() {}
-bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
- javascript << L"{\n";
- javascript << L"var ";
- if (m_wsIdentifier[0] == L'!') {
- WideString tempIdentifier =
- EXCLAMATION_IN_IDENTIFIER +
- m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
- javascript << tempIdentifier;
- } else {
- javascript << m_wsIdentifier;
- }
- javascript << L" = null;\n";
- javascript << L"var ";
- javascript << RUNTIMEBLOCKTEMPARRAY;
- javascript << L" = ";
- javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
- javascript << L"(";
-
- for (const auto& expr : m_pAccessors) {
- if (!expr->ToJavaScript(javascript))
- return false;
- if (expr != m_pAccessors.back())
- javascript << L", ";
- }
- javascript << L");\n";
- javascript << L"var ";
- javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
- javascript << (L" = 0;\n");
- javascript << L"while(";
- javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
- javascript << L" < ";
- javascript << RUNTIMEBLOCKTEMPARRAY;
- javascript << L".length)\n{\n";
- if (m_wsIdentifier[0] == L'!') {
- WideString tempIdentifier =
- EXCLAMATION_IN_IDENTIFIER +
- m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
- javascript << tempIdentifier;
- } else {
- javascript << m_wsIdentifier;
+ if (type == ReturnType::kImplied) {
+ javascript << RUNTIMEFUNCTIONRETURNVALUE;
+ javascript << L" = 0;\n";
}
- javascript << L" = ";
- javascript << RUNTIMEBLOCKTEMPARRAY;
- javascript << L"[";
- javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
- javascript << L"++];\n";
- if (!m_pList->ToJavaScript(javascript))
- return false;
- javascript << L"}\n";
- javascript << L"}\n";
- return !CXFA_IsTooBig(javascript);
-}
-
-bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
- javascript << RUNTIMEFUNCTIONRETURNVALUE;
- javascript << L" = 0;\n";
javascript << L"{\n";
javascript << L"var ";
if (m_wsIdentifier[0] == L'!') {
@@ -735,8 +516,9 @@ bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
javascript << L" = ";
javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT);
javascript << L"(";
+
for (const auto& expr : m_pAccessors) {
- if (!expr->ToJavaScript(javascript))
+ if (!expr->ToJavaScript(javascript, ReturnType::kInfered))
return false;
if (expr != m_pAccessors.back())
javascript << L", ";
@@ -744,7 +526,7 @@ bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
javascript << L");\n";
javascript << L"var ";
javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
- javascript << L" = 0;\n";
+ javascript << (L" = 0;\n");
javascript << L"while(";
javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
javascript << L" < ";
@@ -763,7 +545,7 @@ bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
javascript << L"[";
javascript << RUNTIMEBLOCKTEMPARRAYINDEX;
javascript << L"++];\n";
- if (!m_pList->ToImpliedReturnJS(javascript))
+ if (!m_pList->ToJavaScript(javascript, type))
return false;
javascript << L"}\n";
javascript << L"}\n";
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.h b/xfa/fxfa/fm2js/cxfa_fmexpression.h
index cfbba3af22..104b8976a5 100644
--- a/xfa/fxfa/fm2js/cxfa_fmexpression.h
+++ b/xfa/fxfa/fm2js/cxfa_fmexpression.h
@@ -31,8 +31,7 @@ class CXFA_FMExpression {
CXFA_FMExpression(uint32_t line, XFA_FM_EXPTYPE type);
virtual ~CXFA_FMExpression() {}
- virtual bool ToJavaScript(CFX_WideTextBuf& javascript);
- virtual bool ToImpliedReturnJS(CFX_WideTextBuf&);
+ virtual bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type);
uint32_t GetLine() { return m_line; }
XFA_FM_EXPTYPE GetExpType() const { return m_type; }
@@ -52,8 +51,7 @@ class CXFA_FMFunctionDefinition : public CXFA_FMExpression {
std::vector<std::unique_ptr<CXFA_FMExpression>>&& expressions);
~CXFA_FMFunctionDefinition() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsName;
@@ -69,8 +67,7 @@ class CXFA_FMVarExpression : public CXFA_FMExpression {
std::unique_ptr<CXFA_FMExpression> pInit);
~CXFA_FMVarExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsName;
@@ -83,8 +80,7 @@ class CXFA_FMExpExpression : public CXFA_FMExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExpression);
~CXFA_FMExpExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
std::unique_ptr<CXFA_FMSimpleExpression> m_pExpression;
@@ -97,8 +93,7 @@ class CXFA_FMBlockExpression : public CXFA_FMExpression {
std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressionList);
~CXFA_FMBlockExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
std::vector<std::unique_ptr<CXFA_FMExpression>> m_ExpressionList;
@@ -109,8 +104,7 @@ class CXFA_FMDoExpression : public CXFA_FMExpression {
CXFA_FMDoExpression(uint32_t line, std::unique_ptr<CXFA_FMExpression> pList);
~CXFA_FMDoExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
std::unique_ptr<CXFA_FMExpression> m_pList;
@@ -124,8 +118,7 @@ class CXFA_FMIfExpression : public CXFA_FMExpression {
std::unique_ptr<CXFA_FMExpression> pElseExpression);
~CXFA_FMIfExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
std::unique_ptr<CXFA_FMSimpleExpression> m_pExpression;
@@ -137,8 +130,8 @@ class CXFA_FMLoopExpression : public CXFA_FMExpression {
public:
explicit CXFA_FMLoopExpression(uint32_t line) : CXFA_FMExpression(line) {}
~CXFA_FMLoopExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMWhileExpression : public CXFA_FMLoopExpression {
@@ -148,8 +141,7 @@ class CXFA_FMWhileExpression : public CXFA_FMLoopExpression {
std::unique_ptr<CXFA_FMExpression> pExpression);
~CXFA_FMWhileExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
std::unique_ptr<CXFA_FMSimpleExpression> m_pCondition;
@@ -160,16 +152,16 @@ class CXFA_FMBreakExpression : public CXFA_FMExpression {
public:
explicit CXFA_FMBreakExpression(uint32_t line);
~CXFA_FMBreakExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMContinueExpression : public CXFA_FMExpression {
public:
explicit CXFA_FMContinueExpression(uint32_t line);
~CXFA_FMContinueExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMForExpression : public CXFA_FMLoopExpression {
@@ -183,8 +175,7 @@ class CXFA_FMForExpression : public CXFA_FMLoopExpression {
std::unique_ptr<CXFA_FMExpression> pList);
~CXFA_FMForExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsVariant;
@@ -205,8 +196,7 @@ class CXFA_FMForeachExpression : public CXFA_FMLoopExpression {
std::unique_ptr<CXFA_FMExpression> pList);
~CXFA_FMForeachExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf&) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsIdentifier;
diff --git a/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
index 8582649fec..233fb8633b 100644
--- a/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
@@ -20,7 +20,7 @@ TEST(CXFA_FMParserTest, Empty) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf buf;
- EXPECT_TRUE(ast->ToJavaScript(buf));
+ EXPECT_TRUE(ast->ToJavaScript(buf, ReturnType::kInfered));
// TODO(dsinclair): This is a little weird .....
EXPECT_EQ(L"// comments only", buf.AsStringView());
}
@@ -35,7 +35,7 @@ TEST(CXFA_FMParserTest, CommentOnlyIsError) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf buf;
- EXPECT_TRUE(ast->ToJavaScript(buf));
+ EXPECT_TRUE(ast->ToJavaScript(buf, ReturnType::kInfered));
EXPECT_EQ(L"// comments only", buf.AsStringView());
}
@@ -54,7 +54,7 @@ TEST(CXFA_FMParserTest, CommentThenValue) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf buf;
- EXPECT_TRUE(ast->ToJavaScript(buf));
+ EXPECT_TRUE(ast->ToJavaScript(buf, ReturnType::kInfered));
EXPECT_EQ(ret, buf.AsStringView());
}
@@ -110,7 +110,7 @@ TEST(CXFA_FMParserTest, Parse) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf buf;
- EXPECT_TRUE(ast->ToJavaScript(buf));
+ EXPECT_TRUE(ast->ToJavaScript(buf, ReturnType::kInfered));
EXPECT_EQ(ret, buf.AsStringView());
}
diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
index 373ba916e9..4dcd51d2ed 100644
--- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
@@ -92,16 +92,11 @@ WideStringView XFA_FM_EXPTypeToString(
CXFA_FMSimpleExpression::CXFA_FMSimpleExpression(uint32_t line, XFA_FM_TOKEN op)
: m_line(line), m_op(op) {}
-bool CXFA_FMSimpleExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMSimpleExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
}
-
-bool CXFA_FMSimpleExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
-}
-
XFA_FM_TOKEN CXFA_FMSimpleExpression::GetOperatorToken() const {
return m_op;
}
@@ -109,7 +104,8 @@ XFA_FM_TOKEN CXFA_FMSimpleExpression::GetOperatorToken() const {
CXFA_FMNullExpression::CXFA_FMNullExpression(uint32_t line)
: CXFA_FMSimpleExpression(line, TOKnull) {}
-bool CXFA_FMNullExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMNullExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -124,7 +120,8 @@ CXFA_FMNumberExpression::CXFA_FMNumberExpression(uint32_t line,
CXFA_FMNumberExpression::~CXFA_FMNumberExpression() {}
-bool CXFA_FMNumberExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMNumberExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -139,7 +136,8 @@ CXFA_FMStringExpression::CXFA_FMStringExpression(uint32_t line,
CXFA_FMStringExpression::~CXFA_FMStringExpression() {}
-bool CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -179,7 +177,8 @@ CXFA_FMIdentifierExpression::CXFA_FMIdentifierExpression(
CXFA_FMIdentifierExpression::~CXFA_FMIdentifierExpression() {}
-bool CXFA_FMIdentifierExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMIdentifierExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -217,7 +216,8 @@ CXFA_FMUnaryExpression::CXFA_FMUnaryExpression(
CXFA_FMUnaryExpression::~CXFA_FMUnaryExpression() {}
-bool CXFA_FMUnaryExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMUnaryExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
}
@@ -233,7 +233,8 @@ CXFA_FMBinExpression::CXFA_FMBinExpression(
CXFA_FMBinExpression::~CXFA_FMBinExpression() {}
-bool CXFA_FMBinExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMBinExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth();
}
@@ -245,7 +246,8 @@ CXFA_FMAssignExpression::CXFA_FMAssignExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp2)
: CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {}
-bool CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -254,65 +256,34 @@ bool CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << gs_lpStrExpFuncName[ISFMOBJECT];
javascript << L"(";
CFX_WideTextBuf tempExp1;
- if (!m_pExp1->ToJavaScript(tempExp1))
+ if (!m_pExp1->ToJavaScript(tempExp1, ReturnType::kInfered))
return false;
javascript << tempExp1;
javascript << L"))\n{\n";
- javascript << gs_lpStrExpFuncName[ASSIGN];
- javascript << L"(";
- javascript << tempExp1;
- javascript << L", ";
- CFX_WideTextBuf tempExp2;
- if (!m_pExp2->ToJavaScript(tempExp2))
- return false;
- javascript << tempExp2;
- javascript << L");\n}\n";
- if (m_pExp1->GetOperatorToken() == TOKidentifier &&
- tempExp1.AsStringView() != L"this") {
- javascript << L"else\n{\n";
- javascript << tempExp1;
+ if (type == ReturnType::kImplied) {
+ javascript << RUNTIMEFUNCTIONRETURNVALUE;
javascript << L" = ";
- javascript << gs_lpStrExpFuncName[ASSIGN];
- javascript << L"(";
- javascript << tempExp1;
- javascript << L", ";
- javascript << tempExp2;
- javascript << L");\n}\n";
}
- return !CXFA_IsTooBig(javascript);
-}
-bool CXFA_FMAssignExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {
- CXFA_FMToJavaScriptDepth depthManager;
- if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
- return false;
-
- javascript << L"if (";
- javascript << gs_lpStrExpFuncName[ISFMOBJECT];
- javascript << L"(";
- CFX_WideTextBuf tempExp1;
- if (!m_pExp1->ToJavaScript(tempExp1))
- return false;
- javascript << tempExp1;
- javascript << L"))\n{\n";
- javascript << RUNTIMEFUNCTIONRETURNVALUE;
- javascript << L" = ";
javascript << gs_lpStrExpFuncName[ASSIGN];
javascript << L"(";
javascript << tempExp1;
javascript << L", ";
CFX_WideTextBuf tempExp2;
- if (!m_pExp2->ToJavaScript(tempExp2))
+ if (!m_pExp2->ToJavaScript(tempExp2, ReturnType::kInfered))
return false;
javascript << tempExp2;
javascript << L");\n}\n";
if (m_pExp1->GetOperatorToken() == TOKidentifier &&
tempExp1.AsStringView() != L"this") {
javascript << L"else\n{\n";
- javascript << RUNTIMEFUNCTIONRETURNVALUE;
- javascript << L" = ";
+ if (type == ReturnType::kImplied) {
+ javascript << RUNTIMEFUNCTIONRETURNVALUE;
+ javascript << L" = ";
+ }
+
javascript << tempExp1;
javascript << L" = ";
javascript << gs_lpStrExpFuncName[ASSIGN];
@@ -332,17 +303,18 @@ CXFA_FMLogicalOrExpression::CXFA_FMLogicalOrExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp2)
: CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {}
-bool CXFA_FMLogicalOrExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMLogicalOrExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
javascript << gs_lpStrExpFuncName[LOGICALOR];
javascript << L"(";
- if (!m_pExp1->ToJavaScript(javascript))
+ if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L", ";
- if (!m_pExp2->ToJavaScript(javascript))
+ if (!m_pExp2->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -355,17 +327,18 @@ CXFA_FMLogicalAndExpression::CXFA_FMLogicalAndExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp2)
: CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {}
-bool CXFA_FMLogicalAndExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMLogicalAndExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
javascript << gs_lpStrExpFuncName[LOGICALAND];
javascript << L"(";
- if (!m_pExp1->ToJavaScript(javascript))
+ if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L", ";
- if (!m_pExp2->ToJavaScript(javascript))
+ if (!m_pExp2->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -378,7 +351,8 @@ CXFA_FMEqualityExpression::CXFA_FMEqualityExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp2)
: CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {}
-bool CXFA_FMEqualityExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMEqualityExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -397,10 +371,10 @@ bool CXFA_FMEqualityExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
break;
}
javascript << L"(";
- if (!m_pExp1->ToJavaScript(javascript))
+ if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L", ";
- if (!m_pExp2->ToJavaScript(javascript))
+ if (!m_pExp2->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -413,7 +387,8 @@ CXFA_FMRelationalExpression::CXFA_FMRelationalExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp2)
: CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {}
-bool CXFA_FMRelationalExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMRelationalExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -440,10 +415,10 @@ bool CXFA_FMRelationalExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
break;
}
javascript << L"(";
- if (!m_pExp1->ToJavaScript(javascript))
+ if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L", ";
- if (!m_pExp2->ToJavaScript(javascript))
+ if (!m_pExp2->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -456,7 +431,8 @@ CXFA_FMAdditiveExpression::CXFA_FMAdditiveExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp2)
: CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {}
-bool CXFA_FMAdditiveExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMAdditiveExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -473,10 +449,10 @@ bool CXFA_FMAdditiveExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
break;
}
javascript << L"(";
- if (!m_pExp1->ToJavaScript(javascript))
+ if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L", ";
- if (!m_pExp2->ToJavaScript(javascript))
+ if (!m_pExp2->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -489,8 +465,8 @@ CXFA_FMMultiplicativeExpression::CXFA_FMMultiplicativeExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp2)
: CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {}
-bool CXFA_FMMultiplicativeExpression::ToJavaScript(
- CFX_WideTextBuf& javascript) {
+bool CXFA_FMMultiplicativeExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -507,10 +483,10 @@ bool CXFA_FMMultiplicativeExpression::ToJavaScript(
break;
}
javascript << L"(";
- if (!m_pExp1->ToJavaScript(javascript))
+ if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L", ";
- if (!m_pExp2->ToJavaScript(javascript))
+ if (!m_pExp2->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -521,14 +497,15 @@ CXFA_FMPosExpression::CXFA_FMPosExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp)
: CXFA_FMUnaryExpression(line, TOKplus, std::move(pExp)) {}
-bool CXFA_FMPosExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMPosExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
javascript << gs_lpStrExpFuncName[POSITIVE];
javascript << L"(";
- if (!m_pExp->ToJavaScript(javascript))
+ if (!m_pExp->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -539,14 +516,15 @@ CXFA_FMNegExpression::CXFA_FMNegExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp)
: CXFA_FMUnaryExpression(line, TOKminus, std::move(pExp)) {}
-bool CXFA_FMNegExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMNegExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
javascript << gs_lpStrExpFuncName[NEGATIVE];
javascript << L"(";
- if (!m_pExp->ToJavaScript(javascript))
+ if (!m_pExp->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -557,14 +535,15 @@ CXFA_FMNotExpression::CXFA_FMNotExpression(
std::unique_ptr<CXFA_FMSimpleExpression> pExp)
: CXFA_FMUnaryExpression(line, TOKksnot, std::move(pExp)) {}
-bool CXFA_FMNotExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMNotExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
javascript << gs_lpStrExpFuncName[NOT];
javascript << L"(";
- if (!m_pExp->ToJavaScript(javascript))
+ if (!m_pExp->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -615,13 +594,14 @@ uint32_t CXFA_FMCallExpression::IsMethodWithObjParam(
return 0;
}
-bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
CFX_WideTextBuf funcName;
- if (!m_pExp->ToJavaScript(funcName))
+ if (!m_pExp->ToJavaScript(funcName, ReturnType::kInfered))
return false;
if (m_bIsSomMethod) {
javascript << funcName;
@@ -639,7 +619,7 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
}
javascript << L"(";
const auto& expr = m_Arguments[i];
- if (!expr->ToJavaScript(javascript))
+ if (!expr->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
if (i + 1 < m_Arguments.size()) {
@@ -650,7 +630,7 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
for (const auto& expr : m_Arguments) {
javascript << gs_lpStrExpFuncName[GETFMVALUE];
javascript << L"(";
- if (!expr->ToJavaScript(javascript))
+ if (!expr->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
if (expr != m_Arguments.back())
@@ -688,7 +668,7 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
if (!m_Arguments.empty()) {
const auto& expr = m_Arguments[0];
javascript << L"return ";
- if (!expr->ToJavaScript(javascript))
+ if (!expr->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L";\n}\n";
} else {
@@ -698,7 +678,7 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << L"{\nreturn 0;\n}\n}\n).call(this)\n";
} else {
for (const auto& expr : m_Arguments) {
- if (!expr->ToJavaScript(javascript))
+ if (!expr->ToJavaScript(javascript, ReturnType::kInfered))
return false;
if (expr != m_Arguments.back())
javascript << L", ";
@@ -726,7 +706,8 @@ CXFA_FMDotAccessorExpression::CXFA_FMDotAccessorExpression(
CXFA_FMDotAccessorExpression::~CXFA_FMDotAccessorExpression() {}
-bool CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -735,7 +716,7 @@ bool CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << L"(";
CFX_WideTextBuf tempExp1;
if (m_pExp1) {
- if (!m_pExp1->ToJavaScript(tempExp1))
+ if (!m_pExp1->ToJavaScript(tempExp1, ReturnType::kInfered))
return false;
javascript << tempExp1;
} else {
@@ -760,7 +741,7 @@ bool CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << m_wsIdentifier;
javascript << L"\", ";
}
- if (!m_pExp2->ToJavaScript(javascript))
+ if (!m_pExp2->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -775,7 +756,8 @@ CXFA_FMIndexExpression::CXFA_FMIndexExpression(
m_accessorIndex(accessorIndex),
m_bIsStarIndex(bIsStarIndex) {}
-bool CXFA_FMIndexExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMIndexExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -799,7 +781,7 @@ bool CXFA_FMIndexExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
if (!m_bIsStarIndex) {
javascript << L", ";
if (m_pExp) {
- if (!m_pExp->ToJavaScript(javascript))
+ if (!m_pExp->ToJavaScript(javascript, ReturnType::kInfered))
return false;
} else {
javascript << L"0";
@@ -822,8 +804,8 @@ CXFA_FMDotDotAccessorExpression::CXFA_FMDotDotAccessorExpression(
CXFA_FMDotDotAccessorExpression::~CXFA_FMDotDotAccessorExpression() {}
-bool CXFA_FMDotDotAccessorExpression::ToJavaScript(
- CFX_WideTextBuf& javascript) {
+bool CXFA_FMDotDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -831,7 +813,7 @@ bool CXFA_FMDotDotAccessorExpression::ToJavaScript(
javascript << gs_lpStrExpFuncName[DOTDOT];
javascript << L"(";
CFX_WideTextBuf tempExp1;
- if (!m_pExp1->ToJavaScript(tempExp1))
+ if (!m_pExp1->ToJavaScript(tempExp1, ReturnType::kInfered))
return false;
javascript << tempExp1;
javascript << L", ";
@@ -843,7 +825,7 @@ bool CXFA_FMDotDotAccessorExpression::ToJavaScript(
javascript << L"\"";
javascript << m_wsIdentifier;
javascript << L"\", ";
- if (!m_pExp2->ToJavaScript(javascript))
+ if (!m_pExp2->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L")";
return !CXFA_IsTooBig(javascript);
@@ -858,7 +840,8 @@ CXFA_FMMethodCallExpression::CXFA_FMMethodCallExpression(
std::move(pAccessorExp1),
std::move(pCallExp)) {}
-bool CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
+bool CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& javascript,
+ ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth())
return false;
@@ -866,7 +849,7 @@ bool CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << L"(\nfunction ()\n{\n";
javascript << L"var method_return_value = null;\n";
javascript << L"var accessor_object = ";
- if (!m_pExp1->ToJavaScript(javascript))
+ if (!m_pExp1->ToJavaScript(javascript, ReturnType::kInfered))
return false;
javascript << L";\n";
javascript << L"if (";
@@ -877,7 +860,7 @@ bool CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) {
javascript << L"method_return_value = accessor_object[index].";
CFX_WideTextBuf tempExp2;
- if (!m_pExp2->ToJavaScript(tempExp2))
+ if (!m_pExp2->ToJavaScript(tempExp2, ReturnType::kInfered))
return false;
javascript << tempExp2;
javascript << L";\n}\n}\n";
diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h
index 440b154d3d..e931d724cb 100644
--- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h
+++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h
@@ -55,12 +55,14 @@ enum XFA_FM_AccessorIndex {
ACCESSOR_NEGATIVE_INDEX
};
+enum class ReturnType { kImplied, kInfered };
+
class CXFA_FMSimpleExpression {
public:
CXFA_FMSimpleExpression(uint32_t line, XFA_FM_TOKEN op);
virtual ~CXFA_FMSimpleExpression() {}
- virtual bool ToJavaScript(CFX_WideTextBuf& javascript);
- virtual bool ToImpliedReturnJS(CFX_WideTextBuf& javascript);
+
+ virtual bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type);
XFA_FM_TOKEN GetOperatorToken() const;
@@ -73,14 +75,16 @@ class CXFA_FMNullExpression : public CXFA_FMSimpleExpression {
public:
explicit CXFA_FMNullExpression(uint32_t line);
~CXFA_FMNullExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMNumberExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMNumberExpression(uint32_t line, WideStringView wsNumber);
~CXFA_FMNumberExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsNumber;
@@ -90,7 +94,8 @@ class CXFA_FMStringExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMStringExpression(uint32_t line, WideStringView wsString);
~CXFA_FMStringExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsString;
@@ -100,7 +105,8 @@ class CXFA_FMIdentifierExpression : public CXFA_FMSimpleExpression {
public:
CXFA_FMIdentifierExpression(uint32_t line, WideStringView wsIdentifier);
~CXFA_FMIdentifierExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsIdentifier;
@@ -113,7 +119,7 @@ class CXFA_FMUnaryExpression : public CXFA_FMSimpleExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMUnaryExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
protected:
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp;
@@ -127,7 +133,7 @@ class CXFA_FMBinExpression : public CXFA_FMSimpleExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMBinExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
protected:
std::unique_ptr<CXFA_FMSimpleExpression> m_pExp1;
@@ -141,8 +147,8 @@ class CXFA_FMAssignExpression : public CXFA_FMBinExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMAssignExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
- bool ToImpliedReturnJS(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMLogicalOrExpression : public CXFA_FMBinExpression {
@@ -152,7 +158,8 @@ class CXFA_FMLogicalOrExpression : public CXFA_FMBinExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMLogicalOrExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMLogicalAndExpression : public CXFA_FMBinExpression {
@@ -162,7 +169,8 @@ class CXFA_FMLogicalAndExpression : public CXFA_FMBinExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMLogicalAndExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMEqualityExpression : public CXFA_FMBinExpression {
@@ -172,7 +180,8 @@ class CXFA_FMEqualityExpression : public CXFA_FMBinExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMEqualityExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMRelationalExpression : public CXFA_FMBinExpression {
@@ -182,7 +191,8 @@ class CXFA_FMRelationalExpression : public CXFA_FMBinExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMRelationalExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMAdditiveExpression : public CXFA_FMBinExpression {
@@ -192,7 +202,8 @@ class CXFA_FMAdditiveExpression : public CXFA_FMBinExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMAdditiveExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMMultiplicativeExpression : public CXFA_FMBinExpression {
@@ -203,7 +214,8 @@ class CXFA_FMMultiplicativeExpression : public CXFA_FMBinExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pExp2);
~CXFA_FMMultiplicativeExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMPosExpression : public CXFA_FMUnaryExpression {
@@ -211,7 +223,8 @@ class CXFA_FMPosExpression : public CXFA_FMUnaryExpression {
CXFA_FMPosExpression(uint32_t line,
std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMPosExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMNegExpression : public CXFA_FMUnaryExpression {
@@ -219,7 +232,8 @@ class CXFA_FMNegExpression : public CXFA_FMUnaryExpression {
CXFA_FMNegExpression(uint32_t line,
std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMNegExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMNotExpression : public CXFA_FMUnaryExpression {
@@ -227,7 +241,8 @@ class CXFA_FMNotExpression : public CXFA_FMUnaryExpression {
CXFA_FMNotExpression(uint32_t line,
std::unique_ptr<CXFA_FMSimpleExpression> pExp);
~CXFA_FMNotExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
class CXFA_FMCallExpression : public CXFA_FMUnaryExpression {
@@ -241,7 +256,7 @@ class CXFA_FMCallExpression : public CXFA_FMUnaryExpression {
bool IsBuiltInFunc(CFX_WideTextBuf* funcName);
uint32_t IsMethodWithObjParam(const WideString& methodName);
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
bool m_bIsSomMethod;
@@ -257,7 +272,8 @@ class CXFA_FMDotAccessorExpression : public CXFA_FMBinExpression {
WideStringView wsIdentifier,
std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp);
~CXFA_FMDotAccessorExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsIdentifier;
@@ -270,7 +286,8 @@ class CXFA_FMIndexExpression : public CXFA_FMUnaryExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp,
bool bIsStarIndex);
~CXFA_FMIndexExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
XFA_FM_AccessorIndex m_accessorIndex;
@@ -287,7 +304,7 @@ class CXFA_FMDotDotAccessorExpression : public CXFA_FMBinExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp);
~CXFA_FMDotDotAccessorExpression() override;
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
private:
WideStringView m_wsIdentifier;
@@ -300,7 +317,8 @@ class CXFA_FMMethodCallExpression : public CXFA_FMBinExpression {
std::unique_ptr<CXFA_FMSimpleExpression> pAccessorExp1,
std::unique_ptr<CXFA_FMSimpleExpression> pCallExp);
~CXFA_FMMethodCallExpression() override {}
- bool ToJavaScript(CFX_WideTextBuf& javascript) override;
+
+ bool ToJavaScript(CFX_WideTextBuf& javascript, ReturnType type) override;
};
bool CXFA_IsTooBig(const CFX_WideTextBuf& javascript);
diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp
index 96ccb71ca9..e97df41ad7 100644
--- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp
@@ -26,7 +26,7 @@ TEST(FMCallExpressionTest, more_than_32_arguments) {
CXFA_FMToJavaScriptDepth::Reset();
CXFA_FMCallExpression callExp(0, std::move(exp), std::move(args), true);
CFX_WideTextBuf js;
- callExp.ToJavaScript(js);
+ callExp.ToJavaScript(js, ReturnType::kInfered);
// Generate the result javascript string.
WideString result = L"sign(";
@@ -49,21 +49,24 @@ TEST(FMCallExpressionTest, more_than_32_arguments) {
TEST(FMStringExpressionTest, Empty) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf accumulator;
- CXFA_FMStringExpression(1, WideStringView()).ToJavaScript(accumulator);
+ CXFA_FMStringExpression(1, WideStringView())
+ .ToJavaScript(accumulator, ReturnType::kInfered);
EXPECT_EQ(L"", accumulator.AsStringView());
}
TEST(FMStringExpressionTest, Short) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf accumulator;
- CXFA_FMStringExpression(1, L"a").ToJavaScript(accumulator);
+ CXFA_FMStringExpression(1, L"a").ToJavaScript(accumulator,
+ ReturnType::kInfered);
EXPECT_EQ(L"a", accumulator.AsStringView());
}
TEST(FMStringExpressionTest, Medium) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf accumulator;
- CXFA_FMStringExpression(1, L".abcd.").ToJavaScript(accumulator);
+ CXFA_FMStringExpression(1, L".abcd.")
+ .ToJavaScript(accumulator, ReturnType::kInfered);
EXPECT_EQ(L"\"abcd\"", accumulator.AsStringView());
}
@@ -71,7 +74,8 @@ TEST(FMStringExpressionTest, Long) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf accumulator;
std::vector<WideStringView::UnsignedType> vec(140000, L'A');
- CXFA_FMStringExpression(1, WideStringView(vec)).ToJavaScript(accumulator);
+ CXFA_FMStringExpression(1, WideStringView(vec))
+ .ToJavaScript(accumulator, ReturnType::kInfered);
EXPECT_EQ(140000u, accumulator.GetLength());
}
@@ -79,6 +83,6 @@ TEST(FMStringExpressionTest, Quoted) {
CXFA_FMToJavaScriptDepth::Reset();
CFX_WideTextBuf accumulator;
CXFA_FMStringExpression(1, L".Simon says \"\"run\"\".")
- .ToJavaScript(accumulator);
+ .ToJavaScript(accumulator, ReturnType::kInfered);
EXPECT_EQ(L"\"Simon says \\\"run\\\"\"", accumulator.AsStringView());
}