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#ifndef XFA_INCLUDE_FXJSE_FXJSE_H_ 8#define XFA_INCLUDE_FXJSE_FXJSE_H_ 9 10#include "core/include/fpdfapi/fpdf_parser.h" 11#include "core/include/fxcrt/fx_string.h" 12#include "core/include/fxcrt/fx_system.h" 13 14class CPDFDoc_Environment; 15class CPDF_Page; 16 17typedef struct FXJSE_HRUNTIME_ { void* pData; } * FXJSE_HRUNTIME; 18typedef struct FXJSE_HCONTEXT_ { void* pData; } * FXJSE_HCONTEXT; 19typedef struct FXJSE_HCLASS_ { void* pData; } * FXJSE_HCLASS; 20typedef struct FXJSE_HVALUE_ { void* pData; } * FXJSE_HVALUE; 21typedef struct FXJSE_HOBJECT_ : public FXJSE_HVALUE_{} * FXJSE_HOBJECT; 22 23typedef double FXJSE_DOUBLE; 24void FXJSE_Initialize(); 25void FXJSE_Finalize(); 26FXJSE_HRUNTIME FXJSE_Runtime_Create(); 27void FXJSE_Runtime_Release(FXJSE_HRUNTIME hRuntime); 28typedef struct _FXJSE_CLASS FXJSE_CLASS; 29FXJSE_HCONTEXT FXJSE_Context_Create(FXJSE_HRUNTIME hRuntime, 30 const FXJSE_CLASS* lpGlobalClass = nullptr, 31 void* lpGlobalObject = nullptr); 32void FXJSE_Context_Release(FXJSE_HCONTEXT hContext); 33FXJSE_HVALUE FXJSE_Context_GetGlobalObject(FXJSE_HCONTEXT hContext); 34FXJSE_HRUNTIME FXJSE_Context_GetRuntime(FXJSE_HCONTEXT hContext); 35enum FXJSE_CompatibleModeFlags { 36 FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS = (1 << 0), 37 FXJSE_COMPATIBLEMODEFLAGCOUNT = 1, 38}; 39void FXJSE_Context_EnableCompatibleMode(FXJSE_HCONTEXT hContext, 40 FX_DWORD dwCompatibleFlags); 41class CFXJSE_Arguments { 42 public: 43 FXJSE_HRUNTIME GetRuntime() const; 44 int32_t GetLength() const; 45 FXJSE_HVALUE GetValue(int32_t index) const; 46 FX_BOOL GetBoolean(int32_t index) const; 47 int32_t GetInt32(int32_t index) const; 48 FX_FLOAT GetFloat(int32_t index) const; 49 CFX_ByteString GetUTF8String(int32_t index) const; 50 void* GetObject(int32_t index, FXJSE_HCLASS hClass = nullptr) const; 51 FXJSE_HVALUE GetReturnValue(); 52}; 53typedef void (*FXJSE_FuncCallback)(FXJSE_HOBJECT hThis, 54 const CFX_ByteStringC& szFuncName, 55 CFXJSE_Arguments& args); 56typedef void (*FXJSE_PropAccessor)(FXJSE_HOBJECT hObject, 57 const CFX_ByteStringC& szPropName, 58 FXJSE_HVALUE hValue); 59typedef int32_t (*FXJSE_PropTypeGetter)(FXJSE_HOBJECT hObject, 60 const CFX_ByteStringC& szPropName, 61 FX_BOOL bQueryIn); 62typedef FX_BOOL (*FXJSE_PropDeleter)(FXJSE_HOBJECT hObject, 63 const CFX_ByteStringC& szPropName); 64typedef struct _FXJSE_FUNCTION { 65 const FX_CHAR* name; 66 FXJSE_FuncCallback callbackProc; 67} FXJSE_FUNCTION; 68#define FXJSE_DEF_FUNCTION(functionName, functionCallback) \ 69 { functionName, functionCallback } 70void FXJSE_DefineFunctions(FXJSE_HCONTEXT hContext, 71 const FXJSE_FUNCTION* lpFunctions, 72 int nNum); 73typedef struct _FXJSE_PROPERTY { 74 const FX_CHAR* name; 75 FXJSE_PropAccessor getProc; 76 FXJSE_PropAccessor setProc; 77} FXJSE_PROPERTY; 78enum FXJSE_ClassPropTypes { 79 FXJSE_ClassPropType_None, 80 FXJSE_ClassPropType_Property, 81 FXJSE_ClassPropType_Method 82}; 83typedef struct _FXJSE_CLASS { 84 const FX_CHAR* name; 85 FXJSE_FuncCallback constructor; 86 FXJSE_PROPERTY* properties; 87 FXJSE_FUNCTION* methods; 88 int32_t propNum; 89 int32_t methNum; 90 FXJSE_PropTypeGetter dynPropTypeGetter; 91 FXJSE_PropAccessor dynPropGetter; 92 FXJSE_PropAccessor dynPropSetter; 93 FXJSE_PropDeleter dynPropDeleter; 94 FXJSE_FuncCallback dynMethodCall; 95} FXJSE_CLASS; 96FXJSE_HCLASS FXJSE_DefineClass(FXJSE_HCONTEXT hContext, 97 const FXJSE_CLASS* lpClass); 98FXJSE_HCLASS FXJSE_GetClass(FXJSE_HCONTEXT hContext, 99 const CFX_ByteStringC& szName); 100FXJSE_HVALUE FXJSE_Value_Create(FXJSE_HRUNTIME hRuntime); 101void FXJSE_Value_Release(FXJSE_HVALUE hValue); 102FXJSE_HRUNTIME FXJSE_Value_GetRuntime(FXJSE_HVALUE hValue); 103FX_BOOL FXJSE_Value_IsUndefined(FXJSE_HVALUE hValue); 104FX_BOOL FXJSE_Value_IsNull(FXJSE_HVALUE hValue); 105FX_BOOL FXJSE_Value_IsBoolean(FXJSE_HVALUE hValue); 106FX_BOOL FXJSE_Value_IsUTF8String(FXJSE_HVALUE hValue); 107FX_BOOL FXJSE_Value_IsNumber(FXJSE_HVALUE hValue); 108FX_BOOL FXJSE_Value_IsInteger(FXJSE_HVALUE hValue); 109FX_BOOL FXJSE_Value_IsObject(FXJSE_HVALUE hValue); 110FX_BOOL FXJSE_Value_IsArray(FXJSE_HVALUE hValue); 111FX_BOOL FXJSE_Value_IsFunction(FXJSE_HVALUE hValue); 112FX_BOOL FXJSE_Value_IsDate(FXJSE_HVALUE hValue); 113FX_BOOL FXJSE_Value_ToBoolean(FXJSE_HVALUE hValue); 114FX_FLOAT FXJSE_Value_ToFloat(FXJSE_HVALUE hValue); 115FXJSE_DOUBLE FXJSE_Value_ToDouble(FXJSE_HVALUE hValue); 116int32_t FXJSE_Value_ToInteger(FXJSE_HVALUE hValue); 117void FXJSE_Value_ToUTF8String(FXJSE_HVALUE hValue, CFX_ByteString& szStrOutput); 118void* FXJSE_Value_ToObject(FXJSE_HVALUE hValue, FXJSE_HCLASS hClass); 119void FXJSE_Value_SetUndefined(FXJSE_HVALUE hValue); 120void FXJSE_Value_SetNull(FXJSE_HVALUE hValue); 121void FXJSE_Value_SetBoolean(FXJSE_HVALUE hValue, FX_BOOL bBoolean); 122void FXJSE_Value_SetUTF8String(FXJSE_HVALUE hValue, 123 const CFX_ByteStringC& szString); 124void FXJSE_Value_SetInteger(FXJSE_HVALUE hValue, int32_t nInteger); 125void FXJSE_Value_SetFloat(FXJSE_HVALUE hValue, FX_FLOAT fFloat); 126void FXJSE_Value_SetDouble(FXJSE_HVALUE hValue, FXJSE_DOUBLE dDouble); 127void FXJSE_Value_SetObject(FXJSE_HVALUE hValue, 128 void* lpObject, 129 FXJSE_HCLASS hClass); 130void FXJSE_Value_SetArray(FXJSE_HVALUE hValue, 131 uint32_t uValueCount, 132 FXJSE_HVALUE* rgValues); 133void FXJSE_Value_SetDate(FXJSE_HVALUE hValue, FXJSE_DOUBLE dDouble); 134void FXJSE_Value_Set(FXJSE_HVALUE hValue, FXJSE_HVALUE hOriginalValue); 135FX_BOOL FXJSE_Value_GetObjectProp(FXJSE_HVALUE hValue, 136 const CFX_ByteStringC& szPropName, 137 FXJSE_HVALUE hPropValue); 138FX_BOOL FXJSE_Value_SetObjectProp(FXJSE_HVALUE hValue, 139 const CFX_ByteStringC& szPropName, 140 FXJSE_HVALUE hPropValue); 141FX_BOOL FXJSE_Value_GetObjectPropByIdx(FXJSE_HVALUE hValue, 142 uint32_t uPropIdx, 143 FXJSE_HVALUE hPropValue); 144FX_BOOL FXJSE_Value_SetObjectPropByIdx(FXJSE_HVALUE hValue, 145 uint32_t uPropIdx, 146 FXJSE_HVALUE hPropValue); 147FX_BOOL FXJSE_Value_DeleteObjectProp(FXJSE_HVALUE hValue, 148 const CFX_ByteStringC& szPropName); 149FX_BOOL FXJSE_Value_ObjectHasOwnProp(FXJSE_HVALUE hValue, 150 const CFX_ByteStringC& szPropName, 151 FX_BOOL bUseTypeGetter); 152FX_BOOL FXJSE_Value_SetObjectOwnProp(FXJSE_HVALUE hValue, 153 const CFX_ByteStringC& szPropName, 154 FXJSE_HVALUE hPropValue); 155FX_BOOL FXJSE_Value_CallFunction(FXJSE_HVALUE hFunction, 156 FXJSE_HVALUE hThis, 157 FXJSE_HVALUE hRetValue, 158 uint32_t nArgCount, 159 FXJSE_HVALUE* lpArgs); 160FX_BOOL FXJSE_Value_SetFunctionBind(FXJSE_HVALUE hValue, 161 FXJSE_HVALUE hOldFunction, 162 FXJSE_HVALUE hNewThis); 163FX_BOOL FXJSE_ExecuteScript(FXJSE_HCONTEXT hContext, 164 const FX_CHAR* szScript, 165 FXJSE_HVALUE hRetValue, 166 FXJSE_HVALUE hNewThisObject = nullptr); 167void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, 168 const CFX_ByteStringC& utf8Message); 169FX_BOOL FXJSE_ReturnValue_GetMessage(FXJSE_HVALUE hRetValue, 170 CFX_ByteString& utf8Name, 171 CFX_ByteString& utf8Message); 172FX_BOOL FXJSE_ReturnValue_GetLineInfo(FXJSE_HVALUE hRetValue, 173 int32_t& nLine, 174 int32_t& nCol); 175 176#endif // XFA_INCLUDE_FXJSE_FXJSE_H_ 177