Chromium Code Reviews| Index: fpdfsdk/javascript/JS_Runtime.cpp |
| diff --git a/fpdfsdk/javascript/JS_Runtime.cpp b/fpdfsdk/javascript/JS_Runtime.cpp |
| index 208348f24bc7aecd0a8c90b7c5eaa09b71b5f6b7..4aa78dac59e34b9f71bf31ab71e8baf38b004f2b 100644 |
| --- a/fpdfsdk/javascript/JS_Runtime.cpp |
| +++ b/fpdfsdk/javascript/JS_Runtime.cpp |
| @@ -6,6 +6,8 @@ |
| #include "fpdfsdk/javascript/JS_Runtime.h" |
| +#include <algorithm> |
| + |
| #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. |
| #include "fpdfsdk/include/javascript/IJavaScript.h" |
| #include "fpdfsdk/javascript/Consts.h" |
| @@ -117,14 +119,10 @@ CJS_Runtime::~CJS_Runtime() { |
| for (auto* obs : m_observers) |
| obs->OnDestroyed(); |
| - for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) |
| - delete m_ContextArray.GetAt(i); |
| - |
| - m_ContextArray.RemoveAll(); |
| + m_ContextArray.clear(); |
| m_ConstArrays.clear(); |
| FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects); |
| - m_pApp = NULL; |
| m_pDocument = NULL; |
|
dsinclair
2016/03/28 18:57:33
This isn't needed either as we're destructing, yea
Tom Sepez
2016/03/28 23:47:18
Done.
|
| m_context.Reset(); |
| @@ -183,27 +181,21 @@ void CJS_Runtime::DefineJSObjects() { |
| } |
| IJS_Context* CJS_Runtime::NewContext() { |
| - CJS_Context* p = new CJS_Context(this); |
| - m_ContextArray.Add(p); |
| - return p; |
| + m_ContextArray.push_back(std::unique_ptr<CJS_Context>(new CJS_Context(this))); |
| + return m_ContextArray.back().get(); |
| } |
| void CJS_Runtime::ReleaseContext(IJS_Context* pContext) { |
| - CJS_Context* pJSContext = (CJS_Context*)pContext; |
| - |
| - for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) { |
| - if (pJSContext == m_ContextArray.GetAt(i)) { |
| - delete pJSContext; |
| - m_ContextArray.RemoveAt(i); |
| - break; |
| + for (auto it = m_ContextArray.begin(); it != m_ContextArray.end(); ++it) { |
| + if (it->get() == static_cast<CJS_Context*>(pContext)) { |
| + m_ContextArray.erase(it); |
| + return; |
| } |
| } |
| } |
| IJS_Context* CJS_Runtime::GetCurrentContext() { |
| - if (!m_ContextArray.GetSize()) |
| - return NULL; |
| - return m_ContextArray.GetAt(m_ContextArray.GetSize() - 1); |
| + return m_ContextArray.empty() ? nullptr : m_ContextArray.back().get(); |
| } |
| void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { |