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

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

Issue 2026933002: Remove use of v8:Lockers (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase Created 4 years, 6 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
« no previous file with comments | « fpdfsdk/javascript/cjs_context.cpp ('k') | fpdfsdk/javascript/public_methods_embeddertest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/cjs_runtime.h" 7 #include "fpdfsdk/javascript/cjs_runtime.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 #endif 81 #endif
82 } 82 }
83 #ifndef PDF_ENABLE_XFA 83 #ifndef PDF_ENABLE_XFA
84 FXJS_Initialize(embedderDataSlot, pExternalIsolate); 84 FXJS_Initialize(embedderDataSlot, pExternalIsolate);
85 #else 85 #else
86 m_isolateManaged = FXJS_GetIsolate(&m_isolate); 86 m_isolateManaged = FXJS_GetIsolate(&m_isolate);
87 } 87 }
88 88
89 v8::Isolate* isolate = m_isolate; 89 v8::Isolate* isolate = m_isolate;
90 v8::Isolate::Scope isolate_scope(isolate); 90 v8::Isolate::Scope isolate_scope(isolate);
91 v8::Locker locker(isolate);
92 v8::HandleScope handle_scope(isolate); 91 v8::HandleScope handle_scope(isolate);
93 if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { 92 if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) {
94 CJS_Context* pContext = (CJS_Context*)NewContext(); 93 CJS_Context* pContext = (CJS_Context*)NewContext();
95 FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects); 94 FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects);
96 ReleaseContext(pContext); 95 ReleaseContext(pContext);
97 return; 96 return;
98 #endif 97 #endif
99 } 98 }
100 #ifndef PDF_ENABLE_XFA 99 #ifndef PDF_ENABLE_XFA
101 m_isolateManaged = FXJS_GetIsolate(&m_isolate); 100 m_isolateManaged = FXJS_GetIsolate(&m_isolate);
(...skipping 19 matching lines...) Expand all
121 m_ContextArray.clear(); 120 m_ContextArray.clear();
122 m_ConstArrays.clear(); 121 m_ConstArrays.clear();
123 FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects); 122 FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects);
124 m_context.Reset(); 123 m_context.Reset();
125 if (m_isolateManaged) 124 if (m_isolateManaged)
126 m_isolate->Dispose(); 125 m_isolate->Dispose();
127 } 126 }
128 127
129 void CJS_Runtime::DefineJSObjects() { 128 void CJS_Runtime::DefineJSObjects() {
130 v8::Isolate::Scope isolate_scope(GetIsolate()); 129 v8::Isolate::Scope isolate_scope(GetIsolate());
131 #ifdef PDF_ENABLE_XFA
132 v8::Locker locker(GetIsolate());
133 #endif
134 v8::HandleScope handle_scope(GetIsolate()); 130 v8::HandleScope handle_scope(GetIsolate());
135 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); 131 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
136 v8::Context::Scope context_scope(context); 132 v8::Context::Scope context_scope(context);
137 133
138 // The call order determines the "ObjDefID" assigned to each class. 134 // The call order determines the "ObjDefID" assigned to each class.
139 // ObjDefIDs 0 - 2 135 // ObjDefIDs 0 - 2
140 CJS_Border::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 136 CJS_Border::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
141 CJS_Display::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 137 CJS_Display::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
142 CJS_Font::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 138 CJS_Font::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
143 139
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 186 }
191 } 187 }
192 188
193 IJS_Context* CJS_Runtime::GetCurrentContext() { 189 IJS_Context* CJS_Runtime::GetCurrentContext() {
194 return m_ContextArray.empty() ? nullptr : m_ContextArray.back().get(); 190 return m_ContextArray.empty() ? nullptr : m_ContextArray.back().get();
195 } 191 }
196 192
197 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { 193 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
198 if (m_pDocument != pReaderDoc) { 194 if (m_pDocument != pReaderDoc) {
199 v8::Isolate::Scope isolate_scope(m_isolate); 195 v8::Isolate::Scope isolate_scope(m_isolate);
200 #ifdef PDF_ENABLE_XFA
201 v8::Locker locker(m_isolate);
202 #endif
203 v8::HandleScope handle_scope(m_isolate); 196 v8::HandleScope handle_scope(m_isolate);
204 v8::Local<v8::Context> context = 197 v8::Local<v8::Context> context =
205 v8::Local<v8::Context>::New(m_isolate, m_context); 198 v8::Local<v8::Context>::New(m_isolate, m_context);
206 v8::Context::Scope context_scope(context); 199 v8::Context::Scope context_scope(context);
207 200
208 m_pDocument = pReaderDoc; 201 m_pDocument = pReaderDoc;
209 if (pReaderDoc) { 202 if (pReaderDoc) {
210 v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate()); 203 v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate());
211 if (!pThis.IsEmpty()) { 204 if (!pThis.IsEmpty()) {
212 if (FXJS_GetObjDefnID(pThis) == CJS_Document::g_nObjDefnID) { 205 if (FXJS_GetObjDefnID(pThis) == CJS_Document::g_nObjDefnID) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 CFX_WideString ChangeObjName(const CFX_WideString& str) { 251 CFX_WideString ChangeObjName(const CFX_WideString& str) {
259 CFX_WideString sRet = str; 252 CFX_WideString sRet = str;
260 sRet.Replace(L"_", L"."); 253 sRet.Replace(L"_", L".");
261 return sRet; 254 return sRet;
262 } 255 }
263 FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, 256 FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name,
264 CFXJSE_Value* pValue) { 257 CFXJSE_Value* pValue) {
265 #ifdef PDF_ENABLE_XFA 258 #ifdef PDF_ENABLE_XFA
266 const FX_CHAR* name = utf8Name.c_str(); 259 const FX_CHAR* name = utf8Name.c_str();
267 260
268 v8::Locker lock(GetIsolate());
269 v8::Isolate::Scope isolate_scope(GetIsolate()); 261 v8::Isolate::Scope isolate_scope(GetIsolate());
270 v8::HandleScope handle_scope(GetIsolate()); 262 v8::HandleScope handle_scope(GetIsolate());
271 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext(); 263 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext();
272 v8::Local<v8::Context> context = 264 v8::Local<v8::Context> context =
273 v8::Local<v8::Context>::New(GetIsolate(), m_context); 265 v8::Local<v8::Context>::New(GetIsolate(), m_context);
274 v8::Context::Scope context_scope(context); 266 v8::Context::Scope context_scope(context);
275 267
276 // Caution: We're about to hand to XFA an object that in order to invoke 268 // Caution: We're about to hand to XFA an object that in order to invoke
277 // methods will require that the current v8::Context always has a pointer 269 // methods will require that the current v8::Context always has a pointer
278 // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates 270 // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates
(...skipping 16 matching lines...) Expand all
295 287
296 return TRUE; 288 return TRUE;
297 } 289 }
298 FX_BOOL CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name, 290 FX_BOOL CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name,
299 CFXJSE_Value* pValue) { 291 CFXJSE_Value* pValue) {
300 #ifdef PDF_ENABLE_XFA 292 #ifdef PDF_ENABLE_XFA
301 if (utf8Name.IsEmpty() || !pValue) 293 if (utf8Name.IsEmpty() || !pValue)
302 return FALSE; 294 return FALSE;
303 const FX_CHAR* name = utf8Name.c_str(); 295 const FX_CHAR* name = utf8Name.c_str();
304 v8::Isolate* pIsolate = GetIsolate(); 296 v8::Isolate* pIsolate = GetIsolate();
305 v8::Locker lock(pIsolate);
306 v8::Isolate::Scope isolate_scope(pIsolate); 297 v8::Isolate::Scope isolate_scope(pIsolate);
307 v8::HandleScope handle_scope(pIsolate); 298 v8::HandleScope handle_scope(pIsolate);
308 v8::Local<v8::Context> context = 299 v8::Local<v8::Context> context =
309 v8::Local<v8::Context>::New(pIsolate, m_context); 300 v8::Local<v8::Context>::New(pIsolate, m_context);
310 v8::Context::Scope context_scope(context); 301 v8::Context::Scope context_scope(context);
311 302
312 // v8::Local<v8::Context> tmpCotext = 303 // v8::Local<v8::Context> tmpCotext =
313 // v8::Local<v8::Context>::New(GetIsolate(), m_context); 304 // v8::Local<v8::Context>::New(GetIsolate(), m_context);
314 v8::Local<v8::Value> propvalue = 305 v8::Local<v8::Value> propvalue =
315 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue()); 306 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue());
316 context->Global()->Set( 307 context->Global()->Set(
317 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, 308 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString,
318 utf8Name.GetLength()), 309 utf8Name.GetLength()),
319 propvalue); 310 propvalue);
320 #endif 311 #endif
321 return TRUE; 312 return TRUE;
322 } 313 }
323 314
324 #endif 315 #endif
325 void CJS_Runtime::AddObserver(Observer* observer) { 316 void CJS_Runtime::AddObserver(Observer* observer) {
326 ASSERT(!pdfium::ContainsKey(m_observers, observer)); 317 ASSERT(!pdfium::ContainsKey(m_observers, observer));
327 m_observers.insert(observer); 318 m_observers.insert(observer);
328 } 319 }
329 320
330 void CJS_Runtime::RemoveObserver(Observer* observer) { 321 void CJS_Runtime::RemoveObserver(Observer* observer) {
331 ASSERT(pdfium::ContainsKey(m_observers, observer)); 322 ASSERT(pdfium::ContainsKey(m_observers, observer));
332 m_observers.erase(observer); 323 m_observers.erase(observer);
333 } 324 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/cjs_context.cpp ('k') | fpdfsdk/javascript/public_methods_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698