Dan Sinclair | a325462 | 2017-10-30 20:24:14 +0000 | [diff] [blame] | 1 | // Copyright 2017 PDFium Authors. All rights reserved. |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | a325462 | 2017-10-30 20:24:14 +0000 | [diff] [blame] | 7 | #include "fxjs/cjs_globalvariablearray.h" |
| 8 | |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 9 | #include <utility> |
| 10 | |
Dan Sinclair | a325462 | 2017-10-30 20:24:14 +0000 | [diff] [blame] | 11 | #include "fxjs/cjs_keyvalue.h" |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 12 | #include "third_party/base/ptr_util.h" |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 13 | |
| 14 | CJS_GlobalVariableArray::CJS_GlobalVariableArray() {} |
| 15 | |
| 16 | CJS_GlobalVariableArray::~CJS_GlobalVariableArray() {} |
| 17 | |
Tom Sepez | e063301 | 2018-09-17 23:36:22 +0000 | [diff] [blame] | 18 | CJS_GlobalVariableArray& CJS_GlobalVariableArray::operator=( |
| 19 | const CJS_GlobalVariableArray& that) { |
| 20 | if (this == &that) |
| 21 | return *this; |
| 22 | |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 23 | m_Array.clear(); |
Tom Sepez | e063301 | 2018-09-17 23:36:22 +0000 | [diff] [blame] | 24 | for (int i = 0, sz = that.Count(); i < sz; i++) { |
| 25 | CJS_KeyValue* pOldObjData = that.GetAt(i); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 26 | switch (pOldObjData->nType) { |
| 27 | case JS_GlobalDataType::NUMBER: { |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 28 | auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>(); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 29 | pNewObjData->sKey = pOldObjData->sKey; |
| 30 | pNewObjData->nType = pOldObjData->nType; |
| 31 | pNewObjData->dData = pOldObjData->dData; |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 32 | Add(std::move(pNewObjData)); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 33 | } break; |
| 34 | case JS_GlobalDataType::BOOLEAN: { |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 35 | auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>(); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 36 | pNewObjData->sKey = pOldObjData->sKey; |
| 37 | pNewObjData->nType = pOldObjData->nType; |
| 38 | pNewObjData->bData = pOldObjData->bData; |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 39 | Add(std::move(pNewObjData)); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 40 | } break; |
| 41 | case JS_GlobalDataType::STRING: { |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 42 | auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>(); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 43 | pNewObjData->sKey = pOldObjData->sKey; |
| 44 | pNewObjData->nType = pOldObjData->nType; |
| 45 | pNewObjData->sData = pOldObjData->sData; |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 46 | Add(std::move(pNewObjData)); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 47 | } break; |
| 48 | case JS_GlobalDataType::OBJECT: { |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 49 | auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>(); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 50 | pNewObjData->sKey = pOldObjData->sKey; |
| 51 | pNewObjData->nType = pOldObjData->nType; |
Tom Sepez | e063301 | 2018-09-17 23:36:22 +0000 | [diff] [blame] | 52 | pNewObjData->objData = pOldObjData->objData; |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 53 | Add(std::move(pNewObjData)); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 54 | } break; |
| 55 | case JS_GlobalDataType::NULLOBJ: { |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 56 | auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>(); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 57 | pNewObjData->sKey = pOldObjData->sKey; |
| 58 | pNewObjData->nType = pOldObjData->nType; |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 59 | Add(std::move(pNewObjData)); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 60 | } break; |
| 61 | } |
| 62 | } |
Tom Sepez | e063301 | 2018-09-17 23:36:22 +0000 | [diff] [blame] | 63 | return *this; |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Tom Sepez | 8abd0df | 2018-09-14 23:07:11 +0000 | [diff] [blame] | 66 | void CJS_GlobalVariableArray::Add(std::unique_ptr<CJS_KeyValue> pKeyValue) { |
| 67 | m_Array.push_back(std::move(pKeyValue)); |
weili | 47228ac | 2016-07-20 10:35:31 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | int CJS_GlobalVariableArray::Count() const { |
| 71 | return m_Array.size(); |
| 72 | } |
| 73 | |
| 74 | CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const { |
| 75 | return m_Array.at(index).get(); |
| 76 | } |