Skip to content

Commit

Permalink
src: replace NewFromUtf8 with OneByteString where appropriate
Browse files Browse the repository at this point in the history
PR-URL: #57096
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
jasnell authored Feb 18, 2025
1 parent 2086877 commit a724a9e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 26 deletions.
6 changes: 2 additions & 4 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/node_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 5 additions & 12 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 1 addition & 4 deletions src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/spawn_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit a724a9e

Please sign in to comment.