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