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 FXJS_INCLUDE_FXJSE_H_
8 #define FXJS_INCLUDE_FXJSE_H_
9 
10 #include "core/fxcrt/include/fx_string.h"
11 #include "core/fxcrt/include/fx_system.h"
12 #include "v8/include/v8.h"
13 
14 class CFXJSE_Arguments;
15 class CFXJSE_Value;
16 
17 // C++ object which can be wrapped by CFXJSE_value.
18 class CFXJSE_HostObject {
19  public:
~CFXJSE_HostObject()20   virtual ~CFXJSE_HostObject() {}
21 };
22 
23 typedef void (*FXJSE_FuncCallback)(CFXJSE_Value* pThis,
24                                    const CFX_ByteStringC& szFuncName,
25                                    CFXJSE_Arguments& args);
26 typedef void (*FXJSE_PropAccessor)(CFXJSE_Value* pObject,
27                                    const CFX_ByteStringC& szPropName,
28                                    CFXJSE_Value* pValue);
29 typedef int32_t (*FXJSE_PropTypeGetter)(CFXJSE_Value* pObject,
30                                         const CFX_ByteStringC& szPropName,
31                                         FX_BOOL bQueryIn);
32 typedef FX_BOOL (*FXJSE_PropDeleter)(CFXJSE_Value* pObject,
33                                      const CFX_ByteStringC& szPropName);
34 
35 enum FXJSE_ClassPropTypes {
36   FXJSE_ClassPropType_None,
37   FXJSE_ClassPropType_Property,
38   FXJSE_ClassPropType_Method
39 };
40 
41 struct FXJSE_FUNCTION_DESCRIPTOR {
42   const FX_CHAR* name;
43   FXJSE_FuncCallback callbackProc;
44 };
45 
46 struct FXJSE_PROPERTY_DESCRIPTOR {
47   const FX_CHAR* name;
48   FXJSE_PropAccessor getProc;
49   FXJSE_PropAccessor setProc;
50 };
51 
52 struct FXJSE_CLASS_DESCRIPTOR {
53   const FX_CHAR* name;
54   FXJSE_FuncCallback constructor;
55   const FXJSE_PROPERTY_DESCRIPTOR* properties;
56   const FXJSE_FUNCTION_DESCRIPTOR* methods;
57   int32_t propNum;
58   int32_t methNum;
59   FXJSE_PropTypeGetter dynPropTypeGetter;
60   FXJSE_PropAccessor dynPropGetter;
61   FXJSE_PropAccessor dynPropSetter;
62   FXJSE_PropDeleter dynPropDeleter;
63   FXJSE_FuncCallback dynMethodCall;
64 };
65 
66 void FXJSE_Initialize();
67 void FXJSE_Finalize();
68 
69 v8::Isolate* FXJSE_Runtime_Create_Own();
70 void FXJSE_Runtime_Release(v8::Isolate* pIsolate);
71 
72 void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Message);
73 
74 #endif  // FXJS_INCLUDE_FXJSE_H_
75