From a25fd09cd880ad82aea09a7ffffe3f8e5b121bbe Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 28 Sep 2015 09:06:03 -0700 Subject: XFA: Pass IFXJS_Runtime via V8 contexts, not V8 isolates This makes the XFA branch look more like the master. I suspect a patch was lost during the intial XFA checkin. R=jochen@chromium.org Review URL: https://codereview.chromium.org/1366053003 . --- fpdfsdk/include/javascript/JS_Define.h | 68 +++++++++++++++++++++++++--------- fpdfsdk/include/jsapi/fxjs_v8.h | 4 +- fpdfsdk/src/jsapi/fxjs_v8.cpp | 4 +- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h index 3b5798ef5c..adf69ec0e9 100644 --- a/fpdfsdk/include/javascript/JS_Define.h +++ b/fpdfsdk/include/javascript/JS_Define.h @@ -79,13 +79,18 @@ void JSPropGetter(const char* prop_name_string, v8::Local property, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); - IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); - CJS_PropValue value(isolate); - value.StartGetting(); + v8::Local context = isolate->GetCurrentContext(); + v8::Local v = context->GetEmbedderData(1); + if (v.IsEmpty()) + return; + v8::Local field = v8::Local::Cast(v); + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); + IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); C* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); CFX_WideString sError; + CJS_PropValue value(isolate); + value.StartGetting(); if (!(pObj->*M)(pRuntimeContext, value, sError)) { FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, sError)); @@ -102,13 +107,18 @@ void JSPropSetter(const char* prop_name_string, v8::Local value, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - 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(); + v8::Local context = isolate->GetCurrentContext(); + v8::Local v = context->GetEmbedderData(1); + if (v.IsEmpty()) + return; + v8::Local field = v8::Local::Cast(v); + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); + IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); C* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); CFX_WideString sError; + CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); + propValue.StartSetting(); if (!(pObj->*M)(pRuntimeContext, propValue, sError)) { FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, sError)); @@ -141,8 +151,13 @@ void JSMethod(const char* method_name_string, const char* class_name_string, const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); - IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); + v8::Local context = isolate->GetCurrentContext(); + v8::Local v = context->GetEmbedderData(1); + if (v.IsEmpty()) + return; + v8::Local field = v8::Local::Cast(v); + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); + IFXJS_Context* pRuntimeContext = pRuntime->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 +283,12 @@ void JSSpecialPropGet(const char* class_name, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); v8::Local context = isolate->GetCurrentContext(); - FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); - IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); + v8::Local v = context->GetEmbedderData(1); + if (v.IsEmpty()) + return; + v8::Local field = v8::Local::Cast(v); + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); + IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); @@ -293,8 +312,12 @@ void JSSpecialPropPut(const char* class_name, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); v8::Local context = isolate->GetCurrentContext(); - FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); - IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); + v8::Local v = context->GetEmbedderData(1); + if (v.IsEmpty()) + return; + v8::Local field = v8::Local::Cast(v); + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); + IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); @@ -315,8 +338,12 @@ void JSSpecialPropDel(const char* class_name, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); v8::Local context = isolate->GetCurrentContext(); - FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); - IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); + v8::Local v = context->GetEmbedderData(1); + if (v.IsEmpty()) + return; + v8::Local field = v8::Local::Cast(v); + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); + IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = reinterpret_cast(FXJS_GetPrivate(isolate, info.Holder())); Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); @@ -421,8 +448,13 @@ template & info) { v8::Isolate* isolate = info.GetIsolate(); - FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate); - IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext(); + v8::Local context = isolate->GetCurrentContext(); + v8::Local v = context->GetEmbedderData(1); + if (v.IsEmpty()) + return; + v8::Local field = v8::Local::Cast(v); + IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); + IFXJS_Context* pRuntimeContext = pRuntime->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 a1e3e59797..0b51332dbc 100644 --- a/fpdfsdk/include/jsapi/fxjs_v8.h +++ b/fpdfsdk/include/jsapi/fxjs_v8.h @@ -39,12 +39,10 @@ class FXJS_PerIsolateData { 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) {} + FXJS_PerIsolateData() : m_pFXJSERuntimeData(nullptr) {} }; extern const wchar_t kFXJSValueNameString[]; diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index 1c9bb87883..d7868f1586 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -269,8 +269,8 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate, v8::Context::Scope context_scope(v8Context); FXJS_PerIsolateData::SetUp(pIsolate); - FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); - pData->m_pFXJSRuntime = pFXRuntime; + v8::Local ptr = v8::External::New(pIsolate, pFXRuntime); + v8Context->SetEmbedderData(1, ptr); int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); for (int i = 0; i < maxID; ++i) { -- cgit v1.2.3