From 8a37501fc5d127196a48e4bb3d89a01dc33a5000 Mon Sep 17 00:00:00 2001 From: lifansheng Date: Tue, 25 Oct 2022 10:53:58 +0800 Subject: [PATCH] Fix bug for mergeAbcPath of the application issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I5XIRT?from=project-issue Signed-off-by: lifansheng Change-Id: I8251d837bbb04d4d3f83db15a94d7c414fedaa9b --- frameworks/native/runtime/js_runtime.cpp | 24 ++++++++++++++++--- .../inner_api/runtime/include/js_runtime.h | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index b64c1c4bac..e0ac879910 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -60,7 +60,8 @@ constexpr char ARK_DEBUGGER_LIB_PATH[] = "/system/lib/libark_debugger.z.so"; #endif constexpr char TIMER_TASK[] = "uv_timer_task"; -static constexpr char MERGE_ABC_PATH[] = "/data/storage/el1/bundle/entry/ets/modules.abc"; +constexpr char MERGE_ABC_PATH[] = "/ets/modules.abc"; +constexpr char BUNDLE_INSTALL_PATH[] = "/data/storage/el1/bundle/"; class ArkJsRuntime : public JsRuntime { public: @@ -138,7 +139,16 @@ public: return result; } } else { - if (!runtimeExtractor->GetFileBuffer(MERGE_ABC_PATH, outStream)) { + std::string mergeAbcPath; + if (vm_ && !moduleName_.empty()) { + mergeAbcPath = BUNDLE_INSTALL_PATH + moduleName_ + MERGE_ABC_PATH; + panda::JSNApi::SetAssetPath(vm_, mergeAbcPath); + } else { + HILOG_ERROR("vm is nullptr or moduleName is hole"); + return result; + } + + if (!runtimeExtractor->GetFileBuffer(mergeAbcPath, outStream)) { HILOG_ERROR("Get Module abc file failed"); return result; } @@ -613,6 +623,13 @@ std::unique_ptr JsRuntime::LoadModule( moduleName.c_str(), modulePath.c_str(), hapPath.c_str(), esmodule ? "true" : "false"); HandleScope handleScope(*this); + std::string path = moduleName; + auto pos = path.find("::"); + if (pos != std::string::npos) { + path.erase(pos, path.size() - pos); + moduleName_ = path; + } + NativeValue* classValue = nullptr; auto it = modules_.find(modulePath); @@ -689,7 +706,8 @@ bool JsRuntime::RunScript(const std::string& srcPath, const std::string& hapPath return result; } } else { - if (!runtimeExtractor->GetFileBuffer(MERGE_ABC_PATH, outStream)) { + std::string mergeAbcPath = BUNDLE_INSTALL_PATH + moduleName_ + MERGE_ABC_PATH; + if (!runtimeExtractor->GetFileBuffer(mergeAbcPath, outStream)) { HILOG_ERROR("Get Module abc file failed"); return result; } diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index 432fe3414a..f269fb71e3 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -88,6 +88,7 @@ protected: bool isBundle_ = true; std::unique_ptr nativeEngine_; std::string codePath_; + std::string moduleName_; std::unique_ptr methodRequireNapiRef_; std::shared_ptr eventHandler_; std::unordered_map modules_;