From 5ad45e2f68bb796c562302e9fc2d963c279334c7 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 10 May 2018 20:26:35 +0000 Subject: Cleanup formcalc method generation This CL simplifies the FormCalc method call generation when converted to JavaScript. Currently we output the same chunk of code to run the given method on an array or object per method call. This CL pulls out the common execution code to a pfm_method_runner function which is used instead. An embedder test has been added to verify that method invocation from formcalc works correctly. Bug: chromium:814848 Change-Id: I1ec052eab051053fedcb464d57e0e15228b8c5a2 Reviewed-on: https://pdfium-review.googlesource.com/32372 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp') diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp index 069899311e..e34d4ba127 100644 --- a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression.cpp @@ -676,22 +676,14 @@ bool CXFA_FMMethodCallExpression::ToJavaScript(CFX_WideTextBuf& js, if (!m_pExp1->ToJavaScript(buf, ReturnType::kInfered)) return false; - js << L"(function () {\n"; - js << L"let pfm_cb = 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"if (pfm_rt.is_ary(" << buf << L")) {\n"; - js << L"let method_return_value = null;\n"; - js << L"for (var index = " << buf << L".length - 1; index > 1; index--) {\n"; - js << L"method_return_value = pfm_cb(" << buf << L"[index]);\n"; - js << L"}\n"; - js << L"return method_return_value;\n"; - js << L"} else {\n"; - js << L"return pfm_cb(" << buf << L");\n"; - js << L"}}).call(this)"; + js << L" });\n"; + js << L"}).call(this)"; return !CXFA_IsTooBig(js); } -- cgit v1.2.3