Skip to content

Commit

Permalink
src: add args validation method
Browse files Browse the repository at this point in the history
  • Loading branch information
ardinugrxha committed Jan 7, 2025
1 parent e0af101 commit b4c8fd8
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,9 @@ void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) {
}

void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
if (args.Length() <= 2) {
args.GetIsolate()->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(args.GetIsolate(), "Insufficient arguments")
.ToLocalChecked()));
return;
}

CHECK(args[2]->IsUint32());
Environment* env = Environment::GetCurrent(args);
int backlog;
if (!args[2]->Int32Value(env->context()).To(&backlog)) return;
// explicit cast to fit to libuv's type expectation
int port = static_cast<int>(args[2].As<Uint32>()->Value());
Connect<sockaddr_in>(args, [port](const char* ip_address, sockaddr_in* addr) {
Expand All @@ -293,7 +288,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {

void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[2]->IsUint32());

int port;
if (!args[2]->Int32Value(env->context()).To(&port)) return;
Connect<sockaddr_in6>(args,
Expand Down

0 comments on commit b4c8fd8

Please sign in to comment.