summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/JS_Runtime.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-03-28 16:59:30 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-28 16:59:30 -0700
commit41a53ad771411db3cdd98822f9d240456767fba8 (patch)
tree55ba380c593da9d1c0b8a42bec0ed949b1b29b78 /fpdfsdk/javascript/JS_Runtime.cpp
parent4f1f41f338ce0899e48605c82375a72883f4eb7c (diff)
downloadpdfium-41a53ad771411db3cdd98822f9d240456767fba8.tar.xz
use std::vector in more places in JavaScript bindings code.
use unique_ptrs for app:m_Timers. BUG= Review URL: https://codereview.chromium.org/1834203002
Diffstat (limited to 'fpdfsdk/javascript/JS_Runtime.cpp')
-rw-r--r--fpdfsdk/javascript/JS_Runtime.cpp31
1 files changed, 10 insertions, 21 deletions
diff --git a/fpdfsdk/javascript/JS_Runtime.cpp b/fpdfsdk/javascript/JS_Runtime.cpp
index 208348f24b..44fb340f2d 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,17 +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;
m_context.Reset();
-
if (m_isolateManaged)
m_isolate->Dispose();
}
@@ -183,27 +178,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) {