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