summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp203
1 files changed, 102 insertions, 101 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
index e34d4ba127..63d3d6a23b 100644
--- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp
@@ -80,12 +80,12 @@ XFA_FM_TOKEN CXFA_FMSimpleExpression::GetOperatorToken() const {
CXFA_FMNullExpression::CXFA_FMNullExpression()
: CXFA_FMSimpleExpression(TOKnull) {}
-bool CXFA_FMNullExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) {
+bool CXFA_FMNullExpression::ToJavaScript(CFX_WideTextBuf* js, ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
- js << L"null";
+ *js << L"null";
return !CXFA_IsTooBig(js);
}
@@ -94,13 +94,13 @@ CXFA_FMNumberExpression::CXFA_FMNumberExpression(WideStringView wsNumber)
CXFA_FMNumberExpression::~CXFA_FMNumberExpression() = default;
-bool CXFA_FMNumberExpression::ToJavaScript(CFX_WideTextBuf& js,
+bool CXFA_FMNumberExpression::ToJavaScript(CFX_WideTextBuf* js,
ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
- js << m_wsNumber;
+ *js << m_wsNumber;
return !CXFA_IsTooBig(js);
}
@@ -109,7 +109,7 @@ CXFA_FMStringExpression::CXFA_FMStringExpression(WideStringView wsString)
CXFA_FMStringExpression::~CXFA_FMStringExpression() = default;
-bool CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& js,
+bool CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf* js,
ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
@@ -117,29 +117,29 @@ bool CXFA_FMStringExpression::ToJavaScript(CFX_WideTextBuf& js,
WideString tempStr(m_wsString);
if (tempStr.GetLength() <= 2) {
- js << tempStr;
+ *js << tempStr;
return !CXFA_IsTooBig(js);
}
- js << L"\"";
+ *js << L"\"";
for (size_t i = 1; i < tempStr.GetLength() - 1; i++) {
wchar_t oneChar = tempStr[i];
switch (oneChar) {
case L'\"':
++i;
- js << L"\\\"";
+ *js << L"\\\"";
break;
case 0x0d:
break;
case 0x0a:
- js << L"\\n";
+ *js << L"\\n";
break;
default:
- js.AppendChar(oneChar);
+ js->AppendChar(oneChar);
break;
}
}
- js << L"\"";
+ *js << L"\"";
return !CXFA_IsTooBig(js);
}
@@ -149,32 +149,33 @@ CXFA_FMIdentifierExpression::CXFA_FMIdentifierExpression(
CXFA_FMIdentifierExpression::~CXFA_FMIdentifierExpression() = default;
-bool CXFA_FMIdentifierExpression::ToJavaScript(CFX_WideTextBuf& js,
+bool CXFA_FMIdentifierExpression::ToJavaScript(CFX_WideTextBuf* js,
ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
if (m_wsIdentifier == L"$")
- js << L"this";
+ *js << L"this";
else if (m_wsIdentifier == L"!")
- js << L"xfa.datasets";
+ *js << L"xfa.datasets";
else if (m_wsIdentifier == L"$data")
- js << L"xfa.datasets.data";
+ *js << L"xfa.datasets.data";
else if (m_wsIdentifier == L"$event")
- js << L"xfa.event";
+ *js << L"xfa.event";
else if (m_wsIdentifier == L"$form")
- js << L"xfa.form";
+ *js << L"xfa.form";
else if (m_wsIdentifier == L"$host")
- js << L"xfa.host";
+ *js << L"xfa.host";
else if (m_wsIdentifier == L"$layout")
- js << L"xfa.layout";
+ *js << L"xfa.layout";
else if (m_wsIdentifier == L"$template")
- js << L"xfa.template";
+ *js << L"xfa.template";
else if (m_wsIdentifier[0] == L'!')
- js << L"pfm__excl__" + m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
+ *js << L"pfm__excl__" +
+ m_wsIdentifier.Right(m_wsIdentifier.GetLength() - 1);
else
- js << m_wsIdentifier;
+ *js << m_wsIdentifier;
return !CXFA_IsTooBig(js);
}
@@ -189,35 +190,35 @@ CXFA_FMAssignExpression::CXFA_FMAssignExpression(
CXFA_FMAssignExpression::~CXFA_FMAssignExpression() = default;
-bool CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf& js,
+bool CXFA_FMAssignExpression::ToJavaScript(CFX_WideTextBuf* js,
ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
CFX_WideTextBuf tempExp1;
- if (!m_pExp1->ToJavaScript(tempExp1, ReturnType::kInfered))
+ if (!m_pExp1->ToJavaScript(&tempExp1, ReturnType::kInfered))
return false;
- js << L"if (pfm_rt.is_obj(" << tempExp1 << L"))\n{\n";
+ *js << L"if (pfm_rt.is_obj(" << tempExp1 << L"))\n{\n";
if (type == ReturnType::kImplied)
- js << L"pfm_ret = ";
+ *js << L"pfm_ret = ";
CFX_WideTextBuf tempExp2;
- if (!m_pExp2->ToJavaScript(tempExp2, ReturnType::kInfered))
+ if (!m_pExp2->ToJavaScript(&tempExp2, ReturnType::kInfered))
return false;
- js << L"pfm_rt.asgn_val_op(" << tempExp1 << L", " << tempExp2 << L");\n}\n";
+ *js << L"pfm_rt.asgn_val_op(" << tempExp1 << L", " << tempExp2 << L");\n}\n";
if (m_pExp1->GetOperatorToken() == TOKidentifier &&
tempExp1.AsStringView() != L"this") {
- js << L"else\n{\n";
+ *js << L"else\n{\n";
if (type == ReturnType::kImplied)
- js << L"pfm_ret = ";
+ *js << L"pfm_ret = ";
- js << tempExp1 << L" = pfm_rt.asgn_val_op";
- js << L"(" << tempExp1 << L", " << tempExp2 << L");\n";
- js << L"}\n";
+ *js << tempExp1 << L" = pfm_rt.asgn_val_op";
+ *js << L"(" << tempExp1 << L", " << tempExp2 << L");\n";
+ *js << L"}\n";
}
return !CXFA_IsTooBig(js);
}
@@ -234,18 +235,18 @@ CXFA_FMBinExpression::CXFA_FMBinExpression(
CXFA_FMBinExpression::~CXFA_FMBinExpression() = default;
-bool CXFA_FMBinExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) {
+bool CXFA_FMBinExpression::ToJavaScript(CFX_WideTextBuf* js, ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
- js << L"pfm_rt." << m_OpName << L"(";
+ *js << L"pfm_rt." << m_OpName << L"(";
if (!m_pExp1->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L", ";
+ *js << L", ";
if (!m_pExp2->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L")";
+ *js << L")";
return !CXFA_IsTooBig(js);
}
@@ -365,16 +366,16 @@ CXFA_FMUnaryExpression::CXFA_FMUnaryExpression(
CXFA_FMUnaryExpression::~CXFA_FMUnaryExpression() = default;
-bool CXFA_FMUnaryExpression::ToJavaScript(CFX_WideTextBuf& js,
+bool CXFA_FMUnaryExpression::ToJavaScript(CFX_WideTextBuf* js,
ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
- js << L"pfm_rt." << m_OpName.c_str() << L"(";
+ *js << L"pfm_rt." << m_OpName.c_str() << L"(";
if (!m_pExp->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L")";
+ *js << L")";
return !CXFA_IsTooBig(js);
}
@@ -434,47 +435,47 @@ uint32_t CXFA_FMCallExpression::IsMethodWithObjParam(
return 0;
}
-bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) {
+bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf* js, ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
CFX_WideTextBuf funcName;
- if (!m_pExp->ToJavaScript(funcName, ReturnType::kInfered))
+ if (!m_pExp->ToJavaScript(&funcName, ReturnType::kInfered))
return false;
if (m_bIsSomMethod) {
- js << funcName << L"(";
+ *js << funcName << L"(";
uint32_t methodPara = IsMethodWithObjParam(funcName.MakeString());
if (methodPara > 0) {
for (size_t i = 0; i < m_Arguments.size(); ++i) {
// Currently none of our expressions use objects for a parameter over
// the 6th. Make sure we don't overflow the shift when doing this
// check. If we ever need more the 32 object params we can revisit.
- js << L"pfm_rt.get_";
+ *js << L"pfm_rt.get_";
if (i < 32 && (methodPara & (0x01 << i)) > 0)
- js << L"jsobj";
+ *js << L"jsobj";
else
- js << L"val";
+ *js << L"val";
- js << L"(";
+ *js << L"(";
if (!m_Arguments[i]->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L")";
+ *js << L")";
if (i + 1 < m_Arguments.size())
- js << L", ";
+ *js << L", ";
}
} else {
for (const auto& expr : m_Arguments) {
- js << L"pfm_rt.get_val(";
+ *js << L"pfm_rt.get_val(";
if (!expr->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L")";
+ *js << L")";
if (expr != m_Arguments.back())
- js << L", ";
+ *js << L", ";
}
}
- js << L")";
+ *js << L")";
return !CXFA_IsTooBig(js);
}
@@ -490,38 +491,38 @@ bool CXFA_FMCallExpression::ToJavaScript(CFX_WideTextBuf& js, ReturnType type) {
if (funcName.AsStringView() == L"Eval") {
isEvalFunc = true;
- js << L"eval.call(this, pfm_rt.Translate";
+ *js << L"eval.call(this, pfm_rt.Translate";
} else {
if (funcName.AsStringView() == L"Exists")
isExistsFunc = true;
- js << L"pfm_rt." << funcName;
+ *js << L"pfm_rt." << funcName;
}
- js << L"(";
+ *js << L"(";
if (isExistsFunc) {
- js << L"\n(\nfunction ()\n{\ntry\n{\n";
+ *js << L"\n(\nfunction ()\n{\ntry\n{\n";
if (!m_Arguments.empty()) {
- js << L"return ";
+ *js << L"return ";
if (!m_Arguments[0]->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L";\n}\n";
+ *js << L";\n}\n";
} else {
- js << L"return 0;\n}\n";
+ *js << L"return 0;\n}\n";
}
- js << L"catch(accessExceptions)\n";
- js << L"{\nreturn 0;\n}\n}\n).call(this)\n";
+ *js << L"catch(accessExceptions)\n";
+ *js << L"{\nreturn 0;\n}\n}\n).call(this)\n";
} else {
for (const auto& expr : m_Arguments) {
if (!expr->ToJavaScript(js, ReturnType::kInfered))
return false;
if (expr != m_Arguments.back())
- js << L", ";
+ *js << L", ";
}
}
- js << L")";
+ *js << L")";
if (isEvalFunc)
- js << L")";
+ *js << L")";
return !CXFA_IsTooBig(js);
}
@@ -538,42 +539,42 @@ CXFA_FMDotAccessorExpression::CXFA_FMDotAccessorExpression(
CXFA_FMDotAccessorExpression::~CXFA_FMDotAccessorExpression() = default;
-bool CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& js,
+bool CXFA_FMDotAccessorExpression::ToJavaScript(CFX_WideTextBuf* js,
ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
- js << L"pfm_rt.dot_acc(";
+ *js << L"pfm_rt.dot_acc(";
CFX_WideTextBuf tempExp1;
if (m_pExp1) {
- if (!m_pExp1->ToJavaScript(tempExp1, ReturnType::kInfered))
+ if (!m_pExp1->ToJavaScript(&tempExp1, ReturnType::kInfered))
return false;
- js << tempExp1;
+ *js << tempExp1;
} else {
- js << L"null";
+ *js << L"null";
}
- js << L", \"";
+ *js << L", \"";
if (m_pExp1 && m_pExp1->GetOperatorToken() == TOKidentifier)
- js << tempExp1;
+ *js << tempExp1;
- js << L"\", ";
+ *js << L"\", ";
if (m_op == TOKdotscream)
- js << L"\"#" << m_wsIdentifier << L"\", ";
+ *js << L"\"#" << m_wsIdentifier << L"\", ";
else if (m_op == TOKdotstar)
- js << L"\"*\", ";
+ *js << L"\"*\", ";
else if (m_op == TOKcall)
- js << L"\"\", ";
+ *js << L"\"\", ";
else
- js << L"\"" << m_wsIdentifier << L"\", ";
+ *js << L"\"" << m_wsIdentifier << L"\", ";
if (!m_pExp2->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L")";
+ *js << L")";
return !CXFA_IsTooBig(js);
}
@@ -588,7 +589,7 @@ CXFA_FMIndexExpression::CXFA_FMIndexExpression(
CXFA_FMIndexExpression::~CXFA_FMIndexExpression() = default;
-bool CXFA_FMIndexExpression::ToJavaScript(CFX_WideTextBuf& js,
+bool CXFA_FMIndexExpression::ToJavaScript(CFX_WideTextBuf* js,
ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
@@ -596,29 +597,29 @@ bool CXFA_FMIndexExpression::ToJavaScript(CFX_WideTextBuf& js,
switch (m_accessorIndex) {
case ACCESSOR_NO_INDEX:
- js << L"0";
+ *js << L"0";
break;
case ACCESSOR_NO_RELATIVEINDEX:
- js << L"1";
+ *js << L"1";
break;
case ACCESSOR_POSITIVE_INDEX:
- js << L"2";
+ *js << L"2";
break;
case ACCESSOR_NEGATIVE_INDEX:
- js << L"3";
+ *js << L"3";
break;
default:
- js << L"0";
+ *js << L"0";
}
if (m_bIsStarIndex)
return !CXFA_IsTooBig(js);
- js << L", ";
+ *js << L", ";
if (m_pExp) {
if (!m_pExp->ToJavaScript(js, ReturnType::kInfered))
return false;
} else {
- js << L"0";
+ *js << L"0";
}
return !CXFA_IsTooBig(js);
}
@@ -635,25 +636,25 @@ CXFA_FMDotDotAccessorExpression::CXFA_FMDotDotAccessorExpression(
CXFA_FMDotDotAccessorExpression::~CXFA_FMDotDotAccessorExpression() = default;
-bool CXFA_FMDotDotAccessorExpression::ToJavaScript(CFX_WideTextBuf& js,
+bool CXFA_FMDotDotAccessorExpression::ToJavaScript(CFX_WideTextBuf* js,
ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
- js << L"pfm_rt.dotdot_acc(";
+ *js << L"pfm_rt.dotdot_acc(";
if (!m_pExp1->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L", " << L"\"";
+ *js << L", " << L"\"";
if (m_pExp1->GetOperatorToken() == TOKidentifier) {
if (!m_pExp1->ToJavaScript(js, ReturnType::kInfered))
return false;
}
- js << L"\", \"" << m_wsIdentifier << L"\", ";
+ *js << L"\", \"" << m_wsIdentifier << L"\", ";
if (!m_pExp2->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L")";
+ *js << L")";
return !CXFA_IsTooBig(js);
}
@@ -666,27 +667,27 @@ CXFA_FMMethodCallExpression::CXFA_FMMethodCallExpression(
CXFA_FMMethodCallExpression::~CXFA_FMMethodCallExpression() = default;
-bool CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& js,
+bool CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf* js,
ReturnType type) {
CXFA_FMToJavaScriptDepth depthManager;
if (CXFA_IsTooBig(js) || !depthManager.IsWithinMaxDepth())
return false;
CFX_WideTextBuf buf;
- if (!m_pExp1->ToJavaScript(buf, ReturnType::kInfered))
+ if (!m_pExp1->ToJavaScript(&buf, ReturnType::kInfered))
return false;
- js << L"(function() {\n";
- js << L" return pfm_method_runner(" << buf << L", function(obj) {\n";
- js << L" return obj.";
+ *js << L"(function() {\n";
+ *js << L" return pfm_method_runner(" << buf << L", function(obj) {\n";
+ *js << L" return obj.";
if (!m_pExp2->ToJavaScript(js, ReturnType::kInfered))
return false;
- js << L";\n";
- js << L" });\n";
- js << L"}).call(this)";
+ *js << L";\n";
+ *js << L" });\n";
+ *js << L"}).call(this)";
return !CXFA_IsTooBig(js);
}
-bool CXFA_IsTooBig(const CFX_WideTextBuf& javascript) {
- return javascript.GetSize() >= 256 * 1024 * 1024;
+bool CXFA_IsTooBig(const CFX_WideTextBuf* js) {
+ return js->GetSize() >= 256 * 1024 * 1024;
}