summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-02 08:31:12 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-02 08:31:12 +0000
commit1da20a5792b1e999616b1112cb7222c9272962c0 (patch)
tree6a6fc19c323b71b7fa167d265f5ef79cda8939b4 /fxjs
parent0548d5946c21ad48360e2fe25ded563625db52a8 (diff)
downloadpdfium-1da20a5792b1e999616b1112cb7222c9272962c0.tar.xz
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 <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cfxjse_formcalc_context.cpp32
-rw-r--r--fxjs/cfxjse_formcalc_context.h6
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<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
- std::vector<std::unique_ptr<CFXJSE_Value>> parameterValues;
- unfoldArgs(pThis, args, &parameterValues, 1);
+ std::vector<std::unique_ptr<CFXJSE_Value>> 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<std::unique_ptr<CFXJSE_Value>> CFXJSE_FormCalcContext::unfoldArgs(
CFXJSE_Value* pThis,
- CFXJSE_Arguments& args,
- std::vector<std::unique_ptr<CFXJSE_Value>>* resultValues,
- int32_t iStart) {
- resultValues->clear();
+ CFXJSE_Arguments& args) {
+ std::vector<std::unique_ptr<CFXJSE_Value>> results;
int32_t iCount = 0;
v8::Isolate* pIsolate = ToFormCalcContext(pThis)->GetScriptRuntime();
int32_t argc = args.GetLength();
std::vector<std::unique_ptr<CFXJSE_Value>> 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<CFXJSE_Value>(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<CFXJSE_Value>(pIsolate));
+ results.push_back(pdfium::MakeUnique<CFXJSE_Value>(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<CFXJSE_Value>(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<std::unique_ptr<CFXJSE_Value>> unfoldArgs(
CFXJSE_Value* pThis,
- CFXJSE_Arguments& args,
- std::vector<std::unique_ptr<CFXJSE_Value>>* resultValues,
- int32_t iStart = 0);
+ CFXJSE_Arguments& args);
static void GetObjectDefaultValue(CFXJSE_Value* pObjectValue,
CFXJSE_Value* pDefaultValue);
static bool SetObjectDefaultValue(CFXJSE_Value* pObjectValue,