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