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; + } + } +}