diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2020-06-10 09:20:36 +0300 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2020-06-15 06:52:33 +0300 |
commit | 8f7211a60a45a5fcdbe99fa5150a3c7b30c1b5ed (patch) | |
tree | 0d0d3f5ef71adea6cb624e5041941de2defbbbe1 /src/string_bytes.cc | |
parent | 418f5b61eb49a31a5cdc9c3c94e58b8221bf0c44 (diff) |
src: avoid unnecessary ToLocalChecked calls
This commit removes two unnecessary ToLocalChecked calls in
StringBytes::Encode.
PR-URL: https://github.com/nodejs/node/pull/33824
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/string_bytes.cc')
-rw-r--r-- | src/string_bytes.cc | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 7ee87a8ebe8..d5e98439548 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -644,11 +644,11 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate, return MaybeLocal<Value>(); } auto maybe_buf = Buffer::Copy(isolate, buf, buflen); - if (maybe_buf.IsEmpty()) { + Local<v8::Object> buf; + if (!maybe_buf.ToLocal(&buf)) { *error = node::ERR_MEMORY_ALLOCATION_FAILED(isolate); - return MaybeLocal<Value>(); } - return maybe_buf.ToLocalChecked(); + return buf; } case ASCII: @@ -665,15 +665,17 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate, } case UTF8: - val = String::NewFromUtf8(isolate, - buf, - v8::NewStringType::kNormal, - buflen); - if (val.IsEmpty()) { - *error = node::ERR_STRING_TOO_LONG(isolate); - return MaybeLocal<Value>(); + { + val = String::NewFromUtf8(isolate, + buf, + v8::NewStringType::kNormal, + buflen); + Local<String> str; + if (!val.ToLocal(&str)) { + *error = node::ERR_STRING_TOO_LONG(isolate); + } + return str; } - return val.ToLocalChecked(); case LATIN1: return ExternOneByteString::NewFromCopy(isolate, buf, buflen, error); |