OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 // PDFium wrapper around V8 APIs. PDFium code should include this file rather | 7 // PDFium wrapper around V8 APIs. PDFium code should include this file rather |
8 // than including V8 headers directly. | 8 // than including V8 headers directly. |
9 | 9 |
10 #ifndef FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 10 #ifndef FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
11 #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 11 #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
12 | 12 |
13 #include <v8.h> | 13 #include <v8.h> |
14 #include "../../../core/include/fxcrt/fx_string.h" // For CFX_WideString | 14 #include "../../../core/include/fxcrt/fx_string.h" // For CFX_WideString |
15 | 15 |
16 typedef v8::Value» » » JSValue; | 16 typedef v8::Value JSValue; |
17 typedef v8::Local<v8::Object>» JSObject; | 17 typedef v8::Local<v8::Object> JSObject; |
18 typedef v8::Local<v8::Object>» JSFXObject; | 18 typedef v8::Local<v8::Object> JSFXObject; |
19 | 19 |
20 enum FXJSOBJTYPE | 20 enum FXJSOBJTYPE { |
21 { | 21 JS_DYNAMIC = 0, |
22 » JS_DYNAMIC = 0, | 22 JS_STATIC = 1, |
23 » JS_STATIC = 1, | |
24 }; | 23 }; |
25 | 24 |
26 enum FXJSVALUETYPE | 25 enum FXJSVALUETYPE { |
27 { | 26 VT_unknown, |
28 » VT_unknown, | 27 VT_string, |
29 » VT_string, | 28 VT_number, |
30 » VT_number, | 29 VT_boolean, |
31 » VT_boolean, | 30 VT_date, |
32 » VT_date, | 31 VT_object, |
33 » VT_object, | 32 VT_fxobject, |
34 » VT_fxobject, | 33 VT_null, |
35 » VT_null, | 34 VT_undefined |
36 » VT_undefined | |
37 }; | 35 }; |
38 | 36 |
39 struct FXJSErr | 37 struct FXJSErr { |
40 { | 38 const wchar_t* message; |
41 » const wchar_t* message; | 39 const wchar_t* srcline; |
42 const wchar_t* srcline; | 40 unsigned linnum; |
43 unsigned linnum; | |
44 }; | 41 }; |
45 | 42 |
46 /* --------------------------------------------- API ---------------------------
------------------ */ | 43 /* --------------------------------------------- API |
| 44 * --------------------------------------------- */ |
47 | 45 |
48 typedef v8::Isolate IJS_Runtime; | 46 typedef v8::Isolate IJS_Runtime; |
49 class IFXJS_Context; | 47 class IFXJS_Context; |
50 class IFXJS_Runtime; | 48 class IFXJS_Runtime; |
51 | 49 |
52 typedef void (*LP_CONSTRUCTOR)(IFXJS_Context* cc, v8::Local<v8::Object> obj, v8:
:Local<v8::Object> global); | 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); | 53 typedef void (*LP_DESTRUCTOR)(v8::Local<v8::Object> obj); |
54 | 54 |
55 | 55 int JS_DefineObj(IJS_Runtime* pJSRuntime, |
56 int JS_DefineObj(IJS
_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE eObjType, LP_CONSTRUC
TOR pConstructor, LP_DESTRUCTOR pDestructor); | 56 const wchar_t* sObjName, |
57 int JS_DefineObjMeth
od(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sMethodName, v8::Func
tionCallback pMethodCall); | 57 FXJSOBJTYPE eObjType, |
58 int JS_DefineObjProp
erty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sPropName, v8::Acce
ssorGetterCallback pPropGet, v8::AccessorSetterCallback pPropPut); | 58 LP_CONSTRUCTOR pConstructor, |
59 int JS_DefineObjAllP
roperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::NamedPropertyQueryCallbac
k pPropQurey, v8::NamedPropertyGetterCallback pPropGet, v8::NamedPropertySetterC
allback pPropPut, v8::NamedPropertyDeleterCallback pPropDel); | 59 LP_DESTRUCTOR pDestructor); |
60 int JS_DefineObjCons
t(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sConstName, v8::Local<
v8::Value> pDefault); | 60 int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, |
61 int JS_DefineGlobalM
ethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v8::FunctionCallback
pMethodCall); | 61 int nObjDefnID, |
62 int JS_DefineGlobalC
onst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8::Local<v8::Value> pD
efault); | 62 const wchar_t* sMethodName, |
63 | 63 v8::FunctionCallback pMethodCall); |
64 void JS_InitialRuntime(IJS_Ru
ntime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Global<
v8::Context>& v8PersistentContext); | 64 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, |
65 void JS_ReleaseRuntime(IJS_Ru
ntime* pJSRuntime, v8::Global<v8::Context>& v8PersistentContext); | 65 int nObjDefnID, |
66 void JS_Initial(unsigned int
embedderDataSlot); | 66 const wchar_t* sPropName, |
67 void JS_Release(); | 67 v8::AccessorGetterCallback pPropGet, |
68 int JS_Parse(IJS_Run
time* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length,
FXJSErr* perror); | 68 v8::AccessorSetterCallback pPropPut); |
69 int JS_Execute(IJS_R
untime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long lengt
h, FXJSErr* perror); | 69 int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, |
70 v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRunti
me, IFXJS_Context* pJSContext, int nObjDefnID); | 70 int nObjDefnID, |
71 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime,
int nObjDefnID); | 71 v8::NamedPropertyQueryCallback pPropQurey, |
72 void JS_SetThisObj(IJS_Runtim
e* pJSRuntime, int nThisObjID); | 72 v8::NamedPropertyGetterCallback pPropGet, |
73 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime); | 73 v8::NamedPropertySetterCallback pPropPut, |
74 int JS_GetObjDefnID(
v8::Local<v8::Object> pObj); | 74 v8::NamedPropertyDeleterCallback pPropDel); |
75 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Obje
ct> pObj); | 75 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, |
76 int JS_GetObjDefnID(
IJS_Runtime * pJSRuntime, const wchar_t* pObjName); | 76 int nObjDefnID, |
77 void JS_Error(v8::Isolate* is
olate, const CFX_WideString& message); | 77 const wchar_t* sConstName, |
78 unsigned JS_CalcHash(const wchar_
t* main, unsigned nLen); | 78 v8::Local<v8::Value> pDefault); |
79 unsigned JS_CalcHash(const wchar_
t* main); | 79 int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, |
80 const wchar_t* JS_GetTypeof(v8::Local<v8::Value
> pObj); | 80 const wchar_t* sMethodName, |
81 void JS_SetPrivate(IJS_Runtim
e* pJSRuntime, v8::Local<v8::Object> pObj, void* p); | 81 v8::FunctionCallback pMethodCall); |
82 void* JS_GetPrivate(IJS_Runtim
e* pJSRuntime, v8::Local<v8::Object> pObj); | 82 int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, |
83 void JS_SetPrivate(v8::Local<
v8::Object> pObj, void* p); | 83 const wchar_t* sConstName, |
84 void* JS_GetPrivate(v8::Local<
v8::Object> pObj); | 84 v8::Local<v8::Value> pDefault); |
85 void JS_FreePrivate(void* p); | 85 |
86 void JS_FreePrivate(v8::Local
<v8::Object> pObj); | 86 void JS_InitialRuntime(IJS_Runtime* pJSRuntime, |
87 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object>
pObj); | 87 IFXJS_Runtime* pFXRuntime, |
88 v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRunt
ime, v8::Local<v8::Object> pObj,const wchar_t* PropertyName); | 88 IFXJS_Context* context, |
89 v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJ
SRuntime, v8::Local<v8::Object> pObj); | 89 v8::Global<v8::Context>& v8PersistentContext); |
90 void JS_PutObjectString(IJS_R
untime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, cons
t wchar_t* sValue); | 90 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, |
91 void JS_PutObjectNumber(IJS_R
untime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, int
nValue); | 91 v8::Global<v8::Context>& v8PersistentContext); |
92 void JS_PutObjectNumber(IJS_R
untime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, floa
t fValue); | 92 void JS_Initial(unsigned int embedderDataSlot); |
93 void JS_PutObjectNumber(IJS_R
untime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, doub
le dValue); | 93 void JS_Release(); |
94 void JS_PutObjectBoolean(IJS_
Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, boo
l bValue); | 94 int JS_Parse(IJS_Runtime* pJSRuntime, |
95 void JS_PutObjectObject(IJS_R
untime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, v8::
Local<v8::Object> pPut); | 95 IFXJS_Context* pJSContext, |
96 void JS_PutObjectNull(IJS_Run
time* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName); | 96 const wchar_t* script, |
97 unsigned JS_PutArrayElement(IJS_R
untime* pJSRuntime, v8::Local<v8::Array> pArray,unsigned index,v8::Local<v8::Val
ue> pValue,FXJSVALUETYPE eType); | 97 long length, |
98 v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRunti
me, v8::Local<v8::Array> pArray,unsigned index); | 98 FXJSErr* perror); |
99 unsigned JS_GetArrayLength(v8::Lo
cal<v8::Array> pArray); | 99 int JS_Execute(IJS_Runtime* pJSRuntime, |
100 v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime,
v8::Local<v8::Value> pList, int index); | 100 IFXJS_Context* pJSContext, |
101 | 101 const wchar_t* script, |
102 | 102 long length, |
103 v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime); | 103 FXJSErr* perror); |
104 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int
number); | 104 v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, |
105 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,dou
ble number); | 105 IFXJS_Context* pJSContext, |
106 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,flo
at number); | 106 int nObjDefnID); |
107 v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bo
ol b); | 107 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID); |
108 v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8:
:Local<v8::Object> pObj); | 108 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID); |
109 v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8
::Local<v8::Array> pObj); | 109 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime* pJSRuntime); |
110 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,con
st wchar_t* string); | 110 int JS_GetObjDefnID(v8::Local<v8::Object> pObj); |
111 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,con
st wchar_t* string, unsigned nLen); | 111 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj); |
112 v8::Local<v8::Value> JS_NewNull(); | 112 int JS_GetObjDefnID(IJS_Runtime* pJSRuntime, const wchar_t* pObjName); |
113 v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,doubl
e d); | 113 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message); |
114 v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime); | 114 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen); |
115 | 115 unsigned JS_CalcHash(const wchar_t* main); |
116 | 116 const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj); |
117 int JS_ToInt32(IJS_R
untime* pJSRuntime, v8::Local<v8::Value> pValue); | 117 void JS_SetPrivate(IJS_Runtime* pJSRuntime, |
118 bool JS_ToBoolean(IJS_Runtime
* pJSRuntime, v8::Local<v8::Value> pValue); | 118 v8::Local<v8::Object> pObj, |
119 double JS_ToNumber(IJS_Runtime*
pJSRuntime, v8::Local<v8::Value> pValue); | 119 void* p); |
120 v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, v8:
:Local<v8::Value> pValue); | 120 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj); |
121 CFX_WideString JS_ToString(IJS_Runtime* pJSRunt
ime, v8::Local<v8::Value> pValue); | 121 void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p); |
122 v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, v8::
Local<v8::Value> pValue); | 122 void* JS_GetPrivate(v8::Local<v8::Object> pObj); |
123 void JS_ValueCopy(v8::Local<v
8::Value>& pTo, v8::Local<v8::Value> pFrom); | 123 void JS_FreePrivate(void* p); |
124 | 124 void JS_FreePrivate(v8::Local<v8::Object> pObj); |
125 double JS_GetDateTime(); | 125 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj); |
126 int JS_GetYearFromTi
me(double dt); | 126 v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, |
127 int JS_GetMonthFromT
ime(double dt); | 127 v8::Local<v8::Object> pObj, |
128 int JS_GetDayFromTim
e(double dt); | 128 const wchar_t* PropertyName); |
129 int JS_GetHourFromTi
me(double dt); | 129 v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, |
130 int JS_GetMinFromTim
e(double dt); | 130 v8::Local<v8::Object> pObj); |
131 int JS_GetSecFromTim
e(double dt); | 131 void JS_PutObjectString(IJS_Runtime* pJSRuntime, |
132 double JS_DateParse(const wchar
_t* string); | 132 v8::Local<v8::Object> pObj, |
133 double JS_MakeDay(int nYear, in
t nMonth, int nDay); | 133 const wchar_t* PropertyName, |
134 double JS_MakeTime(int nHour, i
nt nMin, int nSec, int nMs); | 134 const wchar_t* sValue); |
135 double JS_MakeDate(double day,
double time); | 135 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, |
136 bool JS_PortIsNan(double d); | 136 v8::Local<v8::Object> pObj, |
137 double JS_LocalTime(double d); | 137 const wchar_t* PropertyName, |
| 138 int nValue); |
| 139 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, |
| 140 v8::Local<v8::Object> pObj, |
| 141 const wchar_t* PropertyName, |
| 142 float fValue); |
| 143 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime, |
| 144 v8::Local<v8::Object> pObj, |
| 145 const wchar_t* PropertyName, |
| 146 double dValue); |
| 147 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime, |
| 148 v8::Local<v8::Object> pObj, |
| 149 const wchar_t* PropertyName, |
| 150 bool bValue); |
| 151 void JS_PutObjectObject(IJS_Runtime* pJSRuntime, |
| 152 v8::Local<v8::Object> pObj, |
| 153 const wchar_t* PropertyName, |
| 154 v8::Local<v8::Object> pPut); |
| 155 void JS_PutObjectNull(IJS_Runtime* pJSRuntime, |
| 156 v8::Local<v8::Object> pObj, |
| 157 const wchar_t* PropertyName); |
| 158 unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, |
| 159 v8::Local<v8::Array> pArray, |
| 160 unsigned index, |
| 161 v8::Local<v8::Value> pValue, |
| 162 FXJSVALUETYPE eType); |
| 163 v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, |
| 164 v8::Local<v8::Array> pArray, |
| 165 unsigned index); |
| 166 unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray); |
| 167 v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, |
| 168 v8::Local<v8::Value> pList, |
| 169 int index); |
| 170 |
| 171 v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime); |
| 172 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, int number); |
| 173 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, double number); |
| 174 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, float number); |
| 175 v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime, bool b); |
| 176 v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime, |
| 177 v8::Local<v8::Object> pObj); |
| 178 v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime, |
| 179 v8::Local<v8::Array> pObj); |
| 180 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, |
| 181 const wchar_t* string); |
| 182 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime, |
| 183 const wchar_t* string, |
| 184 unsigned nLen); |
| 185 v8::Local<v8::Value> JS_NewNull(); |
| 186 v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime, double d); |
| 187 v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime); |
| 188 |
| 189 int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); |
| 190 bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); |
| 191 double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); |
| 192 v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, |
| 193 v8::Local<v8::Value> pValue); |
| 194 CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, |
| 195 v8::Local<v8::Value> pValue); |
| 196 v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, |
| 197 v8::Local<v8::Value> pValue); |
| 198 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom); |
| 199 |
| 200 double JS_GetDateTime(); |
| 201 int JS_GetYearFromTime(double dt); |
| 202 int JS_GetMonthFromTime(double dt); |
| 203 int JS_GetDayFromTime(double dt); |
| 204 int JS_GetHourFromTime(double dt); |
| 205 int JS_GetMinFromTime(double dt); |
| 206 int JS_GetSecFromTime(double dt); |
| 207 double JS_DateParse(const wchar_t* string); |
| 208 double JS_MakeDay(int nYear, int nMonth, int nDay); |
| 209 double JS_MakeTime(int nHour, int nMin, int nSec, int nMs); |
| 210 double JS_MakeDate(double day, double time); |
| 211 bool JS_PortIsNan(double d); |
| 212 double JS_LocalTime(double d); |
138 | 213 |
139 #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ | 214 #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
OLD | NEW |