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