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