From ed749f2402293d22c3fcc21516f46e91499bb90f Mon Sep 17 00:00:00 2001 From: lifansheng Date: Wed, 22 Sep 2021 14:55:27 +0800 Subject: [PATCH 1/3] modify codecheck Signed-off-by: lifansheng --- util/js_textdecoder.cpp | 5 ++--- util/native_module_util.cpp | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/util/js_textdecoder.cpp b/util/js_textdecoder.cpp index d0b2a40..4d3c9c6 100755 --- a/util/js_textdecoder.cpp +++ b/util/js_textdecoder.cpp @@ -45,8 +45,7 @@ namespace OHOS::Util { (i32Flag & static_cast(ConverterFlags::FATAL_FLG)) == static_cast(ConverterFlags::FATAL_FLG); UErrorCode codeflag = U_ZERO_ERROR; - char *pStr = const_cast(encStr_.c_str()); - UConverter *conv = ucnv_open(pStr, &codeflag); + UConverter *conv = ucnv_open(encStr_.c_str(), &codeflag); if (U_FAILURE(codeflag)) { HILOG_ERROR("ucnv_open failed !"); return; @@ -175,7 +174,7 @@ namespace OHOS::Util { void TextDecoder::SetBomFlag(const UChar *arr, const UErrorCode codeFlag, const DecodeArr decArr, size_t &rstLen, bool &bomFlag) { - if (arr == nullptr ) { + if (arr == nullptr) { return; } if (U_SUCCESS(codeFlag)) { diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index caf7ff3..3681c05 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -135,8 +135,7 @@ namespace OHOS::Util { static std::string PrintfString(const std::string &format, const std::vector &value) { - std::string printInfo; - printInfo = DealWithPrintf(format, value); + std::string printInfo = DealWithPrintf(format, value); return printInfo; } -- Gitee From 3280afb36ceb083280cd55a12e5f7dfbe61424af Mon Sep 17 00:00:00 2001 From: lifansheng Date: Wed, 22 Sep 2021 15:55:53 +0800 Subject: [PATCH 2/3] modify codecheck Signed-off-by: lifansheng --- util/BUILD.gn | 34 ++++++++++++++++++++++ util/js_textdecoder.cpp | 5 ++-- util/native_module_util.cpp | 56 ++++++++++++++++++++++++------------- 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/util/BUILD.gn b/util/BUILD.gn index ea5e47e..cc2856c 100755 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -11,8 +11,33 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") +import("//foundation/ace/ace_engine/ace_config.gni") + +# compile .js to .abc. +action("gen_util_abc") { + visibility = [ ":*" ] + script = "//ark/ts2abc/ts2panda/scripts/generate_js_bytecode.py" + + args = [ + "--src-js", + rebase_path("//base/compileruntime/js_util_module/util/util_js.js"), + "--dst-file", + rebase_path(target_out_dir + "/util.abc"), + "--node", + rebase_path("${node_path}"), + "--frontend-tool-path", + rebase_path("${ts2abc_build_path}"), + "--node-modules", + rebase_path("${node_modules}"), + ] + deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] + + inputs = [ "//base/compileruntime/js_util_module/util/util_js.js" ] + outputs = [ target_out_dir + "/util.abc" ] +} base_output_path = get_label_info(":util_js", "target_out_dir") util_js_obj_path = base_output_path + "/util.o" @@ -22,6 +47,14 @@ gen_js_obj("util_js") { output = util_js_obj_path } +abc_output_path = get_label_info(":util_abc", "target_out_dir") +util_abc_obj_path = abc_output_path + "/util_abc.o" +gen_js_obj("util_abc") { + input = "$target_out_dir/util.abc" + output = util_abc_obj_path + dep = ":gen_util_abc" +} + ohos_shared_library("util") { include_dirs = [ "//foundation/ace/napi", @@ -41,6 +74,7 @@ ohos_shared_library("util") { ] deps = [ + ":util_abc", ":util_js", "//base/compileruntime/js_util_module/util/:util_js", "//foundation/ace/napi/:ace_napi", diff --git a/util/js_textdecoder.cpp b/util/js_textdecoder.cpp index 4d3c9c6..d0b2a40 100755 --- a/util/js_textdecoder.cpp +++ b/util/js_textdecoder.cpp @@ -45,7 +45,8 @@ namespace OHOS::Util { (i32Flag & static_cast(ConverterFlags::FATAL_FLG)) == static_cast(ConverterFlags::FATAL_FLG); UErrorCode codeflag = U_ZERO_ERROR; - UConverter *conv = ucnv_open(encStr_.c_str(), &codeflag); + char *pStr = const_cast(encStr_.c_str()); + UConverter *conv = ucnv_open(pStr, &codeflag); if (U_FAILURE(codeflag)) { HILOG_ERROR("ucnv_open failed !"); return; @@ -174,7 +175,7 @@ namespace OHOS::Util { void TextDecoder::SetBomFlag(const UChar *arr, const UErrorCode codeFlag, const DecodeArr decArr, size_t &rstLen, bool &bomFlag) { - if (arr == nullptr) { + if (arr == nullptr ) { return; } if (U_SUCCESS(codeFlag)) { diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index 3681c05..4507e2a 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -27,6 +27,8 @@ extern const char _binary_util_js_js_start[]; extern const char _binary_util_js_js_end[]; +extern const char _binary_util_abc_start[]; +extern const char _binary_util_abc_end[]; namespace OHOS::Util { static std::string temp = "cdfijoOs"; napi_value RationalNumberClass = nullptr; @@ -113,29 +115,34 @@ namespace OHOS::Util { napi_value *argv = nullptr; if (argc > 0) { argv = new napi_value[argc]; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + char *format = nullptr; + size_t formatsize = 0; + napi_get_value_string_utf8(env, argv[0], nullptr, 0, &formatsize); + if (formatsize > 0) { + format = new char[formatsize + 1]; + napi_get_value_string_utf8(env, argv[0], format, formatsize + 1, &formatsize); + std::string str = format; + delete []format; + delete []argv; + argv = nullptr; + format = nullptr; + return FormatString(env, str); + } else { + return; + } + napi_value res = nullptr; + NAPI_CALL(env, napi_get_undefined(env, &res)); + return res; + } else { + return; } - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - char *format = nullptr; - size_t formatsize = 0; - napi_get_value_string_utf8(env, argv[0], nullptr, 0, &formatsize); - if (formatsize > 0) { - format = new char[formatsize + 1]; - napi_get_value_string_utf8(env, argv[0], format, formatsize + 1, &formatsize); - std::string str = format; - delete []format; - delete []argv; - argv = nullptr; - format = nullptr; - return FormatString(env, str); - } - napi_value res = nullptr; - NAPI_CALL(env, napi_get_undefined(env, &res)); - return res; } static std::string PrintfString(const std::string &format, const std::vector &value) { - std::string printInfo = DealWithPrintf(format, value); + std::string printInfo; + printInfo = DealWithPrintf(format, value); return printInfo; } @@ -843,4 +850,15 @@ namespace OHOS::Util { *buflen = _binary_util_js_js_end - _binary_util_js_js_start; } } -} \ No newline at end of file + // util JS register + extern "C" + __attribute__((visibility("default"))) void NAPI_util_GetABCCode(const char** buf, int* buflen) + { + if (buf != nullptr) { + *buf = _binary_util_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_util_abc_end - _binary_util_abc_start; + } + } +} -- Gitee From d52453a7c06bfcaa1cf3e083204eface00e8110c Mon Sep 17 00:00:00 2001 From: lifansheng Date: Wed, 22 Sep 2021 20:09:20 +0800 Subject: [PATCH 3/3] modify codecheck Signed-off-by: lifansheng --- util/BUILD.gn | 34 ---------------------------------- util/js_base64.cpp | 5 ----- util/js_textdecoder.cpp | 5 ++--- util/js_textdecoder.h | 6 ++++-- util/native_module_util.cpp | 28 +++++----------------------- 5 files changed, 11 insertions(+), 67 deletions(-) diff --git a/util/BUILD.gn b/util/BUILD.gn index cc2856c..ea5e47e 100755 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -11,33 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//ark/ts2abc/ts2panda/ts2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/ace/ace.gni") -import("//foundation/ace/ace_engine/ace_config.gni") - -# compile .js to .abc. -action("gen_util_abc") { - visibility = [ ":*" ] - script = "//ark/ts2abc/ts2panda/scripts/generate_js_bytecode.py" - - args = [ - "--src-js", - rebase_path("//base/compileruntime/js_util_module/util/util_js.js"), - "--dst-file", - rebase_path(target_out_dir + "/util.abc"), - "--node", - rebase_path("${node_path}"), - "--frontend-tool-path", - rebase_path("${ts2abc_build_path}"), - "--node-modules", - rebase_path("${node_modules}"), - ] - deps = [ "//ark/ts2abc/ts2panda:ark_ts2abc_build" ] - - inputs = [ "//base/compileruntime/js_util_module/util/util_js.js" ] - outputs = [ target_out_dir + "/util.abc" ] -} base_output_path = get_label_info(":util_js", "target_out_dir") util_js_obj_path = base_output_path + "/util.o" @@ -47,14 +22,6 @@ gen_js_obj("util_js") { output = util_js_obj_path } -abc_output_path = get_label_info(":util_abc", "target_out_dir") -util_abc_obj_path = abc_output_path + "/util_abc.o" -gen_js_obj("util_abc") { - input = "$target_out_dir/util.abc" - output = util_abc_obj_path - dep = ":gen_util_abc" -} - ohos_shared_library("util") { include_dirs = [ "//foundation/ace/napi", @@ -74,7 +41,6 @@ ohos_shared_library("util") { ] deps = [ - ":util_abc", ":util_js", "//base/compileruntime/js_util_module/util/:util_js", "//foundation/ace/napi/:ace_napi", diff --git a/util/js_base64.cpp b/util/js_base64.cpp index acf91b3..10fad23 100755 --- a/util/js_base64.cpp +++ b/util/js_base64.cpp @@ -97,8 +97,6 @@ namespace OHOS::Util { napi_throw_error(env, "-1", "decode rstring memset_s failed"); } } else { - FreeMemory(ret); - FreeMemory(rstring); napi_throw_error(env, "-2", "outputLen is error !"); } for (size_t i = 0; i < outputLen; i++) { @@ -132,7 +130,6 @@ namespace OHOS::Util { napi_throw_error(env, "-1", "ret path memset_s failed"); } } else { - FreeMemory(ret); napi_throw_error(env, "-2", "outputLen is error !"); } bosom = ret; @@ -193,7 +190,6 @@ namespace OHOS::Util { napi_throw_error(env, "-1", "decode inputString memset_s failed"); } } else { - FreeMemory(inputString); napi_throw_error(env, "-2", "prolen is error !"); } napi_get_value_string_utf8(env, src, inputString, prolen + 1, &prolen); @@ -245,7 +241,6 @@ namespace OHOS::Util { napi_throw_error(env, "-1", "decode retDecode memset_s failed"); } } else { - FreeMemory(retDecode); napi_throw_error(env, "-2", "retLen is error !"); } bosom = retDecode; diff --git a/util/js_textdecoder.cpp b/util/js_textdecoder.cpp index d0b2a40..4d3c9c6 100755 --- a/util/js_textdecoder.cpp +++ b/util/js_textdecoder.cpp @@ -45,8 +45,7 @@ namespace OHOS::Util { (i32Flag & static_cast(ConverterFlags::FATAL_FLG)) == static_cast(ConverterFlags::FATAL_FLG); UErrorCode codeflag = U_ZERO_ERROR; - char *pStr = const_cast(encStr_.c_str()); - UConverter *conv = ucnv_open(pStr, &codeflag); + UConverter *conv = ucnv_open(encStr_.c_str(), &codeflag); if (U_FAILURE(codeflag)) { HILOG_ERROR("ucnv_open failed !"); return; @@ -175,7 +174,7 @@ namespace OHOS::Util { void TextDecoder::SetBomFlag(const UChar *arr, const UErrorCode codeFlag, const DecodeArr decArr, size_t &rstLen, bool &bomFlag) { - if (arr == nullptr ) { + if (arr == nullptr) { return; } if (U_SUCCESS(codeFlag)) { diff --git a/util/js_textdecoder.h b/util/js_textdecoder.h index a0901ae..bc74fda 100755 --- a/util/js_textdecoder.h +++ b/util/js_textdecoder.h @@ -26,7 +26,8 @@ using TransformToolPointer = std::unique_ptr; namespace OHOS::Util { struct DecodeArr { - DecodeArr(UChar *tarPos, size_t tarStaPos, size_t limLen) { + DecodeArr(UChar *tarPos, size_t tarStaPos, size_t limLen) + { this->target = tarPos; this->tarStartPos = tarStaPos; this->limitLen = limLen; @@ -90,7 +91,8 @@ namespace OHOS::Util { ucnv_close(pointer); } private: - void SetBomFlag(const UChar *arr, const UErrorCode codeFlag, const DecodeArr decArr, size_t& rstLen, bool& bomFlag); + void SetBomFlag(const UChar *arr, const UErrorCode codeFlag, const DecodeArr decArr, + size_t& rstLen, bool& bomFlag); void FreedMemory(UChar *pData); napi_env env_; uint32_t label_; diff --git a/util/native_module_util.cpp b/util/native_module_util.cpp index 4507e2a..d5cdde4 100755 --- a/util/native_module_util.cpp +++ b/util/native_module_util.cpp @@ -27,8 +27,6 @@ extern const char _binary_util_js_js_start[]; extern const char _binary_util_js_js_end[]; -extern const char _binary_util_abc_start[]; -extern const char _binary_util_abc_end[]; namespace OHOS::Util { static std::string temp = "cdfijoOs"; napi_value RationalNumberClass = nullptr; @@ -128,21 +126,16 @@ namespace OHOS::Util { argv = nullptr; format = nullptr; return FormatString(env, str); - } else { - return; } - napi_value res = nullptr; - NAPI_CALL(env, napi_get_undefined(env, &res)); - return res; - } else { - return; } + napi_value res = nullptr; + NAPI_CALL(env, napi_get_undefined(env, &res)); + return res; } static std::string PrintfString(const std::string &format, const std::vector &value) { - std::string printInfo; - printInfo = DealWithPrintf(format, value); + std::string printInfo = DealWithPrintf(format, value); return printInfo; } @@ -850,15 +843,4 @@ namespace OHOS::Util { *buflen = _binary_util_js_js_end - _binary_util_js_js_start; } } - // util JS register - extern "C" - __attribute__((visibility("default"))) void NAPI_util_GetABCCode(const char** buf, int* buflen) - { - if (buf != nullptr) { - *buf = _binary_util_abc_start; - } - if (buflen != nullptr) { - *buflen = _binary_util_abc_end - _binary_util_abc_start; - } - } -} +} \ No newline at end of file -- Gitee