From 7992316c30131db15c34057d87aecba7609efab3 Mon Sep 17 00:00:00 2001 From: shikai-123 Date: Mon, 18 Jul 2022 14:32:42 +0800 Subject: [PATCH 1/4] Fix codex issues:https://gitee.com/openharmony/js_util_module/issues/I5HJRN Signed-off-by: shikai-123 --- util/native_module_util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index b866bf7..16a9f6c 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -392,7 +392,7 @@ namespace OHOS::Util { return retVal; } - static bool CheckEncodingFormat(std::string &encoding) + static bool CheckEncodingFormat(const std::string &encoding) { const std::string conventFormat("utf8-t,UTF-8,gbk,GBK,GB2312,gb2312,GB18030,gb18030"); if (conventFormat.find(encoding.c_str()) != conventFormat.npos) { -- Gitee From 3e7b120c66d05ebaa4b09ef003f4fc5745c18a24 Mon Sep 17 00:00:00 2001 From: lukai Date: Sat, 23 Jul 2022 14:57:10 +0800 Subject: [PATCH 2/4] utilxts bugfix issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I5IJY3?from=project-issue 1. u_getDataDirectory() is not thread-safe.It should be called at most once in a process 2. buffer write overflow Signed-off-by: lukai --- util/js_base64.cpp | 2 -- util/js_textdecoder.cpp | 1 - 2 files changed, 3 deletions(-) diff --git a/util/js_base64.cpp b/util/js_base64.cpp index 5443144..70ef655 100755 --- a/util/js_base64.cpp +++ b/util/js_base64.cpp @@ -456,8 +456,6 @@ namespace OHOS::Util { inputDecode = static_cast(resultData) + byteOffset; CreateDecodePromise(env, inputDecode, length); } - delete[] inputString; - inputString = nullptr; return stdDecodeInfo_->promise; } void Base64::CreateDecodePromise(napi_env env, char *inputDecode, size_t length) diff --git a/util/js_textdecoder.cpp b/util/js_textdecoder.cpp index 6bb026d..2ef93df 100755 --- a/util/js_textdecoder.cpp +++ b/util/js_textdecoder.cpp @@ -42,7 +42,6 @@ namespace OHOS::Util { } } label_ = i32Flag; - SetHwIcuDirectory(); bool fatal = (i32Flag & static_cast(ConverterFlags::FATAL_FLG)) == static_cast(ConverterFlags::FATAL_FLG); -- Gitee From eb01ae21c30904d9fffe057d035b9cf23f782db8 Mon Sep 17 00:00:00 2001 From: shikai-123 Date: Tue, 26 Jul 2022 15:18:02 +0800 Subject: [PATCH 3/4] Modify interface name issues: https://gitee.com/openharmony/js_util_module/issues/I5IY2E Signed-off-by: shikai-123 --- util/src/util_js.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/util/src/util_js.ts b/util/src/util_js.ts index c3f91ac..1f514eb 100644 --- a/util/src/util_js.ts +++ b/util/src/util_js.ts @@ -441,7 +441,23 @@ function callbackWrapper(original : Fn) : void Object.defineProperties(cb, descriptors); } -function promiseWrapper(func : Function) : Function +function promiseWrapper(func : Function) : Object +{ + return function (...args : Array) { + return new Promise((resolve, reject) => { + let callback : Function = function (err : Object | string, ...values : Array) { + if (err) { + reject(err); + } else { + resolve(values); + } + }; + func.apply(null, [...args, callback]); + }); + }; +} + +function promisify(func : Function) : Function { return function (...args : Array) { return new Promise((resolve, reject) => { @@ -1012,6 +1028,7 @@ export default { getErrorString: getErrorString, callbackWrapper: callbackWrapper, promiseWrapper: promiseWrapper, + promisify: promisify, createExternalType: createExternalType, TextEncoder: TextEncoder, TextDecoder: TextDecoder, -- Gitee From 6ea8bde23da48084c50035330fa272a873cfcd05 Mon Sep 17 00:00:00 2001 From: xdmal Date: Wed, 27 Jul 2022 18:02:59 +0800 Subject: [PATCH 4/4] Solve the crash problem of calling SetHwIcuDirectory Solve the crash problem of calling SetHwIcuDirectory issue:https://gitee.com/openharmony/js_util_module/issues/I5J8DK Signed-off-by: xdmal --- util/js_textdecoder.cpp | 4 ++++ util/js_textdecoder.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/util/js_textdecoder.cpp b/util/js_textdecoder.cpp index 2ef93df..96b9ecd 100755 --- a/util/js_textdecoder.cpp +++ b/util/js_textdecoder.cpp @@ -42,6 +42,10 @@ namespace OHOS::Util { } } label_ = i32Flag; + { + std::lock_guard lock(decodeLock_); + SetHwIcuDirectory(); + } bool fatal = (i32Flag & static_cast(ConverterFlags::FATAL_FLG)) == static_cast(ConverterFlags::FATAL_FLG); diff --git a/util/js_textdecoder.h b/util/js_textdecoder.h index 8f1d0fc..f37d453 100755 --- a/util/js_textdecoder.h +++ b/util/js_textdecoder.h @@ -17,6 +17,7 @@ #define UTIL_JS_TEXTDECODER_H_ #include +#include #include #include #include "napi/native_api.h" @@ -163,6 +164,7 @@ namespace OHOS::Util { uint32_t label_; std::string encStr_; TransformToolPointer tranTool_; + std::recursive_mutex decodeLock_; }; } #endif // UTIL_JS_TEXTDECODER_H_ -- Gitee