OLD | NEW |
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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 v8::Locker locker(pIsolate); | 367 v8::Locker locker(pIsolate); |
368 #endif // PDF_ENABLE_XFA | 368 #endif // PDF_ENABLE_XFA |
369 v8::HandleScope handle_scope(pIsolate); | 369 v8::HandleScope handle_scope(pIsolate); |
370 v8::Local<v8::Context> context = | 370 v8::Local<v8::Context> context = |
371 v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext); | 371 v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext); |
372 v8::Context::Scope context_scope(context); | 372 v8::Context::Scope context_scope(context); |
373 | 373 |
374 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); | 374 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); |
375 if (!pData) | 375 if (!pData) |
376 return; | 376 return; |
377 pData->ReleaseDynamicObjsMap(); | |
378 | 377 |
379 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); | 378 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); |
380 for (int i = 0; i < maxID; ++i) { | 379 for (int i = 0; i < maxID; ++i) { |
381 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); | 380 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); |
382 v8::Local<v8::Object> pObj; | 381 v8::Local<v8::Object> pObj; |
383 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { | 382 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { |
384 pObj = | 383 pObj = |
385 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); | 384 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); |
386 } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) { | 385 } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) { |
387 pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i)); | 386 pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i)); |
388 delete pStaticObjects->at(i); | 387 delete pStaticObjects->at(i); |
389 pStaticObjects->at(i) = nullptr; | 388 pStaticObjects->at(i) = nullptr; |
390 } | 389 } |
391 | 390 |
392 if (!pObj.IsEmpty()) { | 391 if (!pObj.IsEmpty()) { |
393 if (pObjDef->m_pDestructor) | 392 if (pObjDef->m_pDestructor) |
394 pObjDef->m_pDestructor(pObj); | 393 pObjDef->m_pDestructor(pObj); |
395 FXJS_FreePrivate(pObj); | 394 FXJS_FreePrivate(pObj); |
396 } | 395 } |
397 } | 396 } |
398 | 397 |
399 if (pIsolate == g_isolate && --g_isolate_ref_count > 0) | 398 if (pIsolate == g_isolate && --g_isolate_ref_count > 0) |
400 return; | 399 return; |
401 | 400 |
| 401 pData->ReleaseDynamicObjsMap(); |
402 for (int i = 0; i < maxID; ++i) | 402 for (int i = 0; i < maxID; ++i) |
403 delete CFXJS_ObjDefinition::ForID(pIsolate, i); | 403 delete CFXJS_ObjDefinition::ForID(pIsolate, i); |
404 | 404 |
405 pIsolate->SetData(g_embedderDataSlot, nullptr); | 405 pIsolate->SetData(g_embedderDataSlot, nullptr); |
406 delete pData; | 406 delete pData; |
407 } | 407 } |
408 | 408 |
409 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { | 409 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { |
410 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 410 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
411 return static_cast<IJS_Runtime*>( | 411 return static_cast<IJS_Runtime*>( |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 v8::Local<v8::Value> pValue) { | 814 v8::Local<v8::Value> pValue) { |
815 if (pValue.IsEmpty()) | 815 if (pValue.IsEmpty()) |
816 return v8::Local<v8::Array>(); | 816 return v8::Local<v8::Array>(); |
817 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 817 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
818 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 818 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); |
819 } | 819 } |
820 | 820 |
821 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { | 821 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { |
822 pTo = pFrom; | 822 pTo = pFrom; |
823 } | 823 } |
OLD | NEW |