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. 4 5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7// PDFium wrapper around V8 APIs. PDFium code should include this file rather 8// than including V8 headers directly. 9 10#ifndef FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ 11#define FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ 12 13#include <v8.h> 14#include "../../../core/include/fxcrt/fx_string.h" // For CFX_WideString 15 16typedef v8::Value JSValue; 17typedef v8::Local<v8::Object> JSObject; 18typedef v8::Local<v8::Object> JSFXObject; 19 20enum 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{ 41 const wchar_t* message; 42 const wchar_t* srcline; 43 unsigned linnum; 44}; 45 46/* --------------------------------------------- API --------------------------------------------- */ 47 48typedef v8::Isolate IJS_Runtime; 49class IFXJS_Context; 50class IFXJS_Runtime; 51 52typedef 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); 54 55 56int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned bApplyNew); 57int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall); 58int 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); 60int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sConstName, v8::Local<v8::Value> pDefault); 61int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall); 62int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8::Local<v8::Value> pDefault); 63 64void 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); 66void JS_Initial(); 67void 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); 70v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, int nObjDefnID); 71v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID); 72void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID); 73v8::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); 76int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName); 77void JS_Error(v8::Isolate* isolate, const CFX_WideString& message); 78unsigned JS_CalcHash(const wchar_t* main, unsigned nLen); 79unsigned JS_CalcHash(const wchar_t* main); 80const 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); 101 102 103v8::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); 115 116 117int 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); 124 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 139#endif // FPDFSDK_INCLUDE_JSAPI_FXJS_V8_H_ 140