From aa9b3c96212c0d4eb0c1bd0f400f044016839e18 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 25 May 2020 13:34:17 +0200 Subject: [PATCH] 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 and can return a Local meaning that the additional ToLocalChecked call is avoided. --- src/node_binding.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/node_binding.cc b/src/node_binding.cc index fdd84c39a20b01..719ae95770602a 100644 --- a/src/node_binding.cc +++ b/src/node_binding.cc @@ -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; @@ -644,8 +643,7 @@ void GetLinkedBinding(const FunctionCallbackInfo& args) { Local module = Object::New(env->isolate()); Local exports = Object::New(env->isolate()); Local 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) {