• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The PDFium Authors
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_XFA_FXJSE_H_
8 #define FXJS_XFA_FXJSE_H_
9 
10 #include <stdint.h>
11 
12 #include "core/fxcrt/fx_string.h"
13 #include "v8/include/v8-forward.h"
14 
15 namespace pdfium {
16 namespace fxjse {
17 
18 // These are strings by design. With ASLR, their addresses should be random, so
19 // it should be very unlikely for an object to accidentally have the same tag.
20 extern const char kFuncTag[];
21 extern const char kClassTag[];
22 
23 }  // namespace fxjse
24 }  // namespace pdfium
25 
26 class CFXJSE_FormCalcContext;
27 class CJS_Result;
28 class CJX_Object;
29 
30 enum class FXJSE_ClassPropType {
31   kNone,
32   kProperty,
33   kMethod,
34 };
35 
36 // C++ object which is retrieved from v8 object's slot.
37 class CFXJSE_HostObject {
38  public:
39   static CFXJSE_HostObject* FromV8(v8::Local<v8::Value> arg);
40   virtual ~CFXJSE_HostObject();
41 
42   // Two subclasses.
43   virtual CFXJSE_FormCalcContext* AsFormCalcContext();
44   virtual CJX_Object* AsCJXObject();
45 
46   v8::Local<v8::Object> NewBoundV8Object(v8::Isolate* pIsolate,
47                                          v8::Local<v8::FunctionTemplate> tmpl);
48 
49  protected:
50   CFXJSE_HostObject();
51 };
52 
53 using FXJSE_MethodCallback =
54     CJS_Result (*)(const v8::FunctionCallbackInfo<v8::Value>& info,
55                    const WideString& functionName);
56 using FXJSE_FuncCallback =
57     void (*)(CFXJSE_HostObject* pThis,
58              const v8::FunctionCallbackInfo<v8::Value>& info);
59 using FXJSE_PropGetter = v8::Local<v8::Value> (*)(v8::Isolate* pIsolate,
60                                                   v8::Local<v8::Object> pObject,
61                                                   ByteStringView szPropName);
62 using FXJSE_PropSetter = void (*)(v8::Isolate* pIsolate,
63                                   v8::Local<v8::Object> pObject,
64                                   ByteStringView szPropName,
65                                   v8::Local<v8::Value> pValue);
66 using FXJSE_PropTypeGetter =
67     FXJSE_ClassPropType (*)(v8::Isolate* pIsolate,
68                             v8::Local<v8::Object> pObject,
69                             ByteStringView szPropName,
70                             bool bQueryIn);
71 
72 struct FXJSE_FUNCTION_DESCRIPTOR {
73   const char* tag;  // `pdfium::fxjse::kFuncTag` always.
74   const char* name;
75   FXJSE_FuncCallback callbackProc;
76 };
77 
78 struct FXJSE_CLASS_DESCRIPTOR {
79   const char* tag;  // `pdfium::fxjse::kClassTag` always.
80   const char* name;
81   const FXJSE_FUNCTION_DESCRIPTOR* methods;
82   int32_t methNum;
83   FXJSE_PropTypeGetter dynPropTypeGetter;
84   FXJSE_PropGetter dynPropGetter;
85   FXJSE_PropSetter dynPropSetter;
86   FXJSE_MethodCallback dynMethodCall;
87 };
88 
89 extern const FXJSE_CLASS_DESCRIPTOR kGlobalClassDescriptor;
90 extern const FXJSE_CLASS_DESCRIPTOR kNormalClassDescriptor;
91 extern const FXJSE_CLASS_DESCRIPTOR kVariablesClassDescriptor;
92 extern const FXJSE_CLASS_DESCRIPTOR kFormCalcDescriptor;
93 
94 void FXJSE_ThrowMessage(v8::Isolate* pIsolate, ByteStringView utf8Message);
95 
96 #endif  // FXJS_XFA_FXJSE_H_
97