• 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 #include "frameworks/bridge/declarative_frontend/engine/declarative_engine_loader.h"
17 
18 #include "base/utils/macros.h"
19 
20 #ifdef USE_V8_ENGINE
21 #include "frameworks/bridge/declarative_frontend/engine/v8/v8_declarative_engine.h"
22 #endif
23 
24 #ifdef USE_QUICKJS_ENGINE
25 #include "frameworks/bridge/declarative_frontend/engine/quickjs/qjs_declarative_engine.h"
26 #endif
27 
28 #ifdef USE_ARK_ENGINE
29 #include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
30 #endif
31 
32 namespace OHOS::Ace::Framework {
33 
34 DeclarativeEngineLoader::DeclarativeEngineLoader() = default;
35 DeclarativeEngineLoader::~DeclarativeEngineLoader() = default;
36 
CreateJsEngine(int32_t instanceId) const37 RefPtr<JsEngine> DeclarativeEngineLoader::CreateJsEngine(int32_t instanceId) const
38 {
39 #ifdef USE_V8_ENGINE
40     return AceType::MakeRefPtr<V8DeclarativeEngine>(instanceId);
41 #endif
42 
43 #ifdef USE_QUICKJS_ENGINE
44     return AceType::MakeRefPtr<QJSDeclarativeEngine>(instanceId);
45 #endif
46 
47 #ifdef USE_ARK_ENGINE
48     return AceType::MakeRefPtr<JsiDeclarativeEngine>(instanceId);
49 #endif
50 }
51 
CreateJsEngineUsingSharedRuntime(int32_t instanceId,void * runtime) const52 RefPtr<JsEngine> DeclarativeEngineLoader::CreateJsEngineUsingSharedRuntime(int32_t instanceId, void* runtime) const
53 {
54 #ifdef USE_ARK_ENGINE
55     LOGD("CreateJsEngineUsingSharedRuntime id:%{public}d", instanceId);
56     return AceType::MakeRefPtr<JsiDeclarativeEngine>(instanceId, runtime);
57 #else
58     return nullptr;
59 #endif
60 }
61 
CreateCanvasBridge() const62 RefPtr<BaseCanvasBridge> DeclarativeEngineLoader::CreateCanvasBridge() const
63 {
64     return nullptr;
65 }
66 
CreateXComponentBridge() const67 RefPtr<BaseXComponentBridge> DeclarativeEngineLoader::CreateXComponentBridge() const
68 {
69     return nullptr;
70 }
71 
72 #if defined(BUILT_IN_JS_ENGINE)
GetDeclarative(const char *)73 JsEngineLoader& JsEngineLoader::GetDeclarative(const char*)
74 {
75     return DeclarativeEngineLoader::GetInstance();
76 }
77 #else
OHOS_ACE_GetJsEngineLoader()78 extern "C" ACE_FORCE_EXPORT void* OHOS_ACE_GetJsEngineLoader()
79 {
80     return &DeclarativeEngineLoader::GetInstance();
81 }
82 #endif
83 
84 } // namespace OHOS::Ace::Framework