diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 22e5518b589714..92dba1be59e526 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -149,9 +149,11 @@ int StreamBase::Shutdown(v8::Local req_wrap_obj) { const char* msg = Error(); if (msg != nullptr) { - req_wrap_obj->Set( - env->context(), - env->error_string(), OneByteString(env->isolate(), msg)).Check(); + if (req_wrap_obj->Set(env->context(), + env->error_string(), + OneByteString(env->isolate(), msg)).IsNothing()) { + return 0; + } ClearError(); } @@ -203,9 +205,11 @@ StreamWriteResult StreamBase::Write( const char* msg = Error(); if (msg != nullptr) { - req_wrap_obj->Set(env->context(), - env->error_string(), - OneByteString(env->isolate(), msg)).Check(); + if (req_wrap_obj->Set(env->context(), + env->error_string(), + OneByteString(env->isolate(), msg)).IsNothing()) { + return StreamWriteResult {}; + } ClearError(); } @@ -279,10 +283,12 @@ void StreamReq::Done(int status, const char* error_str) { Environment* env = async_wrap->env(); if (error_str != nullptr) { v8::HandleScope handle_scope(env->isolate()); - async_wrap->object()->Set(env->context(), - env->error_string(), - OneByteString(env->isolate(), error_str)) - .Check(); + if (async_wrap->object()->Set( + env->context(), + env->error_string(), + OneByteString(env->isolate(), error_str)).IsNothing()) { + return; + } } OnDone(status); diff --git a/src/stream_base.cc b/src/stream_base.cc index 5bef709ef0a559..0b05c0aba33d7c 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -106,16 +106,22 @@ int StreamBase::Writev(const FunctionCallbackInfo& args) { if (!all_buffers) { // Determine storage size first for (size_t i = 0; i < count; i++) { - Local chunk = chunks->Get(context, i * 2).ToLocalChecked(); + Local chunk; + if (!chunks->Get(context, i * 2).ToLocal(&chunk)) + return 0; if (Buffer::HasInstance(chunk)) continue; // Buffer chunk, no additional storage required // String chunk - Local string = chunk->ToString(context).ToLocalChecked(); - enum encoding encoding = ParseEncoding(isolate, - chunks->Get(context, i * 2 + 1).ToLocalChecked()); + Local string; + if (!chunk->ToString(context).ToLocal(&string)) + return 0; + Local next_chunk; + if (!chunks->Get(context, i * 2 + 1).ToLocal(&next_chunk)) + return 0; + enum encoding encoding = ParseEncoding(isolate, next_chunk); size_t chunk_size; if (encoding == UTF8 && string->Length() > 65535 && !StringBytes::Size(isolate, string, encoding).To(&chunk_size)) @@ -130,7 +136,9 @@ int StreamBase::Writev(const FunctionCallbackInfo& args) { return UV_ENOBUFS; } else { for (size_t i = 0; i < count; i++) { - Local chunk = chunks->Get(context, i).ToLocalChecked(); + Local chunk; + if (!chunks->Get(context, i).ToLocal(&chunk)) + return 0; bufs[i].base = Buffer::Data(chunk); bufs[i].len = Buffer::Length(chunk); } @@ -145,7 +153,9 @@ int StreamBase::Writev(const FunctionCallbackInfo& args) { offset = 0; if (!all_buffers) { for (size_t i = 0; i < count; i++) { - Local chunk = chunks->Get(context, i * 2).ToLocalChecked(); + Local chunk; + if (!chunks->Get(context, i * 2).ToLocal(&chunk)) + return 0; // Write buffer if (Buffer::HasInstance(chunk)) { @@ -160,9 +170,13 @@ int StreamBase::Writev(const FunctionCallbackInfo& args) { static_cast(bs ? bs->Data() : nullptr) + offset; size_t str_size = (bs ? bs->ByteLength() : 0) - offset; - Local string = chunk->ToString(context).ToLocalChecked(); - enum encoding encoding = ParseEncoding(isolate, - chunks->Get(context, i * 2 + 1).ToLocalChecked()); + Local string; + if (!chunk->ToString(context).ToLocal(&string)) + return 0; + Local next_chunk; + if (!chunks->Get(context, i * 2 + 1).ToLocal(&next_chunk)) + return 0; + enum encoding encoding = ParseEncoding(isolate, next_chunk); str_size = StringBytes::Write(isolate, str_storage, str_size, @@ -207,9 +221,11 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo& args) { send_handle = reinterpret_cast(wrap->GetHandle()); // Reference LibuvStreamWrap instance to prevent it from being garbage // collected before `AfterWrite` is called. - req_wrap_obj->Set(env->context(), - env->handle_string(), - send_handle_obj).Check(); + if (req_wrap_obj->Set(env->context(), + env->handle_string(), + send_handle_obj).IsNothing()) { + return 0; + } } StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj); @@ -312,9 +328,11 @@ int StreamBase::WriteString(const FunctionCallbackInfo& args) { send_handle = reinterpret_cast(wrap->GetHandle()); // Reference LibuvStreamWrap instance to prevent it from being garbage // collected before `AfterWrite` is called. - req_wrap_obj->Set(env->context(), - env->handle_string(), - send_handle_obj).Check(); + if (req_wrap_obj->Set(env->context(), + env->handle_string(), + send_handle_obj).IsNothing()) { + return 0; + } } StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj); diff --git a/src/stream_pipe.cc b/src/stream_pipe.cc index aa636dbb75e9ed..94ba8604bd76c6 100644 --- a/src/stream_pipe.cc +++ b/src/stream_pipe.cc @@ -33,14 +33,26 @@ StreamPipe::StreamPipe(StreamBase* source, // In particular, this makes sure that they are garbage collected as a group, // if that applies to the given streams (for example, Http2Streams use // weak references). - obj->Set(env()->context(), env()->source_string(), source->GetObject()) - .Check(); - source->GetObject()->Set(env()->context(), env()->pipe_target_string(), obj) - .Check(); - obj->Set(env()->context(), env()->sink_string(), sink->GetObject()) - .Check(); - sink->GetObject()->Set(env()->context(), env()->pipe_source_string(), obj) - .Check(); + if (obj->Set(env()->context(), + env()->source_string(), + source->GetObject()).IsNothing()) { + return; + } + if (source->GetObject()->Set(env()->context(), + env()->pipe_target_string(), + obj).IsNothing()) { + return; + } + if (obj->Set(env()->context(), + env()->sink_string(), + sink->GetObject()).IsNothing()) { + return; + } + if (sink->GetObject()->Set(env()->context(), + env()->pipe_source_string(), + obj).IsNothing()) { + return; + } } StreamPipe::~StreamPipe() { @@ -172,7 +184,8 @@ void StreamPipe::WritableListener::OnStreamAfterWrite(WriteWrap* w, Environment* env = pipe->env(); HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); - pipe->MakeCallback(env->oncomplete_string(), 0, nullptr).ToLocalChecked(); + if (pipe->MakeCallback(env->oncomplete_string(), 0, nullptr).IsEmpty()) + return; stream()->RemoveStreamListener(this); } return; diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 2275167ad0eeb6..ff3df6bc5db7bd 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -268,12 +268,12 @@ void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) { CHECK_EQ(type, UV_UNKNOWN_HANDLE); } - if (!pending_obj.IsEmpty()) { - object() - ->Set(env()->context(), - env()->pending_handle_string(), - pending_obj.ToLocalChecked()) - .Check(); + Local local_pending_obj; + if (pending_obj.ToLocal(&local_pending_obj) && + object()->Set(env()->context(), + env()->pending_handle_string(), + local_pending_obj).IsNothing()) { + return; } }