Repository: nodejs/node
Pull request: src: replace NewFromUtf8 with OneByteString where appropriate

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: src/cares_wrap.cc
patch: @@ -1660,11 +1660,9 @@ void CanonicalizeIP(const FunctionCallbackInfo<Value>& args) {
       uv_inet_pton(af = AF_INET6, *ip, result) != 0)
     return;
 
-  char canonical_ip[INET6_ADDRSTRLEN];
+  char canonical_ip[INET6_ADDRSTRLEN]{};
   CHECK_EQ(0, uv_inet_ntop(af, result, canonical_ip, sizeof(canonical_ip)));
-  Local<String> val = String::NewFromUtf8(isolate, canonical_ip)
-      .ToLocalChecked();
-  args.GetReturnValue().Set(val);
+  args.GetReturnValue().Set(OneByteString(isolate, canonical_ip));
 }
 
 void ConvertIpv6StringToBuffer(const FunctionCallbackInfo<Value>& args) {

filename: src/node_binding.cc
patch: @@ -685,8 +685,7 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
 
   Local<Object> module = Object::New(env->isolate());
   Local<Object> exports = Object::New(env->isolate());
-  Local<String> exports_prop =
-      String::NewFromUtf8Literal(env->isolate(), "exports");
+  Local<String> exports_prop = env->exports_string();
   module->Set(env->context(), exports_prop, exports).Check();
 
   if (mod->nm_context_register_func != nullptr) {

filename: src/node_buffer.cc
patch: @@ -72,7 +72,6 @@ using v8::Just;
 using v8::Local;
 using v8::Maybe;
 using v8::MaybeLocal;
-using v8::NewStringType;
 using v8::Nothing;
 using v8::Number;
 using v8::Object;
@@ -1307,12 +1306,9 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) {
     written = simdutf::binary_to_base64(*stack_buf, out_len, buffer.out());
   }
 
-  auto value =
-      String::NewFromOneByte(env->isolate(),
-                             reinterpret_cast<const uint8_t*>(buffer.out()),
-                             NewStringType::kNormal,
-                             written)
-          .ToLocalChecked();
+  auto value = OneByteString(
+      env->isolate(), reinterpret_cast<const uint8_t*>(buffer.out()), written);
+
   return args.GetReturnValue().Set(value);
 }
 
@@ -1362,12 +1358,9 @@ static void Atob(const FunctionCallbackInfo<Value>& args) {
   }
 
   if (result.error == simdutf::error_code::SUCCESS) {
-    auto value =
-        String::NewFromOneByte(env->isolate(),
+    auto value = OneByteString(env->isolate(),
                                reinterpret_cast<const uint8_t*>(buffer.out()),
-                               NewStringType::kNormal,
-                               result.count)
-            .ToLocalChecked();
+                               result.count);
     return args.GetReturnValue().Set(value);
   }
 

filename: src/node_i18n.cc
patch: @@ -330,10 +330,7 @@ void ICUErrorName(const FunctionCallbackInfo<Value>& args) {
   Environment* env = Environment::GetCurrent(args);
   CHECK(args[0]->IsInt32());
   UErrorCode status = static_cast<UErrorCode>(args[0].As<Int32>()->Value());
-  Local<Value> res;
-  if (String::NewFromUtf8(env->isolate(), u_errorName(status)).ToLocal(&res)) {
-    args.GetReturnValue().Set(res);
-  }
+  args.GetReturnValue().Set(OneByteString(env->isolate(), u_errorName(status)));
 }
 
 }  // anonymous namespace

filename: src/spawn_sync.cc
patch: @@ -707,10 +707,10 @@ Local<Object> SyncProcessRunner::BuildResultObject() {
   }
 
   if (term_signal_ > 0)
-    js_result->Set(context, env()->signal_string(),
-                   String::NewFromUtf8(env()->isolate(),
-                                       signo_string(term_signal_))
-                       .ToLocalChecked())
+    js_result
+        ->Set(context,
+              env()->signal_string(),
+              OneByteString(env()->isolate(), signo_string(term_signal_)))
         .Check();
   else
     js_result->Set(context, env()->signal_string(),