OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | |
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | |
9 | |
10 #include "../jsapi/fxjs_v8.h" | |
11 #include "resource.h" | |
12 #include "JS_Object.h" | |
13 #include "JS_Value.h" | |
14 | |
15 struct JSConstSpec { | |
16 const wchar_t* pName; | |
17 double number; | |
18 const wchar_t* string; | |
19 uint8_t t; // 0:double 1:str | |
20 }; | |
21 | |
22 struct JSPropertySpec { | |
23 const wchar_t* pName; | |
24 v8::AccessorGetterCallback pPropGet; | |
25 v8::AccessorSetterCallback pPropPut; | |
26 }; | |
27 | |
28 struct JSMethodSpec { | |
29 const wchar_t* pName; | |
30 v8::FunctionCallback pMethodCall; | |
31 }; | |
32 | |
33 /* ====================================== PUBLIC DEFINE SPEC | |
34 * ============================================== */ | |
35 #define JS_WIDESTRING(widestring) L## #widestring | |
36 | |
37 #define BEGIN_JS_STATIC_CONST(js_class_name) \ | |
38 JSConstSpec js_class_name::JS_Class_Consts[] = { | |
39 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) \ | |
40 { const_name, pValue, L"", 0 } \ | |
41 , | |
42 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) \ | |
43 { const_name, 0, pValue, 1 } \ | |
44 , | |
45 #define END_JS_STATIC_CONST() \ | |
46 { 0, 0, 0, 0 } \ | |
47 } \ | |
48 ; | |
49 | |
50 #define BEGIN_JS_STATIC_PROP(js_class_name) \ | |
51 JSPropertySpec js_class_name::JS_Class_Properties[] = { | |
52 #define JS_STATIC_PROP_ENTRY(prop_name)
\ | |
53 {
\ | |
54 JS_WIDESTRING(prop_name), get_##prop_name##_static, set_##prop_name##_static
\ | |
55 }
\ | |
56 , | |
57 #define END_JS_STATIC_PROP() \ | |
58 { 0, 0, 0 } \ | |
59 } \ | |
60 ; | |
61 | |
62 #define BEGIN_JS_STATIC_METHOD(js_class_name) \ | |
63 JSMethodSpec js_class_name::JS_Class_Methods[] = { | |
64 #define JS_STATIC_METHOD_ENTRY(method_name) \ | |
65 { JS_WIDESTRING(method_name), method_name##_static } \ | |
66 , | |
67 #define END_JS_STATIC_METHOD() \ | |
68 { 0, 0 } \ | |
69 } \ | |
70 ; | |
71 | |
72 /* ======================================== PROP CALLBACK | |
73 * ============================================ */ | |
74 | |
75 template <class C, | |
76 FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideString&)> | |
77 void JSPropGetter(const char* prop_name_string, | |
78 const char* class_name_string, | |
79 v8::Local<v8::String> property, | |
80 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
81 v8::Isolate* isolate = info.GetIsolate(); | |
82 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | |
83 if (!pRuntime) | |
84 return; | |
85 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | |
86 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | |
87 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | |
88 CFX_WideString sError; | |
89 CJS_PropValue value(isolate); | |
90 value.StartGetting(); | |
91 if (!(pObj->*M)(pRuntimeContext, value, sError)) { | |
92 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | |
93 sError)); | |
94 return; | |
95 } | |
96 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | |
97 } | |
98 | |
99 template <class C, | |
100 FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideString&)> | |
101 void JSPropSetter(const char* prop_name_string, | |
102 const char* class_name_string, | |
103 v8::Local<v8::String> property, | |
104 v8::Local<v8::Value> value, | |
105 const v8::PropertyCallbackInfo<void>& info) { | |
106 v8::Isolate* isolate = info.GetIsolate(); | |
107 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | |
108 if (!pRuntime) | |
109 return; | |
110 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | |
111 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | |
112 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | |
113 CFX_WideString sError; | |
114 CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); | |
115 propValue.StartSetting(); | |
116 if (!(pObj->*M)(pRuntimeContext, propValue, sError)) { | |
117 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | |
118 sError)); | |
119 } | |
120 } | |
121 | |
122 #define JS_STATIC_PROP(prop_name, class_name) \ | |
123 static void get_##prop_name##_static( \ | |
124 v8::Local<v8::String> property, \ | |
125 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | |
126 JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ | |
127 property, info); \ | |
128 } \ | |
129 static void set_##prop_name##_static( \ | |
130 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | |
131 const v8::PropertyCallbackInfo<void>& info) { \ | |
132 JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ | |
133 property, value, info); \ | |
134 } | |
135 | |
136 /* ========================================= METHOD CALLBACK | |
137 * =========================================== */ | |
138 | |
139 template <class C, | |
140 FX_BOOL (C::*M)(IFXJS_Context*, | |
141 const CJS_Parameters&, | |
142 CJS_Value&, | |
143 CFX_WideString&)> | |
144 void JSMethod(const char* method_name_string, | |
145 const char* class_name_string, | |
146 const v8::FunctionCallbackInfo<v8::Value>& info) { | |
147 v8::Isolate* isolate = info.GetIsolate(); | |
148 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | |
149 if (!pRuntime) | |
150 return; | |
151 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | |
152 CJS_Parameters parameters; | |
153 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | |
154 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); | |
155 } | |
156 CJS_Value valueRes(isolate); | |
157 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | |
158 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | |
159 CFX_WideString sError; | |
160 if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) { | |
161 FXJS_Error(isolate, JSFormatErrorString(class_name_string, | |
162 method_name_string, sError)); | |
163 return; | |
164 } | |
165 info.GetReturnValue().Set(valueRes.ToV8Value()); | |
166 } | |
167 | |
168 #define JS_STATIC_METHOD(method_name, class_name) \ | |
169 static void method_name##_static( \ | |
170 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | |
171 JSMethod<class_name, &class_name::method_name>(#method_name, #class_name, \ | |
172 info); \ | |
173 } | |
174 | |
175 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ | |
176 static void method_name##_static( \ | |
177 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | |
178 JSMethod<class_alternate, &class_alternate::method_name>( \ | |
179 #method_name, #class_name, info); \ | |
180 } | |
181 | |
182 /* ===================================== JS CLASS | |
183 * =============================================== */ | |
184 | |
185 #define DECLARE_JS_CLASS(js_class_name) \ | |
186 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ | |
187 v8::Local<v8::Object> global); \ | |
188 static void JSDestructor(v8::Local<v8::Object> obj); \ | |
189 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | |
190 static JSConstSpec JS_Class_Consts[]; \ | |
191 static JSPropertySpec JS_Class_Properties[]; \ | |
192 static JSMethodSpec JS_Class_Methods[]; \ | |
193 static const wchar_t* m_pClassName | |
194 | |
195 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \ | |
196 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | |
197 void js_class_name::JSConstructor(IFXJS_Context* cc, \ | |
198 v8::Local<v8::Object> obj, \ | |
199 v8::Local<v8::Object> global) { \ | |
200 CJS_Object* pObj = new js_class_name(obj); \ | |
201 pObj->SetEmbedObject(new class_alternate(pObj)); \ | |
202 FXJS_SetPrivate(NULL, obj, (void*)pObj); \ | |
203 pObj->InitInstance(cc); \ | |
204 } \ | |
205 \ | |
206 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ | |
207 js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj); \ | |
208 pObj->ExitInstance(); \ | |
209 delete pObj; \ | |
210 } \ | |
211 \ | |
212 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | |
213 FXJSOBJTYPE eObjType) { \ | |
214 int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | |
215 eObjType, JSConstructor, JSDestructor); \ | |
216 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ | |
217 FXJS_DefineObjProperty( \ | |
218 pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \ | |
219 JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \ | |
220 } \ | |
221 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ | |
222 FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ | |
223 JS_Class_Methods[i].pMethodCall); \ | |
224 } \ | |
225 } | |
226 | |
227 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \ | |
228 IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name) | |
229 | |
230 /* ======================================== CONST CLASS | |
231 * ============================================ */ | |
232 | |
233 #define DECLARE_JS_CLASS_CONST() \ | |
234 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | |
235 static JSConstSpec JS_Class_Consts[]; \ | |
236 static const wchar_t* m_pClassName | |
237 | |
238 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name) \ | |
239 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | |
240 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | |
241 FXJSOBJTYPE eObjType) { \ | |
242 int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | |
243 eObjType, NULL, NULL); \ | |
244 for (int i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \ | |
245 FXJS_DefineObjConst( \ | |
246 pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \ | |
247 JS_Class_Consts[i].t == 0 \ | |
248 ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number) \ | |
249 : FXJS_NewString(pIsolate, JS_Class_Consts[i].string)); \ | |
250 } \ | |
251 } | |
252 | |
253 /* ===================================== SPECIAL JS CLASS | |
254 * =============================================== */ | |
255 | |
256 template <class Alt> | |
257 void JSSpecialPropQuery(const char*, | |
258 v8::Local<v8::String> property, | |
259 const v8::PropertyCallbackInfo<v8::Integer>& info) { | |
260 v8::Isolate* isolate = info.GetIsolate(); | |
261 v8::String::Utf8Value utf8_value(property); | |
262 CFX_WideString propname = | |
263 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | |
264 CJS_Object* pJSObj = | |
265 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | |
266 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | |
267 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); | |
268 info.GetReturnValue().Set(bRet ? 4 : 0); | |
269 } | |
270 | |
271 template <class Alt> | |
272 void JSSpecialPropGet(const char* class_name, | |
273 v8::Local<v8::String> property, | |
274 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
275 v8::Isolate* isolate = info.GetIsolate(); | |
276 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | |
277 if (!pRuntime) | |
278 return; | |
279 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | |
280 CJS_Object* pJSObj = | |
281 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | |
282 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | |
283 v8::String::Utf8Value utf8_value(property); | |
284 CFX_WideString propname = | |
285 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | |
286 CFX_WideString sError; | |
287 CJS_PropValue value(isolate); | |
288 value.StartGetting(); | |
289 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { | |
290 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); | |
291 return; | |
292 } | |
293 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | |
294 } | |
295 | |
296 template <class Alt> | |
297 void JSSpecialPropPut(const char* class_name, | |
298 v8::Local<v8::String> property, | |
299 v8::Local<v8::Value> value, | |
300 const v8::PropertyCallbackInfo<v8::Value>& info) { | |
301 v8::Isolate* isolate = info.GetIsolate(); | |
302 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | |
303 if (!pRuntime) | |
304 return; | |
305 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | |
306 CJS_Object* pJSObj = | |
307 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | |
308 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | |
309 v8::String::Utf8Value utf8_value(property); | |
310 CFX_WideString propname = | |
311 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | |
312 CFX_WideString sError; | |
313 CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); | |
314 PropValue.StartSetting(); | |
315 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { | |
316 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); | |
317 } | |
318 } | |
319 | |
320 template <class Alt> | |
321 void JSSpecialPropDel(const char* class_name, | |
322 v8::Local<v8::String> property, | |
323 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | |
324 v8::Isolate* isolate = info.GetIsolate(); | |
325 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | |
326 if (!pRuntime) | |
327 return; | |
328 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | |
329 CJS_Object* pJSObj = | |
330 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | |
331 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | |
332 v8::String::Utf8Value utf8_value(property); | |
333 CFX_WideString propname = | |
334 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | |
335 CFX_WideString sError; | |
336 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { | |
337 CFX_ByteString cbName; | |
338 cbName.Format("%s.%s", class_name, "DelProperty"); | |
339 // Probably a missing call to JSFX_Error(). | |
340 } | |
341 } | |
342 | |
343 #define DECLARE_SPECIAL_JS_CLASS(js_class_name) \ | |
344 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \ | |
345 v8::Local<v8::Object> global); \ | |
346 static void JSDestructor(v8::Local<v8::Object> obj); \ | |
347 static JSConstSpec JS_Class_Consts[]; \ | |
348 static JSPropertySpec JS_Class_Properties[]; \ | |
349 static JSMethodSpec JS_Class_Methods[]; \ | |
350 static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \ | |
351 static const wchar_t* m_pClassName; \ | |
352 static void queryprop_##js_class_name##_static( \ | |
353 v8::Local<v8::String> property, \ | |
354 const v8::PropertyCallbackInfo<v8::Integer>& info); \ | |
355 static void getprop_##js_class_name##_static( \ | |
356 v8::Local<v8::String> property, \ | |
357 const v8::PropertyCallbackInfo<v8::Value>& info); \ | |
358 static void putprop_##js_class_name##_static( \ | |
359 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | |
360 const v8::PropertyCallbackInfo<v8::Value>& info); \ | |
361 static void delprop_##js_class_name##_static( \ | |
362 v8::Local<v8::String> property, \ | |
363 const v8::PropertyCallbackInfo<v8::Boolean>& info) | |
364 | |
365 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \ | |
366 const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name); \ | |
367 void js_class_name::queryprop_##js_class_name##_static( \ | |
368 v8::Local<v8::String> property, \ | |
369 const v8::PropertyCallbackInfo<v8::Integer>& info) { \ | |
370 JSSpecialPropQuery<class_alternate>(#class_name, property, info); \ | |
371 } \ | |
372 void js_class_name::getprop_##js_class_name##_static( \ | |
373 v8::Local<v8::String> property, \ | |
374 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | |
375 JSSpecialPropGet<class_alternate>(#class_name, property, info); \ | |
376 } \ | |
377 void js_class_name::putprop_##js_class_name##_static( \ | |
378 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | |
379 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | |
380 JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \ | |
381 } \ | |
382 void js_class_name::delprop_##js_class_name##_static( \ | |
383 v8::Local<v8::String> property, \ | |
384 const v8::PropertyCallbackInfo<v8::Boolean>& info) { \ | |
385 JSSpecialPropDel<class_alternate>(#class_name, property, info); \ | |
386 } \ | |
387 void js_class_name::JSConstructor(IFXJS_Context* cc, \ | |
388 v8::Local<v8::Object> obj, \ | |
389 v8::Local<v8::Object> global) { \ | |
390 CJS_Object* pObj = new js_class_name(obj); \ | |
391 pObj->SetEmbedObject(new class_alternate(pObj)); \ | |
392 FXJS_SetPrivate(NULL, obj, (void*)pObj); \ | |
393 pObj->InitInstance(cc); \ | |
394 } \ | |
395 \ | |
396 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ | |
397 js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj); \ | |
398 ASSERT(pObj != NULL); \ | |
399 pObj->ExitInstance(); \ | |
400 delete pObj; \ | |
401 } \ | |
402 \ | |
403 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | |
404 FXJSOBJTYPE eObjType) { \ | |
405 int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \ | |
406 eObjType, JSConstructor, JSDestructor); \ | |
407 for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \ | |
408 FXJS_DefineObjProperty( \ | |
409 pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \ | |
410 JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \ | |
411 } \ | |
412 \ | |
413 for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \ | |
414 FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \ | |
415 JS_Class_Methods[i].pMethodCall); \ | |
416 } \ | |
417 FXJS_DefineObjAllProperties( \ | |
418 pIsolate, nObjDefnID, \ | |
419 js_class_name::queryprop_##js_class_name##_static, \ | |
420 js_class_name::getprop_##js_class_name##_static, \ | |
421 js_class_name::putprop_##js_class_name##_static, \ | |
422 js_class_name::delprop_##js_class_name##_static); \ | |
423 } | |
424 | |
425 /* ======================================== GLOBAL METHODS | |
426 * ============================================ */ | |
427 | |
428 template <FX_BOOL ( | |
429 *F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)> | |
430 void JSGlobalFunc(const char* func_name_string, | |
431 const v8::FunctionCallbackInfo<v8::Value>& info) { | |
432 v8::Isolate* isolate = info.GetIsolate(); | |
433 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | |
434 if (!pRuntime) | |
435 return; | |
436 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | |
437 CJS_Parameters parameters; | |
438 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | |
439 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); | |
440 } | |
441 CJS_Value valueRes(isolate); | |
442 CFX_WideString sError; | |
443 if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) { | |
444 FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError)); | |
445 return; | |
446 } | |
447 info.GetReturnValue().Set(valueRes.ToV8Value()); | |
448 } | |
449 | |
450 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | |
451 static void fun_name##_static( \ | |
452 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | |
453 JSGlobalFunc<fun_name>(#fun_name, info); \ | |
454 } | |
455 | |
456 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ | |
457 static JSMethodSpec global_methods[]; \ | |
458 static void DefineJSObjects(v8::Isolate* pIsolate) | |
459 | |
460 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | |
461 JSMethodSpec js_class_name::global_methods[] = { | |
462 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ | |
463 JS_STATIC_METHOD_ENTRY(method_name) | |
464 | |
465 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() | |
466 | |
467 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ | |
468 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ | |
469 for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ | |
470 FXJS_DefineGlobalMethod(pIsolate, \ | |
471 js_class_name::global_methods[i].pName, \ | |
472 js_class_name::global_methods[i].pMethodCall); \ | |
473 } \ | |
474 } | |
475 | |
476 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | |
477 | |
478 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ | |
OLD | NEW |