Skip to content

Commit

Permalink
src: avoid unnecessary ToLocalChecked calls
Browse files Browse the repository at this point in the history
This commit removes two unnecessary ToLocalChecked calls in
StringBytes::Encode.

PR-URL: #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>
  • Loading branch information
danbev authored and codebytere committed Jul 10, 2020
1 parent 5609b17 commit ec2452c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,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:
Expand All @@ -674,15 +674,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);
Expand Down

0 comments on commit ec2452c

Please sign in to comment.