summaryrefslogtreecommitdiff
path: root/fxjs/cjs_globalvariablearray.cpp
blob: e8155b6dc00da0849e44ef9f32e6eb1b60f23140 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// 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/cjs_globalvariablearray.h"

#include <utility>

#include "fxjs/cjs_keyvalue.h"
#include "third_party/base/ptr_util.h"

CJS_GlobalVariableArray::CJS_GlobalVariableArray() {}

CJS_GlobalVariableArray::~CJS_GlobalVariableArray() {}

CJS_GlobalVariableArray& CJS_GlobalVariableArray::operator=(
    const CJS_GlobalVariableArray& that) {
  if (this == &that)
    return *this;

  m_Array.clear();
  for (int i = 0, sz = that.Count(); i < sz; i++) {
    CJS_KeyValue* pOldObjData = that.GetAt(i);
    switch (pOldObjData->nType) {
      case JS_GlobalDataType::NUMBER: {
        auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
        pNewObjData->sKey = pOldObjData->sKey;
        pNewObjData->nType = pOldObjData->nType;
        pNewObjData->dData = pOldObjData->dData;
        Add(std::move(pNewObjData));
      } break;
      case JS_GlobalDataType::BOOLEAN: {
        auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
        pNewObjData->sKey = pOldObjData->sKey;
        pNewObjData->nType = pOldObjData->nType;
        pNewObjData->bData = pOldObjData->bData;
        Add(std::move(pNewObjData));
      } break;
      case JS_GlobalDataType::STRING: {
        auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
        pNewObjData->sKey = pOldObjData->sKey;
        pNewObjData->nType = pOldObjData->nType;
        pNewObjData->sData = pOldObjData->sData;
        Add(std::move(pNewObjData));
      } break;
      case JS_GlobalDataType::OBJECT: {
        auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
        pNewObjData->sKey = pOldObjData->sKey;
        pNewObjData->nType = pOldObjData->nType;
        pNewObjData->objData = pOldObjData->objData;
        Add(std::move(pNewObjData));
      } break;
      case JS_GlobalDataType::NULLOBJ: {
        auto pNewObjData = pdfium::MakeUnique<CJS_KeyValue>();
        pNewObjData->sKey = pOldObjData->sKey;
        pNewObjData->nType = pOldObjData->nType;
        Add(std::move(pNewObjData));
      } break;
    }
  }
  return *this;
}

void CJS_GlobalVariableArray::Add(std::unique_ptr<CJS_KeyValue> pKeyValue) {
  m_Array.push_back(std::move(pKeyValue));
}

int CJS_GlobalVariableArray::Count() const {
  return m_Array.size();
}

CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const {
  return m_Array.at(index).get();
}