Skip to content

Commit 5438611

Browse files
danbevcodebytere
authored andcommitted
src: use NewFromUtf8Literal in GetLinkedBinding
This commit changes the usage of NewFromUtf8 to NewFromUtf8Literal. The motivation for this change is that NewFromUtf8Literal is a templated function that takes a char[N] argument so the length of the string can be asserted at compile time, avoiding length checks that NewFromUtf8 performs. My understanding is that since these checks can be performed at compile time, checking that the string is not zero and checking that it is not greater than kMaxLength, this function does not have to return a MaybeLocal<String> and can return a Local<String> meaning that the additional ToLocalChecked call is avoided. PR-URL: #33552 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Zeyu Yang <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8c9e3a9 commit 5438611

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/node_binding.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ using v8::Exception;
233233
using v8::Function;
234234
using v8::FunctionCallbackInfo;
235235
using v8::Local;
236-
using v8::NewStringType;
237236
using v8::Object;
238237
using v8::String;
239238
using v8::Value;
@@ -644,8 +643,7 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
644643
Local<Object> module = Object::New(env->isolate());
645644
Local<Object> exports = Object::New(env->isolate());
646645
Local<String> exports_prop =
647-
String::NewFromUtf8(env->isolate(), "exports", NewStringType::kNormal)
648-
.ToLocalChecked();
646+
String::NewFromUtf8Literal(env->isolate(), "exports");
649647
module->Set(env->context(), exports_prop, exports).Check();
650648

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

0 commit comments

Comments
 (0)