summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-05-10 20:26:35 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-10 20:26:35 +0000
commit5ad45e2f68bb796c562302e9fc2d963c279334c7 (patch)
tree946625dbb27ee8db4eb633832594a8f88d467c71 /xfa/fxfa/fm2js/cxfa_fmexpression.cpp
parent660843f9ea0e75b4efc78d17bbc5661c2d3ea2be (diff)
downloadpdfium-chromium/3427.tar.xz
Cleanup formcalc method generationchromium/3427
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 <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmexpression.cpp')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmexpression.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
index a3c65a2203..ef2153d6be 100644
--- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp
@@ -89,6 +89,16 @@ bool CXFA_FMAST::ToJavaScript(CFX_WideTextBuf& js) {
}
js << L"(function() {\n";
+ js << L"let pfm_method_runner = function(obj, cb) {\n";
+ js << L" if (pfm_rt.is_ary(obj)) {\n";
+ js << L" let pfm_method_return = null;\n";
+ js << L" for (var idx = obj.length -1; idx > 1; idx--) {\n";
+ js << L" pfm_method_return = cb(obj[idx]);\n";
+ js << L" }\n";
+ js << L" return pfm_method_return;\n";
+ js << L" }\n";
+ js << L" return cb(obj);\n";
+ js << L"};\n";
js << L"var pfm_ret = null;\n";
for (const auto& expr : expressions_) {
@@ -100,7 +110,6 @@ bool CXFA_FMAST::ToJavaScript(CFX_WideTextBuf& js) {
js << L"return pfm_rt.get_val(pfm_ret);\n";
js << L"}).call(this);";
-
return !CXFA_IsTooBig(js);
}