From 9ddc1e362b5df5fd665946ca8513e988a6fc624f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=B9=E7=90=BC?= Date: Mon, 11 Aug 2025 20:31:13 +0800 Subject: [PATCH] =?UTF-8?q?dialog=5Fparams=E4=B8=AD=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E4=BF=A1=E6=81=AF=E5=87=BD=E6=95=B0=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E4=B8=BAGetErrorObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王丹琼 Change-Id: I690d9aed307d1a284c75e34d9872f1c1265bc89d Signed-off-by: 王丹琼 --- .../ani/promptaction/src/dialog_params.cpp | 16 ++--- .../promptaction/src/prompt_action_params.cpp | 68 ------------------- .../promptaction/src/prompt_action_params.h | 4 +- .../promptaction/src/prompt_action_utils.cpp | 4 +- .../ets/ani/promptaction/src/toast_params.cpp | 5 +- 5 files changed, 11 insertions(+), 86 deletions(-) diff --git a/interfaces/ets/ani/promptaction/src/dialog_params.cpp b/interfaces/ets/ani/promptaction/src/dialog_params.cpp index 41de3a3377f..41590a662dc 100644 --- a/interfaces/ets/ani/promptaction/src/dialog_params.cpp +++ b/interfaces/ets/ani/promptaction/src/dialog_params.cpp @@ -550,7 +550,7 @@ std::function GetShowDialogCallback(std::shared_ptrenv->GetNull(&args[0]); } else { - args[0] = CreateBusinessError(asyncContext->env, errorCode, "cancel"); + args[0] = OHOS::Ace::Ani::GetErrorObject(asyncContext->env, "cancel", errorCode); } args[1] = CreateShowDialogSuccessResponse(asyncContext->env, successIndex); ani_ref fnReturnVal {}; @@ -605,8 +605,7 @@ std::function GetShowDialogPromise(std::shared_ptrenv, 0, "cancel"); - ani_error error = static_cast(errorRef); + ani_error error = OHOS::Ace::Ani::GetErrorObject(asyncContext->env, "cancel", 0); status = asyncContext->env->PromiseResolver_Reject(asyncContext->deferred, error); if (status != ANI_OK) { TAG_LOGW(OHOS::Ace::AceLogTag::ACE_OVERLAY, @@ -762,7 +761,7 @@ std::function GetShowActionMenuCallback( if (errorCode == OHOS::Ace::ERROR_CODE_NO_ERROR) { asyncContext->env->GetNull(&args[0]); } else { - args[0] = CreateBusinessError(asyncContext->env, errorCode, "cancel"); + args[0] = OHOS::Ace::Ani::GetErrorObject(asyncContext->env, "cancel", errorCode); } args[1] = CreateActionMenuSuccessResponse(asyncContext->env, successIndex); ani_ref fnReturnVal {}; @@ -817,8 +816,7 @@ std::function GetShowActionMenuPromise(std::shared_ptr

env, 0, "cancel"); - ani_error error = static_cast(errorRef); + ani_error error = OHOS::Ace::Ani::GetErrorObject(asyncContext->env, "cancel", 0); status = asyncContext->env->PromiseResolver_Reject(asyncContext->deferred, error); if (status != ANI_OK) { TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, @@ -1396,8 +1394,7 @@ std::function GetOpenCustomDialogPromise(std::shared_ptrenv, errorCode, errorMsg); - ani_error error = static_cast(errorRef); + ani_error error = OHOS::Ace::Ani::GetErrorObject(asyncContext->env, errorMsg, errorCode); ani_status status = asyncContext->env->PromiseResolver_Reject(asyncContext->deferred, error); if (status != ANI_OK) { TAG_LOGW(OHOS::Ace::AceLogTag::ACE_DIALOG, "[ANI] PromiseResolver_Reject fail."); @@ -1453,8 +1450,7 @@ std::function GetCustomDialogContentPromise(std::shared_ptrenv, errorCode, strMsg); - ani_error error = static_cast(errorRef); + ani_error error = OHOS::Ace::Ani::GetErrorObject(asyncContext->env, strMsg, errorCode); ani_status status = asyncContext->env->PromiseResolver_Reject(asyncContext->deferred, error); if (status != ANI_OK) { TAG_LOGW(OHOS::Ace::AceLogTag::ACE_DIALOG, "[ANI] PromiseResolver_Reject fail."); diff --git a/interfaces/ets/ani/promptaction/src/prompt_action_params.cpp b/interfaces/ets/ani/promptaction/src/prompt_action_params.cpp index 70ce1a3beb7..473eb7b83a2 100644 --- a/interfaces/ets/ani/promptaction/src/prompt_action_params.cpp +++ b/interfaces/ets/ani/promptaction/src/prompt_action_params.cpp @@ -1376,74 +1376,6 @@ bool GetShadowParamOpt(ani_env *env, ani_object object, std::optionalString_NewUTF8(msg.c_str(), msg.size(), &aniMsg); - if (status != ANI_OK) { - TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, "String_NewUTF8 fail. status: %{public}d", status); - return nullptr; - } - - ani_ref undefRef; - status = env->GetUndefined(&undefRef); - if (status != ANI_OK) { - TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, "GetUndefined fail. status: %{public}d", status); - return nullptr; - } - - ani_class cls {}; - status = env->FindClass("escompat.Error", &cls); - if (status != ANI_OK) { - TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, "FindClass fail. status: %{public}d", status); - return nullptr; - } - - ani_method method {}; - status = env->Class_FindMethod(cls, "", "C{std.core.String}C{escompat.ErrorOptions}:", &method); - if (status != ANI_OK) { - TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, "Class_FindMethod fail. status: %{public}d", status); - return nullptr; - } - - ani_object obj = nullptr; - status = env->Object_New(cls, method, &obj, aniMsg, undefRef); - if (status != ANI_OK) { - TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, "Object_New fail. status: %{public}d", status); - return nullptr; - } - return obj; -} - -ani_ref CreateBusinessError(ani_env* env, int32_t code, const std::string& msg) -{ - ani_class errorCls; - ani_status status = env->FindClass("@ohos.base.BusinessError", &errorCls); - if (status != ANI_OK) { - TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, "FindClass fail. status: %{public}d", status); - } - - ani_method ctorMethod; - status = env->Class_FindMethod(errorCls, "", "dC{escompat.Error}:", &ctorMethod); - if (status != ANI_OK) { - TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, "Class_FindMethod fail. status: %{public}d", status); - } - - ani_object errorMsg = WrapBusinessError(env, msg); - if (errorMsg == nullptr) { - TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, "WrapBusinessError is null."); - return nullptr; - } - - ani_object errorObj = nullptr; - ani_double errorCode(code); - status = env->Object_New(errorCls, ctorMethod, &errorObj, errorCode, errorMsg); - if (status != ANI_OK) { - TAG_LOGE(OHOS::Ace::AceLogTag::ACE_OVERLAY, "Object_New fail. status: %{public}d", status); - } - return reinterpret_cast(errorObj); -} - bool ResourceIntegerToString(const ResourceInfo& resourceInfo, std::string& result) { auto resourceWrapper = CreateResourceWrapper(resourceInfo); diff --git a/interfaces/ets/ani/promptaction/src/prompt_action_params.h b/interfaces/ets/ani/promptaction/src/prompt_action_params.h index 39dc0365984..25ecfb94d98 100644 --- a/interfaces/ets/ani/promptaction/src/prompt_action_params.h +++ b/interfaces/ets/ani/promptaction/src/prompt_action_params.h @@ -164,8 +164,6 @@ bool GetShadowOptionsOffsetY(ani_env *env, ani_object object, double& result); bool GetShadowOptionsParam(ani_env *env, ani_object object, OHOS::Ace::Shadow& result); bool GetShadowParam(ani_env *env, ani_object object, OHOS::Ace::Shadow& result); bool GetShadowParamOpt(ani_env *env, ani_object object, std::optional& result); -ani_object WrapBusinessError(ani_env* env, const std::string& msg); -ani_ref CreateBusinessError(ani_env* env, int32_t code, const std::string& msg); bool ResourceIntegerToString(const ResourceInfo& resourceInfo, std::string& result); bool GetDimensionParam(ani_env* env, ani_object object, OHOS::Ace::CalcDimension& result); bool GetDimensionParam(ani_env* env, ani_ref ref, OHOS::Ace::CalcDimension& result); @@ -180,4 +178,4 @@ bool GetHoverModeAreaParamOpt(ani_env* env, ani_object object, std::optional& result); -#endif // INTERFACES_ETS_ANI_PROMPTACTION_SRC_PROMPT_ACTION_PARAMS_H \ No newline at end of file +#endif // INTERFACES_ETS_ANI_PROMPTACTION_SRC_PROMPT_ACTION_PARAMS_H diff --git a/interfaces/ets/ani/promptaction/src/prompt_action_utils.cpp b/interfaces/ets/ani/promptaction/src/prompt_action_utils.cpp index b24b6849a01..448849c1d78 100644 --- a/interfaces/ets/ani/promptaction/src/prompt_action_utils.cpp +++ b/interfaces/ets/ani/promptaction/src/prompt_action_utils.cpp @@ -61,13 +61,13 @@ ani_error GetErrorObject(ani_env *env, const std::string &errMsg, int32_t code) { CHECK_NULL_RETURN(env, nullptr); ani_class errClass; - ani_status status = env->FindClass("@ohos.base.BusinessError", &errClass); + ani_status status = env->FindClass("L@ohos/base/BusinessError;", &errClass); if (status != ANI_OK) { TAG_LOGE(AceLogTag::ACE_OVERLAY, "find class failed. status: %{public}d", status); return nullptr; } ani_method ctor; - status = env->Class_FindMethod(errClass, "", ":", &ctor); + status = env->Class_FindMethod(errClass, "", ":V", &ctor); if (status != ANI_OK) { TAG_LOGE(AceLogTag::ACE_OVERLAY, "cannot find constructor for class. status: %{public}d", status); return nullptr; diff --git a/interfaces/ets/ani/promptaction/src/toast_params.cpp b/interfaces/ets/ani/promptaction/src/toast_params.cpp index 31302ae148f..7faf7f13910 100644 --- a/interfaces/ets/ani/promptaction/src/toast_params.cpp +++ b/interfaces/ets/ani/promptaction/src/toast_params.cpp @@ -169,8 +169,7 @@ std::function GetToastPromise(std::shared_ptrenv, errorCode, errorMsg); - ani_error error = static_cast(errorRef); + ani_error error = OHOS::Ace::Ani::GetErrorObject(asyncContext->env, errorMsg, errorCode); ani_status status = asyncContext->env->PromiseResolver_Reject(asyncContext->deferred, error); if (status != ANI_OK) { TAG_LOGW(OHOS::Ace::AceLogTag::ACE_DIALOG, "[ANI] PromiseResolver_Reject fail."); @@ -183,4 +182,4 @@ std::function GetToastPromise(std::shared_ptr