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

Side by Side Diff: fpdfsdk/src/jsapi/fxjs_v8.cpp

Issue 1477583002: Inflict PDF_ENABLE_XFA ifdefs on XFA fpdfsdk/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Remove fsdk_actionhandler.cpp Created 5 years 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/src/javascript/app.cpp ('k') | fpdfsdk/src/jsapi/fxjs_v8_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/include/jsapi/fxjs_v8.h" 7 #include "fpdfsdk/include/jsapi/fxjs_v8.h"
8 8
9 #include "core/include/fxcrt/fx_basic.h" 9 #include "core/include/fxcrt/fx_basic.h"
10 10
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 void FXJS_InitializeRuntime( 275 void FXJS_InitializeRuntime(
276 v8::Isolate* pIsolate, 276 v8::Isolate* pIsolate,
277 IJS_Runtime* pIRuntime, 277 IJS_Runtime* pIRuntime,
278 v8::Global<v8::Context>* pV8PersistentContext, 278 v8::Global<v8::Context>* pV8PersistentContext,
279 std::vector<v8::Global<v8::Object>*>* pStaticObjects) { 279 std::vector<v8::Global<v8::Object>*>* pStaticObjects) {
280 if (pIsolate == g_isolate) 280 if (pIsolate == g_isolate)
281 ++g_isolate_ref_count; 281 ++g_isolate_ref_count;
282 282
283 v8::Isolate::Scope isolate_scope(pIsolate); 283 v8::Isolate::Scope isolate_scope(pIsolate);
284 #ifdef PDF_ENABLE_XFA
284 v8::Locker locker(pIsolate); 285 v8::Locker locker(pIsolate);
286 #endif
285 v8::HandleScope handle_scope(pIsolate); 287 v8::HandleScope handle_scope(pIsolate);
286 v8::Local<v8::Context> v8Context = 288 v8::Local<v8::Context> v8Context =
287 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate)); 289 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate));
288 v8::Context::Scope context_scope(v8Context); 290 v8::Context::Scope context_scope(v8Context);
289 291
290 FXJS_PerIsolateData::SetUp(pIsolate); 292 FXJS_PerIsolateData::SetUp(pIsolate);
291 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); 293 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
292 294
293 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); 295 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
294 pStaticObjects->resize(maxID + 1); 296 pStaticObjects->resize(maxID + 1);
(...skipping 23 matching lines...) Expand all
318 pStaticObjects->at(i) = new v8::Global<v8::Object>(pIsolate, obj); 320 pStaticObjects->at(i) = new v8::Global<v8::Object>(pIsolate, obj);
319 } 321 }
320 } 322 }
321 pV8PersistentContext->Reset(pIsolate, v8Context); 323 pV8PersistentContext->Reset(pIsolate, v8Context);
322 } 324 }
323 325
324 void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, 326 void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
325 v8::Global<v8::Context>* pV8PersistentContext, 327 v8::Global<v8::Context>* pV8PersistentContext,
326 std::vector<v8::Global<v8::Object>*>* pStaticObjects) { 328 std::vector<v8::Global<v8::Object>*>* pStaticObjects) {
327 v8::Isolate::Scope isolate_scope(pIsolate); 329 v8::Isolate::Scope isolate_scope(pIsolate);
330 #ifdef PDF_ENABLE_XFA
328 v8::Locker locker(pIsolate); 331 v8::Locker locker(pIsolate);
332 #endif
329 v8::HandleScope handle_scope(pIsolate); 333 v8::HandleScope handle_scope(pIsolate);
330 v8::Local<v8::Context> context = 334 v8::Local<v8::Context> context =
331 v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext); 335 v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext);
332 v8::Context::Scope context_scope(context); 336 v8::Context::Scope context_scope(context);
333 337
334 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); 338 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
335 if (!pData) 339 if (!pData)
336 return; 340 return;
337 341
342 #ifdef PDF_ENABLE_XFA
338 // XFA, if present, should have already cleaned itself up. 343 // XFA, if present, should have already cleaned itself up.
339 FXSYS_assert(!pData->m_pFXJSERuntimeData); 344 FXSYS_assert(!pData->m_pFXJSERuntimeData);
340 345
346 #endif
341 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); 347 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
342 for (int i = 0; i < maxID; ++i) { 348 for (int i = 0; i < maxID; ++i) {
343 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); 349 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
344 v8::Local<v8::Object> pObj; 350 v8::Local<v8::Object> pObj;
345 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { 351 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) {
346 pObj = 352 pObj =
347 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); 353 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked();
348 } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) { 354 } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) {
349 pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i)); 355 pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i));
350 delete pStaticObjects->at(i); 356 delete pStaticObjects->at(i);
(...skipping 16 matching lines...) Expand all
367 pIsolate->SetData(g_embedderDataSlot, nullptr); 373 pIsolate->SetData(g_embedderDataSlot, nullptr);
368 delete pData; 374 delete pData;
369 } 375 }
370 376
371 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { 377 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) {
372 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 378 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
373 return static_cast<IJS_Runtime*>( 379 return static_cast<IJS_Runtime*>(
374 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); 380 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
375 } 381 }
376 382
383 #ifdef PDF_ENABLE_XFA
377 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context, 384 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context,
378 IJS_Runtime* pIRuntime) { 385 IJS_Runtime* pIRuntime) {
379 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); 386 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
380 } 387 }
381 388
389 #endif
382 int FXJS_Execute(v8::Isolate* pIsolate, 390 int FXJS_Execute(v8::Isolate* pIsolate,
383 IJS_Context* pJSContext, 391 IJS_Context* pJSContext,
384 const wchar_t* script, 392 const wchar_t* script,
385 FXJSErr* pError) { 393 FXJSErr* pError) {
386 v8::Isolate::Scope isolate_scope(pIsolate); 394 v8::Isolate::Scope isolate_scope(pIsolate);
387 v8::TryCatch try_catch(pIsolate); 395 v8::TryCatch try_catch(pIsolate);
388 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode(); 396 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode();
389 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 397 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
390 v8::Local<v8::Script> compiled_script; 398 v8::Local<v8::Script> compiled_script;
391 if (!v8::Script::Compile( 399 if (!v8::Script::Compile(
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 return v8::Local<v8::Array>(); 769 return v8::Local<v8::Array>();
762 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 770 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
763 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 771 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
764 } 772 }
765 773
766 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 774 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
767 pTo = pFrom; 775 pTo = pFrom;
768 } 776 }
769 777
770 778
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/app.cpp ('k') | fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698