Skip to content

Commit

Permalink
src: don't create Undefined if not needed
Browse files Browse the repository at this point in the history
This commit moves the creation of argv and only creates an undefined
value if the passed in status was not 0.

The variable name client_handle was already used in this function but
I've change that usage so that this variable name matches the
onconnection callback functions parameter name clientHandle.

PR-URL: #20573
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
danbev authored and targos committed May 12, 2018
1 parent e01e060 commit 983cb26
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/connection_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
// uv_close() on the handle.
CHECK_EQ(wrap_data->persistent().IsEmpty(), false);

Local<Value> argv[] = {
Integer::New(env->isolate(), status),
Undefined(env->isolate())
};
Local<Value> client_handle;

if (status == 0) {
// Instantiate the client javascript object and handle.
Expand All @@ -59,17 +56,20 @@ void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
// Unwrap the client javascript object.
WrapType* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj);
uv_stream_t* client_handle =
reinterpret_cast<uv_stream_t*>(&wrap->handle_);
uv_stream_t* client = reinterpret_cast<uv_stream_t*>(&wrap->handle_);
// uv_accept can fail if the new connection has already been closed, in
// which case an EAGAIN (resource temporarily unavailable) will be
// returned.
if (uv_accept(handle, client_handle))
if (uv_accept(handle, client))
return;

// Successful accept. Call the onconnection callback in JavaScript land.
argv[1] = client_obj;
client_handle = client_obj;
} else {
client_handle = Undefined(env->isolate());
}

Local<Value> argv[] = { Integer::New(env->isolate(), status), client_handle };
wrap_data->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
}

Expand Down

0 comments on commit 983cb26

Please sign in to comment.