Permalink
Browse files

src: pass along errors from stream obj instantiation

PR-URL: #25734
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information...
addaleax authored and targos committed Jan 27, 2019
1 parent 8032969 commit 29286726798af55d47afd454f6369edc35660601
Showing with 40 additions and 44 deletions.
  1. +4 −3 src/connection_wrap.cc
  2. +6 −7 src/pipe_wrap.cc
  3. +3 −3 src/pipe_wrap.h
  4. +10 −9 src/stream_wrap.cc
  5. +6 −7 src/tcp_wrap.cc
  6. +3 −3 src/tcp_wrap.h
  7. +5 −9 src/udp_wrap.cc
  8. +3 −3 src/udp_wrap.h
@@ -48,9 +48,10 @@ void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,

if (status == 0) {
// Instantiate the client javascript object and handle.
Local<Object> client_obj = WrapType::Instantiate(env,
wrap_data,
WrapType::SOCKET);
Local<Object> client_obj;
if (!WrapType::Instantiate(env, wrap_data, WrapType::SOCKET)
.ToLocal(&client_obj))
return;

// Unwrap the client javascript object.
WrapType* wrap;
@@ -42,16 +42,16 @@ using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Int32;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::String;
using v8::Value;

using AsyncHooks = Environment::AsyncHooks;


Local<Object> PipeWrap::Instantiate(Environment* env,
AsyncWrap* parent,
PipeWrap::SocketType type) {
MaybeLocal<Object> PipeWrap::Instantiate(Environment* env,
AsyncWrap* parent,
PipeWrap::SocketType type) {
EscapableHandleScope handle_scope(env->isolate());
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
CHECK_EQ(false, env->pipe_constructor_template().IsEmpty());
@@ -60,9 +60,8 @@ Local<Object> PipeWrap::Instantiate(Environment* env,
.ToLocalChecked();
CHECK_EQ(false, constructor.IsEmpty());
Local<Value> type_value = Int32::New(env->isolate(), type);
Local<Object> instance =
constructor->NewInstance(env->context(), 1, &type_value).ToLocalChecked();
return handle_scope.Escape(instance);
return handle_scope.EscapeMaybe(
constructor->NewInstance(env->context(), 1, &type_value));
}


@@ -38,9 +38,9 @@ class PipeWrap : public ConnectionWrap<PipeWrap, uv_pipe_t> {
IPC
};

static v8::Local<v8::Object> Instantiate(Environment* env,
AsyncWrap* parent,
SocketType type);
static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
AsyncWrap* parent,
SocketType type);
static void Initialize(v8::Local<v8::Object> target,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
@@ -44,6 +44,7 @@ using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::ReadOnly;
using v8::Signature;
@@ -195,19 +196,17 @@ void LibuvStreamWrap::OnUvAlloc(size_t suggested_size, uv_buf_t* buf) {
*buf = EmitAlloc(suggested_size);
}



template <class WrapType>
static Local<Object> AcceptHandle(Environment* env, LibuvStreamWrap* parent) {
static MaybeLocal<Object> AcceptHandle(Environment* env,
LibuvStreamWrap* parent) {
static_assert(std::is_base_of<LibuvStreamWrap, WrapType>::value ||
std::is_base_of<UDPWrap, WrapType>::value,
"Can only accept stream handles");

EscapableHandleScope scope(env->isolate());
Local<Object> wrap_obj;

wrap_obj = WrapType::Instantiate(env, parent, WrapType::SOCKET);
if (wrap_obj.IsEmpty())
if (!WrapType::Instantiate(env, parent, WrapType::SOCKET).ToLocal(&wrap_obj))
return Local<Object>();

HandleWrap* wrap = Unwrap<HandleWrap>(wrap_obj);
@@ -237,7 +236,7 @@ void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
CHECK_EQ(persistent().IsEmpty(), false);

if (nread > 0) {
Local<Object> pending_obj;
MaybeLocal<Object> pending_obj;

if (type == UV_TCP) {
pending_obj = AcceptHandle<TCPWrap>(env(), this);
@@ -250,9 +249,11 @@ void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
}

if (!pending_obj.IsEmpty()) {
object()->Set(env()->context(),
env()->pending_handle_string(),
pending_obj).FromJust();
object()
->Set(env()->context(),
env()->pending_handle_string(),
pending_obj.ToLocalChecked())
.FromJust();
}
}

@@ -46,17 +46,17 @@ using v8::HandleScope;
using v8::Int32;
using v8::Integer;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::String;
using v8::Uint32;
using v8::Value;

using AsyncHooks = Environment::AsyncHooks;


Local<Object> TCPWrap::Instantiate(Environment* env,
AsyncWrap* parent,
TCPWrap::SocketType type) {
MaybeLocal<Object> TCPWrap::Instantiate(Environment* env,
AsyncWrap* parent,
TCPWrap::SocketType type) {
EscapableHandleScope handle_scope(env->isolate());
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false);
@@ -65,9 +65,8 @@ Local<Object> TCPWrap::Instantiate(Environment* env,
.ToLocalChecked();
CHECK_EQ(constructor.IsEmpty(), false);
Local<Value> type_value = Int32::New(env->isolate(), type);
Local<Object> instance =
constructor->NewInstance(env->context(), 1, &type_value).ToLocalChecked();
return handle_scope.Escape(instance);
return handle_scope.EscapeMaybe(
constructor->NewInstance(env->context(), 1, &type_value));
}


@@ -37,9 +37,9 @@ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> {
SERVER
};

static v8::Local<v8::Object> Instantiate(Environment* env,
AsyncWrap* parent,
SocketType type);
static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
AsyncWrap* parent,
SocketType type);
static void Initialize(v8::Local<v8::Object> target,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
@@ -30,12 +30,12 @@ namespace node {

using v8::Array;
using v8::Context;
using v8::EscapableHandleScope;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Integer;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::PropertyAttribute;
using v8::Signature;
@@ -518,18 +518,14 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv);
}


Local<Object> UDPWrap::Instantiate(Environment* env,
AsyncWrap* parent,
UDPWrap::SocketType type) {
EscapableHandleScope scope(env->isolate());
MaybeLocal<Object> UDPWrap::Instantiate(Environment* env,
AsyncWrap* parent,
UDPWrap::SocketType type) {
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);

// If this assert fires then Initialize hasn't been called yet.
CHECK_EQ(env->udp_constructor_function().IsEmpty(), false);
Local<Object> instance = env->udp_constructor_function()
->NewInstance(env->context()).ToLocalChecked();
return scope.Escape(instance);
return env->udp_constructor_function()->NewInstance(env->context());
}


@@ -61,9 +61,9 @@ class UDPWrap: public HandleWrap {
static void SetTTL(const v8::FunctionCallbackInfo<v8::Value>& args);
static void BufferSize(const v8::FunctionCallbackInfo<v8::Value>& args);

static v8::Local<v8::Object> Instantiate(Environment* env,
AsyncWrap* parent,
SocketType type);
static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
AsyncWrap* parent,
SocketType type);
SET_NO_MEMORY_INFO()
SET_MEMORY_INFO_NAME(UDPWrap)
SET_SELF_SIZE(UDPWrap)

0 comments on commit 2928672

Please sign in to comment.