summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-09-14 23:07:11 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-09-14 23:07:11 +0000
commit8abd0dfe538fcf55c7c8571791b409d7e036ef54 (patch)
tree39a9775e1295d8b73bc4dcadb3298c6cbb0b1a4f /fxjs
parentcb88fa33339ca04c89f340b457f4960d0d4185a2 (diff)
downloadpdfium-8abd0dfe538fcf55c7c8571791b409d7e036ef54.tar.xz
Use unique_ptr<> in CJS_GlobalVariableArray::Add().
Clean up another ten bare |new|s or so. Change-Id: If32b307e5edd844488dfb2020e710214bb6f75a0 Reviewed-on: https://pdfium-review.googlesource.com/42550 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cjs_global.cpp20
-rw-r--r--fxjs/cjs_globalvariablearray.cpp27
-rw-r--r--fxjs/cjs_globalvariablearray.h2
3 files changed, 26 insertions, 23 deletions
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index d9338abcfd..ecf06f10cb 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -418,43 +418,43 @@ void CJS_Global::ObjectToArray(CJS_Runtime* pRuntime,
ByteString sKey = ws.UTF8Encode();
v8::Local<v8::Value> v = pRuntime->GetObjectProperty(pObj, ws);
if (v->IsNumber()) {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ auto pObjElement = pdfium::MakeUnique<CJS_KeyValue>();
pObjElement->nType = JS_GlobalDataType::NUMBER;
pObjElement->sKey = sKey;
pObjElement->dData = pRuntime->ToDouble(v);
- pArray->Add(pObjElement);
+ pArray->Add(std::move(pObjElement));
continue;
}
if (v->IsBoolean()) {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ auto pObjElement = pdfium::MakeUnique<CJS_KeyValue>();
pObjElement->nType = JS_GlobalDataType::BOOLEAN;
pObjElement->sKey = sKey;
pObjElement->dData = pRuntime->ToBoolean(v);
- pArray->Add(pObjElement);
+ pArray->Add(std::move(pObjElement));
continue;
}
if (v->IsString()) {
ByteString sValue = pRuntime->ToWideString(v).ToDefANSI();
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ auto pObjElement = pdfium::MakeUnique<CJS_KeyValue>();
pObjElement->nType = JS_GlobalDataType::STRING;
pObjElement->sKey = sKey;
pObjElement->sData = sValue;
- pArray->Add(pObjElement);
+ pArray->Add(std::move(pObjElement));
continue;
}
if (v->IsObject()) {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ auto pObjElement = pdfium::MakeUnique<CJS_KeyValue>();
pObjElement->nType = JS_GlobalDataType::OBJECT;
pObjElement->sKey = sKey;
ObjectToArray(pRuntime, pRuntime->ToObject(v), &pObjElement->objData);
- pArray->Add(pObjElement);
+ pArray->Add(std::move(pObjElement));
continue;
}
if (v->IsNull()) {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ auto pObjElement = pdfium::MakeUnique<CJS_KeyValue>();
pObjElement->nType = JS_GlobalDataType::NULLOBJ;
pObjElement->sKey = sKey;
- pArray->Add(pObjElement);
+ pArray->Add(std::move(pObjElement));
}
}
}
diff --git a/fxjs/cjs_globalvariablearray.cpp b/fxjs/cjs_globalvariablearray.cpp
index 8bf9f1b305..c4ac00cc9a 100644
--- a/fxjs/cjs_globalvariablearray.cpp
+++ b/fxjs/cjs_globalvariablearray.cpp
@@ -6,7 +6,10 @@
#include "fxjs/cjs_globalvariablearray.h"
+#include <utility>
+
#include "fxjs/cjs_keyvalue.h"
+#include "third_party/base/ptr_util.h"
CJS_GlobalVariableArray::CJS_GlobalVariableArray() {}
@@ -18,45 +21,45 @@ void CJS_GlobalVariableArray::Copy(const CJS_GlobalVariableArray& array) {
CJS_KeyValue* pOldObjData = array.GetAt(i);
switch (pOldObjData->nType) {
case JS_GlobalDataType::NUMBER: {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
pNewObjData->sKey = pOldObjData->sKey;
pNewObjData->nType = pOldObjData->nType;
pNewObjData->dData = pOldObjData->dData;
- Add(pNewObjData);
+ Add(std::move(pNewObjData));
} break;
case JS_GlobalDataType::BOOLEAN: {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
pNewObjData->sKey = pOldObjData->sKey;
pNewObjData->nType = pOldObjData->nType;
pNewObjData->bData = pOldObjData->bData;
- Add(pNewObjData);
+ Add(std::move(pNewObjData));
} break;
case JS_GlobalDataType::STRING: {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
pNewObjData->sKey = pOldObjData->sKey;
pNewObjData->nType = pOldObjData->nType;
pNewObjData->sData = pOldObjData->sData;
- Add(pNewObjData);
+ Add(std::move(pNewObjData));
} break;
case JS_GlobalDataType::OBJECT: {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
pNewObjData->sKey = pOldObjData->sKey;
pNewObjData->nType = pOldObjData->nType;
pNewObjData->objData.Copy(pOldObjData->objData);
- Add(pNewObjData);
+ Add(std::move(pNewObjData));
} break;
case JS_GlobalDataType::NULLOBJ: {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
pNewObjData->sKey = pOldObjData->sKey;
pNewObjData->nType = pOldObjData->nType;
- Add(pNewObjData);
+ Add(std::move(pNewObjData));
} break;
}
}
}
-void CJS_GlobalVariableArray::Add(CJS_KeyValue* p) {
- m_Array.push_back(std::unique_ptr<CJS_KeyValue>(p));
+void CJS_GlobalVariableArray::Add(std::unique_ptr<CJS_KeyValue> pKeyValue) {
+ m_Array.push_back(std::move(pKeyValue));
}
int CJS_GlobalVariableArray::Count() const {
diff --git a/fxjs/cjs_globalvariablearray.h b/fxjs/cjs_globalvariablearray.h
index a249f60be9..a3f46586b9 100644
--- a/fxjs/cjs_globalvariablearray.h
+++ b/fxjs/cjs_globalvariablearray.h
@@ -17,7 +17,7 @@ class CJS_GlobalVariableArray {
CJS_GlobalVariableArray();
~CJS_GlobalVariableArray();
- void Add(CJS_KeyValue* p);
+ void Add(std::unique_ptr<CJS_KeyValue> pKeyValue);
int Count() const;
CJS_KeyValue* GetAt(int index) const;
void Copy(const CJS_GlobalVariableArray& array);