Remove out parameter from CJS_Global::ObjectToArray()
Both of its callers invoke it with emtpy arrays to which new items
are added, so just create the array and return it to the caller.
-- remove unused member while at it.
Change-Id: Id10d73005baadab34ca40137b4d38e9a008bf306
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/77130
Reviewed-by: Hui Yingst <nigi@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index f6681a9..86762e3 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -358,11 +358,10 @@
m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
break;
case CFX_Value::DataType::kObject: {
- std::vector<std::unique_ptr<CFX_KeyValue>> array;
v8::Local<v8::Object> obj =
v8::Local<v8::Object>::New(GetIsolate(), pData->pData);
- ObjectToArray(pRuntime, obj, &array);
- m_pGlobalData->SetGlobalVariableObject(name, std::move(array));
+ m_pGlobalData->SetGlobalVariableObject(name,
+ ObjectToArray(pRuntime, obj));
m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
} break;
case CFX_Value::DataType::kNull:
@@ -373,10 +372,10 @@
}
}
-void CJS_Global::ObjectToArray(
+std::vector<std::unique_ptr<CFX_KeyValue>> CJS_Global::ObjectToArray(
CJS_Runtime* pRuntime,
- v8::Local<v8::Object> pObj,
- std::vector<std::unique_ptr<CFX_KeyValue>>* pArray) {
+ v8::Local<v8::Object> pObj) {
+ std::vector<std::unique_ptr<CFX_KeyValue>> array;
std::vector<WideString> pKeyList = pRuntime->GetObjectPropertyNames(pObj);
for (const auto& ws : pKeyList) {
ByteString sKey = ws.ToUTF8();
@@ -387,7 +386,7 @@
pObjElement->nType = CFX_Value::DataType::kNumber;
pObjElement->sKey = sKey;
pObjElement->dData = pRuntime->ToDouble(v);
- pArray->push_back(std::move(pObjElement));
+ array.push_back(std::move(pObjElement));
continue;
}
if (v->IsBoolean()) {
@@ -395,7 +394,7 @@
pObjElement->nType = CFX_Value::DataType::kBoolean;
pObjElement->sKey = sKey;
pObjElement->dData = pRuntime->ToBoolean(v);
- pArray->push_back(std::move(pObjElement));
+ array.push_back(std::move(pObjElement));
continue;
}
if (v->IsString()) {
@@ -404,24 +403,25 @@
pObjElement->nType = CFX_Value::DataType::kString;
pObjElement->sKey = sKey;
pObjElement->sData = sValue;
- pArray->push_back(std::move(pObjElement));
+ array.push_back(std::move(pObjElement));
continue;
}
if (v->IsObject()) {
auto pObjElement = std::make_unique<CFX_KeyValue>();
pObjElement->nType = CFX_Value::DataType::kObject;
pObjElement->sKey = sKey;
- ObjectToArray(pRuntime, pRuntime->ToObject(v), &pObjElement->objData);
- pArray->push_back(std::move(pObjElement));
+ pObjElement->objData = ObjectToArray(pRuntime, pRuntime->ToObject(v));
+ array.push_back(std::move(pObjElement));
continue;
}
if (v->IsNull()) {
auto pObjElement = std::make_unique<CFX_KeyValue>();
pObjElement->nType = CFX_Value::DataType::kNull;
pObjElement->sKey = sKey;
- pArray->push_back(std::move(pObjElement));
+ array.push_back(std::move(pObjElement));
}
}
+ return array;
}
void CJS_Global::PutObjectProperty(v8::Local<v8::Object> pObj,
diff --git a/fxjs/cjs_global.h b/fxjs/cjs_global.h
index 0580dbb..e251a2e 100644
--- a/fxjs/cjs_global.h
+++ b/fxjs/cjs_global.h
@@ -84,13 +84,12 @@
const ByteString& sData,
v8::Local<v8::Object> pData,
bool bDefaultPersistent);
- void ObjectToArray(CJS_Runtime* pRuntime,
- v8::Local<v8::Object> pObj,
- std::vector<std::unique_ptr<CFX_KeyValue>>* pArray);
+ std::vector<std::unique_ptr<CFX_KeyValue>> ObjectToArray(
+ CJS_Runtime* pRuntime,
+ v8::Local<v8::Object> pObj);
void PutObjectProperty(v8::Local<v8::Object> obj, CFX_KeyValue* pData);
std::map<ByteString, std::unique_ptr<JSGlobalData>> m_MapGlobal;
- WideString m_sFilePath;
CFX_GlobalData* m_pGlobalData;
ObservedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
};