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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 return malloc(length); | 123 return malloc(length); |
124 } | 124 } |
125 | 125 |
126 void FXJS_ArrayBufferAllocator::Free(void* data, size_t length) { | 126 void FXJS_ArrayBufferAllocator::Free(void* data, size_t length) { |
127 free(data); | 127 free(data); |
128 } | 128 } |
129 | 129 |
130 void V8TemplateMapTraits::Dispose(v8::Isolate* isolate, | 130 void V8TemplateMapTraits::Dispose(v8::Isolate* isolate, |
131 v8::Global<v8::Object> value, | 131 v8::Global<v8::Object> value, |
132 void* key) { | 132 void* key) { |
133 v8::Local<v8::Object> obj = value.Get(isolate); | 133 v8::Local<v8::Object> obj = value.Get(isolate); |
Tom Sepez
2016/03/23 21:34:46
Jochen: does this routine need to remove the dispo
| |
134 if (obj.IsEmpty()) | 134 if (obj.IsEmpty()) |
135 return; | 135 return; |
136 int id = FXJS_GetObjDefnID(obj); | 136 int id = FXJS_GetObjDefnID(obj); |
137 if (id == -1) | 137 if (id == -1) |
138 return; | 138 return; |
139 | 139 |
140 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(isolate, id); | 140 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(isolate, id); |
141 if (!pObjDef) | 141 if (!pObjDef) |
142 return; | 142 return; |
143 if (pObjDef->m_pDestructor) | 143 if (pObjDef->m_pDestructor) |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 std::vector<v8::Global<v8::Object>*>* pStaticObjects) { | 364 std::vector<v8::Global<v8::Object>*>* pStaticObjects) { |
365 v8::Isolate::Scope isolate_scope(pIsolate); | 365 v8::Isolate::Scope isolate_scope(pIsolate); |
366 #ifdef PDF_ENABLE_XFA | 366 #ifdef PDF_ENABLE_XFA |
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); | |
375 if (!pData) | |
376 return; | |
377 pData->ReleaseDynamicObjsMap(); | |
378 | |
379 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); | 374 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); |
380 for (int i = 0; i < maxID; ++i) { | 375 for (int i = 0; i < maxID; ++i) { |
381 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); | 376 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); |
382 v8::Local<v8::Object> pObj; | 377 v8::Local<v8::Object> pObj; |
383 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { | 378 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { |
384 pObj = | 379 pObj = |
385 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); | 380 context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); |
386 } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) { | 381 } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) { |
387 pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i)); | 382 pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i)); |
388 delete pStaticObjects->at(i); | 383 delete pStaticObjects->at(i); |
389 pStaticObjects->at(i) = nullptr; | 384 pStaticObjects->at(i) = nullptr; |
390 } | 385 } |
391 | 386 |
392 if (!pObj.IsEmpty()) { | 387 if (!pObj.IsEmpty()) { |
393 if (pObjDef->m_pDestructor) | 388 if (pObjDef->m_pDestructor) |
394 pObjDef->m_pDestructor(pObj); | 389 pObjDef->m_pDestructor(pObj); |
395 FXJS_FreePrivate(pObj); | 390 FXJS_FreePrivate(pObj); |
396 } | 391 } |
397 } | 392 } |
398 | 393 |
399 if (pIsolate == g_isolate && --g_isolate_ref_count > 0) | 394 if (pIsolate == g_isolate && --g_isolate_ref_count > 0) |
400 return; | 395 return; |
401 | 396 |
402 for (int i = 0; i < maxID; ++i) | 397 for (int i = 0; i < maxID; ++i) |
403 delete CFXJS_ObjDefinition::ForID(pIsolate, i); | 398 delete CFXJS_ObjDefinition::ForID(pIsolate, i); |
404 | 399 |
405 pIsolate->SetData(g_embedderDataSlot, nullptr); | 400 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); |
406 delete pData; | 401 if (pData) { |
402 pData->ReleaseDynamicObjsMap(); | |
403 pIsolate->SetData(g_embedderDataSlot, nullptr); | |
404 delete pData; | |
405 } | |
407 } | 406 } |
408 | 407 |
409 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { | 408 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { |
410 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 409 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
411 return static_cast<IJS_Runtime*>( | 410 return static_cast<IJS_Runtime*>( |
412 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); | 411 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); |
413 } | 412 } |
414 | 413 |
415 #ifdef PDF_ENABLE_XFA | 414 #ifdef PDF_ENABLE_XFA |
416 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context, | 415 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context, |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 v8::Local<v8::Value> pValue) { | 813 v8::Local<v8::Value> pValue) { |
815 if (pValue.IsEmpty()) | 814 if (pValue.IsEmpty()) |
816 return v8::Local<v8::Array>(); | 815 return v8::Local<v8::Array>(); |
817 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 816 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
818 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 817 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); |
819 } | 818 } |
820 | 819 |
821 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { | 820 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { |
822 pTo = pFrom; | 821 pTo = pFrom; |
823 } | 822 } |
OLD | NEW |