Remove class CFX_GlobalArray.
It's just a vector of unique_ptr with no special operations.
Change-Id: Ie0e90fac61ff145b0f247e3aaef451efec1e1202
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65710
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/BUILD.gn b/fxjs/BUILD.gn
index 93c3bfa..2fb819c 100644
--- a/fxjs/BUILD.gn
+++ b/fxjs/BUILD.gn
@@ -21,8 +21,6 @@
if (pdf_enable_v8) {
sources += [
- "cfx_globalarray.cpp",
- "cfx_globalarray.h",
"cfx_globaldata.cpp",
"cfx_globaldata.h",
"cfx_keyvalue.cpp",
diff --git a/fxjs/cfx_globalarray.cpp b/fxjs/cfx_globalarray.cpp
deleted file mode 100644
index cf57fc8..0000000
--- a/fxjs/cfx_globalarray.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "fxjs/cfx_globalarray.h"
-
-#include <utility>
-
-#include "fxjs/cfx_keyvalue.h"
-
-CFX_GlobalArray::CFX_GlobalArray() = default;
-
-CFX_GlobalArray::CFX_GlobalArray(CFX_GlobalArray&& that) = default;
-
-CFX_GlobalArray::~CFX_GlobalArray() = default;
-
-CFX_GlobalArray& CFX_GlobalArray::operator=(CFX_GlobalArray&& array) = default;
-
-void CFX_GlobalArray::Add(std::unique_ptr<CFX_KeyValue> pKeyValue) {
- m_Array.push_back(std::move(pKeyValue));
-}
-
-size_t CFX_GlobalArray::Count() const {
- return m_Array.size();
-}
-
-CFX_KeyValue* CFX_GlobalArray::GetAt(int index) const {
- return m_Array.at(index).get();
-}
diff --git a/fxjs/cfx_globalarray.h b/fxjs/cfx_globalarray.h
deleted file mode 100644
index e7e0bde..0000000
--- a/fxjs/cfx_globalarray.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXJS_CFX_GLOBALARRAY_H_
-#define FXJS_CFX_GLOBALARRAY_H_
-
-#include <memory>
-#include <vector>
-
-class CFX_KeyValue;
-
-class CFX_GlobalArray {
- public:
- CFX_GlobalArray();
- CFX_GlobalArray(const CFX_GlobalArray& that) = delete;
- CFX_GlobalArray(CFX_GlobalArray&& that);
- ~CFX_GlobalArray();
-
- CFX_GlobalArray& operator=(const CFX_GlobalArray& array) = delete;
- CFX_GlobalArray& operator=(CFX_GlobalArray&& array);
-
- void Add(std::unique_ptr<CFX_KeyValue> pKeyValue);
- size_t Count() const;
- CFX_KeyValue* GetAt(int index) const;
-
- private:
- std::vector<std::unique_ptr<CFX_KeyValue>> m_Array;
-};
-
-#endif // FXJS_CFX_GLOBALARRAY_H_
diff --git a/fxjs/cfx_globaldata.cpp b/fxjs/cfx_globaldata.cpp
index e22be7f..9131f02 100644
--- a/fxjs/cfx_globaldata.cpp
+++ b/fxjs/cfx_globaldata.cpp
@@ -182,8 +182,9 @@
m_arrayGlobalData.push_back(std::move(pNewData));
}
-void CFX_GlobalData::SetGlobalVariableObject(ByteString sPropName,
- CFX_GlobalArray array) {
+void CFX_GlobalData::SetGlobalVariableObject(
+ ByteString sPropName,
+ std::vector<std::unique_ptr<CFX_KeyValue>> array) {
if (!TrimPropName(&sPropName))
return;
diff --git a/fxjs/cfx_globaldata.h b/fxjs/cfx_globaldata.h
index 91f87af..421a3b4 100644
--- a/fxjs/cfx_globaldata.h
+++ b/fxjs/cfx_globaldata.h
@@ -44,7 +44,9 @@
void SetGlobalVariableNumber(ByteString propname, double dData);
void SetGlobalVariableBoolean(ByteString propname, bool bData);
void SetGlobalVariableString(ByteString propname, const ByteString& sData);
- void SetGlobalVariableObject(ByteString propname, CFX_GlobalArray array);
+ void SetGlobalVariableObject(
+ ByteString propname,
+ std::vector<std::unique_ptr<CFX_KeyValue>> array);
void SetGlobalVariableNull(ByteString propname);
bool SetGlobalVariablePersistent(ByteString propname, bool bPersistent);
bool DeleteGlobalVariable(ByteString propname);
diff --git a/fxjs/cfx_globaldata_unittest.cpp b/fxjs/cfx_globaldata_unittest.cpp
index acc756b..3eb0ac4 100644
--- a/fxjs/cfx_globaldata_unittest.cpp
+++ b/fxjs/cfx_globaldata_unittest.cpp
@@ -53,7 +53,7 @@
TEST(CFXGlobalData, StoreReload) {
TestDelegate delegate;
- CFX_GlobalArray array;
+ std::vector<std::unique_ptr<CFX_KeyValue>> array;
CFX_GlobalData* pInstance = CFX_GlobalData::GetRetainedInstance(&delegate);
pInstance->SetGlobalVariableNumber("double", 2.0);
pInstance->SetGlobalVariableString("string", "clams");
diff --git a/fxjs/cfx_keyvalue.h b/fxjs/cfx_keyvalue.h
index 59c31cb..b66dc12 100644
--- a/fxjs/cfx_keyvalue.h
+++ b/fxjs/cfx_keyvalue.h
@@ -7,8 +7,12 @@
#ifndef FXJS_CFX_KEYVALUE_H_
#define FXJS_CFX_KEYVALUE_H_
+#include <memory>
+#include <vector>
+
#include "core/fxcrt/fx_string.h"
-#include "fxjs/cfx_globalarray.h"
+
+class CFX_KeyValue;
class CFX_Value {
public:
@@ -27,7 +31,7 @@
bool bData;
double dData;
ByteString sData;
- CFX_GlobalArray objData;
+ std::vector<std::unique_ptr<CFX_KeyValue>> objData;
};
class CFX_KeyValue : public CFX_Value {
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 3d61c17..8ac3181 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -393,7 +393,7 @@
m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
break;
case CFX_Value::DataType::OBJECT: {
- CFX_GlobalArray array;
+ 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);
@@ -408,9 +408,10 @@
}
}
-void CJS_Global::ObjectToArray(CJS_Runtime* pRuntime,
- v8::Local<v8::Object> pObj,
- CFX_GlobalArray* pArray) {
+void CJS_Global::ObjectToArray(
+ CJS_Runtime* pRuntime,
+ v8::Local<v8::Object> pObj,
+ std::vector<std::unique_ptr<CFX_KeyValue>>* pArray) {
std::vector<WideString> pKeyList = pRuntime->GetObjectPropertyNames(pObj);
for (const auto& ws : pKeyList) {
ByteString sKey = ws.ToUTF8();
@@ -421,7 +422,7 @@
pObjElement->nType = CFX_Value::DataType::NUMBER;
pObjElement->sKey = sKey;
pObjElement->dData = pRuntime->ToDouble(v);
- pArray->Add(std::move(pObjElement));
+ pArray->push_back(std::move(pObjElement));
continue;
}
if (v->IsBoolean()) {
@@ -429,7 +430,7 @@
pObjElement->nType = CFX_Value::DataType::BOOLEAN;
pObjElement->sKey = sKey;
pObjElement->dData = pRuntime->ToBoolean(v);
- pArray->Add(std::move(pObjElement));
+ pArray->push_back(std::move(pObjElement));
continue;
}
if (v->IsString()) {
@@ -438,7 +439,7 @@
pObjElement->nType = CFX_Value::DataType::STRING;
pObjElement->sKey = sKey;
pObjElement->sData = sValue;
- pArray->Add(std::move(pObjElement));
+ pArray->push_back(std::move(pObjElement));
continue;
}
if (v->IsObject()) {
@@ -446,14 +447,14 @@
pObjElement->nType = CFX_Value::DataType::OBJECT;
pObjElement->sKey = sKey;
ObjectToArray(pRuntime, pRuntime->ToObject(v), &pObjElement->objData);
- pArray->Add(std::move(pObjElement));
+ pArray->push_back(std::move(pObjElement));
continue;
}
if (v->IsNull()) {
auto pObjElement = pdfium::MakeUnique<CFX_KeyValue>();
pObjElement->nType = CFX_Value::DataType::NULLOBJ;
pObjElement->sKey = sKey;
- pArray->Add(std::move(pObjElement));
+ pArray->push_back(std::move(pObjElement));
}
}
}
@@ -464,8 +465,8 @@
if (pRuntime)
return;
- for (int i = 0, sz = pData->objData.Count(); i < sz; i++) {
- CFX_KeyValue* pObjData = pData->objData.GetAt(i);
+ for (size_t i = 0; i < pData->objData.size(); ++i) {
+ CFX_KeyValue* pObjData = pData->objData.at(i).get();
switch (pObjData->nType) {
case CFX_Value::DataType::NUMBER:
pRuntime->PutObjectProperty(pObj, pObjData->sKey.AsStringView(),
diff --git a/fxjs/cjs_global.h b/fxjs/cjs_global.h
index b01a74f..2c89188 100644
--- a/fxjs/cjs_global.h
+++ b/fxjs/cjs_global.h
@@ -76,7 +76,7 @@
bool bDefaultPersistent);
void ObjectToArray(CJS_Runtime* pRuntime,
v8::Local<v8::Object> pObj,
- CFX_GlobalArray* pArray);
+ std::vector<std::unique_ptr<CFX_KeyValue>>* pArray);
void PutObjectProperty(v8::Local<v8::Object> obj, CFX_KeyValue* pData);
std::map<ByteString, std::unique_ptr<JSGlobalData>> m_MapGlobal;