From 9141116074f9209f617d9607e747c8947c952c46 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 26 Feb 2018 18:19:14 +0000 Subject: Fixup AFSimple_Calculate indexing bug The refactoring in [1] introduced a bug where we pulled the wrong array index to get the array of fields to use in the AFSimple_Calculate method. This caused the calculation to not be performed as the fields could not be found. This CL fixes up the index and adds a test to verify we use AFSimple_Calucate to sum two fields. 1- https://pdfium-review.googlesource.com/c/pdfium/+/16670 Bug: chromium:811913 Change-Id: I2abb9fe4fe2d6969ce1876736faadf252ef90575 Reviewed-on: https://pdfium-review.googlesource.com/27670 Commit-Queue: dsinclair Reviewed-by: Ryan Harrison --- fxjs/cjs_publicmethods.cpp | 2 +- fxjs/cjs_publicmethods_embeddertest.cpp | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'fxjs') diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp index 30927beac2..74428c3724 100644 --- a/fxjs/cjs_publicmethods.cpp +++ b/fxjs/cjs_publicmethods.cpp @@ -1587,7 +1587,7 @@ CJS_Return CJS_PublicMethods::AFSimple_Calculate( double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; v8::Local FieldNameArray = - AF_MakeArrayFromList(pRuntime, params[0]); + AF_MakeArrayFromList(pRuntime, params[1]); int nFieldsCount = 0; for (size_t i = 0; i < pRuntime->GetArrayLength(FieldNameArray); ++i) { WideString wsFieldName = diff --git a/fxjs/cjs_publicmethods_embeddertest.cpp b/fxjs/cjs_publicmethods_embeddertest.cpp index dbab0817ce..874f59f5ae 100644 --- a/fxjs/cjs_publicmethods_embeddertest.cpp +++ b/fxjs/cjs_publicmethods_embeddertest.cpp @@ -3,8 +3,10 @@ // found in the LICENSE file. #include +#include #include "core/fxcrt/fx_string.h" +#include "fxjs/cjs_event_context.h" #include "fxjs/cjs_publicmethods.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/js_embedder_test.h" @@ -160,3 +162,37 @@ TEST_F(CJS_PublicMethodsEmbedderTest, MakeFormatDate) { CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"mmddyyyy"); EXPECT_STREQ(L"02012095", formatted_date.c_str()); } + +TEST_F(CJS_PublicMethodsEmbedderTest, AFSimple_CalculateSum) { + v8::Isolate::Scope isolate_scope(isolate()); + v8::HandleScope handle_scope(isolate()); + v8::Context::Scope context_scope(GetV8Context()); + + EXPECT_TRUE(OpenDocument("calculate.pdf")); + auto* page = LoadPage(0); + ASSERT_TRUE(page); + + CJS_Runtime runtime(static_cast(form_handle())); + runtime.NewEventContext(); + + WideString result; + runtime.GetCurrentEventContext()->GetEventHandler()->m_pValue = &result; + + auto ary = runtime.NewArray(); + + runtime.PutArrayElement(ary, 0, runtime.NewString(L"Calc1_A")); + runtime.PutArrayElement(ary, 1, runtime.NewString(L"Calc1_B")); + + std::vector> params; + params.push_back(runtime.NewString("SUM")); + params.push_back(ary); + + CJS_Return ret = CJS_PublicMethods::AFSimple_Calculate(&runtime, params); + UnloadPage(page); + + runtime.GetCurrentEventContext()->GetEventHandler()->m_pValue = nullptr; + + ASSERT_TRUE(!ret.HasError()); + ASSERT_TRUE(!ret.HasReturn()); + ASSERT_EQ(L"7", result); +} -- cgit v1.2.3