clang-format all pdfium code.
[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 FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_
11 #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_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::Local<v8::Object> JSObject;
18 typedef v8::Local<v8::Object> JSFXObject;
19
20 enum FXJSOBJTYPE {
21   JS_DYNAMIC = 0,
22   JS_STATIC = 1,
23 };
24
25 enum FXJSVALUETYPE {
26   VT_unknown,
27   VT_string,
28   VT_number,
29   VT_boolean,
30   VT_date,
31   VT_object,
32   VT_fxobject,
33   VT_null,
34   VT_undefined
35 };
36
37 struct FXJSErr {
38   const wchar_t* message;
39   const wchar_t* srcline;
40   unsigned linnum;
41 };
42
43 /* --------------------------------------------- API
44  * --------------------------------------------- */
45
46 typedef v8::Isolate IJS_Runtime;
47 class IFXJS_Context;
48 class IFXJS_Runtime;
49
50 typedef void (*LP_CONSTRUCTOR)(IFXJS_Context* cc,
51                                v8::Local<v8::Object> obj,
52                                v8::Local<v8::Object> global);
53 typedef void (*LP_DESTRUCTOR)(v8::Local<v8::Object> obj);
54
55 int JS_DefineObj(IJS_Runtime* pJSRuntime,
56                  const wchar_t* sObjName,
57                  FXJSOBJTYPE eObjType,
58                  LP_CONSTRUCTOR pConstructor,
59                  LP_DESTRUCTOR pDestructor);
60 int JS_DefineObjMethod(IJS_Runtime* pJSRuntime,
61                        int nObjDefnID,
62                        const wchar_t* sMethodName,
63                        v8::FunctionCallback pMethodCall);
64 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime,
65                          int nObjDefnID,
66                          const wchar_t* sPropName,
67                          v8::AccessorGetterCallback pPropGet,
68                          v8::AccessorSetterCallback pPropPut);
69 int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime,
70                               int nObjDefnID,
71                               v8::NamedPropertyQueryCallback pPropQurey,
72                               v8::NamedPropertyGetterCallback pPropGet,
73                               v8::NamedPropertySetterCallback pPropPut,
74                               v8::NamedPropertyDeleterCallback pPropDel);
75 int JS_DefineObjConst(IJS_Runtime* pJSRuntime,
76                       int nObjDefnID,
77                       const wchar_t* sConstName,
78                       v8::Local<v8::Value> pDefault);
79 int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime,
80                           const wchar_t* sMethodName,
81                           v8::FunctionCallback pMethodCall);
82 int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime,
83                          const wchar_t* sConstName,
84                          v8::Local<v8::Value> pDefault);
85
86 void JS_InitialRuntime(IJS_Runtime* pJSRuntime,
87                        IFXJS_Runtime* pFXRuntime,
88                        IFXJS_Context* context,
89                        v8::Global<v8::Context>& v8PersistentContext);
90 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime,
91                        v8::Global<v8::Context>& v8PersistentContext);
92 void JS_Initial(unsigned int embedderDataSlot);
93 void JS_Release();
94 int JS_Parse(IJS_Runtime* pJSRuntime,
95              IFXJS_Context* pJSContext,
96              const wchar_t* script,
97              long length,
98              FXJSErr* perror);
99 int JS_Execute(IJS_Runtime* pJSRuntime,
100                IFXJS_Context* pJSContext,
101                const wchar_t* script,
102                long length,
103                FXJSErr* perror);
104 v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime,
105                                          IFXJS_Context* pJSContext,
106                                          int nObjDefnID);
107 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID);
108 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID);
109 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime* pJSRuntime);
110 int JS_GetObjDefnID(v8::Local<v8::Object> pObj);
111 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj);
112 int JS_GetObjDefnID(IJS_Runtime* pJSRuntime, const wchar_t* pObjName);
113 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message);
114 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen);
115 unsigned JS_CalcHash(const wchar_t* main);
116 const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj);
117 void JS_SetPrivate(IJS_Runtime* pJSRuntime,
118                    v8::Local<v8::Object> pObj,
119                    void* p);
120 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj);
121 void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p);
122 void* JS_GetPrivate(v8::Local<v8::Object> pObj);
123 void JS_FreePrivate(void* p);
124 void JS_FreePrivate(v8::Local<v8::Object> pObj);
125 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj);
126 v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime,
127                                          v8::Local<v8::Object> pObj,
128                                          const wchar_t* PropertyName);
129 v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime,
130                                               v8::Local<v8::Object> pObj);
131 void JS_PutObjectString(IJS_Runtime* pJSRuntime,
132                         v8::Local<v8::Object> pObj,
133                         const wchar_t* PropertyName,
134                         const wchar_t* sValue);
135 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,
136                         v8::Local<v8::Object> pObj,
137                         const wchar_t* PropertyName,
138                         int nValue);
139 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,
140                         v8::Local<v8::Object> pObj,
141                         const wchar_t* PropertyName,
142                         float fValue);
143 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,
144                         v8::Local<v8::Object> pObj,
145                         const wchar_t* PropertyName,
146                         double dValue);
147 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,
148                          v8::Local<v8::Object> pObj,
149                          const wchar_t* PropertyName,
150                          bool bValue);
151 void JS_PutObjectObject(IJS_Runtime* pJSRuntime,
152                         v8::Local<v8::Object> pObj,
153                         const wchar_t* PropertyName,
154                         v8::Local<v8::Object> pPut);
155 void JS_PutObjectNull(IJS_Runtime* pJSRuntime,
156                       v8::Local<v8::Object> pObj,
157                       const wchar_t* PropertyName);
158 unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime,
159                             v8::Local<v8::Array> pArray,
160                             unsigned index,
161                             v8::Local<v8::Value> pValue,
162                             FXJSVALUETYPE eType);
163 v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime,
164                                         v8::Local<v8::Array> pArray,
165                                         unsigned index);
166 unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray);
167 v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime,
168                                      v8::Local<v8::Value> pList,
169                                      int index);
170
171 v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime);
172 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, int number);
173 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, double number);
174 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, float number);
175 v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime, bool b);
176 v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,
177                                   v8::Local<v8::Object> pObj);
178 v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,
179                                    v8::Local<v8::Array> pObj);
180 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,
181                                   const wchar_t* string);
182 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,
183                                   const wchar_t* string,
184                                   unsigned nLen);
185 v8::Local<v8::Value> JS_NewNull();
186 v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime, double d);
187 v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime);
188
189 int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
190 bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
191 double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
192 v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime,
193                                   v8::Local<v8::Value> pValue);
194 CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime,
195                            v8::Local<v8::Value> pValue);
196 v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime,
197                                 v8::Local<v8::Value> pValue);
198 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom);
199
200 double JS_GetDateTime();
201 int JS_GetYearFromTime(double dt);
202 int JS_GetMonthFromTime(double dt);
203 int JS_GetDayFromTime(double dt);
204 int JS_GetHourFromTime(double dt);
205 int JS_GetMinFromTime(double dt);
206 int JS_GetSecFromTime(double dt);
207 double JS_DateParse(const wchar_t* string);
208 double JS_MakeDay(int nYear, int nMonth, int nDay);
209 double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
210 double JS_MakeDate(double day, double time);
211 bool JS_PortIsNan(double d);
212 double JS_LocalTime(double d);
213
214 #endif  // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_