diff options
Diffstat (limited to 'xfa/fxfa/fm2js')
-rw-r--r-- | xfa/fxfa/fm2js/xfa_expression.cpp | 323 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_expression.h | 54 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 3 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fmparse.cpp | 103 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fmparse.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_program.cpp | 3 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_simpleexpression.cpp | 242 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_simpleexpression.h | 52 |
8 files changed, 478 insertions, 304 deletions
diff --git a/xfa/fxfa/fm2js/xfa_expression.cpp b/xfa/fxfa/fm2js/xfa_expression.cpp index c1e451eade..324038f7ed 100644 --- a/xfa/fxfa/fm2js/xfa_expression.cpp +++ b/xfa/fxfa/fm2js/xfa_expression.cpp @@ -18,6 +18,11 @@ const wchar_t RUNTIMEBLOCKTEMPARRAY[] = const wchar_t RUNTIMEBLOCKTEMPARRAYINDEX[] = L"foxit_xfa_formcalc_runtime_block_temp_array_index"; +const wchar_t kLessEqual[] = L" <= "; +const wchar_t kGreaterEqual[] = L" >= "; +const wchar_t kPlusEqual[] = L" += "; +const wchar_t kMinusEqual[] = L" -= "; + } // namespace CXFA_FMExpression::CXFA_FMExpression(uint32_t line) @@ -26,9 +31,13 @@ CXFA_FMExpression::CXFA_FMExpression(uint32_t line) CXFA_FMExpression::CXFA_FMExpression(uint32_t line, XFA_FM_EXPTYPE type) : m_type(type), m_line(line) {} -void CXFA_FMExpression::ToJavaScript(CFX_WideTextBuf& javascript) {} +bool CXFA_FMExpression::ToJavaScript(CFX_WideTextBuf& javascript) { + return true; +} -void CXFA_FMExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {} +bool CXFA_FMExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { + return true; +} CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition( uint32_t line, @@ -44,10 +53,10 @@ CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition( CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() {} -void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { if (m_isGlobal && m_pExpressions.empty()) { javascript << L"// comments only"; - return; + return true; } if (m_isGlobal) { javascript << L"(\n"; @@ -78,10 +87,13 @@ void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = null;\n"; for (const auto& expr : m_pExpressions) { + bool ret; if (expr == m_pExpressions.back()) - expr->ToImpliedReturnJS(javascript); + ret = expr->ToImpliedReturnJS(javascript); else - expr->ToJavaScript(javascript); + ret = expr->ToJavaScript(javascript); + if (!ret || CFXA_IsTooBig(javascript)) + return false; } javascript << L"return "; if (m_isGlobal) { @@ -96,9 +108,12 @@ void CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { if (m_isGlobal) { javascript << L").call(this);\n"; } + return true; } -void CXFA_FMFunctionDefinition::ToImpliedReturnJS(CFX_WideTextBuf&) {} +bool CXFA_FMFunctionDefinition::ToImpliedReturnJS(CFX_WideTextBuf&) { + return true; +} CXFA_FMVarExpression::CXFA_FMVarExpression( uint32_t line, @@ -110,7 +125,7 @@ CXFA_FMVarExpression::CXFA_FMVarExpression( CXFA_FMVarExpression::~CXFA_FMVarExpression() {} -void CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"var "; CFX_WideString tempName(m_wsName); if (m_wsName.GetAt(0) == L'!') { @@ -119,7 +134,8 @@ void CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << tempName; javascript << L" = "; if (m_pInit) { - m_pInit->ToJavaScript(javascript); + if (!m_pInit->ToJavaScript(javascript)) + return false; javascript << tempName; javascript << L" = "; javascript << XFA_FM_EXPTypeToString(VARFILTER); @@ -129,9 +145,10 @@ void CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) { } else { javascript << L"\"\";\n"; } + return true; } -void CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { +bool CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << L"var "; CFX_WideString tempName(m_wsName); if (m_wsName.GetAt(0) == L'!') { @@ -140,7 +157,8 @@ void CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << tempName; javascript << L" = "; if (m_pInit) { - m_pInit->ToJavaScript(javascript); + if (!m_pInit->ToJavaScript(javascript)) + return false; javascript << tempName; javascript << L" = "; javascript << XFA_FM_EXPTypeToString(VARFILTER); @@ -154,6 +172,7 @@ void CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << L" = "; javascript << tempName; javascript << L";\n"; + return true; } CXFA_FMExpExpression::CXFA_FMExpExpression( @@ -164,37 +183,38 @@ CXFA_FMExpExpression::CXFA_FMExpExpression( CXFA_FMExpExpression::~CXFA_FMExpExpression() {} -void CXFA_FMExpExpression::ToJavaScript(CFX_WideTextBuf& javascript) { - if (m_pExpression->GetOperatorToken() == TOKassign) { - m_pExpression->ToJavaScript(javascript); - } else { - m_pExpression->ToJavaScript(javascript); +bool CXFA_FMExpExpression::ToJavaScript(CFX_WideTextBuf& javascript) { + bool ret = m_pExpression->ToJavaScript(javascript); + if (m_pExpression->GetOperatorToken() != TOKassign) javascript << L";\n"; - } + return ret; } -void CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { - if (m_pExpression->GetOperatorToken() == TOKassign) { - m_pExpression->ToImpliedReturnJS(javascript); - } else { - if (m_pExpression->GetOperatorToken() == TOKstar || - m_pExpression->GetOperatorToken() == TOKdotstar || - m_pExpression->GetOperatorToken() == TOKdotscream || - m_pExpression->GetOperatorToken() == TOKdotdot || - m_pExpression->GetOperatorToken() == TOKdot) { - javascript << RUNTIMEFUNCTIONRETURNVALUE; - javascript << L" = "; - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; - m_pExpression->ToJavaScript(javascript); - javascript << L");\n"; - } else { - javascript << RUNTIMEFUNCTIONRETURNVALUE; - javascript << L" = "; - m_pExpression->ToJavaScript(javascript); - javascript << L";\n"; - } +bool CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { + if (m_pExpression->GetOperatorToken() == TOKassign) + return m_pExpression->ToImpliedReturnJS(javascript); + + if (m_pExpression->GetOperatorToken() == TOKstar || + m_pExpression->GetOperatorToken() == TOKdotstar || + m_pExpression->GetOperatorToken() == TOKdotscream || + m_pExpression->GetOperatorToken() == TOKdotdot || + m_pExpression->GetOperatorToken() == TOKdot) { + javascript << RUNTIMEFUNCTIONRETURNVALUE; + javascript << L" = "; + javascript << XFA_FM_EXPTypeToString(GETFMVALUE); + javascript << L"("; + if (!m_pExpression->ToJavaScript(javascript)) + return false; + javascript << L");\n"; + return true; } + + javascript << RUNTIMEFUNCTIONRETURNVALUE; + javascript << L" = "; + if (!m_pExpression->ToJavaScript(javascript)) + return false; + javascript << L";\n"; + return true; } CXFA_FMBlockExpression::CXFA_FMBlockExpression( @@ -205,22 +225,29 @@ CXFA_FMBlockExpression::CXFA_FMBlockExpression( CXFA_FMBlockExpression::~CXFA_FMBlockExpression() {} -void CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"{\n"; - for (const auto& expr : m_ExpressionList) - expr->ToJavaScript(javascript); + for (const auto& expr : m_ExpressionList) { + if (!expr->ToJavaScript(javascript) || CFXA_IsTooBig(javascript)) + return false; + } javascript << L"}\n"; + return true; } -void CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { +bool CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << L"{\n"; for (const auto& expr : m_ExpressionList) { + bool ret; if (expr == m_ExpressionList.back()) - expr->ToImpliedReturnJS(javascript); + ret = expr->ToImpliedReturnJS(javascript); else - expr->ToJavaScript(javascript); + ret = expr->ToJavaScript(javascript); + if (!ret || CFXA_IsTooBig(javascript)) + return false; } javascript << L"}\n"; + return true; } CXFA_FMDoExpression::CXFA_FMDoExpression( @@ -230,12 +257,12 @@ CXFA_FMDoExpression::CXFA_FMDoExpression( CXFA_FMDoExpression::~CXFA_FMDoExpression() {} -void CXFA_FMDoExpression::ToJavaScript(CFX_WideTextBuf& javascript) { - m_pList->ToJavaScript(javascript); +bool CXFA_FMDoExpression::ToJavaScript(CFX_WideTextBuf& javascript) { + return m_pList->ToJavaScript(javascript); } -void CXFA_FMDoExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { - m_pList->ToImpliedReturnJS(javascript); +bool CXFA_FMDoExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { + return m_pList->ToImpliedReturnJS(javascript); } CXFA_FMIfExpression::CXFA_FMIfExpression( @@ -250,63 +277,88 @@ CXFA_FMIfExpression::CXFA_FMIfExpression( CXFA_FMIfExpression::~CXFA_FMIfExpression() {} -void CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"if ("; if (m_pExpression) { javascript << XFA_FM_EXPTypeToString(GETFMVALUE); javascript << L"("; - m_pExpression->ToJavaScript(javascript); + if (!m_pExpression->ToJavaScript(javascript)) + return false; javascript << L")"; } javascript << L")\n"; + if (CFXA_IsTooBig(javascript)) + return false; + if (m_pIfExpression) { - m_pIfExpression->ToJavaScript(javascript); + if (!m_pIfExpression->ToJavaScript(javascript)) + return false; + if (CFXA_IsTooBig(javascript)) + return false; } + if (m_pElseExpression) { if (m_pElseExpression->GetExpType() == XFA_FM_EXPTYPE_IF) { javascript << L"else\n"; javascript << L"{\n"; - m_pElseExpression->ToJavaScript(javascript); + if (!m_pElseExpression->ToJavaScript(javascript)) + return false; javascript << L"}\n"; } else { javascript << L"else\n"; - m_pElseExpression->ToJavaScript(javascript); + if (!m_pElseExpression->ToJavaScript(javascript)) + return false; } } + return !CFXA_IsTooBig(javascript); } -void CXFA_FMIfExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { +bool CXFA_FMIfExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"if ("; if (m_pExpression) { javascript << XFA_FM_EXPTypeToString(GETFMVALUE); javascript << L"("; - m_pExpression->ToJavaScript(javascript); + if (!m_pExpression->ToJavaScript(javascript)) + return false; javascript << L")"; } javascript << L")\n"; + if (CFXA_IsTooBig(javascript)) + return false; + if (m_pIfExpression) { - m_pIfExpression->ToImpliedReturnJS(javascript); + if (!m_pIfExpression->ToImpliedReturnJS(javascript)) + return false; + if (CFXA_IsTooBig(javascript)) + return false; } if (m_pElseExpression) { if (m_pElseExpression->GetExpType() == XFA_FM_EXPTYPE_IF) { javascript << L"else\n"; javascript << L"{\n"; - m_pElseExpression->ToImpliedReturnJS(javascript); + if (!m_pElseExpression->ToImpliedReturnJS(javascript)) + return false; javascript << L"}\n"; } else { javascript << L"else\n"; - m_pElseExpression->ToImpliedReturnJS(javascript); + if (!m_pElseExpression->ToImpliedReturnJS(javascript)) + return false; } } + return !CFXA_IsTooBig(javascript); } CXFA_FMLoopExpression::~CXFA_FMLoopExpression() {} -void CXFA_FMLoopExpression::ToJavaScript(CFX_WideTextBuf& javascript) {} +bool CXFA_FMLoopExpression::ToJavaScript(CFX_WideTextBuf& javascript) { + return true; +} -void CXFA_FMLoopExpression::ToImpliedReturnJS(CFX_WideTextBuf&) {} +bool CXFA_FMLoopExpression::ToImpliedReturnJS(CFX_WideTextBuf&) { + return true; +} CXFA_FMWhileExpression::CXFA_FMWhileExpression( uint32_t line, @@ -318,20 +370,32 @@ CXFA_FMWhileExpression::CXFA_FMWhileExpression( CXFA_FMWhileExpression::~CXFA_FMWhileExpression() {} -void CXFA_FMWhileExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMWhileExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"while ("; - m_pCondition->ToJavaScript(javascript); + if (!m_pCondition->ToJavaScript(javascript)) + return false; javascript << L")\n"; - m_pExpression->ToJavaScript(javascript); + if (CFXA_IsTooBig(javascript)) + return false; + + if (!m_pExpression->ToJavaScript(javascript)) + return false; + return !CFXA_IsTooBig(javascript); } -void CXFA_FMWhileExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { +bool CXFA_FMWhileExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"while ("; - m_pCondition->ToJavaScript(javascript); + if (!m_pCondition->ToJavaScript(javascript)) + return false; javascript << L")\n"; - m_pExpression->ToImpliedReturnJS(javascript); + if (CFXA_IsTooBig(javascript)) + return false; + + if (!m_pExpression->ToImpliedReturnJS(javascript)) + return false; + return !CFXA_IsTooBig(javascript); } CXFA_FMBreakExpression::CXFA_FMBreakExpression(uint32_t line) @@ -339,16 +403,18 @@ CXFA_FMBreakExpression::CXFA_FMBreakExpression(uint32_t line) CXFA_FMBreakExpression::~CXFA_FMBreakExpression() {} -void CXFA_FMBreakExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMBreakExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"break;\n"; + return true; } -void CXFA_FMBreakExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { +bool CXFA_FMBreakExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"break;\n"; + return true; } CXFA_FMContinueExpression::CXFA_FMContinueExpression(uint32_t line) @@ -356,16 +422,18 @@ CXFA_FMContinueExpression::CXFA_FMContinueExpression(uint32_t line) CXFA_FMContinueExpression::~CXFA_FMContinueExpression() {} -void CXFA_FMContinueExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMContinueExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"continue;\n"; + return true; } -void CXFA_FMContinueExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { +bool CXFA_FMContinueExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"continue;\n"; + return true; } CXFA_FMForExpression::CXFA_FMForExpression( @@ -380,13 +448,13 @@ CXFA_FMForExpression::CXFA_FMForExpression( m_wsVariant(wsVariant), m_pAssignment(std::move(pAssignment)), m_pAccessor(std::move(pAccessor)), - m_iDirection(iDirection), + m_bDirection(iDirection == 1), m_pStep(std::move(pStep)), m_pList(std::move(pList)) {} CXFA_FMForExpression::~CXFA_FMForExpression() {} -void CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"{\nvar "; CFX_WideString tempVariant; if (m_wsVariant.GetAt(0) == L'!') { @@ -402,40 +470,43 @@ void CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L" = "; javascript << XFA_FM_EXPTypeToString(GETFMVALUE); javascript << L"("; - m_pAssignment->ToJavaScript(javascript); + if (!m_pAssignment->ToJavaScript(javascript)) + return false; javascript << L"); "; javascript << tempVariant; - if (m_iDirection == 1) { - javascript << L" <= "; - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; - m_pAccessor->ToJavaScript(javascript); - javascript << L"); "; - javascript << tempVariant; - javascript << L" += "; - } else { - javascript << L" >= "; - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; - m_pAccessor->ToJavaScript(javascript); - javascript << L"); "; - javascript << tempVariant; - javascript << L" -= "; - } + if (CFXA_IsTooBig(javascript)) + return false; + + 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 (CFXA_IsTooBig(javascript)) + return false; + if (m_pStep) { javascript << XFA_FM_EXPTypeToString(GETFMVALUE); javascript << L"("; - m_pStep->ToJavaScript(javascript); + if (!m_pStep->ToJavaScript(javascript)) + return false; javascript << L")"; + if (CFXA_IsTooBig(javascript)) + return false; } else { javascript << L"1"; } javascript << L")\n"; - m_pList->ToJavaScript(javascript); + if (!m_pList->ToJavaScript(javascript)) + return false; javascript << L"}\n"; + return !CFXA_IsTooBig(javascript); } -void CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { +bool CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"{\nvar "; @@ -453,37 +524,41 @@ void CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << L" = "; javascript << XFA_FM_EXPTypeToString(GETFMVALUE); javascript << L"("; - m_pAssignment->ToJavaScript(javascript); + if (!m_pAssignment->ToJavaScript(javascript)) + return false; javascript << L"); "; javascript << tempVariant; - if (m_iDirection == 1) { - javascript << L" <= "; - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; - m_pAccessor->ToJavaScript(javascript); - javascript << L"); "; - javascript << tempVariant; - javascript << L" += "; - } else { - javascript << L" >= "; - javascript << XFA_FM_EXPTypeToString(GETFMVALUE); - javascript << L"("; - m_pAccessor->ToJavaScript(javascript); - javascript << L"); "; - javascript << tempVariant; - javascript << L" -= "; - } + if (CFXA_IsTooBig(javascript)) + return false; + + javascript << (m_bDirection ? kLessEqual : kGreaterEqual); + javascript << XFA_FM_EXPTypeToString(GETFMVALUE); + javascript << L"("; + if (!m_pAccessor->ToJavaScript(javascript)) + return false; + javascript << L"); "; + javascript << tempVariant; + javascript << L" += "; + javascript << (m_bDirection ? kPlusEqual : kMinusEqual); + if (CFXA_IsTooBig(javascript)) + return false; + if (m_pStep) { javascript << XFA_FM_EXPTypeToString(GETFMVALUE); javascript << L"("; - m_pStep->ToJavaScript(javascript); + if (!m_pStep->ToJavaScript(javascript)) + return false; javascript << L")"; + if (CFXA_IsTooBig(javascript)) + return false; } else { javascript << L"1"; } javascript << L")\n"; - m_pList->ToImpliedReturnJS(javascript); + if (!m_pList->ToImpliedReturnJS(javascript)) + return false; javascript << L"}\n"; + return !CFXA_IsTooBig(javascript); } CXFA_FMForeachExpression::CXFA_FMForeachExpression( @@ -498,7 +573,7 @@ CXFA_FMForeachExpression::CXFA_FMForeachExpression( CXFA_FMForeachExpression::~CXFA_FMForeachExpression() {} -void CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"{\n"; javascript << L"var "; if (m_wsIdentifier.GetAt(0) == L'!') { @@ -516,9 +591,12 @@ void CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"("; for (const auto& expr : m_pAccessors) { - expr->ToJavaScript(javascript); + if (!expr->ToJavaScript(javascript)) + return false; if (expr != m_pAccessors.back()) javascript << L", "; + if (CFXA_IsTooBig(javascript)) + return false; } javascript << L");\n"; javascript << L"var "; @@ -541,12 +619,14 @@ void CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"["; javascript << RUNTIMEBLOCKTEMPARRAYINDEX; javascript << L"++];\n"; - m_pList->ToJavaScript(javascript); + if (!m_pList->ToJavaScript(javascript)) + return false; javascript << L"}\n"; javascript << L"}\n"; + return !CFXA_IsTooBig(javascript); } -void CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { +bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"{\n"; @@ -565,9 +645,12 @@ void CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << XFA_FM_EXPTypeToString(CONCATFMOBJECT); javascript << L"("; for (const auto& expr : m_pAccessors) { - expr->ToJavaScript(javascript); + if (!expr->ToJavaScript(javascript)) + return false; if (expr != m_pAccessors.back()) javascript << L", "; + if (CFXA_IsTooBig(javascript)) + return false; } javascript << L");\n"; javascript << L"var "; @@ -590,7 +673,9 @@ void CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << L"["; javascript << RUNTIMEBLOCKTEMPARRAYINDEX; javascript << L"++];\n"; - m_pList->ToImpliedReturnJS(javascript); + if (!m_pList->ToImpliedReturnJS(javascript)) + return false; javascript << L"}\n"; javascript << L"}\n"; + return !CFXA_IsTooBig(javascript); } diff --git a/xfa/fxfa/fm2js/xfa_expression.h b/xfa/fxfa/fm2js/xfa_expression.h index 9177c305d2..e6022b3e69 100644 --- a/xfa/fxfa/fm2js/xfa_expression.h +++ b/xfa/fxfa/fm2js/xfa_expression.h @@ -28,8 +28,8 @@ class CXFA_FMExpression { explicit CXFA_FMExpression(uint32_t line); CXFA_FMExpression(uint32_t line, XFA_FM_EXPTYPE type); virtual ~CXFA_FMExpression() {} - virtual void ToJavaScript(CFX_WideTextBuf& javascript); - virtual void ToImpliedReturnJS(CFX_WideTextBuf&); + virtual bool ToJavaScript(CFX_WideTextBuf& javascript); + virtual bool ToImpliedReturnJS(CFX_WideTextBuf&); uint32_t GetLine() { return m_line; } XFA_FM_EXPTYPE GetExpType() const { return m_type; } @@ -49,8 +49,8 @@ class CXFA_FMFunctionDefinition : public CXFA_FMExpression { std::vector<std::unique_ptr<CXFA_FMExpression>>&& expressions); ~CXFA_FMFunctionDefinition() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; private: CFX_WideStringC m_wsName; @@ -66,8 +66,8 @@ class CXFA_FMVarExpression : public CXFA_FMExpression { std::unique_ptr<CXFA_FMExpression> pInit); ~CXFA_FMVarExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; private: CFX_WideStringC m_wsName; @@ -80,8 +80,8 @@ class CXFA_FMExpExpression : public CXFA_FMExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExpression); ~CXFA_FMExpExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; private: std::unique_ptr<CXFA_FMSimpleExpression> m_pExpression; @@ -94,8 +94,8 @@ class CXFA_FMBlockExpression : public CXFA_FMExpression { std::vector<std::unique_ptr<CXFA_FMExpression>>&& pExpressionList); ~CXFA_FMBlockExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; private: std::vector<std::unique_ptr<CXFA_FMExpression>> m_ExpressionList; @@ -106,8 +106,8 @@ class CXFA_FMDoExpression : public CXFA_FMExpression { CXFA_FMDoExpression(uint32_t line, std::unique_ptr<CXFA_FMExpression> pList); ~CXFA_FMDoExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; private: std::unique_ptr<CXFA_FMExpression> m_pList; @@ -121,8 +121,8 @@ class CXFA_FMIfExpression : public CXFA_FMExpression { std::unique_ptr<CXFA_FMExpression> pElseExpression); ~CXFA_FMIfExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; private: std::unique_ptr<CXFA_FMSimpleExpression> m_pExpression; @@ -134,8 +134,8 @@ class CXFA_FMLoopExpression : public CXFA_FMExpression { public: explicit CXFA_FMLoopExpression(uint32_t line) : CXFA_FMExpression(line) {} ~CXFA_FMLoopExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; }; class CXFA_FMWhileExpression : public CXFA_FMLoopExpression { @@ -145,8 +145,8 @@ class CXFA_FMWhileExpression : public CXFA_FMLoopExpression { std::unique_ptr<CXFA_FMExpression> pExpression); ~CXFA_FMWhileExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; private: std::unique_ptr<CXFA_FMSimpleExpression> m_pCondition; @@ -157,16 +157,16 @@ class CXFA_FMBreakExpression : public CXFA_FMExpression { public: explicit CXFA_FMBreakExpression(uint32_t line); ~CXFA_FMBreakExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; }; class CXFA_FMContinueExpression : public CXFA_FMExpression { public: explicit CXFA_FMContinueExpression(uint32_t line); ~CXFA_FMContinueExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; }; class CXFA_FMForExpression : public CXFA_FMLoopExpression { @@ -180,14 +180,14 @@ class CXFA_FMForExpression : public CXFA_FMLoopExpression { std::unique_ptr<CXFA_FMExpression> pList); ~CXFA_FMForExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; private: CFX_WideStringC m_wsVariant; std::unique_ptr<CXFA_FMSimpleExpression> m_pAssignment; std::unique_ptr<CXFA_FMSimpleExpression> m_pAccessor; - int32_t m_iDirection; + const bool m_bDirection; std::unique_ptr<CXFA_FMSimpleExpression> m_pStep; std::unique_ptr<CXFA_FMExpression> m_pList; }; @@ -202,8 +202,8 @@ class CXFA_FMForeachExpression : public CXFA_FMLoopExpression { std::unique_ptr<CXFA_FMExpression> pList); ~CXFA_FMForeachExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf&) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf&) override; private: CFX_WideStringC m_wsIdentifier; diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index 8879b94373..716e378ed7 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -6123,8 +6123,7 @@ int32_t CXFA_FM2JSContext::Translate(const CFX_WideStringC& wsFormcalc, if (status) return status; - program.TranslateProgram(*wsJavascript); - return 0; + return program.TranslateProgram(*wsJavascript); } CXFA_FM2JSContext::CXFA_FM2JSContext(v8::Isolate* pScriptIsolate, diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp index 298a2eb334..a7ba901c89 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.cpp +++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp @@ -29,9 +29,9 @@ CXFA_FMParse::~CXFA_FMParse() {} void CXFA_FMParse::NextToken() { m_pToken = m_lexer->NextToken(); while (m_pToken->m_type == TOKreserver) { - if (m_lexer->HasError()) { + if (m_lexer->HasError()) break; - } + m_pToken = m_lexer->NextToken(); } } @@ -64,21 +64,10 @@ CXFA_FMParse::ParseTopExpression() { return expressions; } - if (m_pToken->m_type == TOKfunc) { - expr = ParseFunction(); - if (expr) { - expressions.push_back(std::move(expr)); - } else { - break; - } - } else { - expr = ParseExpression(); - if (expr) { - expressions.push_back(std::move(expr)); - } else { - break; - } - } + expr = m_pToken->m_type == TOKfunc ? ParseFunction() : ParseExpression(); + if (!expr) + break; + expressions.push_back(std::move(expr)); } return expressions; } @@ -108,20 +97,18 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseFunction() { if (m_pToken->m_type == TOKcomma) { NextToken(); continue; - } else if (m_pToken->m_type == TOKrparen) { + } + if (m_pToken->m_type == TOKrparen) NextToken(); - break; - } else { + else Check(TOKrparen); - break; - } } else { CFX_WideString ws_TempString(m_pToken->m_wstring); Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, ws_TempString.c_str()); NextToken(); - break; } + break; } } Check(TOKdo); @@ -131,7 +118,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseFunction() { expressions = ParseTopExpression(); Check(TOKendfunc); } - if (!m_pErrorInfo->message.IsEmpty()) + if (HasError()) return nullptr; return pdfium::MakeUnique<CXFA_FMFunctionDefinition>( @@ -205,7 +192,7 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseVarExpression() { NextToken(); expr = ParseExpExpression(); } - if (!m_pErrorInfo->message.IsEmpty()) + if (HasError()) return nullptr; return pdfium::MakeUnique<CXFA_FMVarExpression>(line, ident, std::move(expr)); @@ -233,7 +220,7 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParseSimpleExpression() { std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseExpExpression() { uint32_t line = m_pToken->m_uLinenum; std::unique_ptr<CXFA_FMSimpleExpression> pExp1 = ParseSimpleExpression(); - if (!m_pErrorInfo->message.IsEmpty()) + if (HasError()) return nullptr; return pdfium::MakeUnique<CXFA_FMExpExpression>(line, std::move(pExp1)); @@ -522,7 +509,8 @@ CXFA_FMParse::ParsePrimaryExpression() { expr = pdfium::MakeUnique<CXFA_FMIdentifierExpression>(line, wsIdentifier); } - } break; + break; + } case TOKif: expr = pdfium::MakeUnique<CXFA_FMIdentifierExpression>( line, m_pToken->m_wstring); @@ -543,7 +531,7 @@ CXFA_FMParse::ParsePrimaryExpression() { break; } expr = ParsePostExpression(std::move(expr)); - if (!m_pErrorInfo->message.IsEmpty()) + if (HasError()) expr.reset(); return expr; } @@ -591,7 +579,8 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( } else { expr.reset(); } - } break; + break; + } case TOKdot: NextToken(); if (m_pToken->m_type == TOKidentifier) { @@ -645,7 +634,7 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( } } else if (m_pToken->m_type == TOKlbracket) { std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); - if (!(m_pErrorInfo->message.IsEmpty())) + if (HasError()) return nullptr; expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( @@ -673,9 +662,9 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( NextToken(); if (m_pToken->m_type == TOKlbracket) { std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); - if (!(m_pErrorInfo->message.IsEmpty())) { + if (HasError()) return nullptr; - } + expr = pdfium::MakeUnique<CXFA_FMDotDotAccessorExpression>( tempLine, std::move(expr), TOKdotdot, tempStr, std::move(s)); } else { @@ -693,41 +682,41 @@ std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParse::ParsePostExpression( return expr; } break; - case TOKdotscream: + case TOKdotscream: { NextToken(); - if (m_pToken->m_type == TOKidentifier) { - CFX_WideStringC tempStr = m_pToken->m_wstring; - 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())) - return nullptr; - - expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( - tempLine, std::move(expr), TOKdotscream, tempStr, std::move(s)); - } else { - std::unique_ptr<CXFA_FMSimpleExpression> s = - pdfium::MakeUnique<CXFA_FMIndexExpression>( - tempLine, ACCESSOR_NO_INDEX, nullptr, false); - expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( - line, std::move(expr), TOKdotscream, tempStr, std::move(s)); - continue; - } - } else { + if (m_pToken->m_type != TOKidentifier) { CFX_WideString ws_TempString(m_pToken->m_wstring); Error(m_pToken->m_uLinenum, kFMErrExpectedIdentifier, ws_TempString.c_str()); return expr; } + CFX_WideStringC tempStr = m_pToken->m_wstring; + uint32_t tempLine = m_pToken->m_uLinenum; + NextToken(); + if (m_pToken->m_type != TOKlbracket) { + std::unique_ptr<CXFA_FMSimpleExpression> s = + pdfium::MakeUnique<CXFA_FMIndexExpression>( + tempLine, ACCESSOR_NO_INDEX, nullptr, false); + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + line, std::move(expr), TOKdotscream, tempStr, std::move(s)); + continue; + } + std::unique_ptr<CXFA_FMSimpleExpression> s = ParseIndexExpression(); + if (HasError()) + return nullptr; + + expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( + tempLine, std::move(expr), TOKdotscream, tempStr, std::move(s)); break; + } case TOKdotstar: { std::unique_ptr<CXFA_FMSimpleExpression> s = pdfium::MakeUnique<CXFA_FMIndexExpression>(line, ACCESSOR_NO_INDEX, nullptr, false); expr = pdfium::MakeUnique<CXFA_FMDotAccessorExpression>( line, std::move(expr), TOKdotstar, L"*", std::move(s)); - } break; + break; + } default: return expr; } @@ -1028,8 +1017,12 @@ std::unique_ptr<CXFA_FMExpression> CXFA_FMParse::ParseDoExpression() { NextToken(); std::unique_ptr<CXFA_FMExpression> expr = ParseBlockExpression(); Check(TOKend); - if (!m_pErrorInfo->message.IsEmpty()) + if (HasError()) return nullptr; return pdfium::MakeUnique<CXFA_FMDoExpression>(line, std::move(expr)); } + +bool CXFA_FMParse::HasError() const { + return !m_pErrorInfo->message.IsEmpty(); +} diff --git a/xfa/fxfa/fm2js/xfa_fmparse.h b/xfa/fxfa/fm2js/xfa_fmparse.h index ccb793ae68..23b01b877c 100644 --- a/xfa/fxfa/fm2js/xfa_fmparse.h +++ b/xfa/fxfa/fm2js/xfa_fmparse.h @@ -48,6 +48,8 @@ class CXFA_FMParse { std::unique_ptr<CXFA_FMSimpleExpression> ParseIndexExpression(); private: + bool HasError() const; + std::unique_ptr<CXFA_FMLexer> m_lexer; CXFA_FMToken* m_pToken; CXFA_FMErrorInfo* const m_pErrorInfo; diff --git a/xfa/fxfa/fm2js/xfa_program.cpp b/xfa/fxfa/fm2js/xfa_program.cpp index 514b7a6a23..6afe332629 100644 --- a/xfa/fxfa/fm2js/xfa_program.cpp +++ b/xfa/fxfa/fm2js/xfa_program.cpp @@ -33,7 +33,8 @@ int32_t CXFA_FMProgram::ParseProgram() { } int32_t CXFA_FMProgram::TranslateProgram(CFX_WideTextBuf& wsJavaScript) { - m_globalFunction->ToJavaScript(wsJavaScript); + if (!m_globalFunction->ToJavaScript(wsJavaScript)) + return -1; wsJavaScript.AppendChar(0); return 0; } diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp index fabdaa60f0..1438ff29a4 100644 --- a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp +++ b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp @@ -120,9 +120,13 @@ CFX_WideStringC XFA_FM_EXPTypeToString( CXFA_FMSimpleExpression::CXFA_FMSimpleExpression(uint32_t line, XFA_FM_TOKEN op) : m_line(line), m_op(op) {} -void CXFA_FMSimpleExpression::ToJavaScript(CFX_WideTextBuf& javascript) {} +bool CXFA_FMSimpleExpression::ToJavaScript(CFX_WideTextBuf& javascript) { + return true; +} -void CXFA_FMSimpleExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) {} +bool CXFA_FMSimpleExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { + return true; +} XFA_FM_TOKEN CXFA_FMSimpleExpression::GetOperatorToken() const { return m_op; @@ -131,8 +135,9 @@ XFA_FM_TOKEN CXFA_FMSimpleExpression::GetOperatorToken() const { CXFA_FMNullExpression::CXFA_FMNullExpression(uint32_t line) : CXFA_FMSimpleExpression(line, TOKnull) {} -void CXFA_FMNullExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMNullExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"null"; + return true; } CXFA_FMNumberExpression::CXFA_FMNumberExpression(uint32_t line, @@ -141,8 +146,9 @@ CXFA_FMNumberExpression::CXFA_FMNumberExpression(uint32_t line, CXFA_FMNumberExpression::~CXFA_FMNumberExpression() {} -void CXFA_FMNumberExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMNumberExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << m_wsNumber; + return true; } CXFA_FMStringExpression::CXFA_FMStringExpression(uint32_t line, @@ -151,11 +157,11 @@ CXFA_FMStringExpression::CXFA_FMStringExpression(uint32_t line, CXFA_FMStringExpression::~CXFA_FMStringExpression() {} -void CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CFX_WideString tempStr(m_wsString); if (tempStr.GetLength() <= 2) { javascript << tempStr; - return; + return true; } javascript.AppendChar(L'\"'); for (int32_t i = 1; i < tempStr.GetLength() - 1; i++) { @@ -176,6 +182,7 @@ void CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& javascript) { } } javascript.AppendChar(L'\"'); + return true; } CXFA_FMIdentifierExpression::CXFA_FMIdentifierExpression( @@ -186,7 +193,7 @@ CXFA_FMIdentifierExpression::CXFA_FMIdentifierExpression( CXFA_FMIdentifierExpression::~CXFA_FMIdentifierExpression() {} -void CXFA_FMIdentifierExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMIdentifierExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CFX_WideString tempStr(m_wsIdentifier); if (tempStr == L"$") { tempStr = L"this"; @@ -208,6 +215,7 @@ void CXFA_FMIdentifierExpression::ToJavaScript(CFX_WideTextBuf& javascript) { tempStr = EXCLAMATION_IN_IDENTIFIER + tempStr.Mid(1); } javascript << tempStr; + return true; } CXFA_FMUnaryExpression::CXFA_FMUnaryExpression( @@ -218,7 +226,9 @@ CXFA_FMUnaryExpression::CXFA_FMUnaryExpression( CXFA_FMUnaryExpression::~CXFA_FMUnaryExpression() {} -void CXFA_FMUnaryExpression::ToJavaScript(CFX_WideTextBuf& javascript) {} +bool CXFA_FMUnaryExpression::ToJavaScript(CFX_WideTextBuf& javascript) { + return true; +} CXFA_FMBinExpression::CXFA_FMBinExpression( uint32_t line, @@ -231,7 +241,9 @@ CXFA_FMBinExpression::CXFA_FMBinExpression( CXFA_FMBinExpression::~CXFA_FMBinExpression() {} -void CXFA_FMBinExpression::ToJavaScript(CFX_WideTextBuf& javascript) {} +bool CXFA_FMBinExpression::ToJavaScript(CFX_WideTextBuf& javascript) { + return true; +} CXFA_FMAssignExpression::CXFA_FMAssignExpression( uint32_t line, @@ -240,20 +252,27 @@ CXFA_FMAssignExpression::CXFA_FMAssignExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp2) : CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {} -void CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"if ("; javascript << gs_lpStrExpFuncName[ISFMOBJECT]; javascript << L"("; - m_pExp1->ToJavaScript(javascript); + CFX_WideTextBuf tempExp1; + if (!m_pExp1->ToJavaScript(tempExp1)) + return false; + javascript << tempExp1; javascript << L"))\n{\n"; javascript << gs_lpStrExpFuncName[ASSIGN]; javascript << L"("; - m_pExp1->ToJavaScript(javascript); + javascript << tempExp1; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + if (CFXA_IsTooBig(javascript)) + return false; + + CFX_WideTextBuf tempExp2; + if (!m_pExp2->ToJavaScript(tempExp2)) + return false; + javascript << tempExp2; javascript << L");\n}\n"; - CFX_WideTextBuf tempExp1; - m_pExp1->ToJavaScript(tempExp1); if (m_pExp1->GetOperatorToken() == TOKidentifier && tempExp1.AsStringC() != L"this") { javascript << L"else\n{\n"; @@ -261,29 +280,37 @@ void CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L" = "; javascript << gs_lpStrExpFuncName[ASSIGN]; javascript << L"("; - m_pExp1->ToJavaScript(javascript); + javascript << tempExp1; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + javascript << tempExp2; javascript << L");\n}\n"; } + return !CFXA_IsTooBig(javascript); } -void CXFA_FMAssignExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { +bool CXFA_FMAssignExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << L"if ("; javascript << gs_lpStrExpFuncName[ISFMOBJECT]; javascript << L"("; - m_pExp1->ToJavaScript(javascript); + 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"("; - m_pExp1->ToJavaScript(javascript); + javascript << tempExp1; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + if (CFXA_IsTooBig(javascript)) + return false; + + CFX_WideTextBuf tempExp2; + if (!m_pExp2->ToJavaScript(tempExp2)) + return false; + javascript << tempExp2; javascript << L");\n}\n"; - CFX_WideTextBuf tempExp1; - m_pExp1->ToJavaScript(tempExp1); if (m_pExp1->GetOperatorToken() == TOKidentifier && tempExp1.AsStringC() != L"this") { javascript << L"else\n{\n"; @@ -293,11 +320,12 @@ void CXFA_FMAssignExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << L" = "; javascript << gs_lpStrExpFuncName[ASSIGN]; javascript << L"("; - m_pExp1->ToJavaScript(javascript); + javascript << tempExp1; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + javascript << tempExp2; javascript << L");\n}\n"; } + return !CFXA_IsTooBig(javascript); } CXFA_FMLogicalOrExpression::CXFA_FMLogicalOrExpression( @@ -307,13 +335,16 @@ CXFA_FMLogicalOrExpression::CXFA_FMLogicalOrExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp2) : CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {} -void CXFA_FMLogicalOrExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMLogicalOrExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << gs_lpStrExpFuncName[LOGICALOR]; javascript << L"("; - m_pExp1->ToJavaScript(javascript); + if (!m_pExp1->ToJavaScript(javascript)) + return false; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + if (!m_pExp2->ToJavaScript(javascript)) + return false; javascript << L")"; + return !CFXA_IsTooBig(javascript); } CXFA_FMLogicalAndExpression::CXFA_FMLogicalAndExpression( @@ -323,13 +354,16 @@ CXFA_FMLogicalAndExpression::CXFA_FMLogicalAndExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp2) : CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {} -void CXFA_FMLogicalAndExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMLogicalAndExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << gs_lpStrExpFuncName[LOGICALAND]; javascript << L"("; - m_pExp1->ToJavaScript(javascript); + if (!m_pExp1->ToJavaScript(javascript)) + return false; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + if (!m_pExp2->ToJavaScript(javascript)) + return false; javascript << L")"; + return !CFXA_IsTooBig(javascript); } CXFA_FMEqualityExpression::CXFA_FMEqualityExpression( @@ -339,7 +373,7 @@ CXFA_FMEqualityExpression::CXFA_FMEqualityExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp2) : CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {} -void CXFA_FMEqualityExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMEqualityExpression::ToJavaScript(CFX_WideTextBuf& javascript) { switch (m_op) { case TOKeq: case TOKkseq: @@ -354,10 +388,13 @@ void CXFA_FMEqualityExpression::ToJavaScript(CFX_WideTextBuf& javascript) { break; } javascript << L"("; - m_pExp1->ToJavaScript(javascript); + if (!m_pExp1->ToJavaScript(javascript)) + return false; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + if (!m_pExp2->ToJavaScript(javascript)) + return false; javascript << L")"; + return !CFXA_IsTooBig(javascript); } CXFA_FMRelationalExpression::CXFA_FMRelationalExpression( @@ -367,7 +404,7 @@ CXFA_FMRelationalExpression::CXFA_FMRelationalExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp2) : CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {} -void CXFA_FMRelationalExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMRelationalExpression::ToJavaScript(CFX_WideTextBuf& javascript) { switch (m_op) { case TOKlt: case TOKkslt: @@ -390,10 +427,13 @@ void CXFA_FMRelationalExpression::ToJavaScript(CFX_WideTextBuf& javascript) { break; } javascript << L"("; - m_pExp1->ToJavaScript(javascript); + if (!m_pExp1->ToJavaScript(javascript)) + return false; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + if (!m_pExp2->ToJavaScript(javascript)) + return false; javascript << L")"; + return !CFXA_IsTooBig(javascript); } CXFA_FMAdditiveExpression::CXFA_FMAdditiveExpression( @@ -403,7 +443,7 @@ CXFA_FMAdditiveExpression::CXFA_FMAdditiveExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp2) : CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {} -void CXFA_FMAdditiveExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMAdditiveExpression::ToJavaScript(CFX_WideTextBuf& javascript) { switch (m_op) { case TOKplus: javascript << gs_lpStrExpFuncName[PLUS]; @@ -416,10 +456,13 @@ void CXFA_FMAdditiveExpression::ToJavaScript(CFX_WideTextBuf& javascript) { break; } javascript << L"("; - m_pExp1->ToJavaScript(javascript); + if (!m_pExp1->ToJavaScript(javascript)) + return false; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + if (!m_pExp2->ToJavaScript(javascript)) + return false; javascript << L")"; + return !CFXA_IsTooBig(javascript); } CXFA_FMMultiplicativeExpression::CXFA_FMMultiplicativeExpression( @@ -429,7 +472,7 @@ CXFA_FMMultiplicativeExpression::CXFA_FMMultiplicativeExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp2) : CXFA_FMBinExpression(line, op, std::move(pExp1), std::move(pExp2)) {} -void CXFA_FMMultiplicativeExpression::ToJavaScript( +bool CXFA_FMMultiplicativeExpression::ToJavaScript( CFX_WideTextBuf& javascript) { switch (m_op) { case TOKmul: @@ -443,10 +486,13 @@ void CXFA_FMMultiplicativeExpression::ToJavaScript( break; } javascript << L"("; - m_pExp1->ToJavaScript(javascript); + if (!m_pExp1->ToJavaScript(javascript)) + return false; javascript << L", "; - m_pExp2->ToJavaScript(javascript); + if (!m_pExp2->ToJavaScript(javascript)) + return false; javascript << L")"; + return !CFXA_IsTooBig(javascript); } CXFA_FMPosExpression::CXFA_FMPosExpression( @@ -454,11 +500,13 @@ CXFA_FMPosExpression::CXFA_FMPosExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp) : CXFA_FMUnaryExpression(line, TOKplus, std::move(pExp)) {} -void CXFA_FMPosExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMPosExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << gs_lpStrExpFuncName[POSITIVE]; javascript << L"("; - m_pExp->ToJavaScript(javascript); + if (!m_pExp->ToJavaScript(javascript)) + return false; javascript << L")"; + return true; } CXFA_FMNegExpression::CXFA_FMNegExpression( @@ -466,11 +514,13 @@ CXFA_FMNegExpression::CXFA_FMNegExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp) : CXFA_FMUnaryExpression(line, TOKminus, std::move(pExp)) {} -void CXFA_FMNegExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMNegExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << gs_lpStrExpFuncName[NEGATIVE]; javascript << L"("; - m_pExp->ToJavaScript(javascript); + if (!m_pExp->ToJavaScript(javascript)) + return false; javascript << L")"; + return true; } CXFA_FMNotExpression::CXFA_FMNotExpression( @@ -478,11 +528,13 @@ CXFA_FMNotExpression::CXFA_FMNotExpression( std::unique_ptr<CXFA_FMSimpleExpression> pExp) : CXFA_FMUnaryExpression(line, TOKksnot, std::move(pExp)) {} -void CXFA_FMNotExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMNotExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << gs_lpStrExpFuncName[NOT]; javascript << L"("; - m_pExp->ToJavaScript(javascript); + if (!m_pExp->ToJavaScript(javascript)) + return false; javascript << L")"; + return true; } CXFA_FMCallExpression::CXFA_FMCallExpression( @@ -535,9 +587,10 @@ uint32_t CXFA_FMCallExpression::IsMethodWithObjParam( return parameters; } -void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CFX_WideTextBuf funcName; - m_pExp->ToJavaScript(funcName); + if (!m_pExp->ToJavaScript(funcName)) + return false; if (m_bIsSomMethod) { javascript << funcName; javascript << L"("; @@ -554,20 +607,26 @@ void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { } javascript << L"("; const auto& expr = m_Arguments[i]; - expr->ToJavaScript(javascript); + if (!expr->ToJavaScript(javascript)) + return false; javascript << L")"; if (i + 1 < m_Arguments.size()) { javascript << L", "; } + if (CFXA_IsTooBig(javascript)) + return false; } } else { for (const auto& expr : m_Arguments) { javascript << gs_lpStrExpFuncName[GETFMVALUE]; javascript << L"("; - expr->ToJavaScript(javascript); + if (!expr->ToJavaScript(javascript)) + return false; javascript << L")"; if (expr != m_Arguments.back()) javascript << L", "; + if (CFXA_IsTooBig(javascript)) + return false; } } javascript << L")"; @@ -597,18 +656,22 @@ void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { if (!m_Arguments.empty()) { const auto& expr = m_Arguments[0]; javascript << L"return "; - expr->ToJavaScript(javascript); + if (!expr->ToJavaScript(javascript)) + return false; javascript << L";\n}\n"; } else { javascript << L"return 0;\n}\n"; } - javascript - << L"catch(accessExceptions)\n{\nreturn 0;\n}\n}\n).call(this)\n"; + javascript << L"catch(accessExceptions)\n"; + javascript << L"{\nreturn 0;\n}\n}\n).call(this)\n"; } else { for (const auto& expr : m_Arguments) { - expr->ToJavaScript(javascript); + if (!expr->ToJavaScript(javascript)) + return false; if (expr != m_Arguments.back()) javascript << L", "; + if (CFXA_IsTooBig(javascript)) + return false; } } javascript << L")"; @@ -616,6 +679,7 @@ void CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L")"; } } + return true; } CXFA_FMDotAccessorExpression::CXFA_FMDotAccessorExpression( @@ -632,19 +696,24 @@ CXFA_FMDotAccessorExpression::CXFA_FMDotAccessorExpression( CXFA_FMDotAccessorExpression::~CXFA_FMDotAccessorExpression() {} -void CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << gs_lpStrExpFuncName[DOT]; javascript << L"("; + CFX_WideTextBuf tempExp1; if (m_pExp1) { - m_pExp1->ToJavaScript(javascript); + if (!m_pExp1->ToJavaScript(tempExp1)) + return false; + javascript << tempExp1; } else { javascript << L"null"; } javascript << L", "; javascript << L"\""; - if (m_pExp1 && m_pExp1->GetOperatorToken() == TOKidentifier) { - m_pExp1->ToJavaScript(javascript); - } + if (CFXA_IsTooBig(javascript)) + return false; + + if (m_pExp1 && m_pExp1->GetOperatorToken() == TOKidentifier) + javascript << tempExp1; javascript << L"\", "; if (m_op == TOKdotscream) { javascript << L"\"#"; @@ -659,8 +728,10 @@ void CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << m_wsIdentifier; javascript << L"\", "; } - m_pExp2->ToJavaScript(javascript); + if (!m_pExp2->ToJavaScript(javascript)) + return false; javascript << L")"; + return !CFXA_IsTooBig(javascript); } CXFA_FMIndexExpression::CXFA_FMIndexExpression( @@ -672,7 +743,7 @@ CXFA_FMIndexExpression::CXFA_FMIndexExpression( m_accessorIndex(accessorIndex), m_bIsStarIndex(bIsStarIndex) {} -void CXFA_FMIndexExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +bool CXFA_FMIndexExpression::ToJavaScript(CFX_WideTextBuf& javascript) { switch (m_accessorIndex) { case ACCESSOR_NO_INDEX: javascript << L"0"; @@ -692,11 +763,13 @@ void CXFA_FMIndexExpression::ToJavaScript(CFX_WideTextBuf& javascript) { if (!m_bIsStarIndex) { javascript << L", "; if (m_pExp) { - m_pExp->ToJavaScript(javascript); + if (!m_pExp->ToJavaScript(javascript)) + return false; } else { javascript << L"0"; } } + return true; } CXFA_FMDotDotAccessorExpression::CXFA_FMDotDotAccessorExpression( @@ -713,22 +786,29 @@ CXFA_FMDotDotAccessorExpression::CXFA_FMDotDotAccessorExpression( CXFA_FMDotDotAccessorExpression::~CXFA_FMDotDotAccessorExpression() {} -void CXFA_FMDotDotAccessorExpression::ToJavaScript( +bool CXFA_FMDotDotAccessorExpression::ToJavaScript( CFX_WideTextBuf& javascript) { javascript << gs_lpStrExpFuncName[DOTDOT]; javascript << L"("; - m_pExp1->ToJavaScript(javascript); + CFX_WideTextBuf tempExp1; + if (!m_pExp1->ToJavaScript(tempExp1)) + return false; + javascript << tempExp1; javascript << L", "; javascript << L"\""; - if (m_pExp1 && m_pExp1->GetOperatorToken() == TOKidentifier) { - m_pExp1->ToJavaScript(javascript); - } + if (CFXA_IsTooBig(javascript)) + return false; + + if (m_pExp1->GetOperatorToken() == TOKidentifier) + javascript << tempExp1; javascript << L"\", "; javascript << L"\""; javascript << m_wsIdentifier; javascript << L"\", "; - m_pExp2->ToJavaScript(javascript); + if (!m_pExp2->ToJavaScript(javascript)) + return false; javascript << L")"; + return !CFXA_IsTooBig(javascript); } CXFA_FMMethodCallExpression::CXFA_FMMethodCallExpression( @@ -740,11 +820,12 @@ CXFA_FMMethodCallExpression::CXFA_FMMethodCallExpression( std::move(pAccessorExp1), std::move(pCallExp)) {} -void CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { +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 = "; - m_pExp1->ToJavaScript(javascript); + if (!m_pExp1->ToJavaScript(javascript)) + return false; javascript << L";\n"; javascript << L"if ("; javascript << gs_lpStrExpFuncName[ISFMARRAY]; @@ -752,11 +833,22 @@ void CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& javascript) { javascript << L"for(var index = accessor_object.length - 1; index > 1; " L"index--)\n{\n"; javascript << L"method_return_value = accessor_object[index]."; - m_pExp2->ToJavaScript(javascript); + if (CFXA_IsTooBig(javascript)) + return false; + + CFX_WideTextBuf tempExp2; + if (!m_pExp2->ToJavaScript(tempExp2)) + return false; + javascript << tempExp2; javascript << L";\n}\n}\n"; javascript << L"else\n{\nmethod_return_value = accessor_object."; - m_pExp2->ToJavaScript(javascript); + javascript << tempExp2; javascript << L";\n}\n"; javascript << L"return method_return_value;\n"; javascript << L"}\n).call(this)"; + return !CFXA_IsTooBig(javascript); +} + +bool CFXA_IsTooBig(const CFX_WideTextBuf& javascript) { + return javascript.GetSize() > 256 * 1024 * 1024; } diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression.h b/xfa/fxfa/fm2js/xfa_simpleexpression.h index af1d02eea5..cb40e2b987 100644 --- a/xfa/fxfa/fm2js/xfa_simpleexpression.h +++ b/xfa/fxfa/fm2js/xfa_simpleexpression.h @@ -59,28 +59,28 @@ class CXFA_FMSimpleExpression { public: CXFA_FMSimpleExpression(uint32_t line, XFA_FM_TOKEN op); virtual ~CXFA_FMSimpleExpression() {} - virtual void ToJavaScript(CFX_WideTextBuf& javascript); - virtual void ToImpliedReturnJS(CFX_WideTextBuf& javascript); + virtual bool ToJavaScript(CFX_WideTextBuf& javascript); + virtual bool ToImpliedReturnJS(CFX_WideTextBuf& javascript); XFA_FM_TOKEN GetOperatorToken() const; protected: uint32_t m_line; - XFA_FM_TOKEN m_op; + const XFA_FM_TOKEN m_op; }; class CXFA_FMNullExpression : public CXFA_FMSimpleExpression { public: explicit CXFA_FMNullExpression(uint32_t line); ~CXFA_FMNullExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMNumberExpression : public CXFA_FMSimpleExpression { public: CXFA_FMNumberExpression(uint32_t line, CFX_WideStringC wsNumber); ~CXFA_FMNumberExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; private: CFX_WideStringC m_wsNumber; @@ -90,7 +90,7 @@ class CXFA_FMStringExpression : public CXFA_FMSimpleExpression { public: CXFA_FMStringExpression(uint32_t line, CFX_WideStringC wsString); ~CXFA_FMStringExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; private: CFX_WideStringC m_wsString; @@ -100,7 +100,7 @@ class CXFA_FMIdentifierExpression : public CXFA_FMSimpleExpression { public: CXFA_FMIdentifierExpression(uint32_t line, CFX_WideStringC wsIdentifier); ~CXFA_FMIdentifierExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; private: CFX_WideStringC m_wsIdentifier; @@ -113,7 +113,7 @@ class CXFA_FMUnaryExpression : public CXFA_FMSimpleExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExp); ~CXFA_FMUnaryExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; protected: std::unique_ptr<CXFA_FMSimpleExpression> m_pExp; @@ -127,7 +127,7 @@ class CXFA_FMBinExpression : public CXFA_FMSimpleExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExp2); ~CXFA_FMBinExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; protected: std::unique_ptr<CXFA_FMSimpleExpression> m_pExp1; @@ -141,8 +141,8 @@ class CXFA_FMAssignExpression : public CXFA_FMBinExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExp1, std::unique_ptr<CXFA_FMSimpleExpression> pExp2); ~CXFA_FMAssignExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; - void ToImpliedReturnJS(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToImpliedReturnJS(CFX_WideTextBuf& javascript) override; }; class CXFA_FMLogicalOrExpression : public CXFA_FMBinExpression { @@ -152,7 +152,7 @@ class CXFA_FMLogicalOrExpression : public CXFA_FMBinExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExp1, std::unique_ptr<CXFA_FMSimpleExpression> pExp2); ~CXFA_FMLogicalOrExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMLogicalAndExpression : public CXFA_FMBinExpression { @@ -162,7 +162,7 @@ class CXFA_FMLogicalAndExpression : public CXFA_FMBinExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExp1, std::unique_ptr<CXFA_FMSimpleExpression> pExp2); ~CXFA_FMLogicalAndExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMEqualityExpression : public CXFA_FMBinExpression { @@ -172,7 +172,7 @@ class CXFA_FMEqualityExpression : public CXFA_FMBinExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExp1, std::unique_ptr<CXFA_FMSimpleExpression> pExp2); ~CXFA_FMEqualityExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMRelationalExpression : public CXFA_FMBinExpression { @@ -182,7 +182,7 @@ class CXFA_FMRelationalExpression : public CXFA_FMBinExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExp1, std::unique_ptr<CXFA_FMSimpleExpression> pExp2); ~CXFA_FMRelationalExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMAdditiveExpression : public CXFA_FMBinExpression { @@ -192,7 +192,7 @@ class CXFA_FMAdditiveExpression : public CXFA_FMBinExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExp1, std::unique_ptr<CXFA_FMSimpleExpression> pExp2); ~CXFA_FMAdditiveExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMMultiplicativeExpression : public CXFA_FMBinExpression { @@ -203,7 +203,7 @@ class CXFA_FMMultiplicativeExpression : public CXFA_FMBinExpression { std::unique_ptr<CXFA_FMSimpleExpression> pExp1, std::unique_ptr<CXFA_FMSimpleExpression> pExp2); ~CXFA_FMMultiplicativeExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMPosExpression : public CXFA_FMUnaryExpression { @@ -211,7 +211,7 @@ class CXFA_FMPosExpression : public CXFA_FMUnaryExpression { CXFA_FMPosExpression(uint32_t line, std::unique_ptr<CXFA_FMSimpleExpression> pExp); ~CXFA_FMPosExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMNegExpression : public CXFA_FMUnaryExpression { @@ -219,7 +219,7 @@ class CXFA_FMNegExpression : public CXFA_FMUnaryExpression { CXFA_FMNegExpression(uint32_t line, std::unique_ptr<CXFA_FMSimpleExpression> pExp); ~CXFA_FMNegExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMNotExpression : public CXFA_FMUnaryExpression { @@ -227,7 +227,7 @@ class CXFA_FMNotExpression : public CXFA_FMUnaryExpression { CXFA_FMNotExpression(uint32_t line, std::unique_ptr<CXFA_FMSimpleExpression> pExp); ~CXFA_FMNotExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; class CXFA_FMCallExpression : public CXFA_FMUnaryExpression { @@ -241,7 +241,7 @@ class CXFA_FMCallExpression : public CXFA_FMUnaryExpression { bool IsBuildInFunc(CFX_WideTextBuf* funcName); uint32_t IsMethodWithObjParam(const CFX_WideStringC& methodName); - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; private: bool m_bIsSomMethod; @@ -257,7 +257,7 @@ class CXFA_FMDotAccessorExpression : public CXFA_FMBinExpression { CFX_WideStringC wsIdentifier, std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp); ~CXFA_FMDotAccessorExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; private: CFX_WideStringC m_wsIdentifier; @@ -270,7 +270,7 @@ class CXFA_FMIndexExpression : public CXFA_FMUnaryExpression { std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp, bool bIsStarIndex); ~CXFA_FMIndexExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; private: XFA_FM_AccessorIndex m_accessorIndex; @@ -287,7 +287,7 @@ class CXFA_FMDotDotAccessorExpression : public CXFA_FMBinExpression { std::unique_ptr<CXFA_FMSimpleExpression> pIndexExp); ~CXFA_FMDotDotAccessorExpression() override; - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; private: CFX_WideStringC m_wsIdentifier; @@ -300,7 +300,9 @@ class CXFA_FMMethodCallExpression : public CXFA_FMBinExpression { std::unique_ptr<CXFA_FMSimpleExpression> pAccessorExp1, std::unique_ptr<CXFA_FMSimpleExpression> pCallExp); ~CXFA_FMMethodCallExpression() override {} - void ToJavaScript(CFX_WideTextBuf& javascript) override; + bool ToJavaScript(CFX_WideTextBuf& javascript) override; }; +bool CFXA_IsTooBig(const CFX_WideTextBuf& javascript); + #endif // XFA_FXFA_FM2JS_XFA_SIMPLEEXPRESSION_H_ |