Wean CJS_Value off of v8::Isolate.
[pdfium.git] / fpdfsdk / src / javascript / JS_Define.h
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_SRC_JAVASCRIPT_JS_DEFINE_H_
8 #define FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_
9
10 #include "../../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 #define JS_WIDESTRING(widestring) L## #widestring
34 #define BEGIN_JS_STATIC_CONST(js_class_name) \
35   JSConstSpec js_class_name::JS_Class_Consts[] = {
36 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) \
37   { const_name, pValue, L"", 0 }                         \
38   ,
39
40 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) \
41   { const_name, 0, pValue, 1 }                           \
42   ,
43
44 #define END_JS_STATIC_CONST() \
45   { 0, 0, 0, 0 }              \
46   }                           \
47   ;
48
49 #define BEGIN_JS_STATIC_PROP(js_class_name) \
50   JSPropertySpec js_class_name::JS_Class_Properties[] = {
51 #define JS_STATIC_PROP_ENTRY(prop_name)                 \
52   {                                                     \
53     JS_WIDESTRING(prop_name), get_##prop_name##_static, \
54         set_##prop_name##_static                        \
55   }                                                     \
56   ,
57
58 #define END_JS_STATIC_PROP() \
59   { 0, 0, 0 }                \
60   }                          \
61   ;
62
63 #define BEGIN_JS_STATIC_METHOD(js_class_name) \
64   JSMethodSpec js_class_name::JS_Class_Methods[] = {
65 #define JS_STATIC_METHOD_ENTRY(method_name)            \
66   { JS_WIDESTRING(method_name), method_name##_static } \
67   ,
68
69 #define END_JS_STATIC_METHOD() \
70   { 0, 0 }                     \
71   }                            \
72   ;
73
74 template <
75     class C,
76     FX_BOOL (C::*M)(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)>
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   CJS_Runtime* pRuntime =
83       static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
84   if (!pRuntime)
85     return;
86   IJS_Context* pContext = pRuntime->GetCurrentContext();
87   CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
88   C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
89   CFX_WideString sError;
90   CJS_PropValue value(pRuntime);
91   value.StartGetting();
92   if (!(pObj->*M)(pContext, value, sError)) {
93     FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
94                                             sError));
95     return;
96   }
97   info.GetReturnValue().Set((v8::Local<v8::Value>)value);
98 }
99
100 template <
101     class C,
102     FX_BOOL (C::*M)(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)>
103 void JSPropSetter(const char* prop_name_string,
104                   const char* class_name_string,
105                   v8::Local<v8::String> property,
106                   v8::Local<v8::Value> value,
107                   const v8::PropertyCallbackInfo<void>& info) {
108   v8::Isolate* isolate = info.GetIsolate();
109   CJS_Runtime* pRuntime =
110       static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
111   if (!pRuntime)
112     return;
113   IJS_Context* pContext = pRuntime->GetCurrentContext();
114   CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
115   C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
116   CFX_WideString sError;
117   CJS_PropValue propValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown));
118   propValue.StartSetting();
119   if (!(pObj->*M)(pContext, propValue, sError)) {
120     FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
121                                             sError));
122   }
123 }
124
125 #define JS_STATIC_PROP(prop_name, class_name)                                 \
126   static void get_##prop_name##_static(                                       \
127       v8::Local<v8::String> property,                                         \
128       const v8::PropertyCallbackInfo<v8::Value>& info) {                      \
129     JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \
130                                                      property, info);         \
131   }                                                                           \
132   static void set_##prop_name##_static(                                       \
133       v8::Local<v8::String> property, v8::Local<v8::Value> value,             \
134       const v8::PropertyCallbackInfo<void>& info) {                           \
135     JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \
136                                                      property, value, info);  \
137   }
138
139 template <class C,
140           FX_BOOL (C::*M)(IJS_Context* cc,
141                           const CJS_Parameters& params,
142                           CJS_Value& vRet,
143                           CFX_WideString& sError)>
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   CJS_Runtime* pRuntime =
149       static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
150   if (!pRuntime)
151     return;
152   IJS_Context* cc = pRuntime->GetCurrentContext();
153   CJS_Parameters parameters;
154   for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
155     parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown));
156   }
157   CJS_Value valueRes(pRuntime);
158   CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
159   C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
160   CFX_WideString sError;
161   if (!(pObj->*M)(cc, parameters, valueRes, sError)) {
162     FXJS_Error(isolate, JSFormatErrorString(class_name_string,
163                                             method_name_string, sError));
164     return;
165   }
166   info.GetReturnValue().Set(valueRes.ToV8Value());
167 }
168
169 #define JS_STATIC_METHOD(method_name, class_name)                             \
170   static void method_name##_static(                                           \
171       const v8::FunctionCallbackInfo<v8::Value>& info) {                      \
172     JSMethod<class_name, &class_name::method_name>(#method_name, #class_name, \
173                                                    info);                     \
174   }
175
176 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \
177   static void method_name##_static(                                        \
178       const v8::FunctionCallbackInfo<v8::Value>& info) {                   \
179     JSMethod<class_alternate, &class_alternate::method_name>(              \
180         #method_name, #class_name, info);                                  \
181   }
182
183 // All JS classes have a name, an object defintion ID, and the ability to
184 // register themselves with FXJS_V8. We never make a BASE class on its own
185 // because it can't really do anything.
186 #define DECLARE_JS_CLASS_BASE_PART()  \
187   static const wchar_t* g_pClassName; \
188   static int g_nObjDefnID;            \
189   static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType);
190
191 #define IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name)           \
192   const wchar_t* js_class_name::g_pClassName = JS_WIDESTRING(class_name); \
193   int js_class_name::g_nObjDefnID = -1;
194
195 // CONST classes provide constants, but not constructors, methods, or props.
196 #define DECLARE_JS_CLASS_CONST() \
197   DECLARE_JS_CLASS_BASE_PART()   \
198   DECLARE_JS_CLASS_CONST_PART()
199
200 #define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name)              \
201   IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name)                \
202   IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name)               \
203   void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,             \
204                                       FXJSOBJTYPE eObjType) {            \
205     g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \
206                                   eObjType, nullptr, nullptr);           \
207     DefineConsts(pIsolate);                                              \
208   }
209
210 #define DECLARE_JS_CLASS_CONST_PART()   \
211   static JSConstSpec JS_Class_Consts[]; \
212   static void DefineConsts(v8::Isolate* pIsolate);
213
214 #define IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name)      \
215   void js_class_name::DefineConsts(v8::Isolate* pIsolate) {           \
216     for (size_t i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) {  \
217       FXJS_DefineObjConst(                                            \
218           pIsolate, g_nObjDefnID, JS_Class_Consts[i].pName,           \
219           JS_Class_Consts[i].t == 0                                   \
220               ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number)   \
221               : FXJS_NewString(pIsolate, JS_Class_Consts[i].string)); \
222     }                                                                 \
223   }
224
225 // Convenience macros for declaring classes without an alternate.
226 #define DECLARE_JS_CLASS() DECLARE_JS_CLASS_RICH()
227 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \
228   IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name)
229
230 // Rich JS classes provide constants, methods, properties, and the ability
231 // to construct native object state.
232 #define DECLARE_JS_CLASS_RICH() \
233   DECLARE_JS_CLASS_BASE_PART()  \
234   DECLARE_JS_CLASS_CONST_PART() \
235   DECLARE_JS_CLASS_RICH_PART()
236
237 #define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \
238   IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name)                   \
239   IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name)                  \
240   IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name)  \
241   void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,                \
242                                       FXJSOBJTYPE eObjType) {               \
243     g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName,    \
244                                   eObjType, JSConstructor, JSDestructor);   \
245     DefineConsts(pIsolate);                                                 \
246     DefineProps(pIsolate);                                                  \
247     DefineMethods(pIsolate);                                                \
248   }
249
250 #define DECLARE_JS_CLASS_RICH_PART()                                     \
251   static void JSConstructor(IJS_Context* cc, v8::Local<v8::Object> obj); \
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(IJS_Context* cc,                          \
261                                     v8::Local<v8::Object> obj) {              \
262     CJS_Object* pObj = new js_class_name(obj);                                \
263     pObj->SetEmbedObject(new class_alternate(pObj));                          \
264     FXJS_SetPrivate(nullptr, obj, (void*)pObj);                               \
265     pObj->InitInstance(cc);                                                   \
266   }                                                                           \
267   void js_class_name::JSDestructor(v8::Local<v8::Object> obj) {               \
268     js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(nullptr, obj);      \
269     pObj->ExitInstance();                                                     \
270     delete pObj;                                                              \
271   }                                                                           \
272   void js_class_name::DefineProps(v8::Isolate* pIsolate) {                    \
273     for (size_t i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) {      \
274       FXJS_DefineObjProperty(                                                 \
275           pIsolate, g_nObjDefnID, JS_Class_Properties[i].pName,               \
276           JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut);  \
277     }                                                                         \
278   }                                                                           \
279   void js_class_name::DefineMethods(v8::Isolate* pIsolate) {                  \
280     for (size_t i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) {         \
281       FXJS_DefineObjMethod(pIsolate, g_nObjDefnID, JS_Class_Methods[i].pName, \
282                            JS_Class_Methods[i].pMethodCall);                  \
283     }                                                                         \
284   }
285
286 // Special JS classes implement methods, props, and queries, but not consts.
287 #define DECLARE_SPECIAL_JS_CLASS() \
288   DECLARE_JS_CLASS_BASE_PART()     \
289   DECLARE_JS_CLASS_CONST_PART()    \
290   DECLARE_JS_CLASS_RICH_PART()     \
291   DECLARE_SPECIAL_JS_CLASS_PART()
292
293 #define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \
294   IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name)                      \
295   IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name)                     \
296   IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name)     \
297   IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate, class_name)  \
298   void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,                   \
299                                       FXJSOBJTYPE eObjType) {                  \
300     g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName,       \
301                                   eObjType, JSConstructor, JSDestructor);      \
302     DefineConsts(pIsolate);                                                    \
303     DefineProps(pIsolate);                                                     \
304     DefineMethods(pIsolate);                                                   \
305     DefineAllProperties(pIsolate);                                             \
306   }
307
308 #define DECLARE_SPECIAL_JS_CLASS_PART()                                        \
309   static void queryprop_static(                                                \
310       v8::Local<v8::String> property,                                          \
311       const v8::PropertyCallbackInfo<v8::Integer>& info);                      \
312   static void getprop_static(v8::Local<v8::String> property,                   \
313                              const v8::PropertyCallbackInfo<v8::Value>& info); \
314   static void putprop_static(v8::Local<v8::String> property,                   \
315                              v8::Local<v8::Value> value,                       \
316                              const v8::PropertyCallbackInfo<v8::Value>& info); \
317   static void delprop_static(                                                  \
318       v8::Local<v8::String> property,                                          \
319       const v8::PropertyCallbackInfo<v8::Boolean>& info);                      \
320   static void DefineAllProperties(v8::Isolate* pIsolate);
321
322 #define IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate,    \
323                                         class_name)                        \
324   void js_class_name::queryprop_static(                                    \
325       v8::Local<v8::String> property,                                      \
326       const v8::PropertyCallbackInfo<v8::Integer>& info) {                 \
327     JSSpecialPropQuery<class_alternate>(#class_name, property, info);      \
328   }                                                                        \
329   void js_class_name::getprop_static(                                      \
330       v8::Local<v8::String> property,                                      \
331       const v8::PropertyCallbackInfo<v8::Value>& info) {                   \
332     JSSpecialPropGet<class_alternate>(#class_name, property, info);        \
333   }                                                                        \
334   void js_class_name::putprop_static(                                      \
335       v8::Local<v8::String> property, v8::Local<v8::Value> value,          \
336       const v8::PropertyCallbackInfo<v8::Value>& info) {                   \
337     JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \
338   }                                                                        \
339   void js_class_name::delprop_static(                                      \
340       v8::Local<v8::String> property,                                      \
341       const v8::PropertyCallbackInfo<v8::Boolean>& info) {                 \
342     JSSpecialPropDel<class_alternate>(#class_name, property, info);        \
343   }                                                                        \
344   void js_class_name::DefineAllProperties(v8::Isolate* pIsolate) {         \
345     FXJS_DefineObjAllProperties(                                           \
346         pIsolate, g_nObjDefnID, js_class_name::queryprop_static,           \
347         js_class_name::getprop_static, js_class_name::putprop_static,      \
348         js_class_name::delprop_static);                                    \
349   }
350
351 template <class Alt>
352 void JSSpecialPropQuery(const char*,
353                         v8::Local<v8::String> property,
354                         const v8::PropertyCallbackInfo<v8::Integer>& info) {
355   v8::Isolate* isolate = info.GetIsolate();
356   v8::String::Utf8Value utf8_value(property);
357   CFX_WideString propname =
358       CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
359   CJS_Object* pJSObj =
360       reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
361   Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
362   FX_BOOL bRet = pObj->QueryProperty(propname.c_str());
363   info.GetReturnValue().Set(bRet ? 4 : 0);
364 }
365
366 template <class Alt>
367 void JSSpecialPropGet(const char* class_name,
368                       v8::Local<v8::String> property,
369                       const v8::PropertyCallbackInfo<v8::Value>& info) {
370   v8::Isolate* isolate = info.GetIsolate();
371   CJS_Runtime* pRuntime =
372       static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
373   if (!pRuntime)
374     return;
375   IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
376   CJS_Object* pJSObj =
377       reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
378   Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
379   v8::String::Utf8Value utf8_value(property);
380   CFX_WideString propname =
381       CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
382   CFX_WideString sError;
383   CJS_PropValue value(pRuntime);
384   value.StartGetting();
385   if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) {
386     FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
387     return;
388   }
389   info.GetReturnValue().Set((v8::Local<v8::Value>)value);
390 }
391
392 template <class Alt>
393 void JSSpecialPropPut(const char* class_name,
394                       v8::Local<v8::String> property,
395                       v8::Local<v8::Value> value,
396                       const v8::PropertyCallbackInfo<v8::Value>& info) {
397   v8::Isolate* isolate = info.GetIsolate();
398   CJS_Runtime* pRuntime =
399       static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
400   if (!pRuntime)
401     return;
402   IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
403   CJS_Object* pJSObj =
404       reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
405   Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
406   v8::String::Utf8Value utf8_value(property);
407   CFX_WideString propname =
408       CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
409   CFX_WideString sError;
410   CJS_PropValue PropValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown));
411   PropValue.StartSetting();
412   if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) {
413     FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
414   }
415 }
416
417 template <class Alt>
418 void JSSpecialPropDel(const char* class_name,
419                       v8::Local<v8::String> property,
420                       const v8::PropertyCallbackInfo<v8::Boolean>& info) {
421   v8::Isolate* isolate = info.GetIsolate();
422   IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
423   if (!pRuntime)
424     return;
425   IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
426   CJS_Object* pJSObj =
427       reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
428   Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
429   v8::String::Utf8Value utf8_value(property);
430   CFX_WideString propname =
431       CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
432   CFX_WideString sError;
433   if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) {
434     CFX_ByteString cbName;
435     cbName.Format("%s.%s", class_name, "DelProperty");
436     // Probably a missing call to JSFX_Error().
437   }
438 }
439
440 template <FX_BOOL (*F)(IJS_Context* cc,
441                        const CJS_Parameters& params,
442                        CJS_Value& vRet,
443                        CFX_WideString& sError)>
444 void JSGlobalFunc(const char* func_name_string,
445                   const v8::FunctionCallbackInfo<v8::Value>& info) {
446   CJS_Runtime* pRuntime =
447       static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate()));
448   if (!pRuntime)
449     return;
450   IJS_Context* cc = pRuntime->GetCurrentContext();
451   CJS_Parameters parameters;
452   for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
453     parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown));
454   }
455   CJS_Value valueRes(pRuntime);
456   CFX_WideString sError;
457   if (!(*F)(cc, parameters, valueRes, sError)) {
458     FXJS_Error(pRuntime->GetIsolate(),
459                JSFormatErrorString(func_name_string, nullptr, sError));
460     return;
461   }
462   info.GetReturnValue().Set(valueRes.ToV8Value());
463 }
464
465 #define JS_STATIC_GLOBAL_FUN(fun_name)                   \
466   static void fun_name##_static(                         \
467       const v8::FunctionCallbackInfo<v8::Value>& info) { \
468     JSGlobalFunc<fun_name>(#fun_name, info);             \
469   }
470
471 #define JS_STATIC_DECLARE_GLOBAL_FUN()  \
472   static JSMethodSpec global_methods[]; \
473   static void DefineJSObjects(v8::Isolate* pIsolate)
474
475 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \
476   JSMethodSpec js_class_name::global_methods[] = {
477 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \
478   JS_STATIC_METHOD_ENTRY(method_name)
479
480 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD()
481
482 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name)                        \
483   void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) {               \
484     for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) {          \
485       FXJS_DefineGlobalMethod(pIsolate,                                      \
486                               js_class_name::global_methods[i].pName,        \
487                               js_class_name::global_methods[i].pMethodCall); \
488     }                                                                        \
489   }
490
491 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p);
492
493 #endif  // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_