From 51c79577921c7c953fc04397d0a2cfb3da042665 Mon Sep 17 00:00:00 2001 From: mmorozov Date: Fri, 30 May 2025 16:39:40 +0300 Subject: [PATCH] Add new array API Issue: #ICJKIY Signed-off-by: mmorozov Change-Id: Ica611932adaa3470bcfbea363630fe8ea56eb60c Signed-off-by: Denis Slynko --- .../js/src/common/ani_helper/type_converter.cpp | 15 +++++---------- .../js/src/common/ani_helper/type_converter.h | 4 ++-- .../js/src/mod_fs/properties/ani/listfile_ani.cpp | 4 ++-- .../js/src/mod_fs/properties/ani/listfile_ani.h | 4 ++-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/interfaces/kits/js/src/common/ani_helper/type_converter.cpp b/interfaces/kits/js/src/common/ani_helper/type_converter.cpp index ba640a84c..89a692ca0 100644 --- a/interfaces/kits/js/src/common/ani_helper/type_converter.cpp +++ b/interfaces/kits/js/src/common/ani_helper/type_converter.cpp @@ -267,20 +267,15 @@ std::tuple TypeConverter::ToAniArrayBuffer(ani_env *env, return { true, static_cast(obj) }; } -std::tuple TypeConverter::ToAniStringList( +std::tuple TypeConverter::ToAniStringList( ani_env *env, const std::string strList[], const uint32_t length) { if (env == nullptr) { return { false, nullptr }; } - auto classDesc = BuiltInTypes::String::classDesc.c_str(); - ani_array_ref result = nullptr; - ani_class cls = nullptr; - if (env->FindClass(classDesc, &cls) != ANI_OK) { - return { false, result }; - } - if (env->Array_New_Ref(cls, length, nullptr, &result) != ANI_OK) { + ani_array result = nullptr; + if (env->Array_New(length, nullptr, &result) != ANI_OK) { return { false, result }; } for (uint32_t i = 0; i < length; i++) { @@ -289,11 +284,11 @@ std::tuple TypeConverter::ToAniStringList( return { false, nullptr }; } - if (env->Array_Set_Ref(result, i, item) != ANI_OK) { + if (env->Array_Set(result, i, item) != ANI_OK) { return { false, nullptr }; } } return { true, result }; } -} // namespace OHOS::FileManagement::ModuleFileIO::ANI \ No newline at end of file +} // namespace OHOS::FileManagement::ModuleFileIO::ANI diff --git a/interfaces/kits/js/src/common/ani_helper/type_converter.h b/interfaces/kits/js/src/common/ani_helper/type_converter.h index bac25493f..a0176dc19 100644 --- a/interfaces/kits/js/src/common/ani_helper/type_converter.h +++ b/interfaces/kits/js/src/common/ani_helper/type_converter.h @@ -39,10 +39,10 @@ public: static std::tuple> EnumToInt32(ani_env *env, const ani_enum_item &enumOp); static std::tuple ToFileInfo(ani_env *env, const ani_object &pathOrFd); static std::tuple ToArrayBuffer(ani_env *env, ani_arraybuffer &buffer); - static std::tuple ToAniStringList( + static std::tuple ToAniStringList( ani_env *env, const std::string strList[], const uint32_t length); }; } // namespace OHOS::FileManagement::ModuleFileIO::ANI -#endif // FILEMANAGEMENT_ANI_TYPE_CONVERTER_H \ No newline at end of file +#endif // FILEMANAGEMENT_ANI_TYPE_CONVERTER_H diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp index 44b8faf6e..337eacf4d 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp @@ -206,7 +206,7 @@ tuple> ParseArgs(ani_env *env, ani_object obj) return { true, make_optional(result) }; } -ani_array_ref ListFileAni::ListFileSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_object obj) +ani_array ListFileAni::ListFileSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_object obj) { auto [succPath, srcPath] = TypeConverter::ToUTF8String(env, path); if (!succPath) { @@ -244,4 +244,4 @@ ani_array_ref ListFileAni::ListFileSync(ani_env *env, [[maybe_unused]] ani_class } // namespace ANI } // namespace ModuleFileIO } // namespace FileManagement -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.h index 63ff7731d..2045ec1cb 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.h @@ -25,7 +25,7 @@ namespace ANI { class ListFileAni final { public: - static ani_array_ref ListFileSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_object obj); + static ani_array ListFileSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_object obj); }; } // namespace ANI @@ -33,4 +33,4 @@ public: } // namespace FileManagement } // namespace OHOS -#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_FILELIST_ANI_H \ No newline at end of file +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_FILELIST_ANI_H -- Gitee