Skip to content

src: improve error handling in tcp_wrap.cc #57211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1627,10 +1627,15 @@ static void MessageChannel(const FunctionCallbackInfo<Value>& args) {

MessagePort::Entangle(port1, port2);

args.This()->Set(context, env->port1_string(), port1->object())
.Check();
args.This()->Set(context, env->port2_string(), port2->object())
.Check();
if (args.This()
->Set(context, env->port1_string(), port1->object())
.IsNothing() ||
args.This()
->Set(context, env->port2_string(), port2->object())
.IsNothing()) {
port1->Close();
port2->Close();
}
}

static void BroadcastChannel(const FunctionCallbackInfo<Value>& args) {
Expand Down
50 changes: 32 additions & 18 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,9 @@ MaybeLocal<Object> AddressToJS(Environment* env,

int port;

if (info.IsEmpty())
if (info.IsEmpty()) {
info = Object::New(env->isolate());
}

switch (addr->sa_family) {
case AF_INET6:
Expand All @@ -413,32 +414,45 @@ MaybeLocal<Object> AddressToJS(Environment* env,
}
}
port = ntohs(a6->sin6_port);
info->Set(env->context(),
env->address_string(),
OneByteString(env->isolate(), ip)).Check();
info->Set(env->context(), env->family_string(), env->ipv6_string()).Check();
info->Set(env->context(),
env->port_string(),
Integer::New(env->isolate(), port)).Check();
if (info->Set(env->context(),
env->address_string(),
OneByteString(env->isolate(), ip))
.IsNothing() ||
info->Set(env->context(), env->family_string(), env->ipv6_string())
.IsNothing() ||
info->Set(env->context(),
env->port_string(),
Integer::New(env->isolate(), port))
.IsNothing()) {
return {};
}
break;

case AF_INET:
a4 = reinterpret_cast<const sockaddr_in*>(addr);
uv_inet_ntop(AF_INET, &a4->sin_addr, ip, sizeof ip);
port = ntohs(a4->sin_port);
info->Set(env->context(),
env->address_string(),
OneByteString(env->isolate(), ip)).Check();
info->Set(env->context(), env->family_string(), env->ipv4_string()).Check();
info->Set(env->context(),
env->port_string(),
Integer::New(env->isolate(), port)).Check();
if (info->Set(env->context(),
env->address_string(),
OneByteString(env->isolate(), ip))
.IsNothing() ||
info->Set(env->context(), env->family_string(), env->ipv4_string())
.IsNothing() ||
info->Set(env->context(),
env->port_string(),
Integer::New(env->isolate(), port))
.IsNothing()) {
return {};
}
break;

default:
info->Set(env->context(),
env->address_string(),
String::Empty(env->isolate())).Check();
if (info->Set(env->context(),
env->address_string(),
String::Empty(env->isolate()))
.IsNothing()) {
return {};
}
}

return scope.Escape(info);
Expand Down
8 changes: 6 additions & 2 deletions src/tty_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) {

if (err == 0) {
Local<Array> a = args[0].As<Array>();
a->Set(env->context(), 0, Integer::New(env->isolate(), width)).Check();
a->Set(env->context(), 1, Integer::New(env->isolate(), height)).Check();
if (a->Set(env->context(), 0, Integer::New(env->isolate(), width))
.IsNothing() ||
a->Set(env->context(), 1, Integer::New(env->isolate(), height))
.IsNothing()) {
return;
}
}

args.GetReturnValue().Set(err);
Expand Down
Loading