From 2311b784fe85a0a1d78f78f0f05586059a63fa65 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 23 Feb 2015 10:22:51 -0800 Subject: Merge to XFA: Replace second set of #defines with templates in JS_Define.h Original Review URL: https://codereview.chromium.org/945623002 TBR=brucedawson@chromium.org Review URL: https://codereview.chromium.org/948083002 --- fpdfsdk/include/javascript/JS_Define.h | 215 ++++++++++++++------------------- 1 file changed, 94 insertions(+), 121 deletions(-) (limited to 'fpdfsdk/include/javascript') diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h index 4c1cef8b90..72a481dfa4 100644 --- a/fpdfsdk/include/javascript/JS_Define.h +++ b/fpdfsdk/include/javascript/JS_Define.h @@ -42,9 +42,8 @@ typedef CFX_WideString JS_ErrorString; #define JS_TRUE (unsigned)1 #define JS_FALSE (unsigned)0 - -#define CJS_PointsArray CFX_ArrayTemplate -#define CJS_IntArray CFX_ArrayTemplate +typedef CFX_ArrayTemplate CJS_PointsArray; +typedef CFX_ArrayTemplate CJS_IntArray; /* ====================================== PUBLIC DEFINE SPEC ============================================== */ #define JS_WIDESTRING(widestring) L###widestring @@ -269,6 +268,84 @@ void js_class_name::GetConsts(JSConstSpec*& pConsts, int& nSize)\ /* ===================================== SPECIAL JS CLASS =============================================== */ +template +void JSSpecialPropQuery(const char *, v8::Local property,const v8::PropertyCallbackInfo& info) { + v8::Isolate* isolate = info.GetIsolate(); + v8::String::Utf8Value utf8_value(property); + CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); + CJS_Object* pJSObj = reinterpret_cast(JS_GetPrivate(isolate, info.Holder())); + Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); + FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); + info.GetReturnValue().Set(bRet ? 4 : 0); +} + +template +void JSSpecialPropGet(const char* class_name, + v8::Local property, + 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(); + CJS_Object* pJSObj = reinterpret_cast(JS_GetPrivate(isolate, info.Holder())); + Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); + v8::String::Utf8Value utf8_value(property); + CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); + JS_ErrorString sError; + CJS_PropValue value(isolate); + value.StartGetting(); + if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { + CFX_ByteString cbName; + cbName.Format("%s.%s", class_name, L"GetProperty"); + JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError); + return; + } + info.GetReturnValue().Set((v8::Handle)value); +} + +template +void JSSpecialPropPut(const char* class_name, + v8::Local property, + v8::Local value, + 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(); + CJS_Object* pJSObj = reinterpret_cast(JS_GetPrivate(isolate, info.Holder())); + Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); + v8::String::Utf8Value utf8_value(property); + CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); + JS_ErrorString sError; + CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown)); + PropValue.StartSetting(); + if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { + CFX_ByteString cbName; + cbName.Format("%s.%s", class_name, "PutProperty"); + JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError); + } +} + +template +void JSSpecialPropDel(const char* class_name, + v8::Local property, + 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(); + CJS_Object* pJSObj = reinterpret_cast(JS_GetPrivate(isolate, info.Holder())); + Alt* pObj = reinterpret_cast(pJSObj->GetEmbedObject()); + v8::String::Utf8Value utf8_value(property); + CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); + JS_ErrorString sError; + if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { + CFX_ByteString cbName; + cbName.Format("%s.%s", class_name, "DelProperty"); + // Probably a missing call to JS_Error(). + } +} + #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj, JSFXObject global);\ static JSBool JSDestructor(JSFXObject obj);\ @@ -280,129 +357,25 @@ void js_class_name::GetConsts(JSConstSpec*& pConsts, int& nSize)\ static JSMethodSpec JS_Class_Methods[];\ static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ static const wchar_t* m_pClassName;\ - static void queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS);\ - static void getprop_##js_class_name##_static(JS_NAMED_PROPGET_ARGS);\ - static void putprop_##js_class_name##_static(JS_NAMED_PROPPUT_ARGS);\ - static void delprop_##js_class_name##_static(JS_PROPDEL_ARGS) + static void queryprop_##js_class_name##_static(v8::Local property,const v8::PropertyCallbackInfo& info);\ + static void getprop_##js_class_name##_static(v8::Local property, const v8::PropertyCallbackInfo& info);\ + static void putprop_##js_class_name##_static(v8::Local property,v8::Local value,const v8::PropertyCallbackInfo& info);\ + static void delprop_##js_class_name##_static(v8::Local property,const v8::PropertyCallbackInfo& info) #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ const wchar_t * js_class_name::m_pClassName = JS_WIDESTRING(class_name);\ - void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS)\ -{\ - v8::Isolate* isolate = info.GetIsolate();\ - v8::String::Utf8Value utf8_value(property);\ - CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());\ - CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ - ASSERT(pJSObj != NULL);\ - class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ - ASSERT(pObj != NULL);\ - FX_BOOL bRet = FALSE;\ - bRet = pObj->QueryProperty(propname.c_str());\ - if (bRet)\ - {\ - info.GetReturnValue().Set(0x004);\ - return ;\ - }\ - else\ - {\ - info.GetReturnValue().Set(0);\ - return ;\ - }\ - return ;\ +void js_class_name::queryprop_##js_class_name##_static(v8::Local property,const v8::PropertyCallbackInfo& info) { \ + JSSpecialPropQuery(#class_name, property, info); \ }\ - void js_class_name::getprop_##js_class_name##_static(JS_NAMED_PROPGET_ARGS)\ -{\ - v8::Isolate* isolate = info.GetIsolate();\ - v8::Local context = isolate->GetCurrentContext();\ - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ - if (pRuntime == NULL) return;\ - IFXJS_Context* cc = pRuntime->GetCurrentContext();\ - v8::String::Utf8Value utf8_value(property);\ - CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());\ - CJS_PropValue value(isolate);\ - value.StartGetting();\ - CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ - ASSERT(pJSObj != NULL);\ - class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ - ASSERT(pObj != NULL);\ - JS_ErrorString sError;\ - FX_BOOL bRet = FALSE;\ - bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\ - if (bRet)\ - {\ - info.GetReturnValue().Set((v8::Handle)value);\ - return ;\ - }\ - else\ - {\ - CFX_ByteString cbName;\ - cbName.Format("%s.%s", #class_name, L"GetProperty");\ - JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ - return ;\ - }\ - JS_Error(NULL,L"GetProperty", L"Embeded object not found!");\ - return ;\ -}\ - void js_class_name::putprop_##js_class_name##_static(JS_NAMED_PROPPUT_ARGS)\ -{\ - v8::Isolate* isolate = info.GetIsolate();\ - v8::Local context = isolate->GetCurrentContext();\ - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ - if (pRuntime == NULL) return;\ - IFXJS_Context* cc = pRuntime->GetCurrentContext();\ - v8::String::Utf8Value utf8_value(property);\ - CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());\ - CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ - PropValue.StartSetting();\ - CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ - if(!pJSObj) return;\ - class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ - ASSERT(pObj != NULL);\ - JS_ErrorString sError;\ - FX_BOOL bRet = FALSE;\ - bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\ - if (bRet)\ - {\ - return ;\ - }\ - else\ - {\ - CFX_ByteString cbName;\ - cbName.Format("%s.%s", #class_name, "PutProperty");\ - JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ - return ;\ - }\ - JS_Error(NULL,L"PutProperty", L"Embeded object not found!");\ - return ;\ -}\ - void js_class_name::delprop_##js_class_name##_static(JS_PROPDEL_ARGS)\ -{\ - v8::Isolate* isolate = info.GetIsolate();\ - v8::Local context = isolate->GetCurrentContext();\ - IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ - if (pRuntime == NULL) return;\ - IFXJS_Context* cc = pRuntime->GetCurrentContext();\ - v8::String::Utf8Value utf8_value(property);\ - CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());\ - CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ - ASSERT(pJSObj != NULL);\ - class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ - ASSERT(pObj != NULL);\ - JS_ErrorString sError;\ - FX_BOOL bRet = FALSE;\ - bRet = pObj->DelProperty(cc, propname.c_str(), sError);\ - if (bRet)\ - {\ - return ;\ - }\ - else\ - {\ - CFX_ByteString cbName;\ - cbName.Format("%s.%s", #class_name, "DelProperty");\ - return ;\ - }\ - return ;\ +void js_class_name::getprop_##js_class_name##_static(v8::Local property, const v8::PropertyCallbackInfo& info) { \ + JSSpecialPropGet(#class_name, property, info); \ +} \ +void js_class_name::putprop_##js_class_name##_static(v8::Local property,v8::Local value,const v8::PropertyCallbackInfo& info) {\ + JSSpecialPropPut(#class_name, property, value, info); \ }\ +void js_class_name::delprop_##js_class_name##_static(v8::Local property,const v8::PropertyCallbackInfo& info) { \ + JSSpecialPropDel(#class_name, property, info); \ +} \ JSBool js_class_name::JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject global)\ {\ CJS_Object* pObj = FX_NEW js_class_name(obj);\ -- cgit v1.2.3