From 27d347b56b1a36d479b4b6b23dca8ea34fecc55c 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. PR-URL: https://github.com/nodejs/node/pull/33552 Reviewed-By: Anna Henningsen Reviewed-By: Richard Lau Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig Reviewed-By: Zeyu Yang Reviewed-By: Ruben Bridgewater Reviewed-By: David Carlier Reviewed-By: Gus Caplan Reviewed-By: James M Snell --- 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) {