From ed7b2b50aa1744e0bc5a60bef12c61fa91d863b7 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 22 Sep 2015 08:36:17 -0700 Subject: XFA: contention between FXJSE and FXJS over isolate data slots This probably broke at 06b60021e when the FXJS slot moved to 0 from 1 unless explicitly overriden by the embedder, which conflicted with the FXJSE_ usage of slot 0. Also simplify some logic used to track global intialization of the underling JS. TEST=run_javascript_tests.py on XFA branch doesn't segv. R=jochen@chromium.org Review URL: https://codereview.chromium.org/1351173002 . --- xfa/src/fxjse/src/runtime.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'xfa') diff --git a/xfa/src/fxjse/src/runtime.cpp b/xfa/src/fxjse/src/runtime.cpp index a7ee67bc2a..4a77b4f165 100644 --- a/xfa/src/fxjse/src/runtime.cpp +++ b/xfa/src/fxjse/src/runtime.cpp @@ -4,6 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include "../../../../fpdfsdk/include/jsapi/fxjs_v8.h" // For per-isolate data. #include "../../foxitlib.h" #include "fxv8.h" #include "runtime.h" @@ -38,11 +39,9 @@ void FXJSE_Initialize() { static void FXJSE_Runtime_DisposeCallback(v8::Isolate* pIsolate) { { v8::Locker locker(pIsolate); - CFXJSE_RuntimeData* pRuntimeData = - reinterpret_cast(pIsolate->GetData(0)); - if (pRuntimeData) { - pIsolate->SetData(0, NULL); - delete pRuntimeData; + if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) { + delete pData->m_pFXJSERuntimeData; + pData->m_pFXJSERuntimeData = nullptr; } } pIsolate->Dispose(); @@ -73,7 +72,6 @@ void FXJSE_Runtime_Release(FXJSE_HRUNTIME hRuntime) { } CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) { CFXJSE_RuntimeData* pRuntimeData = new CFXJSE_RuntimeData(pIsolate); - ASSERT(pRuntimeData); CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate); v8::Local hFuncTemplate = v8::FunctionTemplate::New(pIsolate); @@ -85,15 +83,10 @@ CFXJSE_RuntimeData* CFXJSE_RuntimeData::Create(v8::Isolate* pIsolate) { return pRuntimeData; } CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) { - ASSERT(pIsolate); - CFXJSE_RuntimeData* pRuntimeData = - static_cast(pIsolate->GetData(0)); - if (!pRuntimeData) { - pRuntimeData = CFXJSE_RuntimeData::Create(pIsolate); - ASSERT(pRuntimeData); - pIsolate->SetData(0, pRuntimeData); - } - return pRuntimeData; + FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); + if (!pData->m_pFXJSERuntimeData) + pData->m_pFXJSERuntimeData = CFXJSE_RuntimeData::Create(pIsolate); + return pData->m_pFXJSERuntimeData; } CFXJSE_RuntimeList* CFXJSE_RuntimeData::g_RuntimeList = NULL; void CFXJSE_RuntimeList::AppendRuntime(v8::Isolate* pIsolate) { -- cgit v1.2.3