Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use NewFromUtf8Literal in GetLinkedBinding #33552

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
danbev committed May 25, 2020
commit aa9b3c96212c0d4eb0c1bd0f400f044016839e18
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