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 _JS_DEFINE_H_ | 7 #ifndef _JS_DEFINE_H_ |
8 #define _JS_DEFINE_H_ | 8 #define _JS_DEFINE_H_ |
9 | 9 |
10 #include "../jsapi/fxjs_v8.h" | 10 #include "../jsapi/fxjs_v8.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 { | 25 { |
26 const wchar_t* pName; | 26 const wchar_t* pName; |
27 v8::AccessorGetterCallback pPropGet; | 27 v8::AccessorGetterCallback pPropGet; |
28 v8::AccessorSetterCallback pPropPut; | 28 v8::AccessorSetterCallback pPropPut; |
29 }; | 29 }; |
30 | 30 |
31 struct JSMethodSpec | 31 struct JSMethodSpec |
32 { | 32 { |
33 const wchar_t* pName; | 33 const wchar_t* pName; |
34 v8::FunctionCallback pMethodCall; | 34 v8::FunctionCallback pMethodCall; |
35 unsigned nParamNum; | |
36 }; | 35 }; |
37 | 36 |
38 /* ====================================== PUBLIC DEFINE SPEC ===================
=========================== */ | 37 /* ====================================== PUBLIC DEFINE SPEC ===================
=========================== */ |
39 #define JS_WIDESTRING(widestring) L###widestring | 38 #define JS_WIDESTRING(widestring) L###widestring |
40 | 39 |
41 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class
_Consts[] = { | 40 #define BEGIN_JS_STATIC_CONST(js_class_name) JSConstSpec js_class_name::JS_Class
_Consts[] = { |
42 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) {JS_WIDESTRING(const_na
me), pValue, L"", 0}, | 41 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) {JS_WIDESTRING(const_na
me), pValue, L"", 0}, |
43 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na
me), 0, JS_WIDESTRING(pValue), 1}, | 42 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na
me), 0, JS_WIDESTRING(pValue), 1}, |
44 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; | 43 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; |
45 | 44 |
46 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla
ss_Properties[] = { | 45 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla
ss_Properties[] = { |
47 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na
me##_static, set_##prop_name##_static}, | 46 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na
me##_static, set_##prop_name##_static}, |
48 #define END_JS_STATIC_PROP() {0, 0, 0}}; | 47 #define END_JS_STATIC_PROP() {0, 0, 0}}; |
49 | 48 |
50 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla
ss_Methods[] = { | 49 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla
ss_Methods[] = { |
51 #define JS_STATIC_METHOD_ENTRY(method_name, nargs) {JS_WIDESTRING(method_name),
method_name##_static, nargs}, | 50 #define JS_STATIC_METHOD_ENTRY(method_name) {JS_WIDESTRING(method_name), method_
name##_static}, |
52 #define END_JS_STATIC_METHOD() {0, 0, 0}}; | 51 #define END_JS_STATIC_METHOD() {0, 0}}; |
53 | 52 |
54 /* ======================================== PROP CALLBACK ======================
====================== */ | 53 /* ======================================== PROP CALLBACK ======================
====================== */ |
55 | 54 |
56 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid
eString& sError)> | 55 template <class C, FX_BOOL (C::*M)(IFXJS_Context* cc, CJS_PropValue& vp, CFX_Wid
eString& sError)> |
57 void JSPropGetter(const char* prop_name_string, | 56 void JSPropGetter(const char* prop_name_string, |
58 const char* class_name_string, | 57 const char* class_name_string, |
59 v8::Local<v8::String> property, | 58 v8::Local<v8::String> property, |
60 const v8::PropertyCallbackInfo<v8::Value>& info) { | 59 const v8::PropertyCallbackInfo<v8::Value>& info) { |
61 v8::Isolate* isolate = info.GetIsolate(); | 60 v8::Isolate* isolate = info.GetIsolate(); |
62 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 61 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 {\ | 186 {\ |
188 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor, 0);\ | 187 int nObjDefnID = JS_DefineObj(pRuntime, js_class_name::m_pClassName, eOb
jType, JSConstructor, JSDestructor, 0);\ |
189 if (nObjDefnID >= 0)\ | 188 if (nObjDefnID >= 0)\ |
190 {\ | 189 {\ |
191 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ | 190 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ |
192 {\ | 191 {\ |
193 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr
opPut) < 0) return -1;\ | 192 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet, JS_Class_Properties[j].pPr
opPut) < 0) return -1;\ |
194 }\ | 193 }\ |
195 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ | 194 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ |
196 {\ | 195 {\ |
197 » » » if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName, JS_Class_Methods[k].pMethodCall, JS_Class_Methods[k].nParamNum) <
0) return -1;\ | 196 » » » if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName, JS_Class_Methods[k].pMethodCall) < 0) return -1;\ |
198 }\ | 197 }\ |
199 return nObjDefnID;\ | 198 return nObjDefnID;\ |
200 }\ | 199 }\ |
201 return -1;\ | 200 return -1;\ |
202 } | 201 } |
203 | 202 |
204 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) IMPLEMENT_JS_CLASS_RICH(js
_class_name, class_name, class_name) | 203 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) IMPLEMENT_JS_CLASS_RICH(js
_class_name, class_name, class_name) |
205 | 204 |
206 /* ======================================== CONST CLASS ========================
==================== */ | 205 /* ======================================== CONST CLASS ========================
==================== */ |
207 | 206 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 \ | 364 \ |
366 if (nObjDefnID >= 0)\ | 365 if (nObjDefnID >= 0)\ |
367 {\ | 366 {\ |
368 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ | 367 for (int j=0, szj=sizeof(JS_Class_Properties)/sizeof(JSPropertyS
pec)-1; j<szj; j++)\ |
369 {\ | 368 {\ |
370 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet,JS_Class_Properties[j].pPro
pPut)<0)return -1;\ | 369 if (JS_DefineObjProperty(pRuntime, nObjDefnID, JS_Class_
Properties[j].pName, JS_Class_Properties[j].pPropGet,JS_Class_Properties[j].pPro
pPut)<0)return -1;\ |
371 }\ | 370 }\ |
372 \ | 371 \ |
373 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ | 372 for (int k=0, szk=sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-
1; k<szk; k++)\ |
374 {\ | 373 {\ |
375 » » » if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName,JS_Class_Methods[k].pMethodCall,JS_Class_Methods[k].nParamNum)<0)r
eturn -1;\ | 374 » » » if (JS_DefineObjMethod(pRuntime, nObjDefnID,JS_Class_Met
hods[k].pName,JS_Class_Methods[k].pMethodCall)<0)return -1;\ |
376 }\ | 375 }\ |
377 if (JS_DefineObjAllProperties(pRuntime, nObjDefnID, js_class_nam
e::queryprop_##js_class_name##_static, js_class_name::getprop_##js_class_name##_
static,js_class_name::putprop_##js_class_name##_static,js_class_name::delprop_##
js_class_name##_static)<0) return -1;\ | 376 if (JS_DefineObjAllProperties(pRuntime, nObjDefnID, js_class_nam
e::queryprop_##js_class_name##_static, js_class_name::getprop_##js_class_name##_
static,js_class_name::putprop_##js_class_name##_static,js_class_name::delprop_##
js_class_name##_static)<0) return -1;\ |
378 \ | 377 \ |
379 return nObjDefnID;\ | 378 return nObjDefnID;\ |
380 }\ | 379 }\ |
381 \ | 380 \ |
382 return -1;\ | 381 return -1;\ |
383 } | 382 } |
384 | 383 |
385 /* ======================================== GLOBAL METHODS =====================
======================= */ | 384 /* ======================================== GLOBAL METHODS =====================
======================= */ |
(...skipping 26 matching lines...) Expand all Loading... |
412 JSGlobalFunc<fun_name>(#fun_name, info); \ | 411 JSGlobalFunc<fun_name>(#fun_name, info); \ |
413 } | 412 } |
414 | 413 |
415 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ | 414 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ |
416 static JSMethodSpec global_methods[]; \ | 415 static JSMethodSpec global_methods[]; \ |
417 static int Init(IJS_Runtime* pRuntime) | 416 static int Init(IJS_Runtime* pRuntime) |
418 | 417 |
419 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 418 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
420 JSMethodSpec js_class_name::global_methods[] = { | 419 JSMethodSpec js_class_name::global_methods[] = { |
421 | 420 |
422 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(met
hod_name,nargs) | 421 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) JS_STATIC_METHOD_ENTRY(method_na
me) |
423 | 422 |
424 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() | 423 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() |
425 | 424 |
426 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 425 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
427 int js_class_name::Init(IJS_Runtime* pRuntime)\ | 426 int js_class_name::Init(IJS_Runtime* pRuntime)\ |
428 {\ | 427 {\ |
429 for (int i=0, sz=sizeof(js_class_name::global_methods)/sizeof(JSMethodSp
ec)-1; i<sz; i++)\ | 428 for (int i=0, sz=sizeof(js_class_name::global_methods)/sizeof(JSMethodSp
ec)-1; i<sz; i++)\ |
430 {\ | 429 {\ |
431 if (JS_DefineGlobalMethod(pRuntime,\ | 430 if (JS_DefineGlobalMethod(pRuntime,\ |
432 js_class_name::global_methods[i].pName,\ | 431 js_class_name::global_methods[i].pName,\ |
433 » » » » js_class_name::global_methods[i].pMethodCall,\ | 432 » » » » js_class_name::global_methods[i].pMethodCall\ |
434 » » » » js_class_name::global_methods[i].nParamNum\ | |
435 ) < 0\ | 433 ) < 0\ |
436 )return -1;\ | 434 )return -1;\ |
437 }\ | 435 }\ |
438 return 0;\ | 436 return 0;\ |
439 } | 437 } |
440 | 438 |
441 /* ======================================== GLOBAL CONSTS ======================
====================== */ | 439 /* ======================================== GLOBAL CONSTS ======================
====================== */ |
442 #define DEFINE_GLOBAL_CONST(pRuntime, const_name , const_value)\ | 440 #define DEFINE_GLOBAL_CONST(pRuntime, const_name , const_value)\ |
443 if (JS_DefineGlobalConst(pRuntime,JS_WIDESTRING(const_name),JS_NewString(pRuntim
e,JS_WIDESTRING(const_value)))) return -1 | 441 if (JS_DefineGlobalConst(pRuntime,JS_WIDESTRING(const_name),JS_NewString(pRuntim
e,JS_WIDESTRING(const_value)))) return -1 |
444 | 442 |
(...skipping 17 matching lines...) Expand all Loading... |
462 #define VALUE_NAME_BOOLEAN L"boolean" | 460 #define VALUE_NAME_BOOLEAN L"boolean" |
463 #define VALUE_NAME_DATE L"date" | 461 #define VALUE_NAME_DATE L"date" |
464 #define VALUE_NAME_OBJECT L"object" | 462 #define VALUE_NAME_OBJECT L"object" |
465 #define VALUE_NAME_FXOBJ L"fxobj" | 463 #define VALUE_NAME_FXOBJ L"fxobj" |
466 #define VALUE_NAME_NULL L"null" | 464 #define VALUE_NAME_NULL L"null" |
467 #define VALUE_NAME_UNDEFINED L"undefined" | 465 #define VALUE_NAME_UNDEFINED L"undefined" |
468 | 466 |
469 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); | 467 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); |
470 | 468 |
471 #endif //_JS_DEFINE_H_ | 469 #endif //_JS_DEFINE_H_ |
OLD | NEW |