blob: 8fc514bba3562049b69453283bc7fc6215e37404 [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
dsinclair43554682016-09-29 17:29:48 -07007#ifndef FXJS_FXJSE_H_
8#define FXJS_FXJSE_H_
Tom Sepez99ffdb02016-01-26 14:51:21 -08009
dsinclaira52ab742016-09-29 13:59:29 -070010#include "core/fxcrt/fx_string.h"
11#include "core/fxcrt/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;
dsinclair12a6b0c2016-05-26 11:14:08 -070015class CFXJSE_Value;
Tom Sepez99ffdb02016-01-26 14:51:21 -080016
Tom Sepez8cb88412017-06-01 14:59:33 -070017// C++ object which is retrieved from v8 object's slot.
tsepez2334e9e2016-06-09 09:32:44 -070018class CFXJSE_HostObject {
19 public:
20 virtual ~CFXJSE_HostObject() {}
Tom Sepez8cb88412017-06-01 14:59:33 -070021
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_;
tsepez2334e9e2016-06-09 09:32:44 -070031};
tsepez29adee72016-05-31 14:22:09 -070032
dsinclair12a6b0c2016-05-26 11:14:08 -070033typedef void (*FXJSE_FuncCallback)(CFXJSE_Value* pThis,
Tom Sepez99ffdb02016-01-26 14:51:21 -080034 const CFX_ByteStringC& szFuncName,
35 CFXJSE_Arguments& args);
dsinclair12a6b0c2016-05-26 11:14:08 -070036typedef void (*FXJSE_PropAccessor)(CFXJSE_Value* pObject,
Tom Sepez99ffdb02016-01-26 14:51:21 -080037 const CFX_ByteStringC& szPropName,
dsinclair12a6b0c2016-05-26 11:14:08 -070038 CFXJSE_Value* pValue);
39typedef int32_t (*FXJSE_PropTypeGetter)(CFXJSE_Value* pObject,
Tom Sepez99ffdb02016-01-26 14:51:21 -080040 const CFX_ByteStringC& szPropName,
tsepez304bb912016-11-03 06:10:26 -070041 bool bQueryIn);
42typedef bool (*FXJSE_PropDeleter)(CFXJSE_Value* pObject,
43 const CFX_ByteStringC& szPropName);
Dan Sinclair3a8051c2016-03-15 15:42:31 -040044
Tom Sepez99ffdb02016-01-26 14:51:21 -080045enum FXJSE_ClassPropTypes {
46 FXJSE_ClassPropType_None,
47 FXJSE_ClassPropType_Property,
48 FXJSE_ClassPropType_Method
49};
Dan Sinclair3a8051c2016-03-15 15:42:31 -040050
tsepeze3b2a4e2016-05-26 12:39:34 -070051struct FXJSE_FUNCTION_DESCRIPTOR {
Dan Sinclair812e96c2017-03-13 16:43:37 -040052 const char* name;
Dan Sinclair3a8051c2016-03-15 15:42:31 -040053 FXJSE_FuncCallback callbackProc;
54};
55
tsepeze3b2a4e2016-05-26 12:39:34 -070056struct FXJSE_PROPERTY_DESCRIPTOR {
Dan Sinclair812e96c2017-03-13 16:43:37 -040057 const char* name;
Dan Sinclair3a8051c2016-03-15 15:42:31 -040058 FXJSE_PropAccessor getProc;
59 FXJSE_PropAccessor setProc;
60};
61
tsepeze3b2a4e2016-05-26 12:39:34 -070062struct FXJSE_CLASS_DESCRIPTOR {
Dan Sinclair812e96c2017-03-13 16:43:37 -040063 const char* name;
Tom Sepez99ffdb02016-01-26 14:51:21 -080064 FXJSE_FuncCallback constructor;
tsepez1c9cfe12016-05-26 13:30:56 -070065 const FXJSE_PROPERTY_DESCRIPTOR* properties;
66 const FXJSE_FUNCTION_DESCRIPTOR* methods;
Tom Sepez99ffdb02016-01-26 14:51:21 -080067 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 Sepez2886a252016-02-23 12:09:25 -080074};
Dan Sinclair3a8051c2016-03-15 15:42:31 -040075
76void FXJSE_Initialize();
77void FXJSE_Finalize();
78
tsepezd5f72612016-06-01 14:01:31 -070079v8::Isolate* FXJSE_Runtime_Create_Own();
80void FXJSE_Runtime_Release(v8::Isolate* pIsolate);
Dan Sinclair3a8051c2016-03-15 15:42:31 -040081
dsinclair769b1372016-06-08 13:12:41 -070082void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Message);
Dan Sinclair3a8051c2016-03-15 15:42:31 -040083
dsinclair43554682016-09-29 17:29:48 -070084#endif // FXJS_FXJSE_H_