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 "fxjse/runtime.h" | 7 #include "fxjse/runtime.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 return pIsolate; | 62 return pIsolate; |
63 } | 63 } |
64 | 64 |
65 void FXJSE_Runtime_Release(v8::Isolate* pIsolate) { | 65 void FXJSE_Runtime_Release(v8::Isolate* pIsolate) { |
66 if (!pIsolate) | 66 if (!pIsolate) |
67 return; | 67 return; |
68 CFXJSE_IsolateTracker::g_pInstance->Remove(pIsolate, | 68 CFXJSE_IsolateTracker::g_pInstance->Remove(pIsolate, |
69 FXJSE_Runtime_DisposeCallback); | 69 FXJSE_Runtime_DisposeCallback); |
70 } | 70 } |
71 | 71 |
| 72 CFXJSE_RuntimeData::CFXJSE_RuntimeData(v8::Isolate* pIsolate) |
| 73 : m_pIsolate(pIsolate) {} |
| 74 |
| 75 CFXJSE_RuntimeData::~CFXJSE_RuntimeData() {} |
| 76 |
72 CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) { | 77 CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) { |
73 CFXJSE_RuntimeData* pRuntimeData = new CFXJSE_RuntimeData(pIsolate); | 78 CFXJSE_RuntimeData* pRuntimeData = new CFXJSE_RuntimeData(pIsolate); |
74 CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate); | 79 CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate); |
75 v8::Local<v8::FunctionTemplate> hFuncTemplate = | 80 v8::Local<v8::FunctionTemplate> hFuncTemplate = |
76 v8::FunctionTemplate::New(pIsolate); | 81 v8::FunctionTemplate::New(pIsolate); |
77 v8::Local<v8::Context> hContext = | 82 v8::Local<v8::Context> hContext = |
78 v8::Context::New(pIsolate, 0, hFuncTemplate->InstanceTemplate()); | 83 v8::Context::New(pIsolate, 0, hFuncTemplate->InstanceTemplate()); |
79 hContext->SetSecurityToken(v8::External::New(pIsolate, pIsolate)); | 84 hContext->SetSecurityToken(v8::External::New(pIsolate, pIsolate)); |
80 pRuntimeData->m_hRootContextGlobalTemplate.Reset(pIsolate, hFuncTemplate); | 85 pRuntimeData->m_hRootContextGlobalTemplate.Reset(pIsolate, hFuncTemplate); |
81 pRuntimeData->m_hRootContext.Reset(pIsolate, hContext); | 86 pRuntimeData->m_hRootContext.Reset(pIsolate, hContext); |
82 return pRuntimeData; | 87 return pRuntimeData; |
83 } | 88 } |
84 | 89 |
85 CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) { | 90 CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) { |
86 FXJS_PerIsolateData::SetUp(pIsolate); | 91 FXJS_PerIsolateData::SetUp(pIsolate); |
87 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); | 92 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); |
88 if (!pData->m_pFXJSERuntimeData) | 93 if (!pData->m_pFXJSERuntimeData) |
89 pData->m_pFXJSERuntimeData = CFXJSE_RuntimeData::Create(pIsolate); | 94 pData->m_pFXJSERuntimeData = CFXJSE_RuntimeData::Create(pIsolate); |
90 return pData->m_pFXJSERuntimeData; | 95 return pData->m_pFXJSERuntimeData; |
91 } | 96 } |
92 | 97 |
93 CFXJSE_IsolateTracker* CFXJSE_IsolateTracker::g_pInstance = nullptr; | 98 CFXJSE_IsolateTracker* CFXJSE_IsolateTracker::g_pInstance = nullptr; |
94 | 99 |
| 100 CFXJSE_IsolateTracker::CFXJSE_IsolateTracker() {} |
| 101 |
| 102 CFXJSE_IsolateTracker::~CFXJSE_IsolateTracker() {} |
| 103 |
95 void CFXJSE_IsolateTracker::Append(v8::Isolate* pIsolate) { | 104 void CFXJSE_IsolateTracker::Append(v8::Isolate* pIsolate) { |
96 m_OwnedIsolates.push_back(pIsolate); | 105 m_OwnedIsolates.push_back(pIsolate); |
97 } | 106 } |
98 | 107 |
99 void CFXJSE_IsolateTracker::Remove( | 108 void CFXJSE_IsolateTracker::Remove( |
100 v8::Isolate* pIsolate, | 109 v8::Isolate* pIsolate, |
101 CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) { | 110 CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) { |
102 auto it = std::find(m_OwnedIsolates.begin(), m_OwnedIsolates.end(), pIsolate); | 111 auto it = std::find(m_OwnedIsolates.begin(), m_OwnedIsolates.end(), pIsolate); |
103 bool bFound = it != m_OwnedIsolates.end(); | 112 bool bFound = it != m_OwnedIsolates.end(); |
104 if (bFound) | 113 if (bFound) |
105 m_OwnedIsolates.erase(it); | 114 m_OwnedIsolates.erase(it); |
106 lpfnDisposeCallback(pIsolate, bFound); | 115 lpfnDisposeCallback(pIsolate, bFound); |
107 } | 116 } |
108 | 117 |
109 void CFXJSE_IsolateTracker::RemoveAll( | 118 void CFXJSE_IsolateTracker::RemoveAll( |
110 CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) { | 119 CFXJSE_IsolateTracker::DisposeCallback lpfnDisposeCallback) { |
111 for (v8::Isolate* pIsolate : m_OwnedIsolates) | 120 for (v8::Isolate* pIsolate : m_OwnedIsolates) |
112 lpfnDisposeCallback(pIsolate, true); | 121 lpfnDisposeCallback(pIsolate, true); |
113 | 122 |
114 m_OwnedIsolates.clear(); | 123 m_OwnedIsolates.clear(); |
115 } | 124 } |
OLD | NEW |