From 9bb492af26eca63425f7b9e7a79bace7f6b2c370 Mon Sep 17 00:00:00 2001 From: liuxiyao223 Date: Fri, 15 Dec 2023 16:01:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dall=5FpowerOnOff=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=97=B6libsim=20crash=E9=97=AE=E9=A2=98=20Signed-off?= =?UTF-8?q?-by:=20liuxiyao223=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/js/napi/napi_util.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/frameworks/js/napi/napi_util.cpp b/frameworks/js/napi/napi_util.cpp index 806dcf929..98afb3299 100755 --- a/frameworks/js/napi/napi_util.cpp +++ b/frameworks/js/napi/napi_util.cpp @@ -85,9 +85,10 @@ static std::unordered_map errorMap_ = { { JsErrorCode::JS_ERROR_TELEPHONY_NETWORK_NOT_IN_SERVICE, JS_ERROR_NETWORK_NOT_IN_SERVICE }, { JsErrorCode::JS_ERROR_TELEPHONY_CONFERENCE_EXCEED_LIMIT, JS_ERROR_CONFERENCE_EXCEED_LIMIT_STRING }, { JsErrorCode::JS_ERROR_TELEPHONY_CONFERENCE_CALL_NOT_ACTIVE, JS_ERROR_CONFERENCE_CALL_IS_NOT_ACTIVE_STRING }, - { JsErrorCode::JS_ERROR_TELEPHONY_CALL_COUNTS_EXCEED_LIMIT, JS_ERROR_TELEPHONY_CALL_COUNTS_EXCEED_LIMIT_STRING } - + { JsErrorCode::JS_ERROR_TELEPHONY_CALL_COUNTS_EXCEED_LIMIT, JS_ERROR_TELEPHONY_CALL_COUNTS_EXCEED_LIMIT_STRING }, }; +const std::string ERROR_STRING = "error"; +const std::u16string ERROR_USTRING = u"error"; std::string NapiUtil::GetErrorMessage(int32_t errorCode) { @@ -104,12 +105,22 @@ std::string NapiUtil::GetErrorMessage(int32_t errorCode) std::string NapiUtil::ToUtf8(std::u16string str16) { - return std::wstring_convert, char16_t> {}.to_bytes(str16); + if (str16 == ERROR_USTRING) { + return ERROR_STRING; + } + std::wstring_convert, char16_t> convert(ERROR_STRING); + std::string result = convert.to_bytes(str16); + return result == ERROR_STRING ? "" : result; } std::u16string NapiUtil::ToUtf16(std::string str) { - return std::wstring_convert, char16_t> {}.from_bytes(str); + if (str == ERROR_STRING) { + return ERROR_USTRING; + } + std::wstring_convert, char16_t> convert(ERROR_STRING, ERROR_USTRING); + std::u16string result = convert.from_bytes(str); + return result == ERROR_USTRING ? u"" : result; } napi_value NapiUtil::CreateErrorMessage(napi_env env, const std::string &msg, int32_t errorCode)