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