blob: 72f2a5de018c1aa261efa8deb1b605aa8a6e803b [file] [log] [blame]
John Abd-El-Malek5110c472014-05-17 22:33:34 -07001// 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.
Tom Sepez2311b782015-02-23 10:22:51 -08004
John Abd-El-Malek5110c472014-05-17 22:33:34 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez9a3f8122015-04-07 15:35:48 -07007// PDFium wrapper around V8 APIs. PDFium code should include this file rather
8// than including V8 headers directly.
9
Tom Sepez19922bb2015-05-28 13:23:12 -070010#ifndef FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_
11#define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_
John Abd-El-Malek5110c472014-05-17 22:33:34 -070012
13#include <v8.h>
JUN FANG49ccaeb2015-03-02 17:08:22 -080014#include "../../../core/include/fxcrt/fx_string.h" // For CFX_WideString
John Abd-El-Malek5110c472014-05-17 22:33:34 -070015
Nico Weber9d8ec5a2015-08-04 13:00:21 -070016typedef v8::Value JSValue;
17typedef v8::Local<v8::Object> JSObject;
18typedef v8::Local<v8::Object> JSFXObject;
Tom Sepez9a3f8122015-04-07 15:35:48 -070019
Nico Weber9d8ec5a2015-08-04 13:00:21 -070020enum FXJSOBJTYPE {
21 JS_DYNAMIC = 0,
22 JS_STATIC = 1,
John Abd-El-Malek5110c472014-05-17 22:33:34 -070023};
24
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025enum FXJSVALUETYPE {
26 VT_unknown,
27 VT_string,
28 VT_number,
29 VT_boolean,
30 VT_date,
31 VT_object,
32 VT_fxobject,
33 VT_null,
34 VT_undefined
John Abd-El-Malek5110c472014-05-17 22:33:34 -070035};
36
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037struct FXJSErr {
38 const wchar_t* message;
39 const wchar_t* srcline;
40 unsigned linnum;
John Abd-El-Malek5110c472014-05-17 22:33:34 -070041};
42
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043/* --------------------------------------------- API
44 * --------------------------------------------- */
John Abd-El-Malek5110c472014-05-17 22:33:34 -070045
46typedef v8::Isolate IJS_Runtime;
47class IFXJS_Context;
48class IFXJS_Runtime;
49
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050typedef void (*LP_CONSTRUCTOR)(IFXJS_Context* cc,
51 v8::Local<v8::Object> obj,
52 v8::Local<v8::Object> global);
Jochen Eisingerdfa2c992015-05-19 00:38:00 +020053typedef void (*LP_DESTRUCTOR)(v8::Local<v8::Object> obj);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070054
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055int JS_DefineObj(IJS_Runtime* pJSRuntime,
56 const wchar_t* sObjName,
57 FXJSOBJTYPE eObjType,
58 LP_CONSTRUCTOR pConstructor,
59 LP_DESTRUCTOR pDestructor);
60int JS_DefineObjMethod(IJS_Runtime* pJSRuntime,
61 int nObjDefnID,
62 const wchar_t* sMethodName,
63 v8::FunctionCallback pMethodCall);
64int JS_DefineObjProperty(IJS_Runtime* pJSRuntime,
65 int nObjDefnID,
66 const wchar_t* sPropName,
67 v8::AccessorGetterCallback pPropGet,
68 v8::AccessorSetterCallback pPropPut);
69int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime,
70 int nObjDefnID,
71 v8::NamedPropertyQueryCallback pPropQurey,
72 v8::NamedPropertyGetterCallback pPropGet,
73 v8::NamedPropertySetterCallback pPropPut,
74 v8::NamedPropertyDeleterCallback pPropDel);
75int JS_DefineObjConst(IJS_Runtime* pJSRuntime,
76 int nObjDefnID,
77 const wchar_t* sConstName,
78 v8::Local<v8::Value> pDefault);
79int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime,
80 const wchar_t* sMethodName,
81 v8::FunctionCallback pMethodCall);
82int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime,
83 const wchar_t* sConstName,
84 v8::Local<v8::Value> pDefault);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070085
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086void JS_InitialRuntime(IJS_Runtime* pJSRuntime,
87 IFXJS_Runtime* pFXRuntime,
88 IFXJS_Context* context,
89 v8::Global<v8::Context>& v8PersistentContext);
90void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime,
91 v8::Global<v8::Context>& v8PersistentContext);
92void JS_Initial(unsigned int embedderDataSlot);
93void JS_Release();
94int JS_Parse(IJS_Runtime* pJSRuntime,
95 IFXJS_Context* pJSContext,
96 const wchar_t* script,
97 long length,
98 FXJSErr* perror);
99int JS_Execute(IJS_Runtime* pJSRuntime,
100 IFXJS_Context* pJSContext,
101 const wchar_t* script,
102 long length,
103 FXJSErr* perror);
104v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime,
105 IFXJS_Context* pJSContext,
106 int nObjDefnID);
107v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID);
108void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID);
109v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime* pJSRuntime);
110int JS_GetObjDefnID(v8::Local<v8::Object> pObj);
111IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj);
112int JS_GetObjDefnID(IJS_Runtime* pJSRuntime, const wchar_t* pObjName);
113void JS_Error(v8::Isolate* isolate, const CFX_WideString& message);
114unsigned JS_CalcHash(const wchar_t* main, unsigned nLen);
115unsigned JS_CalcHash(const wchar_t* main);
116const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj);
117void JS_SetPrivate(IJS_Runtime* pJSRuntime,
118 v8::Local<v8::Object> pObj,
119 void* p);
120void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj);
121void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p);
122void* JS_GetPrivate(v8::Local<v8::Object> pObj);
123void JS_FreePrivate(void* p);
124void JS_FreePrivate(v8::Local<v8::Object> pObj);
125v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj);
126v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime,
127 v8::Local<v8::Object> pObj,
128 const wchar_t* PropertyName);
129v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime,
130 v8::Local<v8::Object> pObj);
131void JS_PutObjectString(IJS_Runtime* pJSRuntime,
132 v8::Local<v8::Object> pObj,
133 const wchar_t* PropertyName,
134 const wchar_t* sValue);
135void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,
136 v8::Local<v8::Object> pObj,
137 const wchar_t* PropertyName,
138 int nValue);
139void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,
140 v8::Local<v8::Object> pObj,
141 const wchar_t* PropertyName,
142 float fValue);
143void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,
144 v8::Local<v8::Object> pObj,
145 const wchar_t* PropertyName,
146 double dValue);
147void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,
148 v8::Local<v8::Object> pObj,
149 const wchar_t* PropertyName,
150 bool bValue);
151void JS_PutObjectObject(IJS_Runtime* pJSRuntime,
152 v8::Local<v8::Object> pObj,
153 const wchar_t* PropertyName,
154 v8::Local<v8::Object> pPut);
155void JS_PutObjectNull(IJS_Runtime* pJSRuntime,
156 v8::Local<v8::Object> pObj,
157 const wchar_t* PropertyName);
158unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime,
159 v8::Local<v8::Array> pArray,
160 unsigned index,
161 v8::Local<v8::Value> pValue,
162 FXJSVALUETYPE eType);
163v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime,
164 v8::Local<v8::Array> pArray,
165 unsigned index);
166unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray);
167v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime,
168 v8::Local<v8::Value> pList,
169 int index);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime);
172v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, int number);
173v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, double number);
174v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime, float number);
175v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime, bool b);
176v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,
177 v8::Local<v8::Object> pObj);
178v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,
179 v8::Local<v8::Array> pObj);
180v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,
181 const wchar_t* string);
182v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,
183 const wchar_t* string,
184 unsigned nLen);
185v8::Local<v8::Value> JS_NewNull();
186v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime, double d);
187v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700188
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
190bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
191double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
192v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime,
193 v8::Local<v8::Value> pValue);
194CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime,
195 v8::Local<v8::Value> pValue);
196v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime,
197 v8::Local<v8::Value> pValue);
198void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700199
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200double JS_GetDateTime();
201int JS_GetYearFromTime(double dt);
202int JS_GetMonthFromTime(double dt);
203int JS_GetDayFromTime(double dt);
204int JS_GetHourFromTime(double dt);
205int JS_GetMinFromTime(double dt);
206int JS_GetSecFromTime(double dt);
207double JS_DateParse(const wchar_t* string);
208double JS_MakeDay(int nYear, int nMonth, int nDay);
209double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
210double JS_MakeDate(double day, double time);
211bool JS_PortIsNan(double d);
212double JS_LocalTime(double d);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700213
Tom Sepez19922bb2015-05-28 13:23:12 -0700214#endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_