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

Unified Diff: xfa/fxjse/runtime.cpp

Issue 2025193002: Track shared isolates better in FXJSE. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Stop deleting shared instances Created 4 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « xfa/fxjse/runtime.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: xfa/fxjse/runtime.cpp
diff --git a/xfa/fxjse/runtime.cpp b/xfa/fxjse/runtime.cpp
index 64d685bd5ff097cc4b6969388f7836dd41d1fdc0..40652f57ab03ec93bdf4c2c1098d08b57ec724f0 100644
--- a/xfa/fxjse/runtime.cpp
+++ b/xfa/fxjse/runtime.cpp
@@ -24,18 +24,18 @@ static void FXJSE_KillV8() {
}
void FXJSE_Initialize() {
- if (!CFXJSE_RuntimeData::g_RuntimeList) {
- CFXJSE_RuntimeData::g_RuntimeList = new CFXJSE_RuntimeList;
- }
+ if (!CFXJSE_IsolateTracker::g_pInstance)
+ CFXJSE_IsolateTracker::g_pInstance = new CFXJSE_IsolateTracker;
+
static FX_BOOL bV8Initialized = FALSE;
- if (bV8Initialized) {
+ if (bV8Initialized)
return;
- }
+
bV8Initialized = TRUE;
atexit(FXJSE_KillV8);
}
-static void FXJSE_Runtime_DisposeCallback(v8::Isolate* pIsolate) {
+static void FXJSE_Runtime_DisposeCallback(v8::Isolate* pIsolate, bool bOwned) {
{
v8::Locker locker(pIsolate);
if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) {
@@ -43,40 +43,33 @@ static void FXJSE_Runtime_DisposeCallback(v8::Isolate* pIsolate) {
pData->m_pFXJSERuntimeData = nullptr;
}
}
- pIsolate->Dispose();
+ if (bOwned)
+ pIsolate->Dispose();
}
void FXJSE_Finalize() {
- if (CFXJSE_RuntimeData::g_RuntimeList) {
- CFXJSE_RuntimeData::g_RuntimeList->RemoveAllRuntimes(
+ if (CFXJSE_IsolateTracker::g_pInstance) {
dsinclair 2016/06/01 02:57:36 if (!CFXJSE_IsolateTracker::g_pInstance) return;
Tom Sepez 2016/06/01 20:48:19 Done.
+ CFXJSE_IsolateTracker::g_pInstance->RemoveAll(
FXJSE_Runtime_DisposeCallback);
- delete CFXJSE_RuntimeData::g_RuntimeList;
- CFXJSE_RuntimeData::g_RuntimeList = NULL;
+ delete CFXJSE_IsolateTracker::g_pInstance;
+ CFXJSE_IsolateTracker::g_pInstance = NULL;
dsinclair 2016/06/01 02:57:36 nit: nullptr
Tom Sepez 2016/06/01 20:48:19 Done.
}
}
-v8::Isolate* FXJSE_Runtime_Create() {
+v8::Isolate* FXJSE_Runtime_Create_Own() {
v8::Isolate::CreateParams params;
params.array_buffer_allocator = new FXJSE_ArrayBufferAllocator();
v8::Isolate* pIsolate = v8::Isolate::New(params);
- ASSERT(pIsolate && CFXJSE_RuntimeData::g_RuntimeList);
- CFXJSE_RuntimeData::g_RuntimeList->AppendRuntime(pIsolate);
+ ASSERT(pIsolate && CFXJSE_IsolateTracker::g_pInstance);
+ CFXJSE_IsolateTracker::g_pInstance->Append(pIsolate);
return pIsolate;
}
-void FXJSE_Runtime_Release(v8::Isolate* pIsolate, bool bOwnedRuntime) {
+void FXJSE_Runtime_Release(v8::Isolate* pIsolate) {
if (!pIsolate)
return;
- if (bOwnedRuntime) {
- ASSERT(CFXJSE_RuntimeData::g_RuntimeList);
- CFXJSE_RuntimeData::g_RuntimeList->RemoveRuntime(
- pIsolate, FXJSE_Runtime_DisposeCallback);
- } else {
- if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) {
- delete pData->m_pFXJSERuntimeData;
- pData->m_pFXJSERuntimeData = nullptr;
- }
- }
+ CFXJSE_IsolateTracker::g_pInstance->Remove(pIsolate,
+ FXJSE_Runtime_DisposeCallback);
}
CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) {
@@ -100,27 +93,26 @@ CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) {
return pData->m_pFXJSERuntimeData;
}
-CFXJSE_RuntimeList* CFXJSE_RuntimeData::g_RuntimeList = nullptr;
+CFXJSE_IsolateTracker* CFXJSE_IsolateTracker::g_pInstance = nullptr;
-void CFXJSE_RuntimeList::AppendRuntime(v8::Isolate* pIsolate) {
- m_RuntimeList.push_back(pIsolate);
+void CFXJSE_IsolateTracker::Append(v8::Isolate* pIsolate) {
+ m_OwnedIsolates.push_back(pIsolate);
}
-void CFXJSE_RuntimeList::RemoveRuntime(
+void CFXJSE_IsolateTracker::Remove(
v8::Isolate* pIsolate,
- CFXJSE_RuntimeList::RuntimeDisposeCallback lpfnDisposeCallback) {
- auto it = std::find(m_RuntimeList.begin(), m_RuntimeList.end(), pIsolate);
- if (it != m_RuntimeList.end())
- m_RuntimeList.erase(it);
- if (lpfnDisposeCallback)
- lpfnDisposeCallback(pIsolate);
+ CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) {
+ auto it = std::find(m_OwnedIsolates.begin(), m_OwnedIsolates.end(), pIsolate);
+ bool bFound = it != m_OwnedIsolates.end();
+ if (bFound)
+ m_OwnedIsolates.erase(it);
+ lpfnDisposeCallback(pIsolate, bFound);
}
-void CFXJSE_RuntimeList::RemoveAllRuntimes(
- CFXJSE_RuntimeList::RuntimeDisposeCallback lpfnDisposeCallback) {
- if (lpfnDisposeCallback) {
- for (v8::Isolate* pIsolate : m_RuntimeList)
- lpfnDisposeCallback(pIsolate);
- }
- m_RuntimeList.clear();
+void CFXJSE_IsolateTracker::RemoveAll(
+ CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) {
+ for (v8::Isolate* pIsolate : m_OwnedIsolates)
+ lpfnDisposeCallback(pIsolate, true);
+
+ m_OwnedIsolates.clear();
}
« no previous file with comments | « xfa/fxjse/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698