Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: fpdfsdk/javascript/JS_Runtime.cpp

Issue 1834203002: use std::vector in more places in JavaScript bindings code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@util_printx
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/javascript/JS_Runtime.h" 7 #include "fpdfsdk/javascript/JS_Runtime.h"
8 8
9 #include <algorithm>
10
9 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. 11 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment.
10 #include "fpdfsdk/include/javascript/IJavaScript.h" 12 #include "fpdfsdk/include/javascript/IJavaScript.h"
11 #include "fpdfsdk/javascript/Consts.h" 13 #include "fpdfsdk/javascript/Consts.h"
12 #include "fpdfsdk/javascript/Document.h" 14 #include "fpdfsdk/javascript/Document.h"
13 #include "fpdfsdk/javascript/Field.h" 15 #include "fpdfsdk/javascript/Field.h"
14 #include "fpdfsdk/javascript/Icon.h" 16 #include "fpdfsdk/javascript/Icon.h"
15 #include "fpdfsdk/javascript/JS_Context.h" 17 #include "fpdfsdk/javascript/JS_Context.h"
16 #include "fpdfsdk/javascript/JS_Define.h" 18 #include "fpdfsdk/javascript/JS_Define.h"
17 #include "fpdfsdk/javascript/JS_EventHandler.h" 19 #include "fpdfsdk/javascript/JS_EventHandler.h"
18 #include "fpdfsdk/javascript/JS_GlobalData.h" 20 #include "fpdfsdk/javascript/JS_GlobalData.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 #endif 112 #endif
111 CJS_Context* pContext = (CJS_Context*)NewContext(); 113 CJS_Context* pContext = (CJS_Context*)NewContext();
112 FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); 114 FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects);
113 ReleaseContext(pContext); 115 ReleaseContext(pContext);
114 } 116 }
115 117
116 CJS_Runtime::~CJS_Runtime() { 118 CJS_Runtime::~CJS_Runtime() {
117 for (auto* obs : m_observers) 119 for (auto* obs : m_observers)
118 obs->OnDestroyed(); 120 obs->OnDestroyed();
119 121
120 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) 122 m_ContextArray.clear();
121 delete m_ContextArray.GetAt(i);
122
123 m_ContextArray.RemoveAll();
124 m_ConstArrays.clear(); 123 m_ConstArrays.clear();
125 FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects); 124 FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects);
126 125
127 m_pApp = NULL;
128 m_pDocument = NULL; 126 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.
129 m_context.Reset(); 127 m_context.Reset();
130 128
131 if (m_isolateManaged) 129 if (m_isolateManaged)
132 m_isolate->Dispose(); 130 m_isolate->Dispose();
133 } 131 }
134 132
135 void CJS_Runtime::DefineJSObjects() { 133 void CJS_Runtime::DefineJSObjects() {
136 v8::Isolate::Scope isolate_scope(GetIsolate()); 134 v8::Isolate::Scope isolate_scope(GetIsolate());
137 #ifdef PDF_ENABLE_XFA 135 #ifdef PDF_ENABLE_XFA
138 v8::Locker locker(GetIsolate()); 136 v8::Locker locker(GetIsolate());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 CJS_PublicMethods::DefineJSObjects(GetIsolate()); 174 CJS_PublicMethods::DefineJSObjects(GetIsolate());
177 CJS_GlobalConsts::DefineJSObjects(this); 175 CJS_GlobalConsts::DefineJSObjects(this);
178 CJS_GlobalArrays::DefineJSObjects(this); 176 CJS_GlobalArrays::DefineJSObjects(this);
179 177
180 // ObjDefIDs 21 - 22. 178 // ObjDefIDs 21 - 22.
181 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 179 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
182 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 180 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
183 } 181 }
184 182
185 IJS_Context* CJS_Runtime::NewContext() { 183 IJS_Context* CJS_Runtime::NewContext() {
186 CJS_Context* p = new CJS_Context(this); 184 m_ContextArray.push_back(std::unique_ptr<CJS_Context>(new CJS_Context(this)));
187 m_ContextArray.Add(p); 185 return m_ContextArray.back().get();
188 return p;
189 } 186 }
190 187
191 void CJS_Runtime::ReleaseContext(IJS_Context* pContext) { 188 void CJS_Runtime::ReleaseContext(IJS_Context* pContext) {
192 CJS_Context* pJSContext = (CJS_Context*)pContext; 189 for (auto it = m_ContextArray.begin(); it != m_ContextArray.end(); ++it) {
193 190 if (it->get() == static_cast<CJS_Context*>(pContext)) {
194 for (int i = 0, sz = m_ContextArray.GetSize(); i < sz; i++) { 191 m_ContextArray.erase(it);
195 if (pJSContext == m_ContextArray.GetAt(i)) { 192 return;
196 delete pJSContext;
197 m_ContextArray.RemoveAt(i);
198 break;
199 } 193 }
200 } 194 }
201 } 195 }
202 196
203 IJS_Context* CJS_Runtime::GetCurrentContext() { 197 IJS_Context* CJS_Runtime::GetCurrentContext() {
204 if (!m_ContextArray.GetSize()) 198 return m_ContextArray.empty() ? nullptr : m_ContextArray.back().get();
205 return NULL;
206 return m_ContextArray.GetAt(m_ContextArray.GetSize() - 1);
207 } 199 }
208 200
209 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { 201 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
210 if (m_pDocument != pReaderDoc) { 202 if (m_pDocument != pReaderDoc) {
211 v8::Isolate::Scope isolate_scope(m_isolate); 203 v8::Isolate::Scope isolate_scope(m_isolate);
212 #ifdef PDF_ENABLE_XFA 204 #ifdef PDF_ENABLE_XFA
213 v8::Locker locker(m_isolate); 205 v8::Locker locker(m_isolate);
214 #endif 206 #endif
215 v8::HandleScope handle_scope(m_isolate); 207 v8::HandleScope handle_scope(m_isolate);
216 v8::Local<v8::Context> context = 208 v8::Local<v8::Context> context =
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 #endif 328 #endif
337 void CJS_Runtime::AddObserver(Observer* observer) { 329 void CJS_Runtime::AddObserver(Observer* observer) {
338 ASSERT(!pdfium::ContainsKey(m_observers, observer)); 330 ASSERT(!pdfium::ContainsKey(m_observers, observer));
339 m_observers.insert(observer); 331 m_observers.insert(observer);
340 } 332 }
341 333
342 void CJS_Runtime::RemoveObserver(Observer* observer) { 334 void CJS_Runtime::RemoveObserver(Observer* observer) {
343 ASSERT(pdfium::ContainsKey(m_observers, observer)); 335 ASSERT(pdfium::ContainsKey(m_observers, observer));
344 m_observers.erase(observer); 336 m_observers.erase(observer);
345 } 337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698