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 = V8Function; 37 using JSArray = V8Array; 38 using JSString = V8String; 39 using JSCallbackInfo = V8CallbackInfo; 40 using JSGCMarkCallbackInfo = V8GCMarkCallbackInfo; 41 using JSException = V8Exception; 42 using JSExecutionContext = V8ExecutionContext; 43 using JSObjTemplate = V8ObjTemplate; 44 45 template<class T> ToJSValue(T && val)46inline auto ToJSValue(T&& val) 47 { 48 return V8ValueConvertor::toV8Value(std::forward<T>(val)); 49 }; 50 51 void JsStopPropagation(const v8::FunctionCallbackInfo<v8::Value>& info); 52 53 #elif USE_QUICKJS_ENGINE 54 55 using JSVal = QJSValue; 56 using JSObject = QJSObject; 57 using JSFunc = QJSFunction; 58 using JSArray = QJSArray; 59 using JSString = QJSString; 60 using JSCallbackInfo = QJSCallbackInfo; 61 using JSGCMarkCallbackInfo = QJSGCMarkCallbackInfo; 62 using JSException = QJSException; 63 using JSExecutionContext = QJSExecutionContext; 64 using JSObjTemplate = QJSObjTemplate; 65 66 template<class T> 67 inline auto ToJSValue(T&& val) 68 { 69 return QJSValueConvertor::toQJSValue(std::forward<T>(val)); 70 }; 71 72 JSValue JsStopPropagation(JSContext* ctx, JSValueConst new_target, int argc, JSValueConst* arg); 73 74 #elif USE_ARK_ENGINE 75 76 using JSVal = JsiValue; 77 using JSObject = JsiObject; 78 using JSFunc = JsiFunction; 79 using JSArray = JsiArray; 80 using JSString = JsiString; 81 using JSCallbackInfo = JsiCallbackInfo; 82 using JSGCMarkCallbackInfo = JsiGCMarkCallbackInfo; 83 using JSException = JsiException; 84 using JSExecutionContext = JsiExecutionContext; 85 using JSObjTemplate = JsiObjTemplate; 86 87 template<class T> 88 inline auto ToJSValue(T&& val) 89 { 90 return JsiValueConvertor::toJsiValue(std::forward<T>(val)); 91 }; 92 93 Local<JSValueRef> JsStopPropagation(panda::JsiRuntimeCallInfo *info); 94 95 #endif 96 97 }; // namespace OHOS::Ace::Framework 98 99 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JS_TYPES_H 100