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 "runtime.h" 17 18#ifdef CJ_FRONTEND 19#include "cj_runtime.h" 20#endif 21#include "js_runtime.h" 22 23namespace OHOS { 24namespace AbilityRuntime { 25namespace { 26std::unique_ptr<Runtime> g_preloadedInstance; 27} 28 29std::unique_ptr<Runtime> Runtime::Create(const Runtime::Options& options) 30{ 31 switch (options.lang) { 32 case Runtime::Language::JS: 33 return JsRuntime::Create(options); 34#ifdef CJ_FRONTEND 35 case Runtime::Language::CJ: 36 return CJRuntime::Create(options); 37#endif 38 default: 39 return std::unique_ptr<Runtime>(); 40 } 41} 42 43void Runtime::SavePreloaded(std::unique_ptr<Runtime>&& instance) 44{ 45 if (instance) { 46 instance->FinishPreload(); 47 } 48 g_preloadedInstance = std::move(instance); 49} 50 51std::unique_ptr<Runtime> Runtime::GetPreloaded() 52{ 53 return std::move(g_preloadedInstance); 54} 55} // namespace AbilityRuntime 56} // namespace OHOS 57