John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 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. |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 4 | |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 7 | // PDFium wrapper around V8 APIs. PDFium code should include this file rather |
| 8 | // than including V8 headers directly. |
| 9 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 10 | #ifndef FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
| 11 | #define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 12 | |
| 13 | #include <v8.h> |
JUN FANG | 49ccaeb | 2015-03-02 17:08:22 -0800 | [diff] [blame] | 14 | #include "../../../core/include/fxcrt/fx_string.h" // For CFX_WideString |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 15 | |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 16 | typedef v8::Value JSValue; |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 17 | typedef v8::Local<v8::Object> JSObject; |
| 18 | typedef v8::Local<v8::Object> JSFXObject; |
Tom Sepez | 9a3f812 | 2015-04-07 15:35:48 -0700 | [diff] [blame] | 19 | |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 20 | enum FXJSOBJTYPE |
| 21 | { |
| 22 | JS_DYNAMIC = 0, |
| 23 | JS_STATIC = 1, |
| 24 | }; |
| 25 | |
| 26 | enum 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 | |
| 39 | struct FXJSErr |
| 40 | { |
Tom Sepez | 2311b78 | 2015-02-23 10:22:51 -0800 | [diff] [blame] | 41 | const wchar_t* message; |
| 42 | const wchar_t* srcline; |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 43 | unsigned linnum; |
| 44 | }; |
| 45 | |
| 46 | /* --------------------------------------------- API --------------------------------------------- */ |
| 47 | |
| 48 | typedef v8::Isolate IJS_Runtime; |
| 49 | class IFXJS_Context; |
| 50 | class IFXJS_Runtime; |
| 51 | |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 52 | typedef void (*LP_CONSTRUCTOR)(IFXJS_Context* cc, v8::Local<v8::Object> obj, v8::Local<v8::Object> global); |
| 53 | typedef void (*LP_DESTRUCTOR)(v8::Local<v8::Object> obj); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 54 | |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 55 | |
Lei Zhang | d07958f | 2015-07-22 13:47:50 -0700 | [diff] [blame] | 56 | int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor); |
Tom Sepez | e5350ef | 2015-04-23 18:14:26 -0700 | [diff] [blame] | 57 | int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall); |
John Abd-El-Malek | 41f0590 | 2014-05-20 09:52:29 -0700 | [diff] [blame] | 58 | int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPropPut); |
| 59 | int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::NamedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet, v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pPropDel); |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 60 | int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sConstName, v8::Local<v8::Value> pDefault); |
Tom Sepez | e5350ef | 2015-04-23 18:14:26 -0700 | [diff] [blame] | 61 | int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall); |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 62 | int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8::Local<v8::Value> pDefault); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 63 | |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 64 | void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Global<v8::Context>& v8PersistentContext); |
| 65 | void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8PersistentContext); |
Jochen Eisinger | 06b6002 | 2015-07-30 17:44:35 +0200 | [diff] [blame] | 66 | void JS_Initial(unsigned int embedderDataSlot); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 67 | void JS_Release(); |
| 68 | int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror); |
| 69 | int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror); |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 70 | v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, int nObjDefnID); |
| 71 | v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 72 | void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID); |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 73 | v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime); |
| 74 | int JS_GetObjDefnID(v8::Local<v8::Object> pObj); |
| 75 | IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 76 | int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName); |
Tom Sepez | 3a83266 | 2015-03-02 12:59:05 -0800 | [diff] [blame] | 77 | void JS_Error(v8::Isolate* isolate, const CFX_WideString& message); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 78 | unsigned JS_CalcHash(const wchar_t* main, unsigned nLen); |
| 79 | unsigned JS_CalcHash(const wchar_t* main); |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 80 | const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj); |
| 81 | void JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj, void* p); |
| 82 | void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj); |
| 83 | void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p); |
| 84 | void* JS_GetPrivate(v8::Local<v8::Object> pObj); |
| 85 | void JS_FreePrivate(void* p); |
| 86 | void JS_FreePrivate(v8::Local<v8::Object> pObj); |
| 87 | v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj); |
| 88 | v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj,const wchar_t* PropertyName); |
| 89 | v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj); |
| 90 | void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, const wchar_t* sValue); |
| 91 | void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, int nValue); |
| 92 | void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, float fValue); |
| 93 | void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, double dValue); |
| 94 | void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, bool bValue); |
| 95 | void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName, v8::Local<v8::Object> pPut); |
| 96 | void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const wchar_t* PropertyName); |
| 97 | unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Array> pArray,unsigned index,v8::Local<v8::Value> pValue,FXJSVALUETYPE eType); |
| 98 | v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Array> pArray,unsigned index); |
| 99 | unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray); |
| 100 | v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pList, int index); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 101 | |
| 102 | |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 103 | v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime); |
| 104 | v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number); |
| 105 | v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,double number); |
| 106 | v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,float number); |
| 107 | v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b); |
| 108 | v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj); |
| 109 | v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Local<v8::Array> pObj); |
| 110 | v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string); |
| 111 | v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string, unsigned nLen); |
| 112 | v8::Local<v8::Value> JS_NewNull(); |
| 113 | v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d); |
| 114 | v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 115 | |
| 116 | |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame] | 117 | int JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); |
| 118 | bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); |
| 119 | double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); |
| 120 | v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); |
| 121 | CFX_WideString JS_ToString(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); |
| 122 | v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue); |
| 123 | void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom); |
John Abd-El-Malek | 5110c47 | 2014-05-17 22:33:34 -0700 | [diff] [blame] | 124 | |
| 125 | double JS_GetDateTime(); |
| 126 | int JS_GetYearFromTime(double dt); |
| 127 | int JS_GetMonthFromTime(double dt); |
| 128 | int JS_GetDayFromTime(double dt); |
| 129 | int JS_GetHourFromTime(double dt); |
| 130 | int JS_GetMinFromTime(double dt); |
| 131 | int JS_GetSecFromTime(double dt); |
| 132 | double JS_DateParse(const wchar_t* string); |
| 133 | double JS_MakeDay(int nYear, int nMonth, int nDay); |
| 134 | double JS_MakeTime(int nHour, int nMin, int nSec, int nMs); |
| 135 | double JS_MakeDate(double day, double time); |
| 136 | bool JS_PortIsNan(double d); |
| 137 | double JS_LocalTime(double d); |
| 138 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 139 | #endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ |