From 1da20a5792b1e999616b1112cb7222c9272962c0 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 2 Aug 2018 08:31:12 +0000 Subject: Simplify CFXJSE_FormCalcContext::unfoldArgs(). Return results instead of writing them to an out parameter. Remove start index which is always 1. Change-Id: I4b969a1e27679fca56b2cde1a901a8967c7fa8ce Reviewed-on: https://pdfium-review.googlesource.com/39092 Commit-Queue: Lei Zhang Reviewed-by: Henrique Nakashima --- fxjs/cfxjse_formcalc_context.cpp | 32 +++++++++++++++----------------- fxjs/cfxjse_formcalc_context.h | 6 ++---- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index 94f3256a37..55233c1265 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -3336,8 +3336,8 @@ void CFXJSE_FormCalcContext::Oneof(CFXJSE_Value* pThis, bool bFlags = false; std::unique_ptr argOne = GetSimpleValue(pThis, args, 0); - std::vector> parameterValues; - unfoldArgs(pThis, args, ¶meterValues, 1); + std::vector> parameterValues = + unfoldArgs(pThis, args); for (const auto& value : parameterValues) { if (simpleValueCompare(pThis, argOne.get(), value.get())) { bFlags = true; @@ -5764,19 +5764,18 @@ bool CFXJSE_FormCalcContext::simpleValueCompare(CFXJSE_Value* pThis, } // static -void CFXJSE_FormCalcContext::unfoldArgs( +std::vector> CFXJSE_FormCalcContext::unfoldArgs( CFXJSE_Value* pThis, - CFXJSE_Arguments& args, - std::vector>* resultValues, - int32_t iStart) { - resultValues->clear(); + CFXJSE_Arguments& args) { + std::vector> results; int32_t iCount = 0; v8::Isolate* pIsolate = ToFormCalcContext(pThis)->GetScriptRuntime(); int32_t argc = args.GetLength(); std::vector> argsValue; - for (int32_t i = 0; i < argc - iStart; i++) { - argsValue.push_back(args.GetValue(i + iStart)); + static constexpr int kStart = 1; + for (int32_t i = 0; i < argc - kStart; i++) { + argsValue.push_back(args.GetValue(i + kStart)); if (argsValue[i]->IsArray()) { auto lengthValue = pdfium::MakeUnique(pIsolate); argsValue[i]->GetObjectProperty("length", lengthValue.get()); @@ -5788,10 +5787,10 @@ void CFXJSE_FormCalcContext::unfoldArgs( } for (int32_t i = 0; i < iCount; i++) - resultValues->push_back(pdfium::MakeUnique(pIsolate)); + results.push_back(pdfium::MakeUnique(pIsolate)); int32_t index = 0; - for (int32_t i = 0; i < argc - iStart; i++) { + for (int32_t i = 0; i < argc - kStart; i++) { if (argsValue[i]->IsArray()) { auto lengthValue = pdfium::MakeUnique(pIsolate); argsValue[i]->GetObjectProperty("length", lengthValue.get()); @@ -5805,27 +5804,26 @@ void CFXJSE_FormCalcContext::unfoldArgs( if (propertyValue->IsNull()) { for (int32_t j = 2; j < iLength; j++) { argsValue[i]->GetObjectPropertyByIdx(j, jsObjectValue.get()); - GetObjectDefaultValue(jsObjectValue.get(), - (*resultValues)[index].get()); + GetObjectDefaultValue(jsObjectValue.get(), results[index].get()); index++; } } else { for (int32_t j = 2; j < iLength; j++) { argsValue[i]->GetObjectPropertyByIdx(j, jsObjectValue.get()); jsObjectValue->GetObjectProperty( - propertyValue->ToString().AsStringView(), - (*resultValues)[index].get()); + propertyValue->ToString().AsStringView(), results[index].get()); index++; } } } else if (argsValue[i]->IsObject()) { - GetObjectDefaultValue(argsValue[i].get(), (*resultValues)[index].get()); + GetObjectDefaultValue(argsValue[i].get(), results[index].get()); index++; } else { - (*resultValues)[index]->Assign(argsValue[i].get()); + results[index]->Assign(argsValue[i].get()); index++; } } + return results; } // static diff --git a/fxjs/cfxjse_formcalc_context.h b/fxjs/cfxjse_formcalc_context.h index f60560315e..e95cc5f98c 100644 --- a/fxjs/cfxjse_formcalc_context.h +++ b/fxjs/cfxjse_formcalc_context.h @@ -343,11 +343,9 @@ class CFXJSE_FormCalcContext : public CFXJSE_HostObject { static bool simpleValueCompare(CFXJSE_Value* pThis, CFXJSE_Value* firstValue, CFXJSE_Value* secondValue); - static void unfoldArgs( + static std::vector> unfoldArgs( CFXJSE_Value* pThis, - CFXJSE_Arguments& args, - std::vector>* resultValues, - int32_t iStart = 0); + CFXJSE_Arguments& args); static void GetObjectDefaultValue(CFXJSE_Value* pObjectValue, CFXJSE_Value* pDefaultValue); static bool SetObjectDefaultValue(CFXJSE_Value* pObjectValue, -- cgit v1.2.3