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