• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_DECLARATIVE_FRONTEND_ENGINE_BINDINGS_DEFINES_H
17 #define FOUNDATION_ACE_FRAMEWORKS_DECLARATIVE_FRONTEND_ENGINE_BINDINGS_DEFINES_H
18 
19 #include "frameworks/bridge/declarative_frontend/engine/js_types.h"
20 
21 enum class JavascriptEngine { NONE, QUICKJS, V8, ARK };
22 
23 #ifdef USE_QUICKJS_ENGINE
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 #include "third_party/quickjs/cutils.h"
29 #include "third_party/quickjs/quickjs-libc.h"
30 
31 void* JS_GetOpaqueA(JSValueConst obj, JSClassID* classIds, size_t classIdLen);
32 
33 JSValueConst JS_NewGlobalCConstructor(
34     JSContext* ctx, const char* name, JSCFunction* func, int length, JSValueConst proto);
35 
36 #ifdef __cplusplus
37 }
38 #endif
39 
40 using BindingTarget = JSValue;
41 using FunctionCallback = JSValue (*)(JSContext*, JSValueConst, int, JSValueConst*);
42 using FunctionGetCallback = JSValue (*)(JSContext*, JSValueConst);
43 using FunctionSetCallback = JSValue (*)(JSContext*, JSValueConst, JSValueConst);
44 template<typename T>
45 using MemberFunctionCallback = JSValue (T::*)(JSContext*, JSValueConst, int, JSValueConst*);
46 template<typename T>
47 using MemberFunctionGetCallback = JSValue (T::*)(JSContext*, JSValueConst);
48 template<typename T>
49 using MemberFunctionSetCallback = JSValue (T::*)(JSContext*, JSValueConst, JSValueConst);
50 using ExoticGetterCallback = JSValue (*)(JSContext* ctx, JSValueConst obj, JSAtom atom, JSValueConst receiver);
51 using ExoticSetterCallback = int (*)(
52     JSContext* ctx, JSValueConst obj, JSAtom atom, JSValueConst value, JSValueConst receiver, int flags);
53 using ExoticHasPropertyCallback = int (*)(JSContext* ctx, JSValueConst obj, JSAtom atom);
54 using ExoticIsArrayCallback = int (*)(JSContext* ctx, JSValueConst obj);
55 
56 /* return < 0 if exception or TRUE/FALSE */
57 
58 constexpr const JavascriptEngine cCurrentJSEngine = JavascriptEngine::QUICKJS;
59 
60 #elif USE_V8_ENGINE
61 
62 #include "third_party/v8/include/v8.h"
63 
64 using BindingTarget = v8::Local<v8::ObjectTemplate>;
65 using FunctionCallback = void (*)(const v8::FunctionCallbackInfo<v8::Value>&);
66 using FunctionGetCallback = void (*)(const v8::FunctionCallbackInfo<v8::Value>&);
67 using FunctionSetCallback = void (*)(const v8::FunctionCallbackInfo<v8::Value>&);
68 template<typename T>
69 using MemberFunctionCallback = void (T::*)(const v8::FunctionCallbackInfo<v8::Value>&);
70 template<typename T>
71 using MemberFunctionGetCallback = void (T::*)(const v8::FunctionCallbackInfo<v8::Value>&);
72 template<typename T>
73 using MemberFunctionSetCallback = void (T::*)(const v8::FunctionCallbackInfo<v8::Value>&);
74 using ExoticGetterCallback = int;
75 using ExoticSetterCallback = int;
76 using ExoticHasPropertyCallback = int;
77 using ExoticIsArrayCallback = int;
78 
79 constexpr const JavascriptEngine cCurrentJSEngine = JavascriptEngine::V8;
80 
81 #elif USE_ARK_ENGINE
82 
83 #include "ecmascript/napi/include/jsnapi.h"
84 
85 using BindingTarget = panda::Local<panda::ObjectRef>;
86 using FunctionCallback = panda::Local<panda::JSValueRef>(*)(panda::JsiRuntimeCallInfo*);
87 using FunctionGetCallback = panda::Local<panda::JSValueRef>(*)(panda::JsiRuntimeCallInfo*);
88 using FunctionSetCallback = panda::Local<panda::JSValueRef>(*)(panda::JsiRuntimeCallInfo*);
89 template<typename T>
90 using MemberFunctionCallback = panda::Local<panda::JSValueRef>(T::*)(panda::JsiRuntimeCallInfo*);
91 template<typename T>
92 using MemberFunctionGetCallback = panda::Local<panda::JSValueRef>(T::*)(panda::JsiRuntimeCallInfo*);
93 template<typename T>
94 using MemberFunctionSetCallback = panda::Local<panda::JSValueRef>(T::*)(panda::JsiRuntimeCallInfo*);
95 using ExoticGetterCallback = int;
96 using ExoticSetterCallback = int;
97 using ExoticHasPropertyCallback = int;
98 using ExoticIsArrayCallback = int;
99 
100 constexpr const JavascriptEngine cCurrentJSEngine = JavascriptEngine::ARK;
101 
102 #else
103 #error "No engine selected"
104 #endif
105 
106 using JSFunctionCallback = void (*)(const OHOS::Ace::Framework::JSCallbackInfo&);
107 template<typename T>
108 using JSMemberFunctionCallback = void (T::*)(const OHOS::Ace::Framework::JSCallbackInfo&);
109 template<typename T>
110 using JSDestructorCallback = void (*)(T* instance);
111 template<typename T>
112 using JSGCMarkCallback = void (*)(T* instance, const OHOS::Ace::Framework::JSGCMarkCallbackInfo&);
113 
114 #endif
115