From 332b035a96ffc0d1a048abdb7e32dd90acb2bc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 26 Aug 2018 10:30:32 +0200 Subject: [PATCH] src: use String::Utf8Length with isolate PR-URL: https://github.com/nodejs/node/pull/22531 Reviewed-By: Colin Ihrig Reviewed-By: Daniel Bevenius Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- benchmark/napi/function_args/binding.cc | 2 +- src/node_api.cc | 2 +- src/node_buffer.cc | 7 ++++--- src/string_bytes.cc | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/benchmark/napi/function_args/binding.cc b/benchmark/napi/function_args/binding.cc index 2c8fc7231f8daa..d0c1a079210532 100644 --- a/benchmark/napi/function_args/binding.cc +++ b/benchmark/napi/function_args/binding.cc @@ -19,7 +19,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() + 1; + const int32_t length = str->Utf8Length(args.GetIsolate()) + 1; char* buf = new char[length]; str->WriteUtf8(args.GetIsolate(), buf, length); delete [] buf; diff --git a/src/node_api.cc b/src/node_api.cc index 8ccadab3061cd7..727ca0cf7027f1 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -2399,7 +2399,7 @@ napi_status napi_get_value_string_utf8(napi_env env, if (!buf) { CHECK_ARG(env, result); - *result = val.As()->Utf8Length(); + *result = val.As()->Utf8Length(env->isolate); } else { int copied = val.As()->WriteUtf8( env->isolate, diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 95ffaa1993fb95..9a280f7c127cc6 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -599,7 +599,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(); + str_length = str_obj->Utf8Length(env->isolate()); node::Utf8Value str(env->isolate(), args[1]); memcpy(ts_obj_data + start, *str, MIN(str_length, fill_length)); @@ -689,10 +689,11 @@ void StringWrite(const FunctionCallbackInfo& args) { } void ByteLengthUtf8(const FunctionCallbackInfo &args) { + Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsString()); // Fast case: avoid StringBytes on UTF8 string. Jump to v8. - args.GetReturnValue().Set(args[0].As()->Utf8Length()); + args.GetReturnValue().Set(args[0].As()->Utf8Length(env->isolate())); } // Normalize val to be an integer in the range of [1, -1] since @@ -1062,7 +1063,7 @@ static void EncodeUtf8String(const FunctionCallbackInfo& args) { CHECK(args[0]->IsString()); Local str = args[0].As(); - size_t length = str->Utf8Length(); + size_t length = str->Utf8Length(isolate); char* data = node::UncheckedMalloc(length); str->WriteUtf8(isolate, data, diff --git a/src/string_bytes.cc b/src/string_bytes.cc index c106571a468301..b7f009fe1fcc16 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -465,7 +465,7 @@ size_t StringBytes::Size(Isolate* isolate, case BUFFER: case UTF8: - return str->Utf8Length(); + return str->Utf8Length(isolate); case UCS2: return str->Length() * sizeof(uint16_t);