diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-10-17 21:53:43 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-17 21:53:43 +0000 |
commit | a8a69e742f57a58a61555242751542fbc3fc5267 (patch) | |
tree | cc83f7fdb87aa2f4aee3ca15c119a589d032e359 /fxjs | |
parent | d78358d506c2e700a1177f93bdb915154eefae5c (diff) | |
download | pdfium-a8a69e742f57a58a61555242751542fbc3fc5267.tar.xz |
Nest CJS_GlobalData_Element in CJS_GlobalData.
Why settle for _ when you can have :: ?
No functional change. Move some ctors/initializers out of line
and avoid assignment in some ifs.
Change-Id: I792bca35f38aa8c4ff41d776a789c5525c5d5113
Reviewed-on: https://pdfium-review.googlesource.com/c/44212
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cjs_global.cpp | 2 | ||||
-rw-r--r-- | fxjs/cjs_globaldata.cpp | 38 | ||||
-rw-r--r-- | fxjs/cjs_globaldata.h | 30 |
3 files changed, 38 insertions, 32 deletions
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp index a683ed8bfc..62c528422f 100644 --- a/fxjs/cjs_global.cpp +++ b/fxjs/cjs_global.cpp @@ -328,7 +328,7 @@ void CJS_Global::UpdateGlobalPersistentVariables() { return; for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { - CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); + CJS_GlobalData::Element* pData = m_pGlobalData->GetAt(i); switch (pData->data.nType) { case JS_GlobalDataType::NUMBER: SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::NUMBER, diff --git a/fxjs/cjs_globaldata.cpp b/fxjs/cjs_globaldata.cpp index 0c84d1db72..0872b6af7b 100644 --- a/fxjs/cjs_globaldata.cpp +++ b/fxjs/cjs_globaldata.cpp @@ -55,8 +55,7 @@ void CJS_GlobalData::Release() { } } -CJS_GlobalData::CJS_GlobalData() - : m_RefCount(0), m_sFilePath(SDK_JS_GLOBALDATA_FILENAME) { +CJS_GlobalData::CJS_GlobalData() : m_sFilePath(SDK_JS_GLOBALDATA_FILENAME) { LoadGlobalPersistentVariables(); } @@ -84,7 +83,7 @@ CJS_GlobalData::const_iterator CJS_GlobalData::FindGlobalVariable( return m_arrayGlobalData.end(); } -CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable( +CJS_GlobalData::Element* CJS_GlobalData::GetGlobalVariable( const ByteString& propname) { auto iter = FindGlobalVariable(propname); return iter != m_arrayGlobalData.end() ? iter->get() : nullptr; @@ -95,12 +94,13 @@ void CJS_GlobalData::SetGlobalVariableNumber(ByteString sPropName, if (!TrimPropName(&sPropName)) return; - if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { + CJS_GlobalData::Element* pData = GetGlobalVariable(sPropName); + if (pData) { pData->data.nType = JS_GlobalDataType::NUMBER; pData->data.dData = dData; return; } - auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>(); + auto pNewData = pdfium::MakeUnique<CJS_GlobalData::Element>(); pNewData->data.sKey = std::move(sPropName); pNewData->data.nType = JS_GlobalDataType::NUMBER; pNewData->data.dData = dData; @@ -112,12 +112,13 @@ void CJS_GlobalData::SetGlobalVariableBoolean(ByteString sPropName, if (!TrimPropName(&sPropName)) return; - if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { + CJS_GlobalData::Element* pData = GetGlobalVariable(sPropName); + if (pData) { pData->data.nType = JS_GlobalDataType::BOOLEAN; pData->data.bData = bData; return; } - auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>(); + auto pNewData = pdfium::MakeUnique<CJS_GlobalData::Element>(); pNewData->data.sKey = std::move(sPropName); pNewData->data.nType = JS_GlobalDataType::BOOLEAN; pNewData->data.bData = bData; @@ -129,12 +130,13 @@ void CJS_GlobalData::SetGlobalVariableString(ByteString sPropName, if (!TrimPropName(&sPropName)) return; - if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { + CJS_GlobalData::Element* pData = GetGlobalVariable(sPropName); + if (pData) { pData->data.nType = JS_GlobalDataType::STRING; pData->data.sData = sData; return; } - auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>(); + auto pNewData = pdfium::MakeUnique<CJS_GlobalData::Element>(); pNewData->data.sKey = std::move(sPropName); pNewData->data.nType = JS_GlobalDataType::STRING; pNewData->data.sData = sData; @@ -147,12 +149,13 @@ void CJS_GlobalData::SetGlobalVariableObject( if (!TrimPropName(&sPropName)) return; - if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { + CJS_GlobalData::Element* pData = GetGlobalVariable(sPropName); + if (pData) { pData->data.nType = JS_GlobalDataType::OBJECT; pData->data.objData = array; return; } - auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>(); + auto pNewData = pdfium::MakeUnique<CJS_GlobalData::Element>(); pNewData->data.sKey = std::move(sPropName); pNewData->data.nType = JS_GlobalDataType::OBJECT; pNewData->data.objData = array; @@ -163,11 +166,12 @@ void CJS_GlobalData::SetGlobalVariableNull(ByteString sPropName) { if (!TrimPropName(&sPropName)) return; - if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { + CJS_GlobalData::Element* pData = GetGlobalVariable(sPropName); + if (pData) { pData->data.nType = JS_GlobalDataType::NULLOBJ; return; } - auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>(); + auto pNewData = pdfium::MakeUnique<CJS_GlobalData::Element>(); pNewData->data.sKey = std::move(sPropName); pNewData->data.nType = JS_GlobalDataType::NULLOBJ; m_arrayGlobalData.push_back(std::move(pNewData)); @@ -178,7 +182,7 @@ bool CJS_GlobalData::SetGlobalVariablePersistent(ByteString sPropName, if (!TrimPropName(&sPropName)) return false; - CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName); + CJS_GlobalData::Element* pData = GetGlobalVariable(sPropName); if (!pData) return false; @@ -202,7 +206,7 @@ int32_t CJS_GlobalData::GetSize() const { return pdfium::CollectionSize<int32_t>(m_arrayGlobalData); } -CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const { +CJS_GlobalData::Element* CJS_GlobalData::GetAt(int index) const { if (index < 0 || index >= GetSize()) return nullptr; return m_arrayGlobalData[index].get(); @@ -384,3 +388,7 @@ void CJS_GlobalData::MakeByteString(const ByteString& name, break; } } + +CJS_GlobalData::Element::Element() = default; + +CJS_GlobalData::Element::~Element() = default; diff --git a/fxjs/cjs_globaldata.h b/fxjs/cjs_globaldata.h index 9ce4358fd4..1bff94d298 100644 --- a/fxjs/cjs_globaldata.h +++ b/fxjs/cjs_globaldata.h @@ -15,17 +15,17 @@ class CPDFSDK_FormFillEnvironment; -class CJS_GlobalData_Element { +class CJS_GlobalData { public: - CJS_GlobalData_Element() {} - ~CJS_GlobalData_Element() {} + class Element { + public: + Element(); + ~Element(); - CJS_KeyValue data; - bool bPersistent; -}; + CJS_KeyValue data; + bool bPersistent; + }; -class CJS_GlobalData { - public: static CJS_GlobalData* GetRetainedInstance(CPDFSDK_FormFillEnvironment* pApp); void Release(); @@ -39,13 +39,11 @@ class CJS_GlobalData { bool DeleteGlobalVariable(ByteString propname); int32_t GetSize() const; - CJS_GlobalData_Element* GetAt(int index) const; + Element* GetAt(int index) const; private: - using iterator = - std::vector<std::unique_ptr<CJS_GlobalData_Element>>::iterator; - using const_iterator = - std::vector<std::unique_ptr<CJS_GlobalData_Element>>::const_iterator; + using iterator = std::vector<std::unique_ptr<Element>>::iterator; + using const_iterator = std::vector<std::unique_ptr<Element>>::const_iterator; CJS_GlobalData(); ~CJS_GlobalData(); @@ -53,7 +51,7 @@ class CJS_GlobalData { void LoadGlobalPersistentVariables(); void SaveGlobalPersisitentVariables(); - CJS_GlobalData_Element* GetGlobalVariable(const ByteString& sPropname); + Element* GetGlobalVariable(const ByteString& sPropname); iterator FindGlobalVariable(const ByteString& sPropname); const_iterator FindGlobalVariable(const ByteString& sPropname) const; @@ -67,8 +65,8 @@ class CJS_GlobalData { CJS_KeyValue* pData, CFX_BinaryBuf& sData); - size_t m_RefCount; - std::vector<std::unique_ptr<CJS_GlobalData_Element>> m_arrayGlobalData; + size_t m_RefCount = 0; + std::vector<std::unique_ptr<Element>> m_arrayGlobalData; WideString m_sFilePath; }; |