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 | |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 7 | #ifndef FXJS_FXJSE_H_ |
| 8 | #define FXJS_FXJSE_H_ |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 9 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 10 | #include "core/fxcrt/fx_string.h" |
| 11 | #include "core/fxcrt/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 | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 15 | class CFXJSE_Value; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 16 | |
Tom Sepez | 8cb8841 | 2017-06-01 14:59:33 -0700 | [diff] [blame] | 17 | // C++ object which is retrieved from v8 object's slot. |
tsepez | 2334e9e | 2016-06-09 09:32:44 -0700 | [diff] [blame] | 18 | class CFXJSE_HostObject { |
| 19 | public: |
| 20 | virtual ~CFXJSE_HostObject() {} |
Tom Sepez | 8cb8841 | 2017-06-01 14:59:33 -0700 | [diff] [blame] | 21 | |
| 22 | // Small layering violation here, but we need to distinguish between the |
| 23 | // two kinds of subclasses. |
| 24 | enum Type { kXFA, kFM2JS }; |
| 25 | Type type() const { return type_; } |
| 26 | |
| 27 | protected: |
| 28 | explicit CFXJSE_HostObject(Type type) { type_ = type; } |
| 29 | |
| 30 | Type type_; |
tsepez | 2334e9e | 2016-06-09 09:32:44 -0700 | [diff] [blame] | 31 | }; |
tsepez | 29adee7 | 2016-05-31 14:22:09 -0700 | [diff] [blame] | 32 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 33 | typedef void (*FXJSE_FuncCallback)(CFXJSE_Value* pThis, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame^] | 34 | const ByteStringView& szFuncName, |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 35 | CFXJSE_Arguments& args); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 36 | typedef void (*FXJSE_PropAccessor)(CFXJSE_Value* pObject, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame^] | 37 | const ByteStringView& szPropName, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 38 | CFXJSE_Value* pValue); |
| 39 | typedef int32_t (*FXJSE_PropTypeGetter)(CFXJSE_Value* pObject, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame^] | 40 | const ByteStringView& szPropName, |
tsepez | 304bb91 | 2016-11-03 06:10:26 -0700 | [diff] [blame] | 41 | bool bQueryIn); |
| 42 | typedef bool (*FXJSE_PropDeleter)(CFXJSE_Value* pObject, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame^] | 43 | const ByteStringView& szPropName); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 44 | |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 45 | enum FXJSE_ClassPropTypes { |
| 46 | FXJSE_ClassPropType_None, |
| 47 | FXJSE_ClassPropType_Property, |
| 48 | FXJSE_ClassPropType_Method |
| 49 | }; |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 50 | |
tsepez | e3b2a4e | 2016-05-26 12:39:34 -0700 | [diff] [blame] | 51 | struct FXJSE_FUNCTION_DESCRIPTOR { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 52 | const char* name; |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 53 | FXJSE_FuncCallback callbackProc; |
| 54 | }; |
| 55 | |
tsepez | e3b2a4e | 2016-05-26 12:39:34 -0700 | [diff] [blame] | 56 | struct FXJSE_PROPERTY_DESCRIPTOR { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 57 | const char* name; |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 58 | FXJSE_PropAccessor getProc; |
| 59 | FXJSE_PropAccessor setProc; |
| 60 | }; |
| 61 | |
tsepez | e3b2a4e | 2016-05-26 12:39:34 -0700 | [diff] [blame] | 62 | struct FXJSE_CLASS_DESCRIPTOR { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 63 | const char* name; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 64 | FXJSE_FuncCallback constructor; |
tsepez | 1c9cfe1 | 2016-05-26 13:30:56 -0700 | [diff] [blame] | 65 | const FXJSE_PROPERTY_DESCRIPTOR* properties; |
| 66 | const FXJSE_FUNCTION_DESCRIPTOR* methods; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 67 | int32_t propNum; |
| 68 | int32_t methNum; |
| 69 | FXJSE_PropTypeGetter dynPropTypeGetter; |
| 70 | FXJSE_PropAccessor dynPropGetter; |
| 71 | FXJSE_PropAccessor dynPropSetter; |
| 72 | FXJSE_PropDeleter dynPropDeleter; |
| 73 | FXJSE_FuncCallback dynMethodCall; |
Tom Sepez | 2886a25 | 2016-02-23 12:09:25 -0800 | [diff] [blame] | 74 | }; |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 75 | |
| 76 | void FXJSE_Initialize(); |
| 77 | void FXJSE_Finalize(); |
| 78 | |
tsepez | d5f7261 | 2016-06-01 14:01:31 -0700 | [diff] [blame] | 79 | v8::Isolate* FXJSE_Runtime_Create_Own(); |
| 80 | void FXJSE_Runtime_Release(v8::Isolate* pIsolate); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 81 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame^] | 82 | void FXJSE_ThrowMessage(const ByteStringView& utf8Message); |
Dan Sinclair | 3a8051c | 2016-03-15 15:42:31 -0400 | [diff] [blame] | 83 | |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 84 | #endif // FXJS_FXJSE_H_ |