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_JAVASCRIPT_JS_DEFINE_H_ | 7 #ifndef FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |
8 #define FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ | 8 #define FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "fpdfsdk/javascript/JS_Object.h" | 12 #include "fpdfsdk/javascript/JS_Object.h" |
13 #include "fpdfsdk/javascript/JS_Value.h" | 13 #include "fpdfsdk/javascript/JS_Value.h" |
14 #include "fpdfsdk/javascript/resource.h" | 14 #include "fpdfsdk/javascript/resource.h" |
15 #include "fpdfsdk/jsapi/include/fxjs_v8.h" | 15 #include "fpdfsdk/jsapi/include/fxjs_v8.h" |
16 | 16 |
17 struct JSConstSpec { | 17 struct JSConstSpec { |
18 const wchar_t* pName; | 18 const wchar_t* pName; |
19 double number; | 19 double number; |
20 const wchar_t* string; // NOLINT | 20 const wchar_t* str; |
21 uint8_t t; // 0:double 1:str | 21 uint8_t t; // 0:double 1:str |
22 }; | 22 }; |
23 | 23 |
24 struct JSPropertySpec { | 24 struct JSPropertySpec { |
25 const wchar_t* pName; | 25 const wchar_t* pName; |
26 v8::AccessorGetterCallback pPropGet; | 26 v8::AccessorGetterCallback pPropGet; |
27 v8::AccessorSetterCallback pPropPut; | 27 v8::AccessorSetterCallback pPropPut; |
28 }; | 28 }; |
29 | 29 |
30 struct JSMethodSpec { | 30 struct JSMethodSpec { |
(...skipping 12 matching lines...) Expand all Loading... |
43 { const_name, 0, pValue, 1 } \ | 43 { const_name, 0, pValue, 1 } \ |
44 , | 44 , |
45 | 45 |
46 #define END_JS_STATIC_CONST() \ | 46 #define END_JS_STATIC_CONST() \ |
47 { 0, 0, 0, 0 } \ | 47 { 0, 0, 0, 0 } \ |
48 } \ | 48 } \ |
49 ; // NOLINT | 49 ; // NOLINT |
50 | 50 |
51 #define BEGIN_JS_STATIC_PROP(js_class_name) \ | 51 #define BEGIN_JS_STATIC_PROP(js_class_name) \ |
52 JSPropertySpec js_class_name::JS_Class_Properties[] = { | 52 JSPropertySpec js_class_name::JS_Class_Properties[] = { |
53 #define JS_STATIC_PROP_ENTRY(prop_name)
\ | 53 #define JS_STATIC_PROP_ENTRY(prop_name) \ |
54 {
\ | 54 {JS_WIDESTRING(prop_name), get_##prop_name##_static, \ |
55 JS_WIDESTRING(prop_name), get_##prop_name##_static, \ | 55 set_##prop_name##_static}, // NOLINT |
56 set_##prop_name##_static \ | |
57 }
\ | |
58 , | |
59 | 56 |
60 #define END_JS_STATIC_PROP() \ | 57 #define END_JS_STATIC_PROP() \ |
61 { 0, 0, 0 } \ | 58 { 0, 0, 0 } \ |
62 } \ | 59 } \ |
63 ; // NOLINT | 60 ; // NOLINT |
64 | 61 |
65 #define BEGIN_JS_STATIC_METHOD(js_class_name) \ | 62 #define BEGIN_JS_STATIC_METHOD(js_class_name) \ |
66 JSMethodSpec js_class_name::JS_Class_Methods[] = { | 63 JSMethodSpec js_class_name::JS_Class_Methods[] = { |
67 #define JS_STATIC_METHOD_ENTRY(method_name) \ | 64 #define JS_STATIC_METHOD_ENTRY(method_name) \ |
68 { JS_WIDESTRING(method_name), method_name##_static } \ | 65 { JS_WIDESTRING(method_name), method_name##_static } \ |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 FXJSOBJTYPE eObjType) { \ | 201 FXJSOBJTYPE eObjType) { \ |
205 g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ | 202 g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ |
206 eObjType, nullptr, nullptr); \ | 203 eObjType, nullptr, nullptr); \ |
207 DefineConsts(pIsolate); \ | 204 DefineConsts(pIsolate); \ |
208 } | 205 } |
209 | 206 |
210 #define DECLARE_JS_CLASS_CONST_PART() \ | 207 #define DECLARE_JS_CLASS_CONST_PART() \ |
211 static JSConstSpec JS_Class_Consts[]; \ | 208 static JSConstSpec JS_Class_Consts[]; \ |
212 static void DefineConsts(v8::Isolate* pIsolate); | 209 static void DefineConsts(v8::Isolate* pIsolate); |
213 | 210 |
214 #define IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ | 211 #define IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name) \ |
215 void js_class_name::DefineConsts(v8::Isolate* pIsolate) { \ | 212 void js_class_name::DefineConsts(v8::Isolate* pIsolate) { \ |
216 for (size_t i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \ | 213 for (size_t i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \ |
217 FXJS_DefineObjConst( \ | 214 FXJS_DefineObjConst( \ |
218 pIsolate, g_nObjDefnID, JS_Class_Consts[i].pName, \ | 215 pIsolate, g_nObjDefnID, JS_Class_Consts[i].pName, \ |
219 JS_Class_Consts[i].t == 0 \ | 216 JS_Class_Consts[i].t == 0 \ |
220 ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number) \ | 217 ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number) \ |
221 : FXJS_NewString(pIsolate, JS_Class_Consts[i].string)); \ | 218 : FXJS_NewString(pIsolate, JS_Class_Consts[i].str)); \ |
222 } \ | 219 } \ |
223 } | 220 } |
224 | 221 |
225 // Convenience macros for declaring classes without an alternate. | 222 // Convenience macros for declaring classes without an alternate. |
226 #define DECLARE_JS_CLASS() DECLARE_JS_CLASS_RICH() | 223 #define DECLARE_JS_CLASS() DECLARE_JS_CLASS_RICH() |
227 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ | 224 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ |
228 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) | 225 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) |
229 | 226 |
230 // Rich JS classes provide constants, methods, properties, and the ability | 227 // Rich JS classes provide constants, methods, properties, and the ability |
231 // to construct native object state. | 228 // to construct native object state. |
232 #define DECLARE_JS_CLASS_RICH() \ | 229 #define DECLARE_JS_CLASS_RICH() \ |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ | 481 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
485 FXJS_DefineGlobalMethod(pIsolate, \ | 482 FXJS_DefineGlobalMethod(pIsolate, \ |
486 js_class_name::global_methods[i].pName, \ | 483 js_class_name::global_methods[i].pName, \ |
487 js_class_name::global_methods[i].pMethodCall); \ | 484 js_class_name::global_methods[i].pMethodCall); \ |
488 } \ | 485 } \ |
489 } | 486 } |
490 | 487 |
491 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | 488 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); |
492 | 489 |
493 #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ | 490 #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |
OLD | NEW |