From 2ebc33e549d969f6d776a59f6d313b80d7813bb1 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 13 Aug 2015 16:07:29 -0700 Subject: Merge to XFA: Kill JS_TIMER_MAPARRAY (cherry picked from commit 2a0a26c94ef8131ee29ac4d466c42593cf2ff005) Review URL: https://codereview.chromium.org/1286383004 . R=thestig@chromium.org TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1296493003 . --- fpdfsdk/include/javascript/JS_Object.h | 85 ++++------------------------------ 1 file changed, 9 insertions(+), 76 deletions(-) (limited to 'fpdfsdk/include/javascript/JS_Object.h') diff --git a/fpdfsdk/include/javascript/JS_Object.h b/fpdfsdk/include/javascript/JS_Object.h index caed92b034..e1780567c2 100644 --- a/fpdfsdk/include/javascript/JS_Object.h +++ b/fpdfsdk/include/javascript/JS_Object.h @@ -7,6 +7,8 @@ #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_ #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_ +#include + #include "../fsdk_define.h" // For FX_UINT #include "../fsdk_mgr.h" // For CPDFDoc_Environment #include "../fx_systemhandler.h" // For IFX_SystemHandler @@ -82,77 +84,8 @@ class CJS_Object { v8::Isolate* m_pIsolate; }; -struct JS_TIMER_MAP { - FX_UINT nID; - CJS_Timer* pTimer; -}; - -typedef CFX_ArrayTemplate CTimerMapArray; - -struct JS_TIMER_MAPARRAY { - public: - JS_TIMER_MAPARRAY() {} - - ~JS_TIMER_MAPARRAY() { Reset(); } - - void Reset() { - for (int i = 0, sz = m_Array.GetSize(); i < sz; i++) - delete m_Array.GetAt(i); - - m_Array.RemoveAll(); - } - - void SetAt(FX_UINT nIndex, CJS_Timer* pTimer) { - int i = Find(nIndex); - - if (i >= 0) { - if (JS_TIMER_MAP* pMap = m_Array.GetAt(i)) - pMap->pTimer = pTimer; - } else { - JS_TIMER_MAP* pMap = new JS_TIMER_MAP; - pMap->nID = nIndex; - pMap->pTimer = pTimer; - m_Array.Add(pMap); - } - } - - CJS_Timer* GetAt(FX_UINT nIndex) { - int i = Find(nIndex); - - if (i >= 0) { - if (JS_TIMER_MAP* pMap = m_Array.GetAt(i)) - return pMap->pTimer; - } - return NULL; - } - - void RemoveAt(FX_UINT nIndex) { - int i = Find(nIndex); - - if (i >= 0) { - delete m_Array.GetAt(i); - m_Array.RemoveAt(i); - } - // To prevent potential fake memory leak reported by vc6. - if (m_Array.GetSize() == 0) - m_Array.RemoveAll(); - } - - int Find(FX_UINT nIndex) { - for (int i = 0, sz = m_Array.GetSize(); i < sz; i++) { - if (JS_TIMER_MAP* pMap = m_Array.GetAt(i)) { - if (pMap->nID == nIndex) - return i; - } - } - - return -1; - } - - CTimerMapArray m_Array; -}; - -JS_TIMER_MAPARRAY& GetTimeMap(); +using JSTimerMap = std::map; +JSTimerMap* GetGlobalTimerMap(); class CJS_Runtime; @@ -177,7 +110,7 @@ class CJS_Timer { KillJSTimer(); IFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); m_nTimerID = pHandler->SetTimer(nElapse, TimerProc); - GetTimeMap().SetAt(m_nTimerID, this); + (*GetGlobalTimerMap())[m_nTimerID] = this; m_dwElapse = nElapse; return m_nTimerID; }; @@ -191,7 +124,7 @@ class CJS_Timer { } IFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); pHandler->KillTimer(m_nTimerID); - GetTimeMap().RemoveAt(m_nTimerID); + GetGlobalTimerMap()->erase(m_nTimerID); m_nTimerID = 0; } }; @@ -217,14 +150,14 @@ class CJS_Timer { CFX_WideString GetJScript() const { return m_swJScript; } static void TimerProc(int idEvent) { - if (CJS_Timer* pTimer = GetTimeMap().GetAt(idEvent)) { + const auto it = GetGlobalTimerMap()->find(idEvent); + if (it != GetGlobalTimerMap()->end()) { + CJS_Timer* pTimer = it->second; if (!pTimer->m_bProcessing) { pTimer->m_bProcessing = TRUE; if (pTimer->m_pEmbedObj) pTimer->m_pEmbedObj->TimerProc(pTimer); pTimer->m_bProcessing = FALSE; - } else { - // TRACE(L"BUSY!\n"); } } }; -- cgit v1.2.3