CJS_Context::compile unused
[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_Execute(IJS_Runtime* pJSRuntime,
95                IFXJS_Context* pJSContext,
96                const wchar_t* script,
97                long length,
98                FXJSErr* perror);
99 v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime,
100                                          IFXJS_Context* pJSContext,
101                                          int nObjDefnID);
102 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID);
103 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID);
104 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime* pJSRuntime);
105 int JS_GetObjDefnID(v8::Local<v8::Object> pObj);
106 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj);
107 int JS_GetObjDefnID(IJS_Runtime* pJSRuntime, const wchar_t* pObjName);
108 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message);
109 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen);
110 unsigned JS_CalcHash(const wchar_t* main);
111 const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj);
112 void JS_SetPrivate(IJS_Runtime* pJSRuntime,
113                    v8::Local<v8::Object> pObj,
114                    void* p);
115 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, 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(IJS_Runtime* pJSRuntime,
122                                          v8::Local<v8::Object> pObj,
123                                          const wchar_t* PropertyName);
124 v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime,
125                                               v8::Local<v8::Object> pObj);
126 void JS_PutObjectString(IJS_Runtime* pJSRuntime,
127                         v8::Local<v8::Object> pObj,
128                         const wchar_t* PropertyName,
129                         const wchar_t* sValue);
130 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,
131                         v8::Local<v8::Object> pObj,
132                         const wchar_t* PropertyName,
133                         int nValue);
134 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,
135                         v8::Local<v8::Object> pObj,
136                         const wchar_t* PropertyName,
137                         float fValue);
138 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,
139                         v8::Local<v8::Object> pObj,
140                         const wchar_t* PropertyName,
141                         double dValue);
142 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,
143                          v8::Local<v8::Object> pObj,
144                          const wchar_t* PropertyName,
145                          bool bValue);
146 void JS_PutObjectObject(IJS_Runtime* pJSRuntime,
147                         v8::Local<v8::Object> pObj,
148                         const wchar_t* PropertyName,
149                         v8::Local<v8::Object> pPut);
150 void JS_PutObjectNull(IJS_Runtime* pJSRuntime,
151                       v8::Local<v8::Object> pObj,
152                       const wchar_t* PropertyName);
153 unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime,
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(IJS_Runtime* pJSRuntime,
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(IJS_Runtime* pJSRuntime,
163                                      v8::Local<v8::Value> pList,
164                                      int index);
165
166 v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime);
167 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, int number);
168 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, double number);
169 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, float number);
170 v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime, bool b);
171 v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,
172                                   v8::Local<v8::Object> pObj);
173 v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,
174                                    v8::Local<v8::Array> pObj);
175 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,
176                                   const wchar_t* string);
177 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,
178                                   const wchar_t* string,
179                                   unsigned nLen);
180 v8::Local<v8::Value> JS_NewNull();
181 v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime, double d);
182 v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime);
183
184 int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
185 bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
186 double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
187 v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime,
188                                   v8::Local<v8::Value> pValue);
189 CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime,
190                            v8::Local<v8::Value> pValue);
191 v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime,
192                                 v8::Local<v8::Value> pValue);
193 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom);
194
195 double JS_GetDateTime();
196 int JS_GetYearFromTime(double dt);
197 int JS_GetMonthFromTime(double dt);
198 int JS_GetDayFromTime(double dt);
199 int JS_GetHourFromTime(double dt);
200 int JS_GetMinFromTime(double dt);
201 int JS_GetSecFromTime(double dt);
202 double JS_DateParse(const wchar_t* string);
203 double JS_MakeDay(int nYear, int nMonth, int nDay);
204 double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
205 double JS_MakeDate(double day, double time);
206 bool JS_PortIsNan(double d);
207 double JS_LocalTime(double d);
208
209 #endif  // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_