From cfff2f65aaec70247d020188bc68a0dc4fb34c3e Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 28 Sep 2015 09:44:56 -0700 Subject: Introduce kPerIsolateDataIndex and tidy JS_Define.h Follow-up from https://codereview.chromium.org/1366053003/ - use kPerIsolateDataIndex rather than magic constant 1. - make a helper function for common code in JS_Define.h - remove dead prototypes missed in earlier CL. - fxjs_v8 can't include generic fpdfsdk includes (layering). R=jochen@chromium.org Review URL: https://codereview.chromium.org/1367813003 . --- fpdfsdk/include/javascript/JS_Define.h | 49 ++++++++++------------------------ fpdfsdk/include/jsapi/fxjs_v8.h | 5 +--- 2 files changed, 15 insertions(+), 39 deletions(-) (limited to 'fpdfsdk/include') diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h index 04f5eceef5..0f93b0b38e 100644 --- a/fpdfsdk/include/javascript/JS_Define.h +++ b/fpdfsdk/include/javascript/JS_Define.h @@ -81,12 +81,9 @@ void JSPropGetter(const char* prop_name_string, v8::Local property, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - v8::Local context = isolate->GetCurrentContext(); - v8::Local v = context->GetEmbedderData(1); - if (v.IsEmpty()) + IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); + if (!pRuntime) return; - v8::Local field = v8::Local::Cast(v); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); IFXJS_Context* pContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); C* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); @@ -111,12 +108,9 @@ void JSPropSetter(const char* prop_name_string, v8::Local value, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - v8::Local context = isolate->GetCurrentContext(); - v8::Local v = context->GetEmbedderData(1); - if (v.IsEmpty()) + IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); + if (!pRuntime) return; - v8::Local field = v8::Local::Cast(v); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); IFXJS_Context* pContext = pRuntime->GetCurrentContext(); CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); C* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); @@ -155,12 +149,9 @@ void JSMethod(const char* method_name_string, const char* class_name_string, const v8::FunctionCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - v8::Local context = isolate->GetCurrentContext(); - v8::Local v = context->GetEmbedderData(1); - if (v.IsEmpty()) + IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); + if (!pRuntime) return; - v8::Local field = v8::Local::Cast(v); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); IFXJS_Context* cc = pRuntime->GetCurrentContext(); CJS_Parameters parameters; for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { @@ -286,12 +277,9 @@ void JSSpecialPropGet(const char* class_name, v8::Local property, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - v8::Local context = isolate->GetCurrentContext(); - v8::Local v = context->GetEmbedderData(1); - if (v.IsEmpty()) + IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); + if (!pRuntime) 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())); @@ -315,12 +303,9 @@ void JSSpecialPropPut(const char* class_name, v8::Local value, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - v8::Local context = isolate->GetCurrentContext(); - v8::Local v = context->GetEmbedderData(1); - if (v.IsEmpty()) + IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); + if (!pRuntime) 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())); @@ -341,12 +326,9 @@ void JSSpecialPropDel(const char* class_name, v8::Local property, const v8::PropertyCallbackInfo& info) { v8::Isolate* isolate = info.GetIsolate(); - v8::Local context = isolate->GetCurrentContext(); - v8::Local v = context->GetEmbedderData(1); - if (v.IsEmpty()) + IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); + if (!pRuntime) 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())); @@ -454,12 +436,9 @@ template & info) { v8::Isolate* isolate = info.GetIsolate(); - v8::Local context = isolate->GetCurrentContext(); - v8::Local v = context->GetEmbedderData(1); - if (v.IsEmpty()) + IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); + if (!pRuntime) return; - v8::Local field = v8::Local::Cast(v); - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); IFXJS_Context* cc = pRuntime->GetCurrentContext(); CJS_Parameters parameters; for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h index 15800e24e9..60fcea6341 100644 --- a/fpdfsdk/include/jsapi/fxjs_v8.h +++ b/fpdfsdk/include/jsapi/fxjs_v8.h @@ -69,10 +69,6 @@ void FXJS_Release(); // as part of FXJS_ReleaseRuntime(). void FXJS_PrepareIsolate(v8::Isolate* pIsolate); -// Call before making JS_PrepareIsolate call. -void JS_Initialize(unsigned int embedderDataSlot); -void JS_Release(); - // Call before making JS_Define* calls. Resources allocated here are cleared // as part of JS_ReleaseRuntime(). void JS_PrepareIsolate(v8::Isolate* pIsolate); @@ -117,6 +113,7 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate, v8::Global& v8PersistentContext); void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, v8::Global& v8PersistentContext); +IFXJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate); // Called after FXJS_InitializeRuntime call made. int FXJS_Execute(v8::Isolate* pIsolate, -- cgit v1.2.3