blob: e8155b6dc00da0849e44ef9f32e6eb1b60f23140 [file] [log] [blame]
Dan Sinclaira3254622017-10-30 20:24:14 +00001// Copyright 2017 PDFium Authors. All rights reserved.
weili47228ac2016-07-20 10:35:31 -07002// 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 Sinclaira3254622017-10-30 20:24:14 +00007#include "fxjs/cjs_globalvariablearray.h"
8
Tom Sepez8abd0df2018-09-14 23:07:11 +00009#include <utility>
10
Dan Sinclaira3254622017-10-30 20:24:14 +000011#include "fxjs/cjs_keyvalue.h"
Tom Sepez8abd0df2018-09-14 23:07:11 +000012#include "third_party/base/ptr_util.h"
weili47228ac2016-07-20 10:35:31 -070013
14CJS_GlobalVariableArray::CJS_GlobalVariableArray() {}
15
16CJS_GlobalVariableArray::~CJS_GlobalVariableArray() {}
17
Tom Sepeze0633012018-09-17 23:36:22 +000018CJS_GlobalVariableArray& CJS_GlobalVariableArray::operator=(
19 const CJS_GlobalVariableArray& that) {
20 if (this == &that)
21 return *this;
22
weili47228ac2016-07-20 10:35:31 -070023 m_Array.clear();
Tom Sepeze0633012018-09-17 23:36:22 +000024 for (int i = 0, sz = that.Count(); i < sz; i++) {
25 CJS_KeyValue* pOldObjData = that.GetAt(i);
weili47228ac2016-07-20 10:35:31 -070026 switch (pOldObjData->nType) {
27 case JS_GlobalDataType::NUMBER: {
Tom Sepez8abd0df2018-09-14 23:07:11 +000028 auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
weili47228ac2016-07-20 10:35:31 -070029 pNewObjData->sKey = pOldObjData->sKey;
30 pNewObjData->nType = pOldObjData->nType;
31 pNewObjData->dData = pOldObjData->dData;
Tom Sepez8abd0df2018-09-14 23:07:11 +000032 Add(std::move(pNewObjData));
weili47228ac2016-07-20 10:35:31 -070033 } break;
34 case JS_GlobalDataType::BOOLEAN: {
Tom Sepez8abd0df2018-09-14 23:07:11 +000035 auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
weili47228ac2016-07-20 10:35:31 -070036 pNewObjData->sKey = pOldObjData->sKey;
37 pNewObjData->nType = pOldObjData->nType;
38 pNewObjData->bData = pOldObjData->bData;
Tom Sepez8abd0df2018-09-14 23:07:11 +000039 Add(std::move(pNewObjData));
weili47228ac2016-07-20 10:35:31 -070040 } break;
41 case JS_GlobalDataType::STRING: {
Tom Sepez8abd0df2018-09-14 23:07:11 +000042 auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
weili47228ac2016-07-20 10:35:31 -070043 pNewObjData->sKey = pOldObjData->sKey;
44 pNewObjData->nType = pOldObjData->nType;
45 pNewObjData->sData = pOldObjData->sData;
Tom Sepez8abd0df2018-09-14 23:07:11 +000046 Add(std::move(pNewObjData));
weili47228ac2016-07-20 10:35:31 -070047 } break;
48 case JS_GlobalDataType::OBJECT: {
Tom Sepez8abd0df2018-09-14 23:07:11 +000049 auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
weili47228ac2016-07-20 10:35:31 -070050 pNewObjData->sKey = pOldObjData->sKey;
51 pNewObjData->nType = pOldObjData->nType;
Tom Sepeze0633012018-09-17 23:36:22 +000052 pNewObjData->objData = pOldObjData->objData;
Tom Sepez8abd0df2018-09-14 23:07:11 +000053 Add(std::move(pNewObjData));
weili47228ac2016-07-20 10:35:31 -070054 } break;
55 case JS_GlobalDataType::NULLOBJ: {
Tom Sepez8abd0df2018-09-14 23:07:11 +000056 auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
weili47228ac2016-07-20 10:35:31 -070057 pNewObjData->sKey = pOldObjData->sKey;
58 pNewObjData->nType = pOldObjData->nType;
Tom Sepez8abd0df2018-09-14 23:07:11 +000059 Add(std::move(pNewObjData));
weili47228ac2016-07-20 10:35:31 -070060 } break;
61 }
62 }
Tom Sepeze0633012018-09-17 23:36:22 +000063 return *this;
weili47228ac2016-07-20 10:35:31 -070064}
65
Tom Sepez8abd0df2018-09-14 23:07:11 +000066void CJS_GlobalVariableArray::Add(std::unique_ptr<CJS_KeyValue> pKeyValue) {
67 m_Array.push_back(std::move(pKeyValue));
weili47228ac2016-07-20 10:35:31 -070068}
69
70int CJS_GlobalVariableArray::Count() const {
71 return m_Array.size();
72}
73
74CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const {
75 return m_Array.at(index).get();
76}