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 <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: David Carlier <[email protected]>
  • Loading branch information
danbev authored and codebytere committed Jun 18, 2020
1 parent 2427d65 commit fb2b0a0
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 @@ -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:
Expand All @@ -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);
Expand Down

0 comments on commit fb2b0a0

Please sign in to comment.