Skip to content

Commit b4c8fd8

Browse files
committed
src: add args validation method
1 parent e0af101 commit b4c8fd8

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/tcp_wrap.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,9 @@ void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) {
276276
}
277277

278278
void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
279-
if (args.Length() <= 2) {
280-
args.GetIsolate()->ThrowException(v8::Exception::TypeError(
281-
v8::String::NewFromUtf8(args.GetIsolate(), "Insufficient arguments")
282-
.ToLocalChecked()));
283-
return;
284-
}
285-
286-
CHECK(args[2]->IsUint32());
279+
Environment* env = Environment::GetCurrent(args);
280+
int backlog;
281+
if (!args[2]->Int32Value(env->context()).To(&backlog)) return;
287282
// explicit cast to fit to libuv's type expectation
288283
int port = static_cast<int>(args[2].As<Uint32>()->Value());
289284
Connect<sockaddr_in>(args, [port](const char* ip_address, sockaddr_in* addr) {
@@ -293,7 +288,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
293288

294289
void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
295290
Environment* env = Environment::GetCurrent(args);
296-
CHECK(args[2]->IsUint32());
291+
297292
int port;
298293
if (!args[2]->Int32Value(env->context()).To(&port)) return;
299294
Connect<sockaddr_in6>(args,

0 commit comments

Comments
 (0)