diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2020-05-25 14:34:17 +0300 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2020-05-28 07:01:50 +0300 |
commit | 27d347b56b1a36d479b4b6b23dca8ea34fecc55c (patch) | |
tree | 53cd4b5be576577bbc2acbb2c60f1a64b3c58741 /src/node_binding.cc | |
parent | d12d5ef3ef8e5d9f6a755d72c4b8ddc82658dee9 (diff) |
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.
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'src/node_binding.cc')
-rw-r--r-- | src/node_binding.cc | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/src/node_binding.cc b/src/node_binding.cc index fdd84c39a20..719ae957706 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<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) { |