From 0e68481bf82d629ac972587aed23453a9cfa3ec1 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 17 Apr 2025 10:57:40 -0400 Subject: [PATCH] src: use non-deprecated Utf8LengthV2() method PR-URL: https://github.com/nodejs/node/pull/58070 Reviewed-By: Antoine du Hamel Reviewed-By: Darshan Sen Reviewed-By: Joyee Cheung Reviewed-By: Rafael Gonzaga --- benchmark/napi/function_args/binding.cc | 2 +- src/crypto/crypto_util.cc | 2 +- src/encoding_binding.cc | 2 +- src/js_native_api_v8.cc | 2 +- src/node_buffer.cc | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/benchmark/napi/function_args/binding.cc b/benchmark/napi/function_args/binding.cc index 078fe0ee3ea..e7c3cb40586 100644 --- a/benchmark/napi/function_args/binding.cc +++ b/benchmark/napi/function_args/binding.cc @@ -21,7 +21,7 @@ void CallWithString(const FunctionCallbackInfo& args) { assert(args.Length() == 1 && args[0]->IsString()); if (args.Length() == 1 && args[0]->IsString()) { Local str = args[0].As(); - const int32_t length = str->Utf8Length(args.GetIsolate()) + 1; + const size_t length = str->Utf8LengthV2(args.GetIsolate()) + 1; char* buf = new char[length]; str->WriteUtf8(args.GetIsolate(), buf, length); delete[] buf; diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc index 975345fbef3..a19626ec8ca 100644 --- a/src/crypto/crypto_util.cc +++ b/src/crypto/crypto_util.cc @@ -399,7 +399,7 @@ ByteSource ByteSource::FromStringOrBuffer(Environment* env, ByteSource ByteSource::FromString(Environment* env, Local str, bool ntc) { CHECK(str->IsString()); - size_t size = str->Utf8Length(env->isolate()); + size_t size = str->Utf8LengthV2(env->isolate()); size_t alloc_size = ntc ? size + 1 : size; auto out = DataPointer::Alloc(alloc_size); int opts = String::NO_OPTIONS; diff --git a/src/encoding_binding.cc b/src/encoding_binding.cc index 3cba0e932ed..90d081361f9 100644 --- a/src/encoding_binding.cc +++ b/src/encoding_binding.cc @@ -122,7 +122,7 @@ void BindingData::EncodeUtf8String(const FunctionCallbackInfo& args) { CHECK(args[0]->IsString()); Local str = args[0].As(); - size_t length = str->Utf8Length(isolate); + size_t length = str->Utf8LengthV2(isolate); Local ab; { diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 6e1680a74e2..a84fdae795d 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -2482,7 +2482,7 @@ napi_status NAPI_CDECL napi_get_value_string_utf8( if (!buf) { CHECK_ARG(env, result); - *result = val.As()->Utf8Length(env->isolate); + *result = val.As()->Utf8LengthV2(env->isolate); } else if (bufsize != 0) { int copied = val.As()->WriteUtf8( env->isolate, diff --git a/src/node_buffer.cc b/src/node_buffer.cc index cea48ce3ed1..19f343a7f17 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -639,7 +639,7 @@ void Fill(const FunctionCallbackInfo& args) { // Can't use StringBytes::Write() in all cases. For example if attempting // to write a two byte character into a one byte Buffer. if (enc == UTF8) { - str_length = str_obj->Utf8Length(env->isolate()); + str_length = str_obj->Utf8LengthV2(env->isolate()); node::Utf8Value str(env->isolate(), args[1]); memcpy(ts_obj_data + start, *str, std::min(str_length, fill_length)); @@ -727,8 +727,8 @@ void SlowByteLengthUtf8(const FunctionCallbackInfo& args) { CHECK(args[0]->IsString()); // Fast case: avoid StringBytes on UTF8 string. Jump to v8. - args.GetReturnValue().Set( - args[0].As()->Utf8Length(args.GetIsolate())); + size_t result = args[0].As()->Utf8LengthV2(args.GetIsolate()); + args.GetReturnValue().Set(static_cast(result)); } uint32_t FastByteLengthUtf8(