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

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: 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
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 14 matching lines...) Expand all
365 pIsolate->SetData(g_embedderDataSlot, nullptr); 371 pIsolate->SetData(g_embedderDataSlot, nullptr);
366 delete pData; 372 delete pData;
367 } 373 }
368 374
369 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { 375 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) {
370 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 376 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
371 return static_cast<IJS_Runtime*>( 377 return static_cast<IJS_Runtime*>(
372 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); 378 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
373 } 379 }
374 380
381 #ifdef PDF_ENABLE_XFA
375 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context, 382 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context,
376 IJS_Runtime* pIRuntime) { 383 IJS_Runtime* pIRuntime) {
377 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); 384 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
378 } 385 }
379 386
387 #endif
380 int FXJS_Execute(v8::Isolate* pIsolate, 388 int FXJS_Execute(v8::Isolate* pIsolate,
381 IJS_Context* pJSContext, 389 IJS_Context* pJSContext,
382 const wchar_t* script, 390 const wchar_t* script,
383 FXJSErr* pError) { 391 FXJSErr* pError) {
384 v8::Isolate::Scope isolate_scope(pIsolate); 392 v8::Isolate::Scope isolate_scope(pIsolate);
385 v8::TryCatch try_catch(pIsolate); 393 v8::TryCatch try_catch(pIsolate);
386 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode(); 394 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode();
387 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 395 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
388 v8::Local<v8::Script> compiled_script; 396 v8::Local<v8::Script> compiled_script;
389 if (!v8::Script::Compile( 397 if (!v8::Script::Compile(
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 return v8::Local<v8::Array>(); 767 return v8::Local<v8::Array>();
760 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 768 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
761 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 769 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
762 } 770 }
763 771
764 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 772 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
765 pTo = pFrom; 773 pTo = pFrom;
766 } 774 }
767 775
768 776
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698