From 4ff24e664e13fac146ac6a19a4789dbedd14fd7d Mon Sep 17 00:00:00 2001 From: AXYChen Date: Mon, 2 Jun 2025 15:58:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8F=96info=E5=89=8D=E6=A0=A1?= =?UTF-8?q?=E9=AA=8Cinfo=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: AXYChen Change-Id: I4c111de51f90851b6f9dd097d0e8713f711b9c72 --- .../jsview/js_location_button.cpp | 4 +- .../jsview/js_paste_button.cpp | 4 +- .../jsview/js_save_button.cpp | 4 +- .../jsview/js_sec_button_base.cpp | 47 +++++++++++++++++-- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_location_button.cpp b/frameworks/bridge/declarative_frontend/jsview/js_location_button.cpp index 92112d07549..fd6e0647f84 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_location_button.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_location_button.cpp @@ -32,7 +32,7 @@ namespace OHOS::Ace::Framework { bool JSLocationButton::ParseComponentStyle(const JSCallbackInfo& info, LocationButtonLocationDescription& text, LocationButtonIconStyle& icon, int32_t& bg) { - if (!info[0]->IsObject()) { + if ((info.Length() < 1) || (!info[0]->IsObject())) { return false; } @@ -138,7 +138,7 @@ void JsLocationButtonClickFunction::Execute(GestureEvent& info) void JSLocationButton::JsOnClick(const JSCallbackInfo& info) { - if (!info[0]->IsFunction()) { + if ((info.Length() < 1) || (!info[0]->IsFunction())) { return; } auto jsOnClickFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_paste_button.cpp b/frameworks/bridge/declarative_frontend/jsview/js_paste_button.cpp index fcf1353486f..bd56d1b9688 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_paste_button.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_paste_button.cpp @@ -32,7 +32,7 @@ namespace OHOS::Ace::Framework { bool JSPasteButton::ParseComponentStyle(const JSCallbackInfo& info, PasteButtonPasteDescription& text, PasteButtonIconStyle& icon, int32_t& bg) { - if (!info[0]->IsObject()) { + if ((info.Length() < 1) || (!info[0]->IsObject())) { return false; } @@ -137,7 +137,7 @@ void JsPasteButtonClickFunction::Execute(GestureEvent& info) void JSPasteButton::JsOnClick(const JSCallbackInfo& info) { - if (!info[0]->IsFunction()) { + if ((info.Length() < 1) || (!info[0]->IsFunction())) { return; } auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_save_button.cpp b/frameworks/bridge/declarative_frontend/jsview/js_save_button.cpp index 2df5397d334..30fb0392850 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_save_button.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_save_button.cpp @@ -36,7 +36,7 @@ namespace OHOS::Ace::Framework { bool JSSaveButton::ParseComponentStyle(const JSCallbackInfo& info, SaveButtonSaveDescription& text, SaveButtonIconStyle& icon, int32_t& bg) { - if (!info[0]->IsObject()) { + if ((info.Length() < 1) || (!info[0]->IsObject())) { return false; } @@ -143,7 +143,7 @@ void JsSaveButtonClickFunction::Execute(GestureEvent& info) void JSSaveButton::JsOnClick(const JSCallbackInfo& info) { - if (!info[0]->IsFunction()) { + if ((info.Length() < 1) || (!info[0]->IsFunction())) { return; } auto jsOnClickFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_sec_button_base.cpp b/frameworks/bridge/declarative_frontend/jsview/js_sec_button_base.cpp index aa964882645..a21f10733c8 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_sec_button_base.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_sec_button_base.cpp @@ -35,6 +35,9 @@ const std::vector HEIGHT_ADAPTIVE_POLICY = { TextHeigh void JSSecButtonBase::SetIconSize(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } auto theme = GetTheme(); CHECK_NULL_VOID(theme); @@ -68,6 +71,9 @@ void JSSecButtonBase::SetIconSize(const JSCallbackInfo& info) void JSSecButtonBase::SetIconColor(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } auto theme = GetTheme(); CHECK_NULL_VOID(theme); @@ -80,6 +86,9 @@ void JSSecButtonBase::SetIconColor(const JSCallbackInfo& info) void JSSecButtonBase::SetFontSize(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } auto theme = GetTheme(); CHECK_NULL_VOID(theme); @@ -93,7 +102,7 @@ void JSSecButtonBase::SetFontSize(const JSCallbackInfo& info) void JSSecButtonBase::SetFontStyle(const JSCallbackInfo& info) { - if (!info[0]->IsNumber()) { + if ((info.Length() < 1) || (!info[0]->IsNumber())) { SecurityComponentModelNG::SetFontStyle(Ace::FontStyle::NORMAL); return; } @@ -108,7 +117,7 @@ void JSSecButtonBase::SetFontStyle(const JSCallbackInfo& info) void JSSecButtonBase::SetFontWeight(const JSCallbackInfo& info) { - if (!(info[0]->IsString() || info[0]->IsNumber())) { + if ((info.Length() < 1) || (!(info[0]->IsString() || info[0]->IsNumber()))) { return; } std::string value = info[0]->ToString(); @@ -117,6 +126,9 @@ void JSSecButtonBase::SetFontWeight(const JSCallbackInfo& info) void JSSecButtonBase::SetFontFamily(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } std::vector fontFamilies; if (!ParseJsFontFamilies(info[0], fontFamilies)) { fontFamilies.emplace_back("HarmonyOS Sans"); @@ -126,6 +138,9 @@ void JSSecButtonBase::SetFontFamily(const JSCallbackInfo& info) void JSSecButtonBase::SetFontColor(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } auto theme = GetTheme(); CHECK_NULL_VOID(theme); @@ -138,7 +153,7 @@ void JSSecButtonBase::SetFontColor(const JSCallbackInfo& info) void JSSecButtonBase::SetLayoutDirection(const JSCallbackInfo& info) { - if (!info[0]->IsNumber()) { + if ((info.Length() < 1) || (!info[0]->IsNumber())) { SecurityComponentModelNG::SetTextIconLayoutDirection( SecurityComponentLayoutDirection::HORIZONTAL); return; @@ -156,6 +171,9 @@ void JSSecButtonBase::SetLayoutDirection(const JSCallbackInfo& info) void JSSecButtonBase::SetBackgroundColor(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } auto theme = GetTheme(); CHECK_NULL_VOID(theme); @@ -168,7 +186,7 @@ void JSSecButtonBase::SetBackgroundColor(const JSCallbackInfo& info) void JSSecButtonBase::SetBackgroundBorderStyle(const JSCallbackInfo& info) { - if (!info[0]->IsNumber()) { + if ((info.Length() < 1) || (!info[0]->IsNumber())) { SecurityComponentModelNG::SetBackgroundBorderStyle(BorderStyle::NONE); return; } @@ -183,6 +201,9 @@ void JSSecButtonBase::SetBackgroundBorderStyle(const JSCallbackInfo& info) void JSSecButtonBase::SetBackgroundBorderWidth(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } auto theme = GetTheme(); CHECK_NULL_VOID(theme); @@ -196,6 +217,9 @@ void JSSecButtonBase::SetBackgroundBorderWidth(const JSCallbackInfo& info) void JSSecButtonBase::SetBackgroundBorderColor(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } auto theme = GetTheme(); CHECK_NULL_VOID(theme); @@ -208,6 +232,9 @@ void JSSecButtonBase::SetBackgroundBorderColor(const JSCallbackInfo& info) void JSSecButtonBase::SetBackgroundBorderRadius(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } if (info[0]->IsObject()) { std::optional topLeft; std::optional topRight; @@ -250,6 +277,9 @@ void JSSecButtonBase::SetBackgroundBorderRadius(const JSCallbackInfo& info) void JSSecButtonBase::SetBackgroundPadding(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } if (info[0]->IsObject()) { std::optional left; std::optional right; @@ -289,6 +319,9 @@ void JSSecButtonBase::SetBackgroundPadding(const JSCallbackInfo& info) void JSSecButtonBase::SetTextIconSpace(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } auto theme = GetTheme(); CHECK_NULL_VOID(theme); @@ -302,6 +335,9 @@ void JSSecButtonBase::SetTextIconSpace(const JSCallbackInfo& info) void JSSecButtonBase::SetAlign(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } Alignment alignment; if (!info[0]->IsNumber()) { alignment = Alignment::CENTER; @@ -344,6 +380,9 @@ void JSSecButtonBase::SetMinFontScale(const JSCallbackInfo& info) void JSSecButtonBase::SetMaxLines(const JSCallbackInfo& info) { + if (info.Length() < 1) { + return; + } JSRef args = info[0]; auto value = Infinity(); if (args->ToString() != "Infinity") { -- Gitee