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 . --- fpdfsdk/include/fpdfxfa/fpdfxfa_app.h | 11 +++++++---- fpdfsdk/include/javascript/JS_Define.h | 28 ++++++++++++++-------------- fpdfsdk/include/jsapi/fxjs_v8.h | 29 ++++++++++++++++++++++++----- 3 files changed, 45 insertions(+), 23 deletions(-) (limited to 'fpdfsdk/include') diff --git a/fpdfsdk/include/fpdfxfa/fpdfxfa_app.h b/fpdfsdk/include/fpdfxfa/fpdfxfa_app.h index 49825c3f7f..f5052e3adf 100644 --- a/fpdfsdk/include/fpdfxfa/fpdfxfa_app.h +++ b/fpdfsdk/include/fpdfxfa/fpdfxfa_app.h @@ -23,9 +23,12 @@ class CPDFXFA_App : public IXFA_AppProvider { FX_BOOL AddFormFillEnv(CPDFDoc_Environment* pEnv); FX_BOOL RemoveFormFillEnv(CPDFDoc_Environment* pEnv); - FXJSE_HRUNTIME GetJSERuntime() { return m_hJSERuntime; } - void ReleaseRuntime(); - FX_BOOL InitRuntime(FX_BOOL bReset = FALSE); + FX_BOOL IsJavaScriptInitialized() const { return m_bJavaScriptInitialized; } + void SetJavaScriptInitialized(FX_BOOL bInitialized) { + m_bJavaScriptInitialized = bInitialized; + } + + FXJSE_HRUNTIME GetJSERuntime() const { return m_hJSERuntime; } // IFXA_AppProvider: void GetAppType(CFX_WideString& wsAppType) override; @@ -81,7 +84,7 @@ class CPDFXFA_App : public IXFA_AppProvider { protected: static CPDFXFA_App* g_pApp; - FX_BOOL m_bInitRuntime; + FX_BOOL m_bJavaScriptInitialized; IXFA_App* m_pXFAApp; IXFA_FontMgr* m_pFontMgr; FXJSE_HRUNTIME m_hJSERuntime; diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h index 1addca5cec..3b5798ef5c 100644 --- a/fpdfsdk/include/javascript/JS_Define.h +++ b/fpdfsdk/include/javascript/JS_Define.h @@ -79,8 +79,8 @@ void JSPropGetter(const char* prop_name_string, v8::Local property, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); - IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); + FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); + IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); CJS_PropValue value(isolate); value.StartGetting(); CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); @@ -102,8 +102,8 @@ void JSPropSetter(const char* prop_name_string, v8::Local value, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); - IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); + FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); + IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); propValue.StartSetting(); CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); @@ -141,8 +141,8 @@ void JSMethod(const char* method_name_string, const char* class_name_string, const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); - IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); + FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); + IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); CJS_Parameters parameters; for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); @@ -268,8 +268,8 @@ void JSSpecialPropGet(const char* class_name, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); v8::Local context = isolate->GetCurrentContext(); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); - IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); + FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); + IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); CJS_Object* pJSObj = reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); @@ -293,8 +293,8 @@ void JSSpecialPropPut(const char* class_name, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); v8::Local context = isolate->GetCurrentContext(); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); - IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); + FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); + IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); CJS_Object* pJSObj = reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); @@ -315,8 +315,8 @@ void JSSpecialPropDel(const char* class_name, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); v8::Local context = isolate->GetCurrentContext(); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); - IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); + FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); + IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); CJS_Object* pJSObj = reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); @@ -421,8 +421,8 @@ template & info) { v8::Isolate* isolate = info.GetIsolate(); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); - IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); + FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); + IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); CJS_Parameters parameters; for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h index a1541593a1..a1e3e59797 100644 --- a/fpdfsdk/include/jsapi/fxjs_v8.h +++ b/fpdfsdk/include/jsapi/fxjs_v8.h @@ -11,7 +11,16 @@ #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ #include -#include "../../../core/include/fxcrt/fx_string.h" // For CFX_WideString +#include "../../../core/include/fxcrt/fx_basic.h" + +// FXJS_V8 places no interpretation on these two classes; it merely +// passes them on to the caller-provided FXJS_CONSTRUCTORs. +class IFXJS_Context; +class IFXJS_Runtime; + +// FXJS_V8 places no interpreation on this calass; it merely passes it +// along to XFA. +class CFXJSE_RuntimeData; enum FXJSOBJTYPE { FXJS_DYNAMIC = 0, @@ -24,6 +33,20 @@ struct FXJSErr { unsigned linnum; }; +class FXJS_PerIsolateData { + public: + static void SetUp(v8::Isolate* pIsolate); + static FXJS_PerIsolateData* Get(v8::Isolate* pIsolate); + + CFX_PtrArray m_ObjectDefnArray; + IFXJS_Runtime* m_pFXJSRuntime; + CFXJSE_RuntimeData* m_pFXJSERuntimeData; + + protected: + FXJS_PerIsolateData() + : m_pFXJSRuntime(nullptr), m_pFXJSERuntimeData(nullptr) {} +}; + extern const wchar_t kFXJSValueNameString[]; extern const wchar_t kFXJSValueNameNumber[]; extern const wchar_t kFXJSValueNameBoolean[]; @@ -33,10 +56,6 @@ extern const wchar_t kFXJSValueNameFxobj[]; extern const wchar_t kFXJSValueNameNull[]; extern const wchar_t kFXJSValueNameUndefined[]; -// FXJS_V8 places no interpretation on these two classes; it merely -// passes them on to the caller-provided FXJS_CONSTRUCTORs. -class IFXJS_Context; -class IFXJS_Runtime; class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { void* Allocate(size_t length) override; -- cgit v1.2.3