blob: e291898701561c7a29cd5932b8cf2a07a0e98d7f [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
Tom Sepez9a3f8122015-04-07 15:35:48 -070016typedef v8::Value JSValue;
Jochen Eisingerdfa2c992015-05-19 00:38:00 +020017typedef v8::Local<v8::Object> JSObject;
18typedef v8::Local<v8::Object> JSFXObject;
Tom Sepez9a3f8122015-04-07 15:35:48 -070019
John Abd-El-Malek5110c472014-05-17 22:33:34 -070020enum FXJSOBJTYPE
21{
22 JS_DYNAMIC = 0,
23 JS_STATIC = 1,
24};
25
26enum FXJSVALUETYPE
27{
28 VT_unknown,
29 VT_string,
30 VT_number,
31 VT_boolean,
32 VT_date,
33 VT_object,
34 VT_fxobject,
35 VT_null,
36 VT_undefined
37};
38
39struct FXJSErr
40{
Tom Sepez2311b782015-02-23 10:22:51 -080041 const wchar_t* message;
42 const wchar_t* srcline;
John Abd-El-Malek5110c472014-05-17 22:33:34 -070043 unsigned linnum;
44};
45
46/* --------------------------------------------- API --------------------------------------------- */
47
48typedef v8::Isolate IJS_Runtime;
49class IFXJS_Context;
50class IFXJS_Runtime;
51
Jochen Eisingerdfa2c992015-05-19 00:38:00 +020052typedef void (*LP_CONSTRUCTOR)(IFXJS_Context* cc, v8::Local<v8::Object> obj, v8::Local<v8::Object> global);
53typedef void (*LP_DESTRUCTOR)(v8::Local<v8::Object> obj);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070054
John Abd-El-Malek5110c472014-05-17 22:33:34 -070055
Lei Zhangd07958f2015-07-22 13:47:50 -070056int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor);
Tom Sepeze5350ef2015-04-23 18:14:26 -070057int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall);
John Abd-El-Malek41f05902014-05-20 09:52:29 -070058int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPropPut);
59int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::NamedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet, v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pPropDel);
Jochen Eisingerdfa2c992015-05-19 00:38:00 +020060int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sConstName, v8::Local<v8::Value> pDefault);
Tom Sepeze5350ef2015-04-23 18:14:26 -070061int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall);
Jochen Eisingerdfa2c992015-05-19 00:38:00 +020062int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8::Local<v8::Value> pDefault);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070063
Jochen Eisingerdfa2c992015-05-19 00:38:00 +020064void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Global<v8::Context>& v8PersistentContext);
65void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8PersistentContext);
Jochen Eisinger06b60022015-07-30 17:44:35 +020066void JS_Initial(unsigned int embedderDataSlot);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070067void JS_Release();
68int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
69int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
Jochen Eisingerdfa2c992015-05-19 00:38:00 +020070v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, int nObjDefnID);
71v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070072void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID);
Jochen Eisingerdfa2c992015-05-19 00:38:00 +020073v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime);
74int JS_GetObjDefnID(v8::Local<v8::Object> pObj);
75IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070076int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName);
Tom Sepez3a832662015-03-02 12:59:05 -080077void JS_Error(v8::Isolate* isolate, const CFX_WideString& message);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070078unsigned JS_CalcHash(const wchar_t* main, unsigned nLen);
79unsigned JS_CalcHash(const wchar_t* main);
Jochen Eisingerdfa2c992015-05-19 00:38:00 +020080const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj);
81void JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj, void* p);
82void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj);
83void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p);
84void* JS_GetPrivate(v8::Local<v8::Object> pObj);
85void JS_FreePrivate(void* p);
86void JS_FreePrivate(v8::Local<v8::Object> pObj);
87v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj);
88v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj,const wchar_t* PropertyName);
89v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj);
90void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, const wchar_t* sValue);
91void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, int nValue);
92void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, float fValue);
93void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, double dValue);
94void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, bool bValue);
95void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, v8::Local<v8::Object> pPut);
96void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName);
97unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Array> pArray,unsigned index,v8::Local<v8::Value> pValue,FXJSVALUETYPE eType);
98v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Array> pArray,unsigned index);
99unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray);
100v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pList, int index);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700101
102
Jochen Eisingerdfa2c992015-05-19 00:38:00 +0200103v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime);
104v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number);
105v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,double number);
106v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,float number);
107v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b);
108v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj);
109v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Local<v8::Array> pObj);
110v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string);
111v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string, unsigned nLen);
112v8::Local<v8::Value> JS_NewNull();
113v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d);
114v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700115
116
Jochen Eisingerdfa2c992015-05-19 00:38:00 +0200117int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
118bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
119double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
120v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
121CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
122v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue);
123void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom);
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700124
125double JS_GetDateTime();
126int JS_GetYearFromTime(double dt);
127int JS_GetMonthFromTime(double dt);
128int JS_GetDayFromTime(double dt);
129int JS_GetHourFromTime(double dt);
130int JS_GetMinFromTime(double dt);
131int JS_GetSecFromTime(double dt);
132double JS_DateParse(const wchar_t* string);
133double JS_MakeDay(int nYear, int nMonth, int nDay);
134double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
135double JS_MakeDate(double day, double time);
136bool JS_PortIsNan(double d);
137double JS_LocalTime(double d);
138
Tom Sepez19922bb2015-05-28 13:23:12 -0700139#endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_