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