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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 // PDFium wrapper around V8 APIs. PDFium code should include this file rather
8 // than including V8 headers directly.
10 #ifndef FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_
11 #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_
14 #include "../../../core/include/fxcrt/fx_string.h" // For CFX_WideString
34 const wchar_t* message;
35 const wchar_t* srcline;
39 /* --------------------------------------------- API
40 * --------------------------------------------- */
45 typedef void (*LP_CONSTRUCTOR)(IFXJS_Context* cc,
46 v8::Local<v8::Object> obj,
47 v8::Local<v8::Object> global);
48 typedef void (*LP_DESTRUCTOR)(v8::Local<v8::Object> obj);
50 int JS_DefineObj(v8::Isolate* pIsolate,
51 const wchar_t* sObjName,
53 LP_CONSTRUCTOR pConstructor,
54 LP_DESTRUCTOR pDestructor);
55 int JS_DefineObjMethod(v8::Isolate* pIsolate,
57 const wchar_t* sMethodName,
58 v8::FunctionCallback pMethodCall);
59 int JS_DefineObjProperty(v8::Isolate* pIsolate,
61 const wchar_t* sPropName,
62 v8::AccessorGetterCallback pPropGet,
63 v8::AccessorSetterCallback pPropPut);
64 int JS_DefineObjAllProperties(v8::Isolate* pIsolate,
66 v8::NamedPropertyQueryCallback pPropQurey,
67 v8::NamedPropertyGetterCallback pPropGet,
68 v8::NamedPropertySetterCallback pPropPut,
69 v8::NamedPropertyDeleterCallback pPropDel);
70 int JS_DefineObjConst(v8::Isolate* pIsolate,
72 const wchar_t* sConstName,
73 v8::Local<v8::Value> pDefault);
74 int JS_DefineGlobalMethod(v8::Isolate* pIsolate,
75 const wchar_t* sMethodName,
76 v8::FunctionCallback pMethodCall);
77 int JS_DefineGlobalConst(v8::Isolate* pIsolate,
78 const wchar_t* sConstName,
79 v8::Local<v8::Value> pDefault);
81 void JS_InitialRuntime(v8::Isolate* pIsolate,
82 IFXJS_Runtime* pFXRuntime,
83 IFXJS_Context* context,
84 v8::Global<v8::Context>& v8PersistentContext);
85 void JS_ReleaseRuntime(v8::Isolate* pIsolate,
86 v8::Global<v8::Context>& v8PersistentContext);
87 void JS_Initial(unsigned int embedderDataSlot);
89 int JS_Execute(v8::Isolate* pIsolate,
90 IFXJS_Context* pJSContext,
91 const wchar_t* script,
94 v8::Local<v8::Object> JS_NewFxDynamicObj(v8::Isolate* pIsolate,
95 IFXJS_Context* pJSContext,
97 v8::Local<v8::Object> JS_GetStaticObj(v8::Isolate* pIsolate, int nObjDefnID);
98 v8::Local<v8::Object> JS_GetThisObj(v8::Isolate* pIsolate);
99 int JS_GetObjDefnID(v8::Local<v8::Object> pObj);
100 v8::Isolate* JS_GetRuntime(v8::Local<v8::Object> pObj);
101 int JS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName);
102 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message);
103 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen);
104 unsigned JS_CalcHash(const wchar_t* main);
105 const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj);
106 void JS_SetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, void* p);
107 void* JS_GetPrivate(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj);
108 void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p);
109 void* JS_GetPrivate(v8::Local<v8::Object> pObj);
110 void JS_FreePrivate(void* p);
111 void JS_FreePrivate(v8::Local<v8::Object> pObj);
112 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj);
113 v8::Local<v8::Value> JS_GetObjectElement(v8::Isolate* pIsolate,
114 v8::Local<v8::Object> pObj,
115 const wchar_t* PropertyName);
116 v8::Local<v8::Array> JS_GetObjectElementNames(v8::Isolate* pIsolate,
117 v8::Local<v8::Object> pObj);
118 void JS_PutObjectString(v8::Isolate* pIsolate,
119 v8::Local<v8::Object> pObj,
120 const wchar_t* PropertyName,
121 const wchar_t* sValue);
122 void JS_PutObjectNumber(v8::Isolate* pIsolate,
123 v8::Local<v8::Object> pObj,
124 const wchar_t* PropertyName,
126 void JS_PutObjectNumber(v8::Isolate* pIsolate,
127 v8::Local<v8::Object> pObj,
128 const wchar_t* PropertyName,
130 void JS_PutObjectNumber(v8::Isolate* pIsolate,
131 v8::Local<v8::Object> pObj,
132 const wchar_t* PropertyName,
134 void JS_PutObjectBoolean(v8::Isolate* pIsolate,
135 v8::Local<v8::Object> pObj,
136 const wchar_t* PropertyName,
138 void JS_PutObjectObject(v8::Isolate* pIsolate,
139 v8::Local<v8::Object> pObj,
140 const wchar_t* PropertyName,
141 v8::Local<v8::Object> pPut);
142 void JS_PutObjectNull(v8::Isolate* pIsolate,
143 v8::Local<v8::Object> pObj,
144 const wchar_t* PropertyName);
145 unsigned JS_PutArrayElement(v8::Isolate* pIsolate,
146 v8::Local<v8::Array> pArray,
148 v8::Local<v8::Value> pValue,
149 FXJSVALUETYPE eType);
150 v8::Local<v8::Value> JS_GetArrayElement(v8::Isolate* pIsolate,
151 v8::Local<v8::Array> pArray,
153 unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray);
154 v8::Local<v8::Value> JS_GetListValue(v8::Isolate* pIsolate,
155 v8::Local<v8::Value> pList,
158 v8::Local<v8::Array> JS_NewArray(v8::Isolate* pIsolate);
159 v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, int number);
160 v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, double number);
161 v8::Local<v8::Value> JS_NewNumber(v8::Isolate* pIsolate, float number);
162 v8::Local<v8::Value> JS_NewBoolean(v8::Isolate* pIsolate, bool b);
163 v8::Local<v8::Value> JS_NewObject(v8::Isolate* pIsolate,
164 v8::Local<v8::Object> pObj);
165 v8::Local<v8::Value> JS_NewObject2(v8::Isolate* pIsolate,
166 v8::Local<v8::Array> pObj);
167 v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate, const wchar_t* string);
168 v8::Local<v8::Value> JS_NewString(v8::Isolate* pIsolate,
169 const wchar_t* string,
171 v8::Local<v8::Value> JS_NewNull();
172 v8::Local<v8::Value> JS_NewDate(v8::Isolate* pIsolate, double d);
173 v8::Local<v8::Value> JS_NewValue(v8::Isolate* pIsolate);
175 int JS_ToInt32(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
176 bool JS_ToBoolean(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
177 double JS_ToNumber(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
178 v8::Local<v8::Object> JS_ToObject(v8::Isolate* pIsolate,
179 v8::Local<v8::Value> pValue);
180 CFX_WideString JS_ToString(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
181 v8::Local<v8::Array> JS_ToArray(v8::Isolate* pIsolate,
182 v8::Local<v8::Value> pValue);
183 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom);
185 double JS_GetDateTime();
186 int JS_GetYearFromTime(double dt);
187 int JS_GetMonthFromTime(double dt);
188 int JS_GetDayFromTime(double dt);
189 int JS_GetHourFromTime(double dt);
190 int JS_GetMinFromTime(double dt);
191 int JS_GetSecFromTime(double dt);
192 double JS_DateParse(const wchar_t* string);
193 double JS_MakeDay(int nYear, int nMonth, int nDay);
194 double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
195 double JS_MakeDate(double day, double time);
196 bool JS_PortIsNan(double d);
197 double JS_LocalTime(double d);
199 #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_