blob: 4a85251c0392eededdadba4f56d65f4284a35abf [file] [log] [blame]
Tom Sepez99ffdb02016-01-26 14:51:21 -08001// 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 Sinclair3a8051c2016-03-15 15:42:31 -04007#ifndef XFA_FXJSE_INCLUDE_FXJSE_H_
8#define XFA_FXJSE_INCLUDE_FXJSE_H_
Tom Sepez99ffdb02016-01-26 14:51:21 -08009
Dan Sinclaira8a28e02016-03-23 15:41:39 -040010#include "core/fxcrt/include/fx_string.h"
11#include "core/fxcrt/include/fx_system.h"
dsinclairec3da5b2016-05-25 16:42:05 -070012#include "v8/include/v8.h"
Tom Sepez99ffdb02016-01-26 14:51:21 -080013
Dan Sinclair3a8051c2016-03-15 15:42:31 -040014class CFXJSE_Arguments;
dsinclaire9885e72016-05-26 10:14:00 -070015class CFXJSE_Class;
dsinclair7f2abcc2016-05-26 09:40:27 -070016class CFXJSE_Context;
dsinclair12a6b0c2016-05-26 11:14:08 -070017class CFXJSE_Value;
Tom Sepez99ffdb02016-01-26 14:51:21 -080018
tsepez29adee72016-05-31 14:22:09 -070019class CFXJSE_HostObject {}; // C++ object which can be wrapped by CFXJSE_value.
20
dsinclair12a6b0c2016-05-26 11:14:08 -070021typedef void (*FXJSE_FuncCallback)(CFXJSE_Value* pThis,
Tom Sepez99ffdb02016-01-26 14:51:21 -080022 const CFX_ByteStringC& szFuncName,
23 CFXJSE_Arguments& args);
dsinclair12a6b0c2016-05-26 11:14:08 -070024typedef void (*FXJSE_PropAccessor)(CFXJSE_Value* pObject,
Tom Sepez99ffdb02016-01-26 14:51:21 -080025 const CFX_ByteStringC& szPropName,
dsinclair12a6b0c2016-05-26 11:14:08 -070026 CFXJSE_Value* pValue);
27typedef int32_t (*FXJSE_PropTypeGetter)(CFXJSE_Value* pObject,
Tom Sepez99ffdb02016-01-26 14:51:21 -080028 const CFX_ByteStringC& szPropName,
29 FX_BOOL bQueryIn);
dsinclair12a6b0c2016-05-26 11:14:08 -070030typedef FX_BOOL (*FXJSE_PropDeleter)(CFXJSE_Value* pObject,
Tom Sepez99ffdb02016-01-26 14:51:21 -080031 const CFX_ByteStringC& szPropName);
Dan Sinclair3a8051c2016-03-15 15:42:31 -040032
Tom Sepez99ffdb02016-01-26 14:51:21 -080033enum FXJSE_ClassPropTypes {
34 FXJSE_ClassPropType_None,
35 FXJSE_ClassPropType_Property,
36 FXJSE_ClassPropType_Method
37};
Dan Sinclair3a8051c2016-03-15 15:42:31 -040038
39enum FXJSE_CompatibleModeFlags {
40 FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS = (1 << 0),
41 FXJSE_COMPATIBLEMODEFLAGCOUNT = 1,
42};
43
tsepeze3b2a4e2016-05-26 12:39:34 -070044struct FXJSE_FUNCTION_DESCRIPTOR {
Dan Sinclair3a8051c2016-03-15 15:42:31 -040045 const FX_CHAR* name;
46 FXJSE_FuncCallback callbackProc;
47};
48
tsepeze3b2a4e2016-05-26 12:39:34 -070049struct FXJSE_PROPERTY_DESCRIPTOR {
Dan Sinclair3a8051c2016-03-15 15:42:31 -040050 const FX_CHAR* name;
51 FXJSE_PropAccessor getProc;
52 FXJSE_PropAccessor setProc;
53};
54
tsepeze3b2a4e2016-05-26 12:39:34 -070055struct FXJSE_CLASS_DESCRIPTOR {
Tom Sepez99ffdb02016-01-26 14:51:21 -080056 const FX_CHAR* name;
57 FXJSE_FuncCallback constructor;
tsepez1c9cfe12016-05-26 13:30:56 -070058 const FXJSE_PROPERTY_DESCRIPTOR* properties;
59 const FXJSE_FUNCTION_DESCRIPTOR* methods;
Tom Sepez99ffdb02016-01-26 14:51:21 -080060 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 Sepez2886a252016-02-23 12:09:25 -080067};
Dan Sinclair3a8051c2016-03-15 15:42:31 -040068
69void FXJSE_Initialize();
70void FXJSE_Finalize();
71
dsinclairec3da5b2016-05-25 16:42:05 -070072v8::Isolate* FXJSE_Runtime_Create();
73void FXJSE_Runtime_Release(v8::Isolate* pIsolate, bool bOwnedRuntime);
Dan Sinclair3a8051c2016-03-15 15:42:31 -040074
tsepeze3b2a4e2016-05-26 12:39:34 -070075CFXJSE_Context* FXJSE_Context_Create(
76 v8::Isolate* pIsolate,
tsepez3a005f22016-05-27 17:45:00 -070077 const FXJSE_CLASS_DESCRIPTOR* lpGlobalClass,
tsepez29adee72016-05-31 14:22:09 -070078 CFXJSE_HostObject* lpGlobalObject);
dsinclair7f2abcc2016-05-26 09:40:27 -070079void FXJSE_Context_Release(CFXJSE_Context* pContext);
dsinclair12a6b0c2016-05-26 11:14:08 -070080CFXJSE_Value* FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext);
Dan Sinclair3a8051c2016-03-15 15:42:31 -040081
dsinclair7f2abcc2016-05-26 09:40:27 -070082void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext,
tsepezdeee3d22016-03-25 14:38:58 -070083 uint32_t dwCompatibleFlags);
Dan Sinclair3a8051c2016-03-15 15:42:31 -040084
dsinclaire9885e72016-05-26 10:14:00 -070085CFXJSE_Class* FXJSE_DefineClass(CFXJSE_Context* pContext,
tsepeze3b2a4e2016-05-26 12:39:34 -070086 const FXJSE_CLASS_DESCRIPTOR* lpClass);
Dan Sinclair3a8051c2016-03-15 15:42:31 -040087
dsinclair12a6b0c2016-05-26 11:14:08 -070088FX_BOOL FXJSE_Value_IsUndefined(CFXJSE_Value* pValue);
89FX_BOOL FXJSE_Value_IsNull(CFXJSE_Value* pValue);
90FX_BOOL FXJSE_Value_IsBoolean(CFXJSE_Value* pValue);
91FX_BOOL FXJSE_Value_IsUTF8String(CFXJSE_Value* pValue);
92FX_BOOL FXJSE_Value_IsNumber(CFXJSE_Value* pValue);
93FX_BOOL FXJSE_Value_IsObject(CFXJSE_Value* pValue);
94FX_BOOL FXJSE_Value_IsArray(CFXJSE_Value* pValue);
95FX_BOOL FXJSE_Value_IsFunction(CFXJSE_Value* pValue);
Dan Sinclair3a8051c2016-03-15 15:42:31 -040096
dsinclair12a6b0c2016-05-26 11:14:08 -070097FX_BOOL FXJSE_Value_ToBoolean(CFXJSE_Value* pValue);
98FX_FLOAT FXJSE_Value_ToFloat(CFXJSE_Value* pValue);
99double FXJSE_Value_ToDouble(CFXJSE_Value* pValue);
100int32_t FXJSE_Value_ToInteger(CFXJSE_Value* pValue);
101void FXJSE_Value_ToUTF8String(CFXJSE_Value* pValue,
102 CFX_ByteString& szStrOutput);
tsepez29adee72016-05-31 14:22:09 -0700103CFXJSE_HostObject* FXJSE_Value_ToObject(CFXJSE_Value* pValue,
104 CFXJSE_Class* pClass);
Dan Sinclair3a8051c2016-03-15 15:42:31 -0400105
dsinclair12a6b0c2016-05-26 11:14:08 -0700106void FXJSE_Value_SetUndefined(CFXJSE_Value* pValue);
107void FXJSE_Value_SetNull(CFXJSE_Value* pValue);
108void FXJSE_Value_SetBoolean(CFXJSE_Value* pValue, FX_BOOL bBoolean);
109void FXJSE_Value_SetUTF8String(CFXJSE_Value* pValue,
Tom Sepez99ffdb02016-01-26 14:51:21 -0800110 const CFX_ByteStringC& szString);
dsinclair12a6b0c2016-05-26 11:14:08 -0700111void FXJSE_Value_SetInteger(CFXJSE_Value* pValue, int32_t nInteger);
112void FXJSE_Value_SetFloat(CFXJSE_Value* pValue, FX_FLOAT fFloat);
113void FXJSE_Value_SetDouble(CFXJSE_Value* pValue, double dDouble);
114void FXJSE_Value_SetObject(CFXJSE_Value* pValue,
tsepez29adee72016-05-31 14:22:09 -0700115 CFXJSE_HostObject* lpObject,
dsinclaire9885e72016-05-26 10:14:00 -0700116 CFXJSE_Class* pClass);
dsinclair12a6b0c2016-05-26 11:14:08 -0700117void FXJSE_Value_SetArray(CFXJSE_Value* pValue,
Tom Sepez99ffdb02016-01-26 14:51:21 -0800118 uint32_t uValueCount,
dsinclair12a6b0c2016-05-26 11:14:08 -0700119 CFXJSE_Value** rgValues);
120void FXJSE_Value_Set(CFXJSE_Value* pValue, CFXJSE_Value* pOriginalValue);
Dan Sinclair3a8051c2016-03-15 15:42:31 -0400121
dsinclair12a6b0c2016-05-26 11:14:08 -0700122FX_BOOL FXJSE_Value_GetObjectProp(CFXJSE_Value* pValue,
Tom Sepez99ffdb02016-01-26 14:51:21 -0800123 const CFX_ByteStringC& szPropName,
dsinclair12a6b0c2016-05-26 11:14:08 -0700124 CFXJSE_Value* pPropValue);
125FX_BOOL FXJSE_Value_SetObjectProp(CFXJSE_Value* pValue,
Tom Sepez99ffdb02016-01-26 14:51:21 -0800126 const CFX_ByteStringC& szPropName,
dsinclair12a6b0c2016-05-26 11:14:08 -0700127 CFXJSE_Value* pPropValue);
128FX_BOOL FXJSE_Value_GetObjectPropByIdx(CFXJSE_Value* pValue,
Tom Sepez99ffdb02016-01-26 14:51:21 -0800129 uint32_t uPropIdx,
dsinclair12a6b0c2016-05-26 11:14:08 -0700130 CFXJSE_Value* pPropValue);
131FX_BOOL FXJSE_Value_DeleteObjectProp(CFXJSE_Value* pValue,
Tom Sepez99ffdb02016-01-26 14:51:21 -0800132 const CFX_ByteStringC& szPropName);
dsinclair12a6b0c2016-05-26 11:14:08 -0700133FX_BOOL FXJSE_Value_ObjectHasOwnProp(CFXJSE_Value* pValue,
Tom Sepez99ffdb02016-01-26 14:51:21 -0800134 const CFX_ByteStringC& szPropName,
135 FX_BOOL bUseTypeGetter);
dsinclair12a6b0c2016-05-26 11:14:08 -0700136FX_BOOL FXJSE_Value_SetObjectOwnProp(CFXJSE_Value* pValue,
Tom Sepez99ffdb02016-01-26 14:51:21 -0800137 const CFX_ByteStringC& szPropName,
dsinclair12a6b0c2016-05-26 11:14:08 -0700138 CFXJSE_Value* pPropValue);
Dan Sinclair3a8051c2016-03-15 15:42:31 -0400139
dsinclair12a6b0c2016-05-26 11:14:08 -0700140FX_BOOL FXJSE_Value_SetFunctionBind(CFXJSE_Value* pValue,
141 CFXJSE_Value* pOldFunction,
142 CFXJSE_Value* pNewThis);
Dan Sinclair3a8051c2016-03-15 15:42:31 -0400143
dsinclair7f2abcc2016-05-26 09:40:27 -0700144FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext,
Tom Sepez99ffdb02016-01-26 14:51:21 -0800145 const FX_CHAR* szScript,
dsinclair12a6b0c2016-05-26 11:14:08 -0700146 CFXJSE_Value* pRetValue,
147 CFXJSE_Value* pNewThisObject = nullptr);
Dan Sinclair3a8051c2016-03-15 15:42:31 -0400148
Tom Sepez99ffdb02016-01-26 14:51:21 -0800149void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name,
150 const CFX_ByteStringC& utf8Message);
Dan Sinclair3a8051c2016-03-15 15:42:31 -0400151
Dan Sinclair3a8051c2016-03-15 15:42:31 -0400152#endif // XFA_FXJSE_INCLUDE_FXJSE_H_