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

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

Issue 1399273003: fpdfsdk/ differences with XFA (for didactic purposes only). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Regenerate after taking juns patch 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
285 v8::Locker locker(pIsolate);
286 #endif
284 v8::HandleScope handle_scope(pIsolate); 287 v8::HandleScope handle_scope(pIsolate);
285 v8::Local<v8::Context> v8Context = 288 v8::Local<v8::Context> v8Context =
286 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate)); 289 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate));
287 v8::Context::Scope context_scope(v8Context); 290 v8::Context::Scope context_scope(v8Context);
288 291
289 FXJS_PerIsolateData::SetUp(pIsolate); 292 FXJS_PerIsolateData::SetUp(pIsolate);
290 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); 293 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
291 294
292 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); 295 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
293 pStaticObjects->resize(maxID + 1); 296 pStaticObjects->resize(maxID + 1);
(...skipping 23 matching lines...) Expand all
317 pStaticObjects->at(i) = new v8::Global<v8::Object>(pIsolate, obj); 320 pStaticObjects->at(i) = new v8::Global<v8::Object>(pIsolate, obj);
318 } 321 }
319 } 322 }
320 pV8PersistentContext->Reset(pIsolate, v8Context); 323 pV8PersistentContext->Reset(pIsolate, v8Context);
321 } 324 }
322 325
323 void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, 326 void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
324 v8::Global<v8::Context>* pV8PersistentContext, 327 v8::Global<v8::Context>* pV8PersistentContext,
325 std::vector<v8::Global<v8::Object>*>* pStaticObjects) { 328 std::vector<v8::Global<v8::Object>*>* pStaticObjects) {
326 v8::Isolate::Scope isolate_scope(pIsolate); 329 v8::Isolate::Scope isolate_scope(pIsolate);
330 #ifdef PDF_ENABLE_XFA
331 v8::Locker locker(pIsolate);
332 #endif
327 v8::HandleScope handle_scope(pIsolate); 333 v8::HandleScope handle_scope(pIsolate);
328 v8::Local<v8::Context> context = 334 v8::Local<v8::Context> context =
329 v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext); 335 v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext);
330 v8::Context::Scope context_scope(context); 336 v8::Context::Scope context_scope(context);
331 337
332 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); 338 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate);
333 if (!pData) 339 if (!pData)
334 return; 340 return;
335 341
342 #ifdef PDF_ENABLE_XFA
343 // XFA, if present, should have already cleaned itself up.
344 FXSYS_assert(!pData->m_pFXJSERuntimeData);
345
346 #endif
336 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); 347 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
337 for (int i = 0; i < maxID; ++i) { 348 for (int i = 0; i < maxID; ++i) {
338 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); 349 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
339 v8::Local<v8::Object> pObj; 350 v8::Local<v8::Object> pObj;
340 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { 351 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) {
341 pObj = 352 pObj =
342 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); 353 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked();
343 } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) { 354 } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) {
344 pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i)); 355 pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i));
345 delete pStaticObjects->at(i); 356 delete pStaticObjects->at(i);
(...skipping 16 matching lines...) Expand all
362 pIsolate->SetData(g_embedderDataSlot, nullptr); 373 pIsolate->SetData(g_embedderDataSlot, nullptr);
363 delete pData; 374 delete pData;
364 } 375 }
365 376
366 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { 377 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) {
367 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 378 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
368 return static_cast<IJS_Runtime*>( 379 return static_cast<IJS_Runtime*>(
369 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); 380 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
370 } 381 }
371 382
383 #ifdef PDF_ENABLE_XFA
384 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context,
385 IJS_Runtime* pIRuntime) {
386 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
387 }
388
389 #endif
372 int FXJS_Execute(v8::Isolate* pIsolate, 390 int FXJS_Execute(v8::Isolate* pIsolate,
373 IJS_Context* pJSContext, 391 IJS_Context* pJSContext,
374 const wchar_t* script, 392 const wchar_t* script,
375 FXJSErr* pError) { 393 FXJSErr* pError) {
376 v8::Isolate::Scope isolate_scope(pIsolate); 394 v8::Isolate::Scope isolate_scope(pIsolate);
377 v8::TryCatch try_catch(pIsolate); 395 v8::TryCatch try_catch(pIsolate);
378 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode(); 396 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode();
379 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 397 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
380 v8::Local<v8::Script> compiled_script; 398 v8::Local<v8::Script> compiled_script;
381 if (!v8::Script::Compile( 399 if (!v8::Script::Compile(
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 return v8::Local<v8::Array>(); 769 return v8::Local<v8::Array>();
752 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 770 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
753 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 771 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
754 } 772 }
755 773
756 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) {
757 pTo = pFrom; 775 pTo = pFrom;
758 } 776 }
759 777
760 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