Chromium Code Reviews| 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 "xfa/fxjse/context.h" | 7 #include "xfa/fxjse/context.h" |
| 8 | 8 |
| 9 #include "xfa/fxjse/class.h" | 9 #include "xfa/fxjse/class.h" |
| 10 #include "xfa/fxjse/scope_inline.h" | 10 #include "xfa/fxjse/scope_inline.h" |
| 11 #include "xfa/fxjse/util_inline.h" | 11 #include "xfa/fxjse/util_inline.h" |
| 12 #include "xfa/fxjse/value.h" | 12 #include "xfa/fxjse/value.h" |
| 13 | 13 |
| 14 FXJSE_HCONTEXT FXJSE_Context_Create(FXJSE_HRUNTIME hRuntime, | 14 FXJSE_HCONTEXT FXJSE_Context_Create(FXJSE_HRUNTIME hRuntime, |
| 15 const FXJSE_CLASS* lpGlobalClass, | 15 const FXJSE_CLASS* lpGlobalClass, |
| 16 void* lpGlobalObject) { | 16 void* lpGlobalObject) { |
| 17 CFXJSE_Context* pContext = CFXJSE_Context::Create( | 17 CFXJSE_Context* pContext = CFXJSE_Context::Create( |
| 18 reinterpret_cast<v8::Isolate*>(hRuntime), lpGlobalClass, lpGlobalObject); | 18 reinterpret_cast<v8::Isolate*>(hRuntime), lpGlobalClass, lpGlobalObject); |
| 19 return reinterpret_cast<FXJSE_HCONTEXT>(pContext); | 19 return reinterpret_cast<FXJSE_HCONTEXT>(pContext); |
| 20 } | 20 } |
| 21 | 21 |
| 22 void FXJSE_Context_Release(FXJSE_HCONTEXT hContext) { | 22 void FXJSE_Context_Release(FXJSE_HCONTEXT hContext) { |
| 23 CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext); | 23 delete hContext; |
|
Tom Sepez
2016/04/28 21:47:23
No, there's a brutal reinterpret cast going on her
Lei Zhang
2016/04/28 22:31:10
Done.
| |
| 24 if (pContext) { | |
| 25 delete pContext; | |
| 26 } | |
| 27 } | 24 } |
| 28 | 25 |
| 29 FXJSE_HVALUE FXJSE_Context_GetGlobalObject(FXJSE_HCONTEXT hContext) { | 26 FXJSE_HVALUE FXJSE_Context_GetGlobalObject(FXJSE_HCONTEXT hContext) { |
| 30 CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext); | 27 CFXJSE_Context* pContext = reinterpret_cast<CFXJSE_Context*>(hContext); |
| 31 if (!pContext) { | 28 if (!pContext) { |
| 32 return NULL; | 29 return NULL; |
| 33 } | 30 } |
| 34 CFXJSE_Value* lpValue = CFXJSE_Value::Create(pContext->GetRuntime()); | 31 CFXJSE_Value* lpValue = CFXJSE_Value::Create(pContext->GetRuntime()); |
| 35 ASSERT(lpValue); | 32 ASSERT(lpValue); |
| 36 pContext->GetGlobalObject(lpValue); | 33 pContext->GetGlobalObject(lpValue); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 pIsolate, CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext); | 142 pIsolate, CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext); |
| 146 hNewContext->SetSecurityToken(hRootContext->GetSecurityToken()); | 143 hNewContext->SetSecurityToken(hRootContext->GetSecurityToken()); |
| 147 v8::Local<v8::Object> hGlobalObject = | 144 v8::Local<v8::Object> hGlobalObject = |
| 148 FXJSE_GetGlobalObjectFromContext(hNewContext); | 145 FXJSE_GetGlobalObjectFromContext(hNewContext); |
| 149 FXJSE_UpdateObjectBinding(hGlobalObject, lpGlobalObject); | 146 FXJSE_UpdateObjectBinding(hGlobalObject, lpGlobalObject); |
| 150 pContext->m_hContext.Reset(pIsolate, hNewContext); | 147 pContext->m_hContext.Reset(pIsolate, hNewContext); |
| 151 return pContext; | 148 return pContext; |
| 152 } | 149 } |
| 153 | 150 |
| 154 CFXJSE_Context::~CFXJSE_Context() { | 151 CFXJSE_Context::~CFXJSE_Context() { |
| 155 for (int32_t i = 0, count = m_rgClasses.GetSize(); i < count; i++) { | 152 for (int32_t i = 0, count = m_rgClasses.GetSize(); i < count; i++) |
| 156 CFXJSE_Class* pClass = m_rgClasses[i]; | 153 delete m_rgClasses[i]; |
| 157 if (pClass) { | |
| 158 delete pClass; | |
| 159 } | |
| 160 } | |
| 161 m_rgClasses.RemoveAll(); | 154 m_rgClasses.RemoveAll(); |
| 162 } | 155 } |
| 163 | 156 |
| 164 void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) { | 157 void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) { |
| 165 ASSERT(pValue); | 158 ASSERT(pValue); |
| 166 CFXJSE_ScopeUtil_IsolateHandleContext scope(this); | 159 CFXJSE_ScopeUtil_IsolateHandleContext scope(this); |
| 167 v8::Local<v8::Context> hContext = | 160 v8::Local<v8::Context> hContext = |
| 168 v8::Local<v8::Context>::New(m_pIsolate, m_hContext); | 161 v8::Local<v8::Context>::New(m_pIsolate, m_hContext); |
| 169 v8::Local<v8::Object> hGlobalObject = hContext->Global(); | 162 v8::Local<v8::Object> hGlobalObject = hContext->Global(); |
| 170 pValue->ForceSetValue(hGlobalObject); | 163 pValue->ForceSetValue(hGlobalObject); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 return TRUE; | 207 return TRUE; |
| 215 } | 208 } |
| 216 } | 209 } |
| 217 if (lpRetValue) { | 210 if (lpRetValue) { |
| 218 lpRetValue->m_hValue.Reset(m_pIsolate, | 211 lpRetValue->m_hValue.Reset(m_pIsolate, |
| 219 FXJSE_CreateReturnValue(m_pIsolate, trycatch)); | 212 FXJSE_CreateReturnValue(m_pIsolate, trycatch)); |
| 220 } | 213 } |
| 221 return FALSE; | 214 return FALSE; |
| 222 } | 215 } |
| 223 } | 216 } |
| OLD | NEW |