From d8eb8cffbb4fa3689dae4fbca12d7caba7432c1c Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sat, 15 Jul 2023 13:51:04 -0400 Subject: [PATCH] src: use string_view for utf-8 string creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/48722 Reviewed-By: Gerhard Stöbich Reviewed-By: Luigi Pinca --- src/util.cc | 55 ++++++++++++++++++++++++++++++++--------------------- src/util.h | 22 ++++++++++----------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/util.cc b/src/util.cc index 91c69a98c49c41..f28f906b4b7b6b 100644 --- a/src/util.cc +++ b/src/util.cc @@ -358,7 +358,7 @@ Local NewFunctionTemplate( void SetMethod(Local context, Local that, - const char* name, + const std::string_view name, v8::FunctionCallback callback) { Isolate* isolate = context->GetIsolate(); Local function = @@ -372,14 +372,15 @@ void SetMethod(Local context, // kInternalized strings are created in the old space. const v8::NewStringType type = v8::NewStringType::kInternalized; Local name_string = - v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked(); + v8::String::NewFromUtf8(isolate, name.data(), type, name.size()) + .ToLocalChecked(); that->Set(context, name_string, function).Check(); function->SetName(name_string); // NODE_SET_METHOD() compatibility. } void SetMethod(v8::Isolate* isolate, v8::Local that, - const char* name, + const std::string_view name, v8::FunctionCallback callback) { Local t = NewFunctionTemplate(isolate, @@ -390,13 +391,14 @@ void SetMethod(v8::Isolate* isolate, // kInternalized strings are created in the old space. const v8::NewStringType type = v8::NewStringType::kInternalized; Local name_string = - v8::String::NewFromUtf8(isolate, name, type).ToLocalChecked(); + v8::String::NewFromUtf8(isolate, name.data(), type, name.size()) + .ToLocalChecked(); that->Set(name_string, t); } void SetFastMethod(Isolate* isolate, Local