diff --git a/interfaces/kits/js/src/common/ani_helper/ani_helper.h b/interfaces/kits/js/src/common/ani_helper/ani_helper.h index f600a41df81ba8238df6a32b8bcb39bc20afc633..bd5ca58ff3b815404f2f1da9e2e60796b9daa761 100644 --- a/interfaces/kits/js/src/common/ani_helper/ani_helper.h +++ b/interfaces/kits/js/src/common/ani_helper/ani_helper.h @@ -33,7 +33,8 @@ namespace OHOS::FileManagement::ModuleFileIO::ANI { using namespace std; using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature; -inline shared_ptr& GetMainHandler() { +inline shared_ptr &GetMainHandler() +{ thread_local shared_ptr mainHandler; return mainHandler; } @@ -41,60 +42,54 @@ inline shared_ptr& GetMainHandler() { class AniHelper { public: template - static ani_status SetFieldValue( - ani_env *env, const ani_class &cls, ani_object &obj, const char *fieldName, const T &value) + static ani_status SetFieldValue(ani_env *env, ani_object &obj, const string_view &key, const T &value) { - ani_field field; - auto status = env->Class_FindField(cls, fieldName, &field); - if (status != ANI_OK) { - return status; - } - + ani_status status = ANI_ERROR; if constexpr (is_same_v || is_same_v || is_same_v) { - status = env->Object_SetField_Int(obj, field, value); - } else if constexpr (is_same_v || is_same_v) { - status = env->Object_SetField_Long(obj, field, value); + status = env->Object_SetFieldByName_Int(obj, key.data(), static_cast(value)); + } else if constexpr (is_same_v || is_same_v || is_same_v) { + status = env->Object_SetFieldByName_Long(obj, key.data(), static_cast(value)); } else if constexpr (is_same_v || is_same_v) { - status = env->Object_SetField_Double(obj, field, value); + status = env->Object_SetFieldByName_Double(obj, key.data(), static_cast(value)); } else if constexpr (is_same_v || is_same_v) { - status = env->Object_SetField_Boolean(obj, field, value); + status = env->Object_SetFieldByName_Boolean(obj, key.data(), static_cast(value)); } else if constexpr (is_same_v || is_same_v) { auto [succ, aniStr] = TypeConverter::ToAniString(env, value); if (!succ) { return ANI_ERROR; } - status = env->Object_SetField_Ref(obj, field, move(aniStr)); - } else if constexpr (is_base_of_v) { - status = env->Object_SetField_Ref(obj, field, value); + status = env->Object_SetFieldByName_Ref(obj, key.data(), move(aniStr)); + } else if constexpr (std::is_pointer_v && std::is_base_of_v<__ani_ref, std::remove_pointer_t>) { + status = env->Object_SetFieldByName_Ref(obj, key.data(), value); } else { + HILOGE("Invalid ani value type!"); return ANI_INVALID_TYPE; } return status; } template - static ani_status SetPropertyValue( - ani_env *env, const ani_class &cls, ani_object &obj, const string &property, const T &value) + static ani_status SetPropertyValue(ani_env *env, ani_object &obj, const string_view &key, const T &value) { - ani_method method; - string setter = "" + property; - auto status = env->Class_FindMethod(cls, setter.c_str(), nullptr, &method); - if (status != ANI_OK) { - return status; - } - - if constexpr (is_same_v || is_same_v) { + ani_status status = ANI_ERROR; + if constexpr (is_same_v || is_same_v || is_same_v) { + status = env->Object_SetPropertyByName_Int(obj, key.data(), static_cast(value)); + } else if constexpr (is_same_v || is_same_v || is_same_v) { + status = env->Object_SetPropertyByName_Long(obj, key.data(), static_cast(value)); + } else if constexpr (is_same_v || is_same_v) { + status = env->Object_SetPropertyByName_Double(obj, key.data(), static_cast(value)); + } else if constexpr (is_same_v || is_same_v) { + status = env->Object_SetPropertyByName_Boolean(obj, key.data(), static_cast(value)); + } else if constexpr (is_same_v || is_same_v) { auto [succ, aniStr] = TypeConverter::ToAniString(env, value); if (!succ) { return ANI_ERROR; } - status = env->Object_CallMethod_Void(obj, method, move(aniStr)); - } else if constexpr (is_base_of_v || is_same_v || is_same_v || - is_same_v || is_same_v || is_same_v || - is_same_v || is_same_v || is_same_v || - is_same_v) { - status = env->Object_CallMethod_Void(obj, method, value); + status = env->Object_SetPropertyByName_Ref(obj, key.data(), move(aniStr)); + } else if constexpr (std::is_pointer_v && std::is_base_of_v<__ani_ref, std::remove_pointer_t>) { + status = env->Object_SetPropertyByName_Ref(obj, key.data(), value); } else { + HILOGE("Invalid ani value type!"); return ANI_INVALID_TYPE; } return status; @@ -186,7 +181,7 @@ public: return false; } - auto& mainHandler = GetMainHandler(); + auto &mainHandler = GetMainHandler(); if (mainHandler == nullptr) { shared_ptr runner = OHOS::AppExecFwk::EventRunner::GetMainEventRunner(); if (!runner) { diff --git a/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp b/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp index a632f6f88bcf3f525da01aee43c3fec964e25f29..dcac3780299e79ef9834546a26745e732669effb 100644 --- a/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp +++ b/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp @@ -64,7 +64,7 @@ const string BuiltInTypes::ArrayBuffer::ctorSig = Builder::BuildSignatureDescrip // BuiltInTypes::BigInt const Type BuiltInTypes::BigInt::classType = Builder::BuildClass("escompat.BigInt"); const string BuiltInTypes::BigInt::classDesc = BuiltInTypes::BigInt::classType.Descriptor(); -const string BuiltInTypes::BigInt::ctorSig = Builder::BuildSignatureDescriptor({ BasicTypes::doubleType }); +const string BuiltInTypes::BigInt::ctorSig = Builder::BuildSignatureDescriptor({ BasicTypes::longType }); // BuiltInTypes::BusinessError const Type BuiltInTypes::BusinessError::classType = Builder::BuildClass("@ohos.base.BusinessError"); const string BuiltInTypes::BusinessError::classDesc = BuiltInTypes::BusinessError::classType.Descriptor(); diff --git a/interfaces/kits/js/src/common/ani_helper/error_handler.h b/interfaces/kits/js/src/common/ani_helper/error_handler.h index b1c1c7f5aee89e28307d417594d52bded41d15e8..c9a9f7a491f99245ad17b62ca1f2f8298da40050 100644 --- a/interfaces/kits/js/src/common/ani_helper/error_handler.h +++ b/interfaces/kits/js/src/common/ani_helper/error_handler.h @@ -106,28 +106,22 @@ private: return { ANI_ERROR, nullptr }; } - auto [succ, message] = TypeConverter::ToAniString(env, errMsg); - if (!succ) { - HILOGE("Convert errMsg to ani string failed"); - return { ANI_ERROR, nullptr }; - } - ani_status status = ANI_ERROR; - status = env->Object_SetPropertyByName_Ref(obj, "message", message); + status = AniHelper::SetPropertyValue(env, obj, "message", errMsg); if (status != ANI_OK) { HILOGE("Set property 'message' value failed"); return { status, nullptr }; } - status = env->Object_SetPropertyByName_Int(obj, "code", code); + status = AniHelper::SetPropertyValue(env, obj, "code", code); if (status != ANI_OK) { HILOGE("Set property 'code' value failed"); return { status, nullptr }; } if (errData.has_value()) { - status = env->Object_SetPropertyByName_Ref(obj, "data", errData.value()); + status = AniHelper::SetPropertyValue(env, obj, "data", errData.value()); if (status != ANI_OK) { HILOGE("Set property 'data' value failed"); return { status, nullptr }; diff --git a/interfaces/kits/js/src/mod_fs/class_atomicfile/ani/atomicfile_ani.cpp b/interfaces/kits/js/src/mod_fs/class_atomicfile/ani/atomicfile_ani.cpp index 71666f6ead96ebef7a5f3a0c3023665fd6cbc1c3..614c53008e32b485f4830e4f4d521df46105d815 100644 --- a/interfaces/kits/js/src/mod_fs/class_atomicfile/ani/atomicfile_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/class_atomicfile/ani/atomicfile_ani.cpp @@ -53,9 +53,8 @@ void AtomicFileAni::Constructor(ani_env *env, ani_object obj, ani_string pathObj return; } - if (ANI_OK != - env->Object_SetFieldByName_Long(obj, "nativePtr", - static_cast(reinterpret_cast(ret.GetData().value())))) { + ani_long ptr = static_cast(reinterpret_cast(ret.GetData().value())); + if (ANI_OK != AniHelper::SetFieldValue(env, obj, "nativePtr", ptr)) { HILOGE("Failed to wrap entity for obj AtomicFile"); ErrorHandler::Throw(env, EIO); return; diff --git a/interfaces/kits/js/src/mod_fs/class_file/ani/file_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_file/ani/file_wrapper.cpp index b314615db7a01e642b50dfd1f3c2e1fd82accb42..6ae6ae46eb56248de9883e30a7bbfcf14b94d581 100644 --- a/interfaces/kits/js/src/mod_fs/class_file/ani/file_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_file/ani/file_wrapper.cpp @@ -50,9 +50,10 @@ static bool SetFileProperties(ani_env *env, ani_class cls, ani_object obj, const return false; } + ani_status ret; const auto &fd = fdRet.GetData().value(); - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "fd", fd)) { - HILOGE("Set fd field value failed!"); + if ((ret = AniHelper::SetPropertyValue(env, obj, "fd", fd)) != ANI_OK) { + HILOGE("Set fd field value failed! ret: %{public}d", ret); return false; } @@ -63,8 +64,8 @@ static bool SetFileProperties(ani_env *env, ani_class cls, ani_object obj, const } const auto &path = pathRet.GetData().value(); - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "path", path)) { - HILOGE("Set path field value failed!"); + if (ANI_OK != AniHelper::SetPropertyValue(env, obj, "path", path)) { + HILOGE("Set path field value failed! ret: %{public}d", ret); return false; } @@ -75,8 +76,8 @@ static bool SetFileProperties(ani_env *env, ani_class cls, ani_object obj, const } const auto &name = nameRet.GetData().value(); - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "name", name)) { - HILOGE("Set name field value failed!"); + if (ANI_OK != AniHelper::SetPropertyValue(env, obj, "name", name)) { + HILOGE("Set name field value failed! ret: %{public}d", ret); return false; } return true; diff --git a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.cpp b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.cpp index b89bec3eb8b8070721a88d5822b88e3ca34fd954..2109da97b4e1c035ac8b7be17bdc9c60fe107051 100644 --- a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.cpp @@ -305,26 +305,20 @@ static ani_object CreateReadStreamOptions(ani_env *env, int64_t start, int64_t e return nullptr; } - ani_field startField = nullptr; - if (ANI_OK != env->Class_FindField(cls, "start", &startField)) { - HILOGE("Cannot find start in class %s", className); - return nullptr; - } - - ani_field endField = nullptr; - if (ANI_OK != env->Class_FindField(cls, "end", &endField)) { - HILOGE("Cannot find end in class %s", className); - return nullptr; - } - if (start >= 0) { - env->Object_SetField_Int(obj, startField, start); + auto ret = AniHelper::SetFieldValue(env, obj, "start", start); + if (ret != ANI_OK) { + HILOGE("Set 'start' field value failed! ret: %{public}d", ret); + return nullptr; + } } + if (end >= 0) { - env->Object_SetField_Int(obj, endField, end); - } - if (obj == nullptr) { - HILOGE("CreateReadStreamOptions is nullptr"); + auto ret = AniHelper::SetFieldValue(env, obj, "end", end); + if (ret != ANI_OK) { + HILOGE("Set 'end' field value failed! ret: %{public}d", ret); + return nullptr; + } } return move(obj); @@ -351,21 +345,18 @@ static ani_object CreateWriteStreamOptions(ani_env *env, int64_t start, int flag return nullptr; } - ani_field modeField = nullptr; - if (ANI_OK != env->Class_FindField(cls, "mode", &modeField)) { - HILOGE("Cannot find mode in class %s", className); - return nullptr; - } - - ani_field startField = nullptr; - if (ANI_OK != env->Class_FindField(cls, "start", &startField)) { - HILOGE("Cannot find start in class %s", className); + auto ret = AniHelper::SetFieldValue(env, obj, "mode", flags); + if (ret != ANI_OK) { + HILOGE("Set 'mode' field value failed! ret: %{public}d", ret); return nullptr; } - env->Object_SetField_Int(obj, modeField, flags); if (start >= 0) { - env->Object_SetField_Int(obj, startField, start); + ret = AniHelper::SetFieldValue(env, obj, "start", start); + if (ret != ANI_OK) { + HILOGE("Set 'start' field value failed! ret: %{public}d", ret); + return nullptr; + } } return move(obj); diff --git a/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.cpp b/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.cpp index b8efe806e026de0b7c54f2b29aab3d76007120ac..c36e6306023b27867cd8c6773be462511c574372 100644 --- a/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/class_readeriterator/ani/reader_iterator_result_ani.cpp @@ -58,13 +58,13 @@ ani_object ReaderIteratorResultAni::Wrap(ani_env *env, const ReaderIteratorResul } const auto &done = result->done; - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "done", static_cast(done))) { + if (ANI_OK != AniHelper::SetPropertyValue(env, obj, "done", done)) { HILOGE("Set 'done' field value failed!"); return nullptr; } const auto &value = result->value; - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "value", value)) { + if (ANI_OK != AniHelper::SetPropertyValue(env, obj, "value", value)) { HILOGE("Set 'value' field value failed!"); return nullptr; } diff --git a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp index 656e8e86198bdb45245229f10a80cf24b62dc569..63daa0de912d792b51505c5a62e30ea7f98cb057 100644 --- a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp @@ -32,21 +32,7 @@ using namespace std; using namespace OHOS::FileManagement::ModuleFileIO; using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature; -static ani_status SetNumProperty( - ani_env *env, const ani_class &cls, ani_object &object, const char *name, ani_long &value) -{ - ani_method setter; - ani_status ret; - if ((ret = env->Class_FindMethod(cls, name, nullptr, &setter)) != ANI_OK) { - HILOGE("Class_FindMethod Fail %{private}s, err: %{private}d", name, ret); - return ret; - } - - return env->Object_CallMethod_Void(object, setter, value); -} - -static ani_status SetBigIntProperty( - ani_env *env, const ani_class &statCls, ani_object &statObject, const char *name, ani_double &value) +static ani_status SetBigIntProperty(ani_env *env, ani_object &statObject, const char *name, int64_t value) { ani_object object = {}; auto classDesc = BuiltInTypes::BigInt::classDesc.c_str(); @@ -54,7 +40,7 @@ static ani_status SetBigIntProperty( ani_status ret; if ((ret = env->FindClass(classDesc, &cls)) != ANI_OK) { - HILOGE("Not found %{private}s, err: %{private}d", classDesc, ret); + HILOGE("Not found %{public}s, err: %{public}d", classDesc, ret); return ret; } @@ -62,22 +48,22 @@ static ani_status SetBigIntProperty( auto ctorSig = BuiltInTypes::BigInt::ctorSig.c_str(); ani_method ctor; if (ANI_OK != env->Class_FindMethod(cls, ctorDesc, ctorSig, &ctor)) { - HILOGE("Not found ctor, err: %{private}d", ret); + HILOGE("Not found ctor, err: %{public}d", ret); return ret; } if ((ret = env->Object_New(cls, ctor, &object, value)) != ANI_OK) { - HILOGE("New BigIntProperty Fail, err: %{private}d", ret); + HILOGE("New BigIntProperty Fail, err: %{public}d", ret); return ret; } - ani_method setter; - if ((ret = env->Class_FindMethod(statCls, name, nullptr, &setter)) != ANI_OK) { - HILOGE("Class_FindMethod Fail %{private}s, err: %{private}d", name, ret); + ret = AniHelper::SetPropertyValue(env, statObject, name, object); + if (ret != ANI_OK) { + HILOGE("SetPropertyValue Fail %{public}s, err: %{public}d", name, ret); return ret; } - return env->Object_CallMethod_Void(statObject, setter, object); + return ANI_OK; } static ani_enum_item GetLocationEnumIndex(ani_env *env, const Location &value) @@ -86,7 +72,7 @@ static ani_enum_item GetLocationEnumIndex(ani_env *env, const Location &value) auto classDesc = FS::LocationType::classDesc.c_str(); ani_status ret = env->FindEnum(classDesc, &enumType); if (ret != ANI_OK) { - HILOGE("FindEnum %{private}s failed, err: %{private}d", classDesc, ret); + HILOGE("FindEnum %{public}s failed, err: %{public}d", classDesc, ret); return nullptr; } @@ -101,81 +87,70 @@ static ani_enum_item GetLocationEnumIndex(ani_env *env, const Location &value) ani_enum_item enumItem; ret = env->Enum_GetEnumItemByIndex(enumType, index, &enumItem); if (ret != ANI_OK) { - HILOGE("Enum_GetEnumItemByIndex failed, index: %{private}zu, err: %{private}d", index, ret); + HILOGE("Enum_GetEnumItemByIndex failed, index: %{public}zu, err: %{public}d", index, ret); return nullptr; } return enumItem; } -static ani_status SetEnumLocation( - ani_env *env, const ani_class &cls, ani_object &object, const char *name, const Location &value) +static ani_status SetEnumLocation(ani_env *env, ani_object &object, const char *name, const Location &value) { - ani_method setter; - ani_status ret; - if ((ret = env->Class_FindMethod(cls, name, nullptr, &setter)) != ANI_OK) { - HILOGE("Class_FindMethod Fail %{private}s, err: %{private}d", name, ret); + ani_enum_item location = GetLocationEnumIndex(env, value); + if (location == nullptr) { + return ANI_ERROR; + } + + ani_status ret = AniHelper::SetPropertyValue(env, object, name, location); + if (ret != ANI_OK) { + HILOGE("SetPropertyValue Fail %{public}s, err: %{public}d", name, ret); return ret; } - return env->Object_CallMethod_Void(object, setter, GetLocationEnumIndex(env, value)); + return ANI_OK; } -const static string MODE_SETTER = Builder::BuildSetterName("mode"); -const static string UID_SETTER = Builder::BuildSetterName("uid"); -const static string GID_SETTER = Builder::BuildSetterName("gid"); -const static string SIZE_SETTER = Builder::BuildSetterName("size"); -const static string ATIME_SETTER = Builder::BuildSetterName("atime"); -const static string MTIME_SETTER = Builder::BuildSetterName("mtime"); -const static string CTIME_SETTER = Builder::BuildSetterName("ctime"); -const static string INO_SETTER = Builder::BuildSetterName("ino"); -const static string ATIME_NS_SETTER = Builder::BuildSetterName("atimeNs"); -const static string MTIME_NS_SETTER = Builder::BuildSetterName("mtimeNs"); -const static string CTIME_NS_SETTER = Builder::BuildSetterName("ctimeNs"); -const static string LOCATION_SETTER = Builder::BuildSetterName("location"); - -static ani_status SetProperties(ani_env *env, const ani_class &cls, ani_object &statObject, FsStat *fsStat) +static ani_status SetProperties(ani_env *env, ani_object &statObject, FsStat *fsStat) { ani_status ret; - vector> numProperties = { - { MODE_SETTER, fsStat->GetMode() }, - { UID_SETTER, fsStat->GetUid() }, - { GID_SETTER, fsStat->GetGid() }, - { SIZE_SETTER, fsStat->GetSize() }, - { ATIME_SETTER, fsStat->GetAtime() }, - { MTIME_SETTER, fsStat->GetMtime() }, - { CTIME_SETTER, fsStat->GetCtime() }, + vector> numProperties = { + { "mode", fsStat->GetMode() }, + { "uid", fsStat->GetUid() }, + { "gid", fsStat->GetGid() }, + { "size", fsStat->GetSize() }, + { "atime", fsStat->GetAtime() }, + { "mtime", fsStat->GetMtime() }, + { "ctime", fsStat->GetCtime() }, }; for (auto iter : numProperties) { auto key = iter.first.data(); auto value = iter.second; - ret = SetNumProperty(env, cls, statObject, key, value); + ret = AniHelper::SetPropertyValue(env, statObject, key, value); if (ret != ANI_OK) { - HILOGE("Object_CallMethod_Void Fail %{private}s, err: %{private}d", key, ret); + HILOGE("SetPropertyValue Fail %{public}s, err: %{public}d", key, ret); return ret; } } - vector> bigIntProperties = { - { INO_SETTER, ani_double(static_cast(fsStat->GetIno())) }, - { ATIME_NS_SETTER, ani_double(static_cast(fsStat->GetAtimeNs())) }, - { MTIME_NS_SETTER, ani_double(static_cast(fsStat->GetMtimeNs())) }, - { CTIME_NS_SETTER, ani_double(static_cast(fsStat->GetCtimeNs())) }, + vector> bigIntProperties = { + { "ino", fsStat->GetIno() }, + { "atimeNs", fsStat->GetAtimeNs() }, + { "mtimeNs", fsStat->GetMtimeNs() }, + { "ctimeNs", fsStat->GetCtimeNs() }, }; for (auto iter : bigIntProperties) { auto key = iter.first.data(); auto value = iter.second; - ret = SetBigIntProperty(env, cls, statObject, key, value); + ret = SetBigIntProperty(env, statObject, key, value); if (ret != ANI_OK) { - HILOGE("Object_CallMethod_Void Fail %{private}s, err: %{private}d", key, ret); + HILOGE("SetBigIntProperty Fail %{public}s, err: %{public}d", key, ret); return ret; } } #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) - auto key = LOCATION_SETTER.c_str(); - if ((ret = SetEnumLocation(env, cls, statObject, key, static_cast(fsStat->GetLocation()))) != ANI_OK) { - HILOGE("Object_CallMethod_Void Fail %{private}s, err: %{private}d", key, ret); + if ((ret = SetEnumLocation(env, statObject, "location", static_cast(fsStat->GetLocation()))) != ANI_OK) { + HILOGE("SetEnumLocation Fail, err: %{public}d", ret); return ret; } #endif @@ -195,7 +170,7 @@ ani_object StatWrapper::Wrap(ani_env *env, FsStat *fsStat) ani_status ret; if ((ret = env->FindClass(classDesc, &cls)) != ANI_OK) { - HILOGE("Not found %{private}s, err: %{private}d", classDesc, ret); + HILOGE("Not found %{public}s, err: %{public}d", classDesc, ret); return nullptr; } @@ -203,17 +178,17 @@ ani_object StatWrapper::Wrap(ani_env *env, FsStat *fsStat) auto ctorSig = FS::StatInner::ctorSig.c_str(); ani_method ctor; if (ANI_OK != env->Class_FindMethod(cls, ctorDesc, ctorSig, &ctor)) { - HILOGE("Not found ctor, err: %{private}d", ret); + HILOGE("Not found ctor, err: %{public}d", ret); return nullptr; } if ((ret = env->Object_New(cls, ctor, &statObject, reinterpret_cast(fsStat))) != ANI_OK) { - HILOGE("New StatInner Fail, err: %{private}d", ret); + HILOGE("New StatInner Fail, err: %{public}d", ret); return nullptr; } - if ((ret = SetProperties(env, cls, statObject, fsStat)) != ANI_OK) { - HILOGE("SetProperties Fail, err: %{private}d", ret); + if ((ret = SetProperties(env, statObject, fsStat)) != ANI_OK) { + HILOGE("SetProperties Fail, err: %{public}d", ret); return nullptr; } @@ -225,7 +200,7 @@ FsStat *StatWrapper::Unwrap(ani_env *env, ani_object object) ani_long fsStat; auto ret = env->Object_GetFieldByName_Long(object, "nativeStat", &fsStat); if (ret != ANI_OK) { - HILOGE("Unwrap fsStat err: %{private}d", ret); + HILOGE("Unwrap fsStat err: %{public}d", ret); return nullptr; } return reinterpret_cast(fsStat); diff --git a/interfaces/kits/js/src/mod_fs/class_tasksignal/ani/task_signal_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_tasksignal/ani/task_signal_wrapper.cpp index 79be6423190c34796a9b015ac57405afc7f0bda5..3a38f9d740973db8b2521903ceb28e09afa1e17d 100644 --- a/interfaces/kits/js/src/mod_fs/class_tasksignal/ani/task_signal_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_tasksignal/ani/task_signal_wrapper.cpp @@ -56,7 +56,7 @@ bool TaskSignalWrapper::Wrap(ani_env *env, ani_object object, const FsTaskSignal ani_long ptr = static_cast(reinterpret_cast(signal)); - auto status = env->Object_SetFieldByName_Long(object, "nativeTaskSignal", ptr); + auto status = AniHelper::SetFieldValue(env, object, "nativeTaskSignal", ptr); if (status != ANI_OK) { HILOGE("Wrap taskSignal obj failed! status: %{public}d", status); return false; diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp index f2a7ecc9c63d9777b8a66beecbc609dc83c91dfe..51e7ac53dee0f2611e119721a3508cb5d6edbd89 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp @@ -66,7 +66,7 @@ static ani_object Wrap(ani_env *env, const FsRandomAccessFile *rafFile) } const auto &fd = fdRet.GetData().value(); - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "fd", fd)) { + if (ANI_OK != AniHelper::SetPropertyValue(env, obj, "fd", fd)) { HILOGE("Set fd field value failed!"); return nullptr; } @@ -78,7 +78,7 @@ static ani_object Wrap(ani_env *env, const FsRandomAccessFile *rafFile) } const auto &fp = fpRet.GetData().value(); - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "filePointer", fp)) { + if (ANI_OK != AniHelper::SetPropertyValue(env, obj, "filePointer", fp)) { HILOGE("Set fp field value failed!"); return nullptr; } diff --git a/interfaces/kits/js/src/mod_hash/class_hashstream/ani/hashstream_ani.cpp b/interfaces/kits/js/src/mod_hash/class_hashstream/ani/hashstream_ani.cpp index 49079f114e175112a30ad6e7340cb250df0ffb5a..440f5c6a5c94a7243c613652a6b9f91f6db43ea1 100644 --- a/interfaces/kits/js/src/mod_hash/class_hashstream/ani/hashstream_ani.cpp +++ b/interfaces/kits/js/src/mod_hash/class_hashstream/ani/hashstream_ani.cpp @@ -109,8 +109,8 @@ void HashStreamAni::Constructor(ani_env *env, ani_object obj, ani_string alg) return; } - if (ANI_OK != - env->Object_SetFieldByName_Long(obj, "nativePtr", reinterpret_cast(ret.GetData().value()))) { + ani_long ptr = static_cast(reinterpret_cast(ret.GetData().value())); + if (ANI_OK != AniHelper::SetFieldValue(env, obj, "nativePtr", ptr)) { HILOGE("Failed to wrap entity for obj HashStream"); ErrorHandler::Throw(env, EIO); return;