Skip to content

Commit

Permalink
src: use NewFromUtf8Literal in GetLinkedBinding
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
danbev authored and codebytere committed Jun 18, 2020
1 parent 8c9e3a9 commit 5438611
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/node_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ using v8::Exception;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
Expand Down Expand Up @@ -644,8 +643,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::NewFromUtf8(env->isolate(), "exports", NewStringType::kNormal)
.ToLocalChecked();
String::NewFromUtf8Literal(env->isolate(), "exports");
module->Set(env->context(), exports_prop, exports).Check();

if (mod->nm_context_register_func != nullptr) {
Expand Down

0 comments on commit 5438611

Please sign in to comment.