Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [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. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 7 | #ifndef XFA_FXJSE_INCLUDE_FXJSE_H_ |
| 8 | #define XFA_FXJSE_INCLUDE_FXJSE_H_ |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 9 | |
Dan Sinclair | a8a28e0 | 2016-03-23 15:41:39 -0400 | [diff] [blame] | 10 | #include "core/fxcrt/include/fx_string.h" |
| 11 | #include "core/fxcrt/include/fx_system.h" |
dsinclair | ec3da5b | 2016-05-25 16:42:05 -0700 | [diff] [blame] | 12 | #include "v8/include/v8.h" |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 13 | |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 14 | class CFXJSE_Arguments; |
dsinclair | e9885e7 | 2016-05-26 10:14:00 -0700 | [diff] [blame] | 15 | class CFXJSE_Class; |
dsinclair | 7f2abcc | 2016-05-26 09:40:27 -0700 | [diff] [blame] | 16 | class CFXJSE_Context; |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 17 | class CFXJSE_Value; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 18 | |
tsepez | 29adee7 | 2016-05-31 14:22:09 -0700 | [diff] [blame^] | 19 | class CFXJSE_HostObject {}; // C++ object which can be wrapped by CFXJSE_value. |
| 20 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 21 | typedef void (*FXJSE_FuncCallback)(CFXJSE_Value* pThis, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 22 | const CFX_ByteStringC& szFuncName, |
| 23 | CFXJSE_Arguments& args); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 24 | typedef void (*FXJSE_PropAccessor)(CFXJSE_Value* pObject, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 25 | const CFX_ByteStringC& szPropName, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 26 | CFXJSE_Value* pValue); |
| 27 | typedef int32_t (*FXJSE_PropTypeGetter)(CFXJSE_Value* pObject, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 28 | const CFX_ByteStringC& szPropName, |
| 29 | FX_BOOL bQueryIn); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 30 | typedef FX_BOOL (*FXJSE_PropDeleter)(CFXJSE_Value* pObject, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 31 | const CFX_ByteStringC& szPropName); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 32 | |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 33 | enum FXJSE_ClassPropTypes { |
| 34 | FXJSE_ClassPropType_None, |
| 35 | FXJSE_ClassPropType_Property, |
| 36 | FXJSE_ClassPropType_Method |
| 37 | }; |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 38 | |
| 39 | enum FXJSE_CompatibleModeFlags { |
| 40 | FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS = (1 << 0), |
| 41 | FXJSE_COMPATIBLEMODEFLAGCOUNT = 1, |
| 42 | }; |
| 43 | |
tsepez | e3b2a4e | 2016-05-26 12:39:34 -0700 | [diff] [blame] | 44 | struct FXJSE_FUNCTION_DESCRIPTOR { |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 45 | const FX_CHAR* name; |
| 46 | FXJSE_FuncCallback callbackProc; |
| 47 | }; |
| 48 | |
tsepez | e3b2a4e | 2016-05-26 12:39:34 -0700 | [diff] [blame] | 49 | struct FXJSE_PROPERTY_DESCRIPTOR { |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 50 | const FX_CHAR* name; |
| 51 | FXJSE_PropAccessor getProc; |
| 52 | FXJSE_PropAccessor setProc; |
| 53 | }; |
| 54 | |
tsepez | e3b2a4e | 2016-05-26 12:39:34 -0700 | [diff] [blame] | 55 | struct FXJSE_CLASS_DESCRIPTOR { |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 56 | const FX_CHAR* name; |
| 57 | FXJSE_FuncCallback constructor; |
tsepez | 1c9cfe1 | 2016-05-26 13:30:56 -0700 | [diff] [blame] | 58 | const FXJSE_PROPERTY_DESCRIPTOR* properties; |
| 59 | const FXJSE_FUNCTION_DESCRIPTOR* methods; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 60 | int32_t propNum; |
| 61 | int32_t methNum; |
| 62 | FXJSE_PropTypeGetter dynPropTypeGetter; |
| 63 | FXJSE_PropAccessor dynPropGetter; |
| 64 | FXJSE_PropAccessor dynPropSetter; |
| 65 | FXJSE_PropDeleter dynPropDeleter; |
| 66 | FXJSE_FuncCallback dynMethodCall; |
Tom Sepez | 2886a25 | 2016-02-23 12:09:25 -0800 | [diff] [blame] | 67 | }; |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 68 | |
| 69 | void FXJSE_Initialize(); |
| 70 | void FXJSE_Finalize(); |
| 71 | |
dsinclair | ec3da5b | 2016-05-25 16:42:05 -0700 | [diff] [blame] | 72 | v8::Isolate* FXJSE_Runtime_Create(); |
| 73 | void FXJSE_Runtime_Release(v8::Isolate* pIsolate, bool bOwnedRuntime); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 74 | |
tsepez | e3b2a4e | 2016-05-26 12:39:34 -0700 | [diff] [blame] | 75 | CFXJSE_Context* FXJSE_Context_Create( |
| 76 | v8::Isolate* pIsolate, |
tsepez | 3a005f2 | 2016-05-27 17:45:00 -0700 | [diff] [blame] | 77 | const FXJSE_CLASS_DESCRIPTOR* lpGlobalClass, |
tsepez | 29adee7 | 2016-05-31 14:22:09 -0700 | [diff] [blame^] | 78 | CFXJSE_HostObject* lpGlobalObject); |
dsinclair | 7f2abcc | 2016-05-26 09:40:27 -0700 | [diff] [blame] | 79 | void FXJSE_Context_Release(CFXJSE_Context* pContext); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 80 | CFXJSE_Value* FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 81 | |
dsinclair | 7f2abcc | 2016-05-26 09:40:27 -0700 | [diff] [blame] | 82 | void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext, |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 83 | uint32_t dwCompatibleFlags); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 84 | |
dsinclair | e9885e7 | 2016-05-26 10:14:00 -0700 | [diff] [blame] | 85 | CFXJSE_Class* FXJSE_DefineClass(CFXJSE_Context* pContext, |
tsepez | e3b2a4e | 2016-05-26 12:39:34 -0700 | [diff] [blame] | 86 | const FXJSE_CLASS_DESCRIPTOR* lpClass); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 87 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 88 | FX_BOOL FXJSE_Value_IsUndefined(CFXJSE_Value* pValue); |
| 89 | FX_BOOL FXJSE_Value_IsNull(CFXJSE_Value* pValue); |
| 90 | FX_BOOL FXJSE_Value_IsBoolean(CFXJSE_Value* pValue); |
| 91 | FX_BOOL FXJSE_Value_IsUTF8String(CFXJSE_Value* pValue); |
| 92 | FX_BOOL FXJSE_Value_IsNumber(CFXJSE_Value* pValue); |
| 93 | FX_BOOL FXJSE_Value_IsObject(CFXJSE_Value* pValue); |
| 94 | FX_BOOL FXJSE_Value_IsArray(CFXJSE_Value* pValue); |
| 95 | FX_BOOL FXJSE_Value_IsFunction(CFXJSE_Value* pValue); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 96 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 97 | FX_BOOL FXJSE_Value_ToBoolean(CFXJSE_Value* pValue); |
| 98 | FX_FLOAT FXJSE_Value_ToFloat(CFXJSE_Value* pValue); |
| 99 | double FXJSE_Value_ToDouble(CFXJSE_Value* pValue); |
| 100 | int32_t FXJSE_Value_ToInteger(CFXJSE_Value* pValue); |
| 101 | void FXJSE_Value_ToUTF8String(CFXJSE_Value* pValue, |
| 102 | CFX_ByteString& szStrOutput); |
tsepez | 29adee7 | 2016-05-31 14:22:09 -0700 | [diff] [blame^] | 103 | CFXJSE_HostObject* FXJSE_Value_ToObject(CFXJSE_Value* pValue, |
| 104 | CFXJSE_Class* pClass); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 105 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 106 | void FXJSE_Value_SetUndefined(CFXJSE_Value* pValue); |
| 107 | void FXJSE_Value_SetNull(CFXJSE_Value* pValue); |
| 108 | void FXJSE_Value_SetBoolean(CFXJSE_Value* pValue, FX_BOOL bBoolean); |
| 109 | void FXJSE_Value_SetUTF8String(CFXJSE_Value* pValue, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 110 | const CFX_ByteStringC& szString); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 111 | void FXJSE_Value_SetInteger(CFXJSE_Value* pValue, int32_t nInteger); |
| 112 | void FXJSE_Value_SetFloat(CFXJSE_Value* pValue, FX_FLOAT fFloat); |
| 113 | void FXJSE_Value_SetDouble(CFXJSE_Value* pValue, double dDouble); |
| 114 | void FXJSE_Value_SetObject(CFXJSE_Value* pValue, |
tsepez | 29adee7 | 2016-05-31 14:22:09 -0700 | [diff] [blame^] | 115 | CFXJSE_HostObject* lpObject, |
dsinclair | e9885e7 | 2016-05-26 10:14:00 -0700 | [diff] [blame] | 116 | CFXJSE_Class* pClass); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 117 | void FXJSE_Value_SetArray(CFXJSE_Value* pValue, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 118 | uint32_t uValueCount, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 119 | CFXJSE_Value** rgValues); |
| 120 | void FXJSE_Value_Set(CFXJSE_Value* pValue, CFXJSE_Value* pOriginalValue); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 121 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 122 | FX_BOOL FXJSE_Value_GetObjectProp(CFXJSE_Value* pValue, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 123 | const CFX_ByteStringC& szPropName, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 124 | CFXJSE_Value* pPropValue); |
| 125 | FX_BOOL FXJSE_Value_SetObjectProp(CFXJSE_Value* pValue, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 126 | const CFX_ByteStringC& szPropName, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 127 | CFXJSE_Value* pPropValue); |
| 128 | FX_BOOL FXJSE_Value_GetObjectPropByIdx(CFXJSE_Value* pValue, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 129 | uint32_t uPropIdx, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 130 | CFXJSE_Value* pPropValue); |
| 131 | FX_BOOL FXJSE_Value_DeleteObjectProp(CFXJSE_Value* pValue, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 132 | const CFX_ByteStringC& szPropName); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 133 | FX_BOOL FXJSE_Value_ObjectHasOwnProp(CFXJSE_Value* pValue, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 134 | const CFX_ByteStringC& szPropName, |
| 135 | FX_BOOL bUseTypeGetter); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 136 | FX_BOOL FXJSE_Value_SetObjectOwnProp(CFXJSE_Value* pValue, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 137 | const CFX_ByteStringC& szPropName, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 138 | CFXJSE_Value* pPropValue); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 139 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 140 | FX_BOOL FXJSE_Value_SetFunctionBind(CFXJSE_Value* pValue, |
| 141 | CFXJSE_Value* pOldFunction, |
| 142 | CFXJSE_Value* pNewThis); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 143 | |
dsinclair | 7f2abcc | 2016-05-26 09:40:27 -0700 | [diff] [blame] | 144 | FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 145 | const FX_CHAR* szScript, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 146 | CFXJSE_Value* pRetValue, |
| 147 | CFXJSE_Value* pNewThisObject = nullptr); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 148 | |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 149 | void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, |
| 150 | const CFX_ByteStringC& utf8Message); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 151 | |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 152 | #endif // XFA_FXJSE_INCLUDE_FXJSE_H_ |