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