From 6d90bba16485115e733b257104a08ea075faeef5 Mon Sep 17 00:00:00 2001 From: liujiaxing19 Date: Mon, 25 Nov 2024 14:21:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9D=8F=E5=91=B3?= =?UTF-8?q?=E9=81=93=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiaxing19 Change-Id: Ifffad6bad789e2db2f10a7417946278909347094 --- .../interfaces/js/kits/napi/napi_hidebug.cpp | 58 +++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp index 24eb8c161..7eb1eac93 100644 --- a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp +++ b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp @@ -932,24 +932,8 @@ static bool JudgeValueRange(const std::string &type, int32_t value) return false; } -static bool GetAppResourceLimitParam(napi_env env, napi_callback_info info, std::string& type, - int32_t& value, bool& enabledDebugLog) +static bool GetAndCheckFilenameParamLength(napi_env &env, napi_value *argv, size_t &bufLen) { - const int valueNum = 3; - size_t argc = valueNum; - napi_value argv[valueNum] = { nullptr }; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - if (argc != valueNum) { - HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam failed. Invalid numbers of params!"); - return false; - } - if (!MatchValueType(env, argv[FIRST_POS], napi_string) && - !MatchValueType(env, argv[SECOND_POS], napi_number) && - !MatchValueType(env, argv[THIRD_POS], napi_boolean)) { - HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam params type error."); - return false; - } - size_t bufLen = 0; napi_status status = napi_get_value_string_utf8(env, argv[FIRST_POS], nullptr, 0, &bufLen); if (status != napi_ok) { HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam failed. Get input filename param length failed."); @@ -960,6 +944,11 @@ static bool GetAppResourceLimitParam(napi_env env, napi_callback_info info, std: HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam failed. input filename param length is illegal."); return false; } + return true; +} + +static bool GetAndCheckResourceType(napi_env &env, napi_value *argv, size_t &bufLen, std::string &type) +{ std::vector buf(bufLen + 1, 0); napi_get_value_string_utf8(env, argv[FIRST_POS], buf.data(), bufLen + 1, &bufLen); type = std::string(buf.data()); @@ -972,6 +961,11 @@ static bool GetAppResourceLimitParam(napi_env env, napi_callback_info info, std: HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam failed. Resource type is invalid."); return false; } + return true; +} + +static bool GetAndCheckInputValue(napi_env &env, napi_value *argv, std::string &type, int32_t &value) +{ if (napi_get_value_int32(env, argv[SECOND_POS], &value) != napi_ok || value < 0) { HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam failed. Input value error."); return false; @@ -980,6 +974,36 @@ static bool GetAppResourceLimitParam(napi_env env, napi_callback_info info, std: HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam failed. The value range is invalid."); return false; } + return true; +} + +static bool GetAppResourceLimitParam(napi_env env, napi_callback_info info, std::string& type, + int32_t& value, bool& enabledDebugLog) +{ + const int valueNum = 3; + size_t argc = valueNum; + napi_value argv[valueNum] = { nullptr }; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc != valueNum) { + HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam failed. Invalid numbers of params!"); + return false; + } + if (!MatchValueType(env, argv[FIRST_POS], napi_string) && + !MatchValueType(env, argv[SECOND_POS], napi_number) && + !MatchValueType(env, argv[THIRD_POS], napi_boolean)) { + HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam params type error."); + return false; + } + size_t bufLen = 0; + if (!GetAndCheckFilenameParamLength(env, argv, bufLen)) { + return false; + } + if (!GetAndCheckResourceType(env, argv, bufLen, type)) { + return false; + } + if (!GetAndCheckInputValue(env, argv, type, value)) { + return false; + } if (napi_get_value_bool(env, argv[THIRD_POS], &enabledDebugLog) != napi_ok) { HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam failed. Get input enabledDebugLog failed."); return false; -- Gitee From ce83aaa542a9b1b422e1bf56797312312dbbdf6c Mon Sep 17 00:00:00 2001 From: liujiaxing19 Date: Thu, 28 Nov 2024 09:24:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9D=8F=E5=91=B3?= =?UTF-8?q?=E9=81=93=E6=B8=85=E7=90=862?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujiaxing19 Change-Id: Ic74e373411e8856dd0077de9a8ee86815a270c98 --- hidebug/interfaces/js/kits/napi/napi_hidebug.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp index 7eb1eac93..ee3795847 100644 --- a/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp +++ b/hidebug/interfaces/js/kits/napi/napi_hidebug.cpp @@ -932,7 +932,7 @@ static bool JudgeValueRange(const std::string &type, int32_t value) return false; } -static bool GetAndCheckFilenameParamLength(napi_env &env, napi_value *argv, size_t &bufLen) +static bool CheckFilenameParamLength(napi_env &env, napi_value *argv, size_t &bufLen) { napi_status status = napi_get_value_string_utf8(env, argv[FIRST_POS], nullptr, 0, &bufLen); if (status != napi_ok) { @@ -947,7 +947,7 @@ static bool GetAndCheckFilenameParamLength(napi_env &env, napi_value *argv, size return true; } -static bool GetAndCheckResourceType(napi_env &env, napi_value *argv, size_t &bufLen, std::string &type) +static bool CheckResourceType(napi_env &env, napi_value *argv, size_t &bufLen, std::string &type) { std::vector buf(bufLen + 1, 0); napi_get_value_string_utf8(env, argv[FIRST_POS], buf.data(), bufLen + 1, &bufLen); @@ -964,7 +964,7 @@ static bool GetAndCheckResourceType(napi_env &env, napi_value *argv, size_t &buf return true; } -static bool GetAndCheckInputValue(napi_env &env, napi_value *argv, std::string &type, int32_t &value) +static bool CheckInputValue(napi_env &env, napi_value *argv, std::string &type, int32_t &value) { if (napi_get_value_int32(env, argv[SECOND_POS], &value) != napi_ok || value < 0) { HILOG_ERROR(LOG_CORE, "GetAppResourceLimitParam failed. Input value error."); @@ -995,13 +995,13 @@ static bool GetAppResourceLimitParam(napi_env env, napi_callback_info info, std: return false; } size_t bufLen = 0; - if (!GetAndCheckFilenameParamLength(env, argv, bufLen)) { + if (!CheckFilenameParamLength(env, argv, bufLen)) { return false; } - if (!GetAndCheckResourceType(env, argv, bufLen, type)) { + if (!CheckResourceType(env, argv, bufLen, type)) { return false; } - if (!GetAndCheckInputValue(env, argv, type, value)) { + if (!CheckInputValue(env, argv, type, value)) { return false; } if (napi_get_value_bool(env, argv[THIRD_POS], &enabledDebugLog) != napi_ok) { -- Gitee