From 9cf1433386496c492418be6836b3568e424c2bd0 Mon Sep 17 00:00:00 2001 From: AnBetter Date: Fri, 11 Apr 2025 14:17:53 +0800 Subject: [PATCH 1/8] Implementation of GC DFX Issue: [Feature]: https://gitee.com/openharmony/arkui_napi/issues/IC0DAS Reason: Implementation of GC DFX Description: Implementation of GC DFX Change-Id: Ic8931c816cc9a4783f3d2f6f968fef51d1710541 Signed-off-by: AnBetter --- interfaces/inner_api/napi/native_node_api.h | 3 ++ .../impl/ark/ark_native_reference.cpp | 11 +++++ native_engine/impl/ark/ark_native_reference.h | 2 + native_engine/native_api.cpp | 37 +++++++++++++++++ test/unittest/test_napi.cpp | 41 +++++++++++++++++++ 5 files changed, 94 insertions(+) diff --git a/interfaces/inner_api/napi/native_node_api.h b/interfaces/inner_api/napi/native_node_api.h index 36fb825d0..6c3e080f6 100644 --- a/interfaces/inner_api/napi/native_node_api.h +++ b/interfaces/inner_api/napi/native_node_api.h @@ -213,6 +213,9 @@ NAPI_EXTERN napi_status napi_wrap_with_xref(napi_env env, void* native_object, napi_finalize finalize_cb, napi_ref* result); +NAPI_EXTERN napi_status napi_is_alive_object(napi_env env, napi_ref ref, bool* result); +NAPI_EXTERN napi_status napi_is_contain_object(napi_env env, napi_ref ref, bool* result); +NAPI_EXTERN napi_status napi_is_xref_type(napi_env env, napi_value js_object, bool* result); #endif // PANDA_JS_ETS_HYBRID_MODE NAPI_EXTERN napi_status napi_register_appstate_callback(napi_env env, NapiAppStateCallback callback); diff --git a/native_engine/impl/ark/ark_native_reference.cpp b/native_engine/impl/ark/ark_native_reference.cpp index fe0c88a31..f086ba26a 100644 --- a/native_engine/impl/ark/ark_native_reference.cpp +++ b/native_engine/impl/ark/ark_native_reference.cpp @@ -229,4 +229,15 @@ void ArkNativeReference::MarkFromObject() { value_.MarkFromObject(); } + +bool ArkNativeReference::IsObjectAlive() +{ + return value_.IsObjectAlive(); +} + +bool ArkNativeReference::IsValidHeapObject() +{ + return value_.IsValidHeapObject(); +} + #endif // PANDA_JS_ETS_HYBRID_MODE diff --git a/native_engine/impl/ark/ark_native_reference.h b/native_engine/impl/ark/ark_native_reference.h index a359de638..10b0c7367 100644 --- a/native_engine/impl/ark/ark_native_reference.h +++ b/native_engine/impl/ark/ark_native_reference.h @@ -92,6 +92,8 @@ public: void ResetFinalizer() override; #ifdef PANDA_JS_ETS_HYBRID_MODE void MarkFromObject(); + bool IsObjectAlive(); + bool IsValidHeapObject(); #endif // PANDA_JS_ETS_HYBRID_MODE private: diff --git a/native_engine/native_api.cpp b/native_engine/native_api.cpp index c9e9894ea..0228afa07 100644 --- a/native_engine/native_api.cpp +++ b/native_engine/native_api.cpp @@ -4436,6 +4436,24 @@ NAPI_EXTERN napi_status napi_mark_from_object(napi_env env, napi_ref ref) return napi_clear_last_error(env); } +NAPI_EXTERN napi_status napi_is_alive_object(napi_env env, napi_ref ref, bool *result) +{ + NAPI_PREAMBLE(env); + CHECK_ARG(env, ref); + ArkNativeReference* reference = reinterpret_cast(ref); + *result = reference->IsObjectAlive(); + return napi_clear_last_error(env); +} + +NAPI_EXTERN napi_status napi_is_contain_object(napi_env env, napi_ref ref, bool *result) +{ + NAPI_PREAMBLE(env); + CHECK_ARG(env, ref); + ArkNativeReference* reference = reinterpret_cast(ref); + *result = reference->IsValidHeapObject(); + return napi_clear_last_error(env); +} + NAPI_EXTERN napi_status napi_create_xref(napi_env env, napi_value value, uint32_t initial_refcount, napi_ref* result) { CHECK_ENV(env); @@ -4480,4 +4498,23 @@ NAPI_EXTERN napi_status napi_wrap_with_xref(napi_env env, nativeObject->DefineProperty(vm, key, attr); return GET_RETURN_STATUS(env); } + +NAPI_EXTERN napi_status napi_is_xref_type(napi_env env, napi_value js_object, bool* result) +{ + *result = false; + NAPI_PREAMBLE(env); + CHECK_ARG(env, js_object); + CHECK_ARG(env, result); + + auto nativeValue = LocalValueFromJsValue(js_object); + auto engine = reinterpret_cast(env); + auto vm = engine->GetEcmaVm(); + CHECK_AND_CONVERT_TO_OBJECT(env, vm, nativeValue, nativeObject); + Local key = panda::StringRef::GetProxyNapiWrapperString(vm); + + if (nativeObject->Has(vm, key)) { + *result = true; + } + return GET_RETURN_STATUS(env); +} #endif // PANDA_JS_ETS_HYBRID_MODE \ No newline at end of file diff --git a/test/unittest/test_napi.cpp b/test/unittest/test_napi.cpp index dc41875b7..33686a0a6 100644 --- a/test/unittest/test_napi.cpp +++ b/test/unittest/test_napi.cpp @@ -8902,6 +8902,47 @@ HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test004, testing::ext::TestSize.L ASSERT_EQ(status, napi_bigint_expected); } +HWTEST_F(NapiBasicTest, NapiIsAliveObjectTest001, testing::ext::TestSize.Level1) +{ + napi_env env = reinterpret_cast(engine_); + napi_value obj; + napi_ref result = nullptr; + bool res = false; + + napi_create_object(env, &obj); + napi_status status = + napi_wrap_with_xref(env, obj, (void*)TEST_STRING, [](napi_env, void* data, void* hint) {}, &result); + ASSERT_EQ(status, napi_ok); + status = napi_is_alive_object(env, result, &res); + ASSERT_EQ(status, napi_ok); +} + +HWTEST_F(NapiBasicTest, NapiIsValidHeapObjectTest001, testing::ext::TestSize.Level1) +{ + napi_env env = reinterpret_cast(engine_); + napi_value obj; + napi_ref result = nullptr; + bool res = false; + + napi_create_object(env, &obj); + napi_status status = + napi_wrap_with_xref(env, obj, (void*)TEST_STRING, [](napi_env, void* data, void* hint) {}, &result); + ASSERT_EQ(status, napi_ok); + status = napi_is_contain_object(env, result, &res); + ASSERT_EQ(status, napi_ok); +} + +HWTEST_F(NapiBasicTest, NapiIsXrefTypeTest001, testing::ext::TestSize.Level1) +{ + napi_env env = reinterpret_cast(engine_); + napi_value obj; + bool res = false; + + napi_create_object(env, &obj); + napi_status status = napi_is_xref_type(env, obj, &res); + ASSERT_EQ(status, napi_ok); +} + HWTEST_F(NapiBasicTest, NapiGetValueBigintInt64Test005, testing::ext::TestSize.Level1) { napi_env env = reinterpret_cast(engine_); -- Gitee From 2d94ed0229949d729c4aea16bebe7df57d3a3f5b Mon Sep 17 00:00:00 2001 From: zhao1d Date: Sat, 24 May 2025 20:10:02 +0800 Subject: [PATCH 2/8] =?UTF-8?q?napi=E9=80=82=E9=85=8D1.0=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E9=80=82=E9=85=8D1.2=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E7=9A=84interface(0328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICAAIG Signed-off-by: zhao1d Change-Id: I20533daacec0004418f3dd52f27d8d4081fd1697 --- interfaces/inner_api/napi/native_node_api.h | 1 + native_engine/native_node_api.cpp | 14 ++++++++++++++ test/unittest/test_napi.cpp | 15 +++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/interfaces/inner_api/napi/native_node_api.h b/interfaces/inner_api/napi/native_node_api.h index 6c3e080f6..713571120 100644 --- a/interfaces/inner_api/napi/native_node_api.h +++ b/interfaces/inner_api/napi/native_node_api.h @@ -216,6 +216,7 @@ NAPI_EXTERN napi_status napi_wrap_with_xref(napi_env env, NAPI_EXTERN napi_status napi_is_alive_object(napi_env env, napi_ref ref, bool* result); NAPI_EXTERN napi_status napi_is_contain_object(napi_env env, napi_ref ref, bool* result); NAPI_EXTERN napi_status napi_is_xref_type(napi_env env, napi_value js_object, bool* result); +NAPI_EXTERN napi_status napi_get_ets_implements(napi_env env, napi_value value, napi_value* result); #endif // PANDA_JS_ETS_HYBRID_MODE NAPI_EXTERN napi_status napi_register_appstate_callback(napi_env env, NapiAppStateCallback callback); diff --git a/native_engine/native_node_api.cpp b/native_engine/native_node_api.cpp index de8b2b64f..830b43961 100644 --- a/native_engine/native_node_api.cpp +++ b/native_engine/native_node_api.cpp @@ -624,3 +624,17 @@ NAPI_EXTERN napi_status napi_make_callback(napi_env env, } return GET_RETURN_STATUS(env); } + +NAPI_EXTERN napi_status napi_get_ets_implements(napi_env env, napi_value value, napi_value* result) +{ + NAPI_PREAMBLE(env); + CHECK_ARG(env, value); + CHECK_ARG(env, result); + + auto nativeValue = LocalValueFromJsValue(value); + auto engine = reinterpret_cast(env); + auto vm = engine->GetEcmaVm(); + Local implementsValue = panda::JSNApi::GetImplements(vm, nativeValue); + *result = JsValueFromLocalValue(implementsValue); + return GET_RETURN_STATUS(env); +} diff --git a/test/unittest/test_napi.cpp b/test/unittest/test_napi.cpp index 33686a0a6..78285de1b 100644 --- a/test/unittest/test_napi.cpp +++ b/test/unittest/test_napi.cpp @@ -8130,6 +8130,21 @@ HWTEST_F(NapiBasicTest, NapiMakeCallbackTest002, testing::ext::TestSize.Level1) ASSERT_EQ(status, napi_invalid_arg); } +/** + * @tc.name: NapiGetEtsImplementsTest + * @tc.desc: Test interface of napi_get_ets_implements + * @tc.type: FUNC + */ +HWTEST_F(NapiBasicTest, NapiGetEtsImplementsTest, testing::ext::TestSize.Level1) +{ + napi_env env = reinterpret_cast(engine_); + napi_value value = nullptr; + napi_value result = nullptr; + + napi_status status = napi_get_ets_implements(env, value, &result); + ASSERT_EQ(status, napi_invalid_arg); +} + HWTEST_F(NapiBasicTest, NapiAsyncDestroyTest001, testing::ext::TestSize.Level1) { napi_env env = reinterpret_cast(engine_); -- Gitee From 86862a8c47cb53641311407f04d25994fc70ee6f Mon Sep 17 00:00:00 2001 From: oh_ci Date: Thu, 26 Jun 2025 13:01:20 +0000 Subject: [PATCH 3/8] update .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md. Signed-off-by: oh_ci --- .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md index 7d9bbc496..1f4ef3faf 100644 --- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md +++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -49,4 +49,8 @@ - [ ] 无相关crash产生 - [ ] 不涉及,无需验证 +### L0新增用例自检结果 +- [ ] 是,有新增L0用例,且完成自检 +- [ ] 否 + ### 将上述测试的截图贴到下面 -- Gitee From 79796878ee242e965bb82cd6ca1b2f787e77004d Mon Sep 17 00:00:00 2001 From: z00932658 Date: Wed, 4 Jun 2025 16:56:38 +0800 Subject: [PATCH 4/8] Fix isHybrid for napi Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICI82G Signed-off-by: zhushihao Change-Id: I768896756a16f7ef6b6a6b88b94a676d9b12ef01 --- interfaces/inner_api/napi/native_node_api.h | 4 +++ interfaces/kits/napi/native_api.h | 5 ---- native_engine/impl/ark/ark_native_engine.cpp | 31 ++++++++++++++++++-- native_engine/impl/ark/ark_native_engine.h | 3 +- native_engine/native_api.cpp | 7 ++--- native_engine/native_engine.h | 3 +- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/interfaces/inner_api/napi/native_node_api.h b/interfaces/inner_api/napi/native_node_api.h index 713571120..f7135405d 100644 --- a/interfaces/inner_api/napi/native_node_api.h +++ b/interfaces/inner_api/napi/native_node_api.h @@ -65,6 +65,10 @@ typedef enum { using NapiAppStateCallback = void (*)(int state, int64_t timestamp); +NAPI_EXTERN napi_status napi_load_module_with_info_hybrid(napi_env env, + const char* path, + const char* module_info, + napi_value* result); NAPI_EXTERN napi_status napi_create_limit_runtime(napi_env env, napi_env* result_env); NAPI_EXTERN void napi_module_with_js_register(napi_module_with_js* mod); NAPI_EXTERN napi_status napi_is_callable(napi_env env, napi_value value, bool* result); diff --git a/interfaces/kits/napi/native_api.h b/interfaces/kits/napi/native_api.h index 88309b852..09943bef0 100644 --- a/interfaces/kits/napi/native_api.h +++ b/interfaces/kits/napi/native_api.h @@ -85,11 +85,6 @@ NAPI_EXTERN napi_status napi_load_module_with_info(napi_env env, const char* path, const char* module_info, napi_value* result); -NAPI_EXTERN napi_status napi_load_module_with_info_hybrid(napi_env env, - const char* path, - const char* module_info, - napi_value* result, - bool isHybrid = false); NAPI_EXTERN napi_status napi_create_object_with_properties(napi_env env, napi_value* result, size_t property_count, diff --git a/native_engine/impl/ark/ark_native_engine.cpp b/native_engine/impl/ark/ark_native_engine.cpp index 7e5fd80b2..a3d4cef14 100644 --- a/native_engine/impl/ark/ark_native_engine.cpp +++ b/native_engine/impl/ark/ark_native_engine.cpp @@ -1493,7 +1493,7 @@ napi_value ArkNativeEngine::NapiLoadModule(const char* path) return JsValueFromLocalValue(scope.Escape(exportObj)); } -napi_value ArkNativeEngine::NapiLoadModuleWithInfo(const char* path, const char* module_info, bool isHybrid) +napi_value ArkNativeEngine::NapiLoadModuleWithInfo(const char* path, const char* module_info) { if (path == nullptr) { HILOG_ERROR("ArkNativeEngine:The module name is empty"); @@ -1506,7 +1506,34 @@ napi_value ArkNativeEngine::NapiLoadModuleWithInfo(const char* path, const char* std::string modulePath; if (module_info != nullptr) { modulePath = module_info; - exportObj = panda::JSNApi::GetModuleNameSpaceWithModuleInfo(vm_, inputPath, modulePath, isHybrid); + exportObj = panda::JSNApi::GetModuleNameSpaceWithModuleInfoForNormalApp(vm_, inputPath, modulePath); + } else { + exportObj = NapiLoadNativeModule(inputPath); + } + + if (panda::JSNApi::HasPendingException(vm_)) { + HILOG_WARN("ArkNativeEngine:NapiLoadModuleWithInfo failed."); + panda::JSNApi::PrintExceptionInfo(vm_); + panda::JSNApi::GetAndClearUncaughtException(vm_); // clear exception here + return JsValueFromLocalValue(scope.Escape(undefObj)); + } + return JsValueFromLocalValue(scope.Escape(exportObj)); +} + +napi_value ArkNativeEngine::NapiLoadModuleWithInfoForHybridApp(const char* path, const char* module_info) +{ + if (path == nullptr) { + HILOG_ERROR("ArkNativeEngine:The module name is empty"); + return nullptr; + } + panda::EscapeLocalScope scope(vm_); + Local undefObj = JSValueRef::Undefined(vm_); + Local exportObj(undefObj); + std::string inputPath(path); + std::string modulePath; + if (module_info != nullptr) { + modulePath = module_info; + exportObj = panda::JSNApi::GetModuleNameSpaceWithModuleInfoForHybridApp(vm_, inputPath, modulePath); } else { exportObj = NapiLoadNativeModule(inputPath); } diff --git a/native_engine/impl/ark/ark_native_engine.h b/native_engine/impl/ark/ark_native_engine.h index 8101b3b41..7d3230ef5 100644 --- a/native_engine/impl/ark/ark_native_engine.h +++ b/native_engine/impl/ark/ark_native_engine.h @@ -330,7 +330,8 @@ public: const std::string& moduleName, bool isAppModule, const std::string& id, const std::string& param, const std::string& instanceName, void** instance); napi_value NapiLoadModule(const char* path) override; - napi_value NapiLoadModuleWithInfo(const char* path, const char* module_info, bool isHybrid = false) override; + napi_value NapiLoadModuleWithInfo(const char* path, const char* module_info) override; + napi_value NapiLoadModuleWithInfoForHybridApp(const char* path, const char* module_info) override; std::string GetOhmurl(std::string str); Local NapiLoadNativeModule(std::string path); NativeReference* GetPromiseRejectCallBackRef() diff --git a/native_engine/native_api.cpp b/native_engine/native_api.cpp index 0228afa07..08641f4c8 100644 --- a/native_engine/native_api.cpp +++ b/native_engine/native_api.cpp @@ -3135,13 +3135,12 @@ NAPI_EXTERN napi_status napi_load_module_with_info(napi_env env, NAPI_EXTERN napi_status napi_load_module_with_info_hybrid(napi_env env, const char* path, const char* module_info, - napi_value* result, - bool isHybrid) + napi_value* result) { NAPI_PREAMBLE(env); CHECK_ARG(env, result); auto engine = reinterpret_cast(env); - *result = engine->NapiLoadModuleWithInfo(path, module_info, isHybrid); + *result = engine->NapiLoadModuleWithInfoForHybridApp(path, module_info); return GET_RETURN_STATUS(env); } // Memory management @@ -4393,7 +4392,7 @@ NAPI_EXTERN napi_status napi_load_module_with_module_request(napi_env env, const if (request_name[0] == NAME_SPACE_TAG) { // load module with OhmUrl auto [path, module_info] = panda::JSNApi::ResolveOhmUrl(request_name); - napi_load_module_with_info_hybrid(env, path.c_str(), module_info.c_str(), result, true); + napi_load_module_with_info_hybrid(env, path.c_str(), module_info.c_str(), result); } else { napi_load_module_with_path(env, request_name, result); } diff --git a/native_engine/native_engine.h b/native_engine/native_engine.h index ca528856c..48d73ce78 100644 --- a/native_engine/native_engine.h +++ b/native_engine/native_engine.h @@ -491,7 +491,8 @@ public: void SetModuleLoadChecker(const std::shared_ptr& moduleCheckerDelegate); virtual napi_value NapiLoadModule(const char* path) = 0; - virtual napi_value NapiLoadModuleWithInfo(const char* path, const char* module_info, bool isHybrid = false) = 0; + virtual napi_value NapiLoadModuleWithInfo(const char* path, const char* module_info) = 0; + virtual napi_value NapiLoadModuleWithInfoForHybridApp(const char* path, const char* module_info) = 0; virtual std::string GetPkgName(const std::string &moduleName) = 0; double NewAsyncId() -- Gitee From eaecf2aa10daf442f0665b110d091e3f86e52b9b Mon Sep 17 00:00:00 2001 From: z00932658 Date: Thu, 26 Jun 2025 10:11:50 +0800 Subject: [PATCH 5/8] Add tests for NapiLoadModuleWithInfoForHybridApp Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICI82G Signed-off-by: zhushihao --- test/unittest/test_napi.cpp | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/unittest/test_napi.cpp b/test/unittest/test_napi.cpp index 78285de1b..ac12aad68 100644 --- a/test/unittest/test_napi.cpp +++ b/test/unittest/test_napi.cpp @@ -12562,6 +12562,46 @@ HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoTest004, testing::ext::TestSize.Le ASSERT_EQ(result2->error_code, napi_generic_failure); } +/** + * @tc.name: NapiLoadModuleWithInfoForHybridAppTest + * @tc.desc: Test interface of napi_load_module_with_info_hybrid + * @tc.type: FUNC + */ +HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoForHybridAppTest001, testing::ext::TestSize.Level1) +{ + auto res = napi_load_module_with_info_hybrid(nullptr, nullptr, nullptr, nullptr); + ASSERT_EQ(res, napi_invalid_arg); +} + +/** + * @tc.name: NapiLoadModuleWithInfoForHybridAppTest + * @tc.desc: Test interface of napi_load_module_with_info_hybrid + * @tc.type: FUNC + */ +HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoForHybridAppTest002, testing::ext::TestSize.Level1) +{ + ASSERT_NE(engine_, nullptr); + napi_env env = reinterpret_cast(engine_); + + auto res = napi_load_module_with_info_hybrid(env, nullptr, nullptr, nullptr); + ASSERT_EQ(res, napi_invalid_arg); +} + +/** + * @tc.name: NapiLoadModuleWithInfoForHybridAppTest + * @tc.desc: Test interface of napi_load_module_with_info_hybrid + * @tc.type: FUNC + */ +HWTEST_F(NapiBasicTest, NapiLoadModuleWithInfoForHybridAppTest003, testing::ext::TestSize.Level1) +{ + ASSERT_NE(engine_, nullptr); + napi_env env = reinterpret_cast(engine_); + + napi_value result = nullptr; + auto res = napi_load_module_with_info_hybrid(env, nullptr, nullptr, &result); + ASSERT_EQ(res, napi_ok); +} + /** * @tc.name: NapiSerializeTest * @tc.desc: Test interface of napi_serialize -- Gitee From c7e240d279450109d19f75364dfb4e7c3fafd03b Mon Sep 17 00:00:00 2001 From: yangzk Date: Mon, 23 Jun 2025 14:42:01 +0800 Subject: [PATCH 6/8] =?UTF-8?q?Description:=20=E6=94=AF=E6=8C=81=E9=80=9A?= =?UTF-8?q?=E8=BF=87nativeModuleManager=E5=88=9B=E5=BB=BA=E5=92=8C?= =?UTF-8?q?=E8=8E=B7=E5=8F=96Dl=5Fnamespace=20IssueNo:#ICGTGD=20Sig:=20SIG?= =?UTF-8?q?=5FApplicationFramework=20Feature=20or=20Bugfix:=20Bugfix=20Bin?= =?UTF-8?q?ary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangzk Change-Id: I0bc98926b092d09b81b33a4bb3ea0558efd4380e --- module_manager/native_module_manager.cpp | 21 ++++++++++++++++++- module_manager/native_module_manager.h | 1 + .../module_manager_test.cpp | 14 +++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/module_manager/native_module_manager.cpp b/module_manager/native_module_manager.cpp index 78c61488a..c5c74a3ea 100644 --- a/module_manager/native_module_manager.cpp +++ b/module_manager/native_module_manager.cpp @@ -43,6 +43,10 @@ enum ModuleLoadFailedReason : uint32_t { MODULE_LOAD_SUCCESS = 0, MODULE_NOT_EXIST = 1, }; +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(__BIONIC__) && !defined(IOS_PLATFORM) && \ + !defined(LINUX_PLATFORM) +constexpr char MODULE_NS[] = "moduleNs_"; +#endif } // namespace NativeModuleManager* NativeModuleManager::instance_ = NULL; @@ -454,7 +458,7 @@ void NativeModuleManager::CreateLdNamespace(const std::string moduleName, const Dl_namespace ns; // Create module ns. - std::string nsName = "moduleNs_" + moduleName; + std::string nsName = MODULE_NS + moduleName; dlns_init(&ns, nsName.c_str()); dlns_get(nullptr, ¤t_ns); @@ -502,6 +506,21 @@ void NativeModuleManager::CreateLdNamespace(const std::string moduleName, const #endif } +bool NativeModuleManager::GetLdNamespaceName(const std::string &moduleName, std::string &nsName) +{ +#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(__BIONIC__) && !defined(IOS_PLATFORM) && \ + !defined(LINUX_PLATFORM) + if (nsMap_.find(moduleName) == nsMap_.end()) { + HILOG_ERROR("not found ns: %{public}s", moduleName.c_str()); + return false; + } + nsName = MODULE_NS + moduleName; + return true; +#else + return false; +#endif +} + void NativeModuleManager::SetAppLibPath(const std::string& moduleName, const std::vector& appLibPath, const bool& isSystemApp) { diff --git a/module_manager/native_module_manager.h b/module_manager/native_module_manager.h index 1a45d5db0..be8ce6bb0 100644 --- a/module_manager/native_module_manager.h +++ b/module_manager/native_module_manager.h @@ -84,6 +84,7 @@ public: void Register(NativeModule* nativeModule); void SetAppLibPath(const std::string& moduleName, const std::vector& appLibPath, const bool& isSystemApp = false); + bool GetLdNamespaceName(const std::string &moduleName, std::string &nsName); NativeModule* LoadNativeModule(const char* moduleName, const char* path, bool isAppModule, std::string& errInfo, bool internal = false, const char* relativePath = ""); void SetNativeEngine(std::string moduleName, NativeEngine* nativeEngine); diff --git a/module_manager/test/unittest/module_manager_test/module_manager_test.cpp b/module_manager/test/unittest/module_manager_test/module_manager_test.cpp index 9722ade09..61bc45214 100644 --- a/module_manager/test/unittest/module_manager_test/module_manager_test.cpp +++ b/module_manager/test/unittest/module_manager_test/module_manager_test.cpp @@ -49,6 +49,8 @@ void ModuleManagerTest::TearDown() MockResetModuleManagerState(); } +constexpr char MODULE_NS[] = "moduleNs_"; + /* * @tc.name: LoadNativeModuleTest_001 * @tc.desc: test NativeModule's LoadNativeModule function @@ -227,7 +229,13 @@ HWTEST_F(ModuleManagerTest, LoadNativeModuleTest_008, TestSize.Level1) moduleManager->Register(nullptr); moduleManager->CreateSharedLibsSonames(); + std::string nsName; + bool res = moduleManager->GetLdNamespaceName(moduleName, nsName); + EXPECT_EQ(res, false); moduleManager->CreateLdNamespace(moduleName, libPath, true); + res = moduleManager->GetLdNamespaceName(moduleName, nsName); + EXPECT_EQ(res, true); + EXPECT_STREQ(nsName.c_str(), (MODULE_NS + moduleName).c_str()); GTEST_LOG_(INFO) << "ModuleManagerTest, LoadNativeModuleTest_008 end"; } @@ -245,7 +253,13 @@ HWTEST_F(ModuleManagerTest, LoadNativeModuleTest_009, TestSize.Level1) std::shared_ptr moduleManager = std::make_shared(); ASSERT_NE(nullptr, moduleManager); + std::string nsName; + bool res = moduleManager->GetLdNamespaceName(moduleName, nsName); + EXPECT_EQ(res, false); moduleManager->CreateLdNamespace(moduleName, libPath, false); + res = moduleManager->GetLdNamespaceName(moduleName, nsName); + EXPECT_EQ(res, true); + EXPECT_STREQ(nsName.c_str(), (MODULE_NS + moduleName).c_str()); std::vector appLibPath; moduleManager->SetAppLibPath(moduleName, appLibPath, false); GTEST_LOG_(INFO) << "ModuleManagerTest, LoadNativeModuleTest_009 end"; -- Gitee From 64d62d16e3bf88e1b737527e4baee154f37f63cd Mon Sep 17 00:00:00 2001 From: zhao1d Date: Thu, 10 Jul 2025 21:39:12 +0800 Subject: [PATCH 7/8] napi 1.0runtime adapt 1.2runtime interface cherrypick 0603 Signed-off-by: zhao1d Change-Id: Ifcc1dd902aee391390f3c51f25cd2822eec39741 --- interfaces/inner_api/napi/native_node_api.h | 1 + native_engine/native_node_api.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/interfaces/inner_api/napi/native_node_api.h b/interfaces/inner_api/napi/native_node_api.h index f7135405d..036567b55 100644 --- a/interfaces/inner_api/napi/native_node_api.h +++ b/interfaces/inner_api/napi/native_node_api.h @@ -221,6 +221,7 @@ NAPI_EXTERN napi_status napi_is_alive_object(napi_env env, napi_ref ref, bool* r NAPI_EXTERN napi_status napi_is_contain_object(napi_env env, napi_ref ref, bool* result); NAPI_EXTERN napi_status napi_is_xref_type(napi_env env, napi_value js_object, bool* result); NAPI_EXTERN napi_status napi_get_ets_implements(napi_env env, napi_value value, napi_value* result); +NAPI_EXTERN napi_status napi_setup_hybrid_environment(napi_env env); #endif // PANDA_JS_ETS_HYBRID_MODE NAPI_EXTERN napi_status napi_register_appstate_callback(napi_env env, NapiAppStateCallback callback); diff --git a/native_engine/native_node_api.cpp b/native_engine/native_node_api.cpp index 830b43961..732c4638c 100644 --- a/native_engine/native_node_api.cpp +++ b/native_engine/native_node_api.cpp @@ -638,3 +638,13 @@ NAPI_EXTERN napi_status napi_get_ets_implements(napi_env env, napi_value value, *result = JsValueFromLocalValue(implementsValue); return GET_RETURN_STATUS(env); } + +NAPI_EXTERN napi_status napi_setup_hybrid_environment(napi_env env) +{ + NAPI_PREAMBLE(env); + + auto engine = reinterpret_cast(env); + auto vm = engine->GetEcmaVm(); + panda::JSNApi::InitHybridVMEnv(vm); + return GET_RETURN_STATUS(env); +} -- Gitee From 48560ebf69918b4719461868b9152c29046529bd Mon Sep 17 00:00:00 2001 From: z00932658 Date: Wed, 23 Jul 2025 09:33:51 +0800 Subject: [PATCH 8/8] Merge branch 0603 into master Issue: https://gitee.com/openharmony/arkui_napi/issues/ICO4DG Signed-off-by: zhushihao Change-Id: I6c2bb89b0155a91db125974437b5e5c9255dec19 --- interfaces/inner_api/napi/native_node_api.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interfaces/inner_api/napi/native_node_api.h b/interfaces/inner_api/napi/native_node_api.h index d8dc67e92..0b92f6703 100644 --- a/interfaces/inner_api/napi/native_node_api.h +++ b/interfaces/inner_api/napi/native_node_api.h @@ -67,10 +67,6 @@ typedef enum { using NapiAppStateCallback = void (*)(int state, int64_t timestamp); -NAPI_EXTERN napi_status napi_load_module_with_info_hybrid(napi_env env, - const char* path, - const char* module_info, - napi_value* result); NAPI_EXTERN napi_status napi_create_limit_runtime(napi_env env, napi_env* result_env); NAPI_EXTERN void napi_module_with_js_register(napi_module_with_js* mod); NAPI_EXTERN napi_status napi_is_callable(napi_env env, napi_value value, bool* result); -- Gitee