blob: 3ea5054e17e3372a6361e92fd2dfc3b6a0cd6e68 [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.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef FXJSAPI_H
8#define FXJSAPI_H
9
10#include <v8.h>
John Abd-El-Malek5110c472014-05-17 22:33:34 -070011
12enum FXJSOBJTYPE
13{
14 JS_DYNAMIC = 0,
15 JS_STATIC = 1,
16};
17
18enum FXJSVALUETYPE
19{
20 VT_unknown,
21 VT_string,
22 VT_number,
23 VT_boolean,
24 VT_date,
25 VT_object,
26 VT_fxobject,
27 VT_null,
28 VT_undefined
29};
30
31struct FXJSErr
32{
33 const wchar_t* message;
34 const wchar_t* srcline;
35 unsigned linnum;
36};
37
38/* --------------------------------------------- API --------------------------------------------- */
39
40typedef v8::Isolate IJS_Runtime;
41class IFXJS_Context;
42class IFXJS_Runtime;
43
44
45#ifndef JSCRIPT_ARGS
46#define JSCRIPT_ARGS
47
48#define JS_PROPGET_ARGS v8::Local<v8::String> property,const v8::PropertyCallbackInfo<v8::Value>& info
49#define JS_PROPPUT_ARGS v8::Local<v8::String> property,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<void>& info
50#define JS_METHOD_ARGS const v8::FunctionCallbackInfo<v8::Value>& info
51#define JS_CONSTRUCTOR_ARGS IFXJS_Context* cc, v8::Handle<v8::Object> obj, v8::Handle<v8::Object> global
52#define JS_DESTRUCTOR_ARGS v8::Handle<v8::Object> obj
53
54#define JS_PROPQUERY_ARGS v8::Local<v8::String> property,const v8::PropertyCallbackInfo<v8::Integer>& info
55#define JS_NAMED_PROPGET_ARGS JS_PROPGET_ARGS
56#define JS_NAMED_PROPPUT_ARGS v8::Local<v8::String> property,v8::Local<v8::Value> value,const v8::PropertyCallbackInfo<v8::Value>& info
57#define JS_PROPDEL_ARGS v8::Local<v8::String> property,const v8::PropertyCallbackInfo<v8::Boolean>& info
58
59typedef unsigned (*LP_CONSTRUCTOR)(JS_CONSTRUCTOR_ARGS);
60typedef unsigned (*LP_DESTRUCTOR)(JS_DESTRUCTOR_ARGS);
61
62#endif
63
64int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned bApplyNew);
John Abd-El-Malek41f05902014-05-20 09:52:29 -070065int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall, unsigned nParamNum);
66int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPropPut);
67int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::NamedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet, v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pPropDel);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070068int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sConstName, v8::Handle<v8::Value> pDefault);
John Abd-El-Malek41f05902014-05-20 09:52:29 -070069int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v8::FunctionCallback pMethodCall, unsigned nParamNum);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070070int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8::Handle<v8::Value> pDefault);
71
72void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Persistent<v8::Context>& v8PersistentContext);
73void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8PersistentContext);
74void JS_Initial();
75void JS_Release();
76int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
77int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
78v8::Handle<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, int nObjDefnID);
79v8::Handle<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID);
80void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID);
81v8::Handle<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime);
82int JS_GetObjDefnID(v8::Handle<v8::Object> pObj);
83IJS_Runtime* JS_GetRuntime(v8::Handle<v8::Object> pObj);
84int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName);
85void JS_Error(v8::Value * pError,const wchar_t * main,const wchar_t * sub);
86unsigned JS_CalcHash(const wchar_t* main, unsigned nLen);
87unsigned JS_CalcHash(const wchar_t* main);
88const wchar_t* JS_GetTypeof(v8::Handle<v8::Value> pObj);
89const wchar_t* JS_GetClassname(v8::Handle<v8::Object> pObj);
90void JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj, void* p);
91void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj);
92void JS_SetPrivate(v8::Handle<v8::Object> pObj, void* p);
93void* JS_GetPrivate(v8::Handle<v8::Object> pObj);
94void JS_FreePrivate(v8::Handle<v8::Object> pObj);
95v8::Handle<v8::Value> JS_GetObjectValue(v8::Handle<v8::Object> pObj);
96v8::Handle<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj,const wchar_t* PropertyName);
97v8::Handle<v8::Array> JS_GetObjectElementNames(v8::Handle<v8::Object> pObj);
98void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, const wchar_t* sValue);
99void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, int nValue);
100void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, float fValue);
101void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, double dValue);
102void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, bool bValue);
103void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName, v8::Handle<v8::Object> pPut);
104void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const wchar_t* PropertyName);
105unsigned JS_PutArrayElement(v8::Handle<v8::Array> pArray,unsigned index,v8::Handle<v8::Value> pValue,FXJSVALUETYPE eType);
106v8::Handle<v8::Value> JS_GetArrayElemnet(v8::Handle<v8::Array> pArray,unsigned index);
107unsigned JS_GetArrayLength(v8::Handle<v8::Array> pArray);
108v8::Handle<v8::Value> JS_GetListValue(v8::Handle<v8::Value> pList, int index);
109
110
111v8::Handle<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime);
112v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number);
113v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,double number);
114v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,float number);
115v8::Handle<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b);
116v8::Handle<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj);
117v8::Handle<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Handle<v8::Array> pObj);
118v8::Handle<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string);
119v8::Handle<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string, unsigned nLen);
120v8::Handle<v8::Value> JS_NewNull();
121v8::Handle<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d);
122v8::Handle<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime);
123
124
125int JS_ToInt32(v8::Handle<v8::Value> pValue);
126bool JS_ToBoolean(v8::Handle<v8::Value> pValue);
127double JS_ToNumber(v8::Handle<v8::Value> pValue);
128v8::Handle<v8::Object> JS_ToObject(v8::Handle<v8::Value> pValue);
129CFX_WideString JS_ToString(v8::Handle<v8::Value> pValue);
130v8::Handle<v8::Array> JS_ToArray(v8::Handle<v8::Value> pValue);
131void JS_ValueCopy(v8::Handle<v8::Value>& pTo, v8::Handle<v8::Value> pFrom);
132
133double JS_GetDateTime();
134int JS_GetYearFromTime(double dt);
135int JS_GetMonthFromTime(double dt);
136int JS_GetDayFromTime(double dt);
137int JS_GetHourFromTime(double dt);
138int JS_GetMinFromTime(double dt);
139int JS_GetSecFromTime(double dt);
140double JS_DateParse(const wchar_t* string);
141double JS_MakeDay(int nYear, int nMonth, int nDay);
142double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
143double JS_MakeDate(double day, double time);
144bool JS_PortIsNan(double d);
145double JS_LocalTime(double d);
146
147#endif //FXJSAPI_H