src: replace NewFromUtf8 with OneByteString where appropriate · nodejs/node@5dab48f · GitHub
Skip to content

Commit 5dab48f

Browse files
jasnellRafaelGSS
authored andcommitted
src: replace NewFromUtf8 with OneByteString where appropriate
PR-URL: #57096 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 0fe60b4 commit 5dab48f

5 files changed

Lines changed: 13 additions & 25 deletions

File tree

src/cares_wrap.cc

Lines changed: 2 additions & 4 deletions

src/node_binding.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,7 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
683683

684684
Local<Object> module = Object::New(env->isolate());
685685
Local<Object> exports = Object::New(env->isolate());
686-
Local<String> exports_prop =
687-
String::NewFromUtf8Literal(env->isolate(), "exports");
686+
Local<String> exports_prop = env->exports_string();
688687
module->Set(env->context(), exports_prop, exports).Check();
689688

690689
if (mod->nm_context_register_func != nullptr) {

src/node_buffer.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ using v8::Just;
7171
using v8::Local;
7272
using v8::Maybe;
7373
using v8::MaybeLocal;
74-
using v8::NewStringType;
7574
using v8::Nothing;
7675
using v8::Number;
7776
using v8::Object;
@@ -1310,12 +1309,9 @@ static void Btoa(const FunctionCallbackInfo<Value>& args) {
13101309
written = simdutf::binary_to_base64(*stack_buf, out_len, buffer.out());
13111310
}
13121311

1313-
auto value =
1314-
String::NewFromOneByte(env->isolate(),
1315-
reinterpret_cast<const uint8_t*>(buffer.out()),
1316-
NewStringType::kNormal,
1317-
written)
1318-
.ToLocalChecked();
1312+
auto value = OneByteString(
1313+
env->isolate(), reinterpret_cast<const uint8_t*>(buffer.out()), written);
1314+
13191315
return args.GetReturnValue().Set(value);
13201316
}
13211317

@@ -1365,12 +1361,9 @@ static void Atob(const FunctionCallbackInfo<Value>& args) {
13651361
}
13661362

13671363
if (result.error == simdutf::error_code::SUCCESS) {
1368-
auto value =
1369-
String::NewFromOneByte(env->isolate(),
1364+
auto value = OneByteString(env->isolate(),
13701365
reinterpret_cast<const uint8_t*>(buffer.out()),
1371-
NewStringType::kNormal,
1372-
result.count)
1373-
.ToLocalChecked();
1366+
result.count);
13741367
return args.GetReturnValue().Set(value);
13751368
}
13761369

src/node_i18n.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ void ICUErrorName(const FunctionCallbackInfo<Value>& args) {
327327
Environment* env = Environment::GetCurrent(args);
328328
CHECK(args[0]->IsInt32());
329329
UErrorCode status = static_cast<UErrorCode>(args[0].As<Int32>()->Value());
330-
args.GetReturnValue().Set(
331-
String::NewFromUtf8(env->isolate(),
332-
u_errorName(status)).ToLocalChecked());
330+
args.GetReturnValue().Set(OneByteString(env->isolate(), u_errorName(status)));
333331
}
334332

335333
} // anonymous namespace

src/spawn_sync.cc

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)