e08196d6f18becabc735ea7d9483ca190674e7c7
[pdfium.git] / fpdfsdk / include / jsapi / fxjs_v8.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 FXJSAPI_H
8 #define FXJSAPI_H
9
10 #include <v8.h>
11
12 enum FXJSOBJTYPE
13 {
14         JS_DYNAMIC = 0,
15         JS_STATIC = 1,
16 };
17
18 enum FXJSVALUETYPE
19 {
20         VT_unknown,
21         VT_string,
22         VT_number,
23         VT_boolean,
24         VT_date,
25         VT_object,
26         VT_fxobject,
27         VT_null,
28         VT_undefined
29 };
30
31 struct FXJSErr
32 {
33         const wchar_t* message; 
34     const wchar_t* srcline;     
35     unsigned linnum;
36 };
37
38 /* --------------------------------------------- API --------------------------------------------- */
39
40 typedef v8::Isolate IJS_Runtime;
41 class IFXJS_Context;
42 class IFXJS_Runtime;
43
44
45 #ifndef JSCRIPT_ARGS
46 #define JSCRIPT_ARGS
47
48 #define JS_CONSTRUCTOR_ARGS             IFXJS_Context* cc, v8::Handle<v8::Object> obj, v8::Handle<v8::Object> global
49 #define JS_DESTRUCTOR_ARGS              v8::Handle<v8::Object> obj
50
51 #define JS_PROPQUERY_ARGS               v8::Local<v8::String> property,const v8::PropertyCallbackInfo<v8::Integer>& info
52 #define JS_NAMED_PROPGET_ARGS           v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info
53
54 #define JS_NAMED_PROPPUT_ARGS   v8::Local<v8::String> property,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<v8::Value>& info
55 #define JS_PROPDEL_ARGS                 v8::Local<v8::String> property,const v8::PropertyCallbackInfo<v8::Boolean>& info
56
57 typedef unsigned (*LP_CONSTRUCTOR)(JS_CONSTRUCTOR_ARGS);
58 typedef unsigned (*LP_DESTRUCTOR)(JS_DESTRUCTOR_ARGS);
59
60 #endif
61
62 int                                                             JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned bApplyNew);
63 int                                                             JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall, unsigned nParamNum);
64 int                                                             JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPropPut);
65 int                                                             JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::NamedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet, v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pPropDel);
66 int                                                             JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sConstName, v8::Handle<v8::Value> pDefault);
67 int                                                             JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall, unsigned nParamNum);
68 int                                                             JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8::Handle<v8::Value> pDefault);
69
70 void                                                    JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Persistent<v8::Context>& v8PersistentContext);
71 void                                                    JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8PersistentContext);
72 void                                                    JS_Initial(); 
73 void                                                    JS_Release();
74 int                                                             JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
75 int                                                             JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
76 v8::Handle<v8::Object>                  JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, int nObjDefnID);
77 v8::Handle<v8::Object>                  JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID);
78 void                                                    JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID);
79 v8::Handle<v8::Object>                  JS_GetThisObj(IJS_Runtime * pJSRuntime);
80 int                                                             JS_GetObjDefnID(v8::Handle<v8::Object> pObj);
81 IJS_Runtime*                                    JS_GetRuntime(v8::Handle<v8::Object> pObj);
82 int                                                             JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName);
83 void                                                    JS_Error(v8::Value * pError,const wchar_t * main,const wchar_t * sub);
84 unsigned                                                JS_CalcHash(const wchar_t* main, unsigned nLen);
85 unsigned                                                JS_CalcHash(const wchar_t* main);
86 const wchar_t*                                  JS_GetTypeof(v8::Handle<v8::Value> pObj);
87 const wchar_t*                                  JS_GetClassname(v8::Handle<v8::Object> pObj);
88 void                                                    JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj, void* p);
89 void*                                                   JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj);
90 void                                                    JS_SetPrivate(v8::Handle<v8::Object> pObj, void* p);
91 void*                                                   JS_GetPrivate(v8::Handle<v8::Object> pObj);
92 void                                                    JS_FreePrivate(v8::Handle<v8::Object> pObj);
93 v8::Handle<v8::Value>                   JS_GetObjectValue(v8::Handle<v8::Object> pObj);
94 v8::Handle<v8::Value>                   JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj,const wchar_t* PropertyName);
95 v8::Handle<v8::Array>                   JS_GetObjectElementNames(v8::Handle<v8::Object> pObj);
96 void                                                    JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, const wchar_t* sValue);
97 void                                                    JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, int nValue);
98 void                                                    JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, float fValue);
99 void                                                    JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, double dValue);
100 void                                                    JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, bool bValue);
101 void                                                    JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, v8::Handle<v8::Object> pPut);
102 void                                                    JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName);
103 unsigned                                                JS_PutArrayElement(v8::Handle<v8::Array> pArray,unsigned index,v8::Handle<v8::Value> pValue,FXJSVALUETYPE eType);
104 v8::Handle<v8::Value>                   JS_GetArrayElemnet(v8::Handle<v8::Array> pArray,unsigned index);
105 unsigned                                                JS_GetArrayLength(v8::Handle<v8::Array> pArray);
106 v8::Handle<v8::Value>                   JS_GetListValue(v8::Handle<v8::Value> pList, int index);
107
108
109 v8::Handle<v8::Array>                   JS_NewArray(IJS_Runtime* pJSRuntime);
110 v8::Handle<v8::Value>                   JS_NewNumber(IJS_Runtime* pJSRuntime,int number);
111 v8::Handle<v8::Value>                   JS_NewNumber(IJS_Runtime* pJSRuntime,double number);
112 v8::Handle<v8::Value>                   JS_NewNumber(IJS_Runtime* pJSRuntime,float number);
113 v8::Handle<v8::Value>                   JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b);
114 v8::Handle<v8::Value>                   JS_NewObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj);
115 v8::Handle<v8::Value>                   JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Handle<v8::Array> pObj);
116 v8::Handle<v8::Value>                   JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string);
117 v8::Handle<v8::Value>                   JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string, unsigned nLen);
118 v8::Handle<v8::Value>                   JS_NewNull();
119 v8::Handle<v8::Value>                   JS_NewDate(IJS_Runtime* pJSRuntime,double d);
120 v8::Handle<v8::Value>                   JS_NewValue(IJS_Runtime* pJSRuntime);
121
122
123 int                                                             JS_ToInt32(v8::Handle<v8::Value> pValue);
124 bool                                                    JS_ToBoolean(v8::Handle<v8::Value> pValue);
125 double                                                  JS_ToNumber(v8::Handle<v8::Value> pValue);
126 v8::Handle<v8::Object>                  JS_ToObject(v8::Handle<v8::Value> pValue);
127 CFX_WideString                                  JS_ToString(v8::Handle<v8::Value> pValue);
128 v8::Handle<v8::Array>                   JS_ToArray(v8::Handle<v8::Value> pValue);
129 void                                                    JS_ValueCopy(v8::Handle<v8::Value>& pTo, v8::Handle<v8::Value> pFrom);
130
131 double                                                  JS_GetDateTime();
132 int                                                             JS_GetYearFromTime(double dt);
133 int                                                             JS_GetMonthFromTime(double dt);
134 int                                                             JS_GetDayFromTime(double dt);
135 int                                                             JS_GetHourFromTime(double dt);
136 int                                                             JS_GetMinFromTime(double dt);
137 int                                                             JS_GetSecFromTime(double dt);
138 double                                                  JS_DateParse(const wchar_t* string);
139 double                                                  JS_MakeDay(int nYear, int nMonth, int nDay);
140 double                                                  JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
141 double                                                  JS_MakeDate(double day, double time);
142 bool                                                    JS_PortIsNan(double d);
143 double                                                  JS_LocalTime(double d);
144
145 #endif //FXJSAPI_H