Index: fxjs/cfxjse_runtimedata.cpp |
diff --git a/fxjse/runtime.cpp b/fxjs/cfxjse_runtimedata.cpp |
similarity index 71% |
rename from fxjse/runtime.cpp |
rename to fxjs/cfxjse_runtimedata.cpp |
index b5f2f33a75094472abe9e6dc7aeb2d79edb4528b..f58f5f852d62d3621e5e9b56d1f0b312784319c6 100644 |
--- a/fxjse/runtime.cpp |
+++ b/fxjs/cfxjse_runtimedata.cpp |
@@ -1,15 +1,15 @@ |
-// Copyright 2014 PDFium Authors. All rights reserved. |
+// Copyright 2016 PDFium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
-#include "fxjse/runtime.h" |
- |
-#include <algorithm> |
+#include "fxjs/cfxjse_runtimedata.h" |
#include "fpdfsdk/jsapi/include/fxjs_v8.h" |
-#include "fxjse/scope_inline.h" |
+#include "fxjs/cfxjse_isolatetracker.h" |
+ |
+namespace { |
// Duplicates fpdfsdk's cjs_runtime.h, but keeps XFA from depending on it. |
// TODO(tsepez): make a single version of this. |
@@ -19,10 +19,21 @@ class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
void Free(void* data, size_t length) override { free(data); } |
}; |
-static void FXJSE_KillV8() { |
+void Runtime_DisposeCallback(v8::Isolate* pIsolate, bool bOwned) { |
+ if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) { |
+ delete pData->m_pFXJSERuntimeData; |
+ pData->m_pFXJSERuntimeData = nullptr; |
+ } |
+ if (bOwned) |
+ pIsolate->Dispose(); |
+} |
+ |
+void KillV8() { |
v8::V8::Dispose(); |
} |
+} // namespace |
+ |
void FXJSE_Initialize() { |
if (!CFXJSE_IsolateTracker::g_pInstance) |
CFXJSE_IsolateTracker::g_pInstance = new CFXJSE_IsolateTracker; |
@@ -32,23 +43,14 @@ void FXJSE_Initialize() { |
return; |
bV8Initialized = TRUE; |
- atexit(FXJSE_KillV8); |
-} |
- |
-static void FXJSE_Runtime_DisposeCallback(v8::Isolate* pIsolate, bool bOwned) { |
- if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) { |
- delete pData->m_pFXJSERuntimeData; |
- pData->m_pFXJSERuntimeData = nullptr; |
- } |
- if (bOwned) |
- pIsolate->Dispose(); |
+ atexit(KillV8); |
} |
void FXJSE_Finalize() { |
if (!CFXJSE_IsolateTracker::g_pInstance) |
return; |
- CFXJSE_IsolateTracker::g_pInstance->RemoveAll(FXJSE_Runtime_DisposeCallback); |
+ CFXJSE_IsolateTracker::g_pInstance->RemoveAll(Runtime_DisposeCallback); |
delete CFXJSE_IsolateTracker::g_pInstance; |
CFXJSE_IsolateTracker::g_pInstance = nullptr; |
} |
@@ -65,8 +67,7 @@ v8::Isolate* FXJSE_Runtime_Create_Own() { |
void FXJSE_Runtime_Release(v8::Isolate* pIsolate) { |
if (!pIsolate) |
return; |
- CFXJSE_IsolateTracker::g_pInstance->Remove(pIsolate, |
- FXJSE_Runtime_DisposeCallback); |
+ CFXJSE_IsolateTracker::g_pInstance->Remove(pIsolate, Runtime_DisposeCallback); |
} |
CFXJSE_RuntimeData::CFXJSE_RuntimeData(v8::Isolate* pIsolate) |
@@ -102,29 +103,3 @@ CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) { |
} |
CFXJSE_IsolateTracker* CFXJSE_IsolateTracker::g_pInstance = nullptr; |
- |
-CFXJSE_IsolateTracker::CFXJSE_IsolateTracker() {} |
- |
-CFXJSE_IsolateTracker::~CFXJSE_IsolateTracker() {} |
- |
-void CFXJSE_IsolateTracker::Append(v8::Isolate* pIsolate) { |
- m_OwnedIsolates.push_back(pIsolate); |
-} |
- |
-void CFXJSE_IsolateTracker::Remove( |
- v8::Isolate* 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_IsolateTracker::RemoveAll( |
- CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) { |
- for (v8::Isolate* pIsolate : m_OwnedIsolates) |
- lpfnDisposeCallback(pIsolate, true); |
- |
- m_OwnedIsolates.clear(); |
-} |