| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 7 #ifndef FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
| 8 #define FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 8 #define FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
| 9 | 9 |
| 10 #include "../../include/jsapi/fxjs_v8.h" | 10 #include "../../include/jsapi/fxjs_v8.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const wchar_t* pName; | 23 const wchar_t* pName; |
| 24 v8::AccessorGetterCallback pPropGet; | 24 v8::AccessorGetterCallback pPropGet; |
| 25 v8::AccessorSetterCallback pPropPut; | 25 v8::AccessorSetterCallback pPropPut; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 struct JSMethodSpec { | 28 struct JSMethodSpec { |
| 29 const wchar_t* pName; | 29 const wchar_t* pName; |
| 30 v8::FunctionCallback pMethodCall; | 30 v8::FunctionCallback pMethodCall; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 /* ====================================== PUBLIC DEFINE SPEC | |
| 34 * ============================================== */ | |
| 35 #define JS_WIDESTRING(widestring) L## #widestring | 33 #define JS_WIDESTRING(widestring) L## #widestring |
| 36 | |
| 37 #define BEGIN_JS_STATIC_CONST(js_class_name) \ | 34 #define BEGIN_JS_STATIC_CONST(js_class_name) \ |
| 38 JSConstSpec js_class_name::JS_Class_Consts[] = { | 35 JSConstSpec js_class_name::JS_Class_Consts[] = { |
| 39 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) \ | 36 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) \ |
| 40 { const_name, pValue, L"", 0 } \ | 37 { const_name, pValue, L"", 0 } \ |
| 41 , | 38 , |
| 39 |
| 42 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) \ | 40 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) \ |
| 43 { const_name, 0, pValue, 1 } \ | 41 { const_name, 0, pValue, 1 } \ |
| 44 , | 42 , |
| 43 |
| 45 #define END_JS_STATIC_CONST() \ | 44 #define END_JS_STATIC_CONST() \ |
| 46 { 0, 0, 0, 0 } \ | 45 { 0, 0, 0, 0 } \ |
| 47 } \ | 46 } \ |
| 48 ; | 47 ; |
| 49 | 48 |
| 50 #define BEGIN_JS_STATIC_PROP(js_class_name) \ | 49 #define BEGIN_JS_STATIC_PROP(js_class_name) \ |
| 51 JSPropertySpec js_class_name::JS_Class_Properties[] = { | 50 JSPropertySpec js_class_name::JS_Class_Properties[] = { |
| 52 #define JS_STATIC_PROP_ENTRY(prop_name) \ | 51 #define JS_STATIC_PROP_ENTRY(prop_name) \ |
| 53 { \ | 52 { \ |
| 54 JS_WIDESTRING(prop_name), get_##prop_name##_static, \ | 53 JS_WIDESTRING(prop_name), get_##prop_name##_static, \ |
| 55 set_##prop_name##_static \ | 54 set_##prop_name##_static \ |
| 56 } \ | 55 } \ |
| 57 , | 56 , |
| 57 |
| 58 #define END_JS_STATIC_PROP() \ | 58 #define END_JS_STATIC_PROP() \ |
| 59 { 0, 0, 0 } \ | 59 { 0, 0, 0 } \ |
| 60 } \ | 60 } \ |
| 61 ; | 61 ; |
| 62 | 62 |
| 63 #define BEGIN_JS_STATIC_METHOD(js_class_name) \ | 63 #define BEGIN_JS_STATIC_METHOD(js_class_name) \ |
| 64 JSMethodSpec js_class_name::JS_Class_Methods[] = { | 64 JSMethodSpec js_class_name::JS_Class_Methods[] = { |
| 65 #define JS_STATIC_METHOD_ENTRY(method_name) \ | 65 #define JS_STATIC_METHOD_ENTRY(method_name) \ |
| 66 { JS_WIDESTRING(method_name), method_name##_static } \ | 66 { JS_WIDESTRING(method_name), method_name##_static } \ |
| 67 , | 67 , |
| 68 |
| 68 #define END_JS_STATIC_METHOD() \ | 69 #define END_JS_STATIC_METHOD() \ |
| 69 { 0, 0 } \ | 70 { 0, 0 } \ |
| 70 } \ | 71 } \ |
| 71 ; | 72 ; |
| 72 | 73 |
| 73 /* ======================================== PROP CALLBACK | |
| 74 * ============================================ */ | |
| 75 | |
| 76 template <class C, | 74 template <class C, |
| 77 FX_BOOL (C::*M)(IFXJS_Context* cc, | 75 FX_BOOL (C::*M)(IFXJS_Context* cc, |
| 78 CJS_PropValue& vp, | 76 CJS_PropValue& vp, |
| 79 CFX_WideString& sError)> | 77 CFX_WideString& sError)> |
| 80 void JSPropGetter(const char* prop_name_string, | 78 void JSPropGetter(const char* prop_name_string, |
| 81 const char* class_name_string, | 79 const char* class_name_string, |
| 82 v8::Local<v8::String> property, | 80 v8::Local<v8::String> property, |
| 83 const v8::PropertyCallbackInfo<v8::Value>& info) { | 81 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 84 v8::Isolate* isolate = info.GetIsolate(); | 82 v8::Isolate* isolate = info.GetIsolate(); |
| 85 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 83 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ | 129 JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ |
| 132 property, info); \ | 130 property, info); \ |
| 133 } \ | 131 } \ |
| 134 static void set_##prop_name##_static( \ | 132 static void set_##prop_name##_static( \ |
| 135 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | 133 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ |
| 136 const v8::PropertyCallbackInfo<void>& info) { \ | 134 const v8::PropertyCallbackInfo<void>& info) { \ |
| 137 JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ | 135 JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ |
| 138 property, value, info); \ | 136 property, value, info); \ |
| 139 } | 137 } |
| 140 | 138 |
| 141 /* ========================================= METHOD CALLBACK | |
| 142 * =========================================== */ | |
| 143 | |
| 144 template <class C, | 139 template <class C, |
| 145 FX_BOOL (C::*M)(IFXJS_Context* cc, | 140 FX_BOOL (C::*M)(IFXJS_Context* cc, |
| 146 const CJS_Parameters& params, | 141 const CJS_Parameters& params, |
| 147 CJS_Value& vRet, | 142 CJS_Value& vRet, |
| 148 CFX_WideString& sError)> | 143 CFX_WideString& sError)> |
| 149 void JSMethod(const char* method_name_string, | 144 void JSMethod(const char* method_name_string, |
| 150 const char* class_name_string, | 145 const char* class_name_string, |
| 151 const v8::FunctionCallbackInfo<v8::Value>& info) { | 146 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 152 v8::Isolate* isolate = info.GetIsolate(); | 147 v8::Isolate* isolate = info.GetIsolate(); |
| 153 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 148 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 177 info); \ | 172 info); \ |
| 178 } | 173 } |
| 179 | 174 |
| 180 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ | 175 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ |
| 181 static void method_name##_static( \ | 176 static void method_name##_static( \ |
| 182 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 177 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 183 JSMethod<class_alternate, &class_alternate::method_name>( \ | 178 JSMethod<class_alternate, &class_alternate::method_name>( \ |
| 184 #method_name, #class_name, info); \ | 179 #method_name, #class_name, info); \ |
| 185 } | 180 } |
| 186 | 181 |
| 187 /* ===================================== JS CLASS | 182 // All JS classes have a name, an object defintion ID, and the ability to |
| 188 * =============================================== */ | 183 // register themselves with FXJS_V8. We never make a BASE class on its own |
| 184 // because it can't really do anything. |
| 185 #define DECLARE_JS_CLASS_BASE_PART() \ |
| 186 static const wchar_t* g_pClassName; \ |
| 187 static int g_nObjDefnID; \ |
| 188 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); |
| 189 | 189 |
| 190 #define DECLARE_JS_CLASS(js_class_name) \ | 190 #define IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ |
| 191 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ | 191 const wchar_t* js_class_name::g_pClassName = JS_WIDESTRING(class_name); \ |
| 192 v8::Local<v8::Object> global); \ | 192 int js_class_name::g_nObjDefnID = -1; |
| 193 static void JSDestructor(v8::Local<v8::Object> obj); \ | |
| 194 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | |
| 195 static JSConstSpec JS_Class_Consts[]; \ | |
| 196 static JSPropertySpec JS_Class_Properties[]; \ | |
| 197 static JSMethodSpec JS_Class_Methods[]; \ | |
| 198 static const wchar_t* m_pClassName | |
| 199 | 193 |
| 200 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ | 194 // CONST classes provide constants, but not constructors, methods, or props. |
| 201 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 195 #define DECLARE_JS_CLASS_CONST() \ |
| 202 void js_class_name::JSConstructor(IFXJS_Context* cc, \ | 196 DECLARE_JS_CLASS_BASE_PART() \ |
| 203 v8::Local<v8::Object> obj, \ | 197 DECLARE_JS_CLASS_CONST_PART() |
| 204 v8::Local<v8::Object> global) { \ | 198 |
| 205 CJS_Object* pObj = new js_class_name(obj); \ | 199 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ |
| 206 pObj->SetEmbedObject(new class_alternate(pObj)); \ | 200 IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ |
| 207 FXJS_SetPrivate(NULL, obj, (void*)pObj); \ | 201 IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ |
| 208 pObj->InitInstance(cc); \ | 202 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 209 } \ | 203 FXJSOBJTYPE eObjType) { \ |
| 210 \ | 204 g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ |
| 211 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ | 205 eObjType, nullptr, nullptr); \ |
| 212 js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj); \ | 206 DefineConsts(pIsolate); \ |
| 213 pObj->ExitInstance(); \ | |
| 214 delete pObj; \ | |
| 215 } \ | |
| 216 \ | |
| 217 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | |
| 218 FXJSOBJTYPE eObjType) { \ | |
| 219 int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | |
| 220 eObjType, JSConstructor, JSDestructor); \ | |
| 221 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ | |
| 222 FXJS_DefineObjProperty( \ | |
| 223 pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \ | |
| 224 JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \ | |
| 225 } \ | |
| 226 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ | |
| 227 FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ | |
| 228 JS_Class_Methods[i].pMethodCall); \ | |
| 229 } \ | |
| 230 } | 207 } |
| 231 | 208 |
| 209 #define DECLARE_JS_CLASS_CONST_PART() \ |
| 210 static JSConstSpec JS_Class_Consts[]; \ |
| 211 static void DefineConsts(v8::Isolate* pIsolate); |
| 212 |
| 213 #define IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ |
| 214 void js_class_name::DefineConsts(v8::Isolate* pIsolate) { \ |
| 215 for (size_t i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \ |
| 216 FXJS_DefineObjConst( \ |
| 217 pIsolate, g_nObjDefnID, JS_Class_Consts[i].pName, \ |
| 218 JS_Class_Consts[i].t == 0 \ |
| 219 ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number) \ |
| 220 : FXJS_NewString(pIsolate, JS_Class_Consts[i].string)); \ |
| 221 } \ |
| 222 } |
| 223 |
| 224 // Convenience macros for declaring classes without an alternate. |
| 225 #define DECLARE_JS_CLASS() DECLARE_JS_CLASS_RICH() |
| 232 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ | 226 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ |
| 233 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) | 227 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) |
| 234 | 228 |
| 235 /* ======================================== CONST CLASS | 229 // Rich JS classes provide constants, methods, properties, and the ability |
| 236 * ============================================ */ | 230 // to construct native object state. |
| 231 #define DECLARE_JS_CLASS_RICH() \ |
| 232 DECLARE_JS_CLASS_BASE_PART() \ |
| 233 DECLARE_JS_CLASS_CONST_PART() \ |
| 234 DECLARE_JS_CLASS_RICH_PART() |
| 237 | 235 |
| 238 #define DECLARE_JS_CLASS_CONST() \ | 236 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ |
| 239 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | 237 IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ |
| 240 static JSConstSpec JS_Class_Consts[]; \ | 238 IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ |
| 241 static const wchar_t* m_pClassName | 239 IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name) \ |
| 242 | 240 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 243 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ | 241 FXJSOBJTYPE eObjType) { \ |
| 244 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | 242 g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ |
| 245 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | 243 eObjType, JSConstructor, JSDestructor); \ |
| 246 FXJSOBJTYPE eObjType) { \ | 244 DefineConsts(pIsolate); \ |
| 247 int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | 245 DefineProps(pIsolate); \ |
| 248 eObjType, NULL, NULL); \ | 246 DefineMethods(pIsolate); \ |
| 249 for (int i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \ | |
| 250 FXJS_DefineObjConst( \ | |
| 251 pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ | |
| 252 JS_Class_Consts[i].t == 0 \ | |
| 253 ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number) \ | |
| 254 : FXJS_NewString(pIsolate, JS_Class_Consts[i].string)); \ | |
| 255 } \ | |
| 256 } | 247 } |
| 257 | 248 |
| 258 /* ===================================== SPECIAL JS CLASS | 249 #define DECLARE_JS_CLASS_RICH_PART() \ |
| 259 * =============================================== */ | 250 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ |
| 251 v8::Local<v8::Object> global); \ |
| 252 static void JSDestructor(v8::Local<v8::Object> obj); \ |
| 253 static void DefineProps(v8::Isolate* pIsoalte); \ |
| 254 static void DefineMethods(v8::Isolate* pIsoalte); \ |
| 255 static JSPropertySpec JS_Class_Properties[]; \ |
| 256 static JSMethodSpec JS_Class_Methods[]; |
| 257 |
| 258 #define IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, \ |
| 259 class_name) \ |
| 260 void js_class_name::JSConstructor(IFXJS_Context* cc, \ |
| 261 v8::Local<v8::Object> obj, \ |
| 262 v8::Local<v8::Object> global) { \ |
| 263 CJS_Object* pObj = new js_class_name(obj); \ |
| 264 pObj->SetEmbedObject(new class_alternate(pObj)); \ |
| 265 FXJS_SetPrivate(nullptr, obj, (void*)pObj); \ |
| 266 pObj->InitInstance(cc); \ |
| 267 } \ |
| 268 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ |
| 269 js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(nullptr, obj); \ |
| 270 pObj->ExitInstance(); \ |
| 271 delete pObj; \ |
| 272 } \ |
| 273 void js_class_name::DefineProps(v8::Isolate* pIsolate) { \ |
| 274 for (size_t i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ |
| 275 FXJS_DefineObjProperty( \ |
| 276 pIsolate, g_nObjDefnID, JS_Class_Properties[i].pName, \ |
| 277 JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \ |
| 278 } \ |
| 279 } \ |
| 280 void js_class_name::DefineMethods(v8::Isolate* pIsolate) { \ |
| 281 for (size_t i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ |
| 282 FXJS_DefineObjMethod(pIsolate, g_nObjDefnID, JS_Class_Methods[i].pName, \ |
| 283 JS_Class_Methods[i].pMethodCall); \ |
| 284 } \ |
| 285 } |
| 286 |
| 287 // Special JS classes implement methods, props, and queries, but not consts. |
| 288 #define DECLARE_SPECIAL_JS_CLASS() \ |
| 289 DECLARE_JS_CLASS_BASE_PART() \ |
| 290 DECLARE_JS_CLASS_CONST_PART() \ |
| 291 DECLARE_JS_CLASS_RICH_PART() \ |
| 292 DECLARE_SPECIAL_JS_CLASS_PART() |
| 293 |
| 294 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ |
| 295 IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name) \ |
| 296 IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ |
| 297 IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name) \ |
| 298 IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate, class_name) \ |
| 299 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 300 FXJSOBJTYPE eObjType) { \ |
| 301 g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ |
| 302 eObjType, JSConstructor, JSDestructor); \ |
| 303 DefineConsts(pIsolate); \ |
| 304 DefineProps(pIsolate); \ |
| 305 DefineMethods(pIsolate); \ |
| 306 DefineAllProperties(pIsolate); \ |
| 307 } |
| 308 |
| 309 #define DECLARE_SPECIAL_JS_CLASS_PART() \ |
| 310 static void queryprop_static( \ |
| 311 v8::Local<v8::String> property, \ |
| 312 const v8::PropertyCallbackInfo<v8::Integer>& info); \ |
| 313 static void getprop_static(v8::Local<v8::String> property, \ |
| 314 const v8::PropertyCallbackInfo<v8::Value>& info); \ |
| 315 static void putprop_static(v8::Local<v8::String> property, \ |
| 316 v8::Local<v8::Value> value, \ |
| 317 const v8::PropertyCallbackInfo<v8::Value>& info); \ |
| 318 static void delprop_static( \ |
| 319 v8::Local<v8::String> property, \ |
| 320 const v8::PropertyCallbackInfo<v8::Boolean>& info); \ |
| 321 static void DefineAllProperties(v8::Isolate* pIsolate); |
| 322 |
| 323 #define IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate, \ |
| 324 class_name) \ |
| 325 void js_class_name::queryprop_static( \ |
| 326 v8::Local<v8::String> property, \ |
| 327 const v8::PropertyCallbackInfo<v8::Integer>& info) { \ |
| 328 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ |
| 329 } \ |
| 330 void js_class_name::getprop_static( \ |
| 331 v8::Local<v8::String> property, \ |
| 332 const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
| 333 JSSpecialPropGet<class_alternate>(#class_name, property, info); \ |
| 334 } \ |
| 335 void js_class_name::putprop_static( \ |
| 336 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ |
| 337 const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
| 338 JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \ |
| 339 } \ |
| 340 void js_class_name::delprop_static( \ |
| 341 v8::Local<v8::String> property, \ |
| 342 const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ |
| 343 JSSpecialPropDel<class_alternate>(#class_name, property, info); \ |
| 344 } \ |
| 345 void js_class_name::DefineAllProperties(v8::Isolate* pIsolate) { \ |
| 346 FXJS_DefineObjAllProperties( \ |
| 347 pIsolate, g_nObjDefnID, js_class_name::queryprop_static, \ |
| 348 js_class_name::getprop_static, js_class_name::putprop_static, \ |
| 349 js_class_name::delprop_static); \ |
| 350 } |
| 260 | 351 |
| 261 template <class Alt> | 352 template <class Alt> |
| 262 void JSSpecialPropQuery(const char*, | 353 void JSSpecialPropQuery(const char*, |
| 263 v8::Local<v8::String> property, | 354 v8::Local<v8::String> property, |
| 264 const v8::PropertyCallbackInfo<v8::Integer>& info) { | 355 const v8::PropertyCallbackInfo<v8::Integer>& info) { |
| 265 v8::Isolate* isolate = info.GetIsolate(); | 356 v8::Isolate* isolate = info.GetIsolate(); |
| 266 v8::String::Utf8Value utf8_value(property); | 357 v8::String::Utf8Value utf8_value(property); |
| 267 CFX_WideString propname = | 358 CFX_WideString propname = |
| 268 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 359 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
| 269 CJS_Object* pJSObj = | 360 CJS_Object* pJSObj = |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 CFX_WideString propname = | 429 CFX_WideString propname = |
| 339 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 430 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
| 340 CFX_WideString sError; | 431 CFX_WideString sError; |
| 341 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { | 432 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { |
| 342 CFX_ByteString cbName; | 433 CFX_ByteString cbName; |
| 343 cbName.Format("%s.%s", class_name, "DelProperty"); | 434 cbName.Format("%s.%s", class_name, "DelProperty"); |
| 344 // Probably a missing call to JSFX_Error(). | 435 // Probably a missing call to JSFX_Error(). |
| 345 } | 436 } |
| 346 } | 437 } |
| 347 | 438 |
| 348 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ | |
| 349 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ | |
| 350 v8::Local<v8::Object> global); \ | |
| 351 static void JSDestructor(v8::Local<v8::Object> obj); \ | |
| 352 static JSConstSpec JS_Class_Consts[]; \ | |
| 353 static JSPropertySpec JS_Class_Properties[]; \ | |
| 354 static JSMethodSpec JS_Class_Methods[]; \ | |
| 355 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | |
| 356 static const wchar_t* m_pClassName; \ | |
| 357 static void queryprop_##js_class_name##_static( \ | |
| 358 v8::Local<v8::String> property, \ | |
| 359 const v8::PropertyCallbackInfo<v8::Integer>& info); \ | |
| 360 static void getprop_##js_class_name##_static( \ | |
| 361 v8::Local<v8::String> property, \ | |
| 362 const v8::PropertyCallbackInfo<v8::Value>& info); \ | |
| 363 static void putprop_##js_class_name##_static( \ | |
| 364 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | |
| 365 const v8::PropertyCallbackInfo<v8::Value>& info); \ | |
| 366 static void delprop_##js_class_name##_static( \ | |
| 367 v8::Local<v8::String> property, \ | |
| 368 const v8::PropertyCallbackInfo<v8::Boolean>& info) | |
| 369 | |
| 370 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ | |
| 371 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | |
| 372 void js_class_name::queryprop_##js_class_name##_static( \ | |
| 373 v8::Local<v8::String> property, \ | |
| 374 const v8::PropertyCallbackInfo<v8::Integer>& info) { \ | |
| 375 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ | |
| 376 } \ | |
| 377 void js_class_name::getprop_##js_class_name##_static( \ | |
| 378 v8::Local<v8::String> property, \ | |
| 379 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | |
| 380 JSSpecialPropGet<class_alternate>(#class_name, property, info); \ | |
| 381 } \ | |
| 382 void js_class_name::putprop_##js_class_name##_static( \ | |
| 383 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | |
| 384 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | |
| 385 JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \ | |
| 386 } \ | |
| 387 void js_class_name::delprop_##js_class_name##_static( \ | |
| 388 v8::Local<v8::String> property, \ | |
| 389 const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ | |
| 390 JSSpecialPropDel<class_alternate>(#class_name, property, info); \ | |
| 391 } \ | |
| 392 void js_class_name::JSConstructor(IFXJS_Context* cc, \ | |
| 393 v8::Local<v8::Object> obj, \ | |
| 394 v8::Local<v8::Object> global) { \ | |
| 395 CJS_Object* pObj = new js_class_name(obj); \ | |
| 396 pObj->SetEmbedObject(new class_alternate(pObj)); \ | |
| 397 FXJS_SetPrivate(NULL, obj, (void*)pObj); \ | |
| 398 pObj->InitInstance(cc); \ | |
| 399 } \ | |
| 400 \ | |
| 401 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ | |
| 402 js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj); \ | |
| 403 ASSERT(pObj != NULL); \ | |
| 404 pObj->ExitInstance(); \ | |
| 405 delete pObj; \ | |
| 406 } \ | |
| 407 \ | |
| 408 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | |
| 409 FXJSOBJTYPE eObjType) { \ | |
| 410 int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | |
| 411 eObjType, JSConstructor, JSDestructor); \ | |
| 412 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ | |
| 413 FXJS_DefineObjProperty( \ | |
| 414 pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \ | |
| 415 JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \ | |
| 416 } \ | |
| 417 \ | |
| 418 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ | |
| 419 FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ | |
| 420 JS_Class_Methods[i].pMethodCall); \ | |
| 421 } \ | |
| 422 FXJS_DefineObjAllProperties( \ | |
| 423 pIsolate, nObjDefnID, \ | |
| 424 js_class_name::queryprop_##js_class_name##_static, \ | |
| 425 js_class_name::getprop_##js_class_name##_static, \ | |
| 426 js_class_name::putprop_##js_class_name##_static, \ | |
| 427 js_class_name::delprop_##js_class_name##_static); \ | |
| 428 } | |
| 429 | |
| 430 /* ======================================== GLOBAL METHODS | |
| 431 * ============================================ */ | |
| 432 | |
| 433 template <FX_BOOL (*F)(IFXJS_Context* cc, | 439 template <FX_BOOL (*F)(IFXJS_Context* cc, |
| 434 const CJS_Parameters& params, | 440 const CJS_Parameters& params, |
| 435 CJS_Value& vRet, | 441 CJS_Value& vRet, |
| 436 CFX_WideString& sError)> | 442 CFX_WideString& sError)> |
| 437 void JSGlobalFunc(const char* func_name_string, | 443 void JSGlobalFunc(const char* func_name_string, |
| 438 const v8::FunctionCallbackInfo<v8::Value>& info) { | 444 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 439 v8::Isolate* isolate = info.GetIsolate(); | 445 v8::Isolate* isolate = info.GetIsolate(); |
| 440 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 446 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| 441 if (!pRuntime) | 447 if (!pRuntime) |
| 442 return; | 448 return; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 466 | 472 |
| 467 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 473 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
| 468 JSMethodSpec js_class_name::global_methods[] = { | 474 JSMethodSpec js_class_name::global_methods[] = { |
| 469 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ | 475 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ |
| 470 JS_STATIC_METHOD_ENTRY(method_name) | 476 JS_STATIC_METHOD_ENTRY(method_name) |
| 471 | 477 |
| 472 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() | 478 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() |
| 473 | 479 |
| 474 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 480 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
| 475 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ | 481 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ |
| 476 for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ | 482 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
| 477 FXJS_DefineGlobalMethod(pIsolate, \ | 483 FXJS_DefineGlobalMethod(pIsolate, \ |
| 478 js_class_name::global_methods[i].pName, \ | 484 js_class_name::global_methods[i].pName, \ |
| 479 js_class_name::global_methods[i].pMethodCall); \ | 485 js_class_name::global_methods[i].pMethodCall); \ |
| 480 } \ | 486 } \ |
| 481 } | 487 } |
| 482 | 488 |
| 483 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | 489 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); |
| 484 | 490 |
| 485 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 491 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
| OLD | NEW |