• 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JS_TYPES_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JS_TYPES_H
18 
19 #ifdef USE_V8_ENGINE
20 #include "frameworks/bridge/declarative_frontend/engine/v8/v8_types.h"
21 #elif USE_QUICKJS_ENGINE
22 #include "frameworks/bridge/declarative_frontend/engine/quickjs/qjs_types.h"
23 #elif USE_ARK_ENGINE
24 #include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.h"
25 #endif
26 
27 namespace OHOS::Ace::Framework {
28 
29 #ifdef USE_V8_ENGINE
30 // QJS already has JSValue so we can't use that.
31 // Put QJS APIs within a namespace called "qjs"
32 // This way we will make sure there won't be any name clashes
33 using JSVal = V8Value;
34 using JSObject = V8Object;
35 // QJS has JSFunction typedef
36 using JSFunc = V8Funktion;
37 using JSArray = V8Array;
38 using JSCallbackInfo = V8CallbackInfo;
39 using JSGCMarkCallbackInfo = V8GCMarkCallbackInfo;
40 using JSException = V8Exception;
41 using JSExecutionContext = V8ExecutionContext;
42 using JSObjTemplate = V8ObjTemplate;
43 
44 template<class T>
ToJSValue(T && val)45 inline auto ToJSValue(T&& val)
46 {
47     return V8ValueConvertor::toV8Value(std::forward<T>(val));
48 };
49 
50 void JsStopPropagation(const v8::FunctionCallbackInfo<v8::Value>& info);
51 
52 #elif USE_QUICKJS_ENGINE
53 
54 using JSVal = QJSValue;
55 using JSObject = QJSObject;
56 using JSFunc = QJSFunction;
57 using JSArray = QJSArray;
58 using JSCallbackInfo = QJSCallbackInfo;
59 using JSGCMarkCallbackInfo = QJSGCMarkCallbackInfo;
60 using JSException = QJSException;
61 using JSExecutionContext = QJSExecutionContext;
62 using JSObjTemplate = QJSObjTemplate;
63 
64 template<class T>
65 inline auto ToJSValue(T&& val)
66 {
67     return QJSValueConvertor::toQJSValue(std::forward<T>(val));
68 };
69 
70 JSValue JsStopPropagation(JSContext* ctx, JSValueConst new_target, int argc, JSValueConst* arg);
71 
72 #elif USE_ARK_ENGINE
73 
74 using JSVal = JsiValue;
75 using JSObject = JsiObject;
76 using JSFunc = JsiFunction;
77 using JSArray = JsiArray;
78 using JSCallbackInfo = JsiCallbackInfo;
79 using JSGCMarkCallbackInfo = JsiGCMarkCallbackInfo;
80 using JSException = JsiException;
81 using JSExecutionContext = JsiExecutionContext;
82 using JSObjTemplate = JsiObjTemplate;
83 
84 template<class T>
85 inline auto ToJSValue(T&& val)
86 {
87     return JsiValueConvertor::toJsiValue(std::forward<T>(val));
88 };
89 
90 Local<JSValueRef> JsStopPropagation(EcmaVM*, Local<JSValueRef>, const Local<JSValueRef> [], int32_t, void*);
91 
92 #endif
93 
94 }; // namespace OHOS::Ace::Framework
95 
96 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JS_TYPES_H
97