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