diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 7ee87a8ebe8e30..d5e98439548655 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -644,11 +644,11 @@ MaybeLocal StringBytes::Encode(Isolate* isolate, return MaybeLocal(); } auto maybe_buf = Buffer::Copy(isolate, buf, buflen); - if (maybe_buf.IsEmpty()) { + Local buf; + if (!maybe_buf.ToLocal(&buf)) { *error = node::ERR_MEMORY_ALLOCATION_FAILED(isolate); - return MaybeLocal(); } - return maybe_buf.ToLocalChecked(); + return buf; } case ASCII: @@ -665,15 +665,17 @@ MaybeLocal 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(); + { + val = String::NewFromUtf8(isolate, + buf, + v8::NewStringType::kNormal, + buflen); + Local 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);