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 <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
danbev authored and codebytere committed Jun 30, 2020
1 parent c85f41e commit 609d395
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 609d395

Please sign in to comment.