@@ -155,7 +155,7 @@ function createServer(options, connectionListener) {
155155
156156// Target API:
157157//
158- // var s = net.connect({port: 80, host: 'google.com'}, function() {
158+ // let s = net.connect({port: 80, host: 'google.com'}, function() {
159159// ...
160160// });
161161//
@@ -190,7 +190,7 @@ function connect(...args) {
190190// For Server.prototype.listen(), the [...] part is [, backlog]
191191// but will not be handled here (handled in listen())
192192function normalizeArgs ( args ) {
193- var arr ;
193+ let arr ;
194194
195195 if ( args . length === 0 ) {
196196 arr = [ { } , null ] ;
@@ -199,7 +199,7 @@ function normalizeArgs(args) {
199199 }
200200
201201 const arg0 = args [ 0 ] ;
202- var options = { } ;
202+ let options = { } ;
203203 if ( typeof arg0 === 'object' && arg0 !== null ) {
204204 // (options[...][, cb])
205205 options = arg0 ;
@@ -382,7 +382,7 @@ ObjectSetPrototypeOf(Socket, stream.Duplex);
382382
383383// Refresh existing timeouts.
384384Socket . prototype . _unrefTimer = function _unrefTimer ( ) {
385- for ( var s = this ; s !== null ; s = s . _parent ) {
385+ for ( let s = this ; s !== null ; s = s . _parent ) {
386386 if ( s [ kTimeout ] )
387387 s [ kTimeout ] . refresh ( ) ;
388388 }
@@ -558,7 +558,7 @@ function tryReadStart(socket) {
558558 // Not already reading, start the flow
559559 debug ( 'Socket._handle.readStart' ) ;
560560 socket . _handle . reading = true ;
561- var err = socket . _handle . readStart ( ) ;
561+ const err = socket . _handle . readStart ( ) ;
562562 if ( err )
563563 socket . destroy ( errnoException ( err , 'read' ) ) ;
564564}
@@ -646,15 +646,15 @@ Socket.prototype._destroy = function(exception, cb) {
646646
647647 this . readable = this . writable = false ;
648648
649- for ( var s = this ; s !== null ; s = s . _parent ) {
649+ for ( let s = this ; s !== null ; s = s . _parent ) {
650650 clearTimeout ( s [ kTimeout ] ) ;
651651 }
652652
653653 debug ( 'close' ) ;
654654 if ( this . _handle ) {
655655 if ( this !== process . stderr )
656656 debug ( 'close handle' ) ;
657- var isException = exception ? true : false ;
657+ const isException = exception ? true : false ;
658658 // `bytesRead` and `kBytesWritten` should be accessible after `.destroy()`
659659 this [ kBytesRead ] = this . _handle . bytesRead ;
660660 this [ kBytesWritten ] = this . _handle . bytesWritten ;
@@ -686,8 +686,8 @@ Socket.prototype._getpeername = function() {
686686 if ( ! this . _handle || ! this . _handle . getpeername ) {
687687 return { } ;
688688 }
689- var out = { } ;
690- var err = this . _handle . getpeername ( out ) ;
689+ const out = { } ;
690+ const err = this . _handle . getpeername ( out ) ;
691691 if ( err ) return { } ; // FIXME(bnoordhuis) Throw?
692692 this . _peername = out ;
693693 }
@@ -724,8 +724,8 @@ Socket.prototype._getsockname = function() {
724724 return { } ;
725725 }
726726 if ( ! this . _sockname ) {
727- var out = { } ;
728- var err = this . _handle . getsockname ( out ) ;
727+ const out = { } ;
728+ const err = this . _handle . getsockname ( out ) ;
729729 if ( err ) return { } ; // FIXME(bnoordhuis) Throw?
730730 this . _sockname = out ;
731731 }
@@ -796,7 +796,7 @@ protoGetter('_bytesDispatched', function _bytesDispatched() {
796796} ) ;
797797
798798protoGetter ( 'bytesWritten' , function bytesWritten ( ) {
799- var bytes = this . _bytesDispatched ;
799+ let bytes = this . _bytesDispatched ;
800800 const state = this . _writableState ;
801801 const data = this . _pendingData ;
802802 const encoding = this . _pendingEncoding ;
@@ -813,7 +813,7 @@ protoGetter('bytesWritten', function bytesWritten() {
813813
814814 if ( Array . isArray ( data ) ) {
815815 // Was a writev, iterate over chunks to get total length
816- for ( var i = 0 ; i < data . length ; i ++ ) {
816+ for ( let i = 0 ; i < data . length ; i ++ ) {
817817 const chunk = data [ i ] ;
818818
819819 if ( data . allBuffers || chunk instanceof Buffer )
@@ -843,7 +843,7 @@ function checkBindError(err, port, handle) {
843843 // getsockname() method. Non-issue for now, the cluster module doesn't
844844 // really support pipes anyway.
845845 if ( err === 0 && port > 0 && handle . getsockname ) {
846- var out = { } ;
846+ const out = { } ;
847847 err = handle . getsockname ( out ) ;
848848 if ( err === 0 && port !== out . port ) {
849849 debug ( `checkBindError, bound to ${ out . port } instead of ${ port } ` ) ;
@@ -861,7 +861,7 @@ function internalConnect(
861861
862862 assert ( self . connecting ) ;
863863
864- var err ;
864+ let err ;
865865
866866 if ( localAddress || localPort ) {
867867 if ( addressType === 4 ) {
@@ -903,8 +903,8 @@ function internalConnect(
903903 }
904904
905905 if ( err ) {
906- var sockname = self . _getsockname ( ) ;
907- var details ;
906+ const sockname = self . _getsockname ( ) ;
907+ let details ;
908908
909909 if ( sockname ) {
910910 details = sockname . address + ':' + sockname . port ;
@@ -1127,15 +1127,15 @@ function afterConnect(status, handle, req, readable, writable) {
11271127
11281128 } else {
11291129 self . connecting = false ;
1130- var details ;
1130+ let details ;
11311131 if ( req . localAddress && req . localPort ) {
11321132 details = req . localAddress + ':' + req . localPort ;
11331133 }
1134- var ex = exceptionWithHostPort ( status ,
1135- 'connect' ,
1136- req . address ,
1137- req . port ,
1138- details ) ;
1134+ const ex = exceptionWithHostPort ( status ,
1135+ 'connect' ,
1136+ req . address ,
1137+ req . port ,
1138+ details ) ;
11391139 if ( details ) {
11401140 ex . localAddress = req . localAddress ;
11411141 ex . localPort = req . localPort ;
@@ -1199,11 +1199,11 @@ function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; }
11991199
12001200// Returns handle if it can be created, or error code if it can't
12011201function createServerHandle ( address , port , addressType , fd , flags ) {
1202- var err = 0 ;
1202+ let err = 0 ;
12031203 // Assign handle in listen, and clean up if bind or listen fails
1204- var handle ;
1204+ let handle ;
12051205
1206- var isTCP = false ;
1206+ let isTCP = false ;
12071207 if ( typeof fd === 'number' && fd >= 0 ) {
12081208 try {
12091209 handle = createHandle ( fd , true ) ;
@@ -1221,7 +1221,7 @@ function createServerHandle(address, port, addressType, fd, flags) {
12211221 } else if ( port === - 1 && addressType === - 1 ) {
12221222 handle = new Pipe ( PipeConstants . SERVER ) ;
12231223 if ( process . platform === 'win32' ) {
1224- var instances = parseInt ( process . env . NODE_PENDING_PIPE_INSTANCES ) ;
1224+ const instances = parseInt ( process . env . NODE_PENDING_PIPE_INSTANCES ) ;
12251225 if ( ! Number . isNaN ( instances ) ) {
12261226 handle . setPendingInstances ( instances ) ;
12271227 }
@@ -1266,7 +1266,7 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) {
12661266 } else {
12671267 debug ( 'setupListenHandle: create a handle' ) ;
12681268
1269- var rval = null ;
1269+ let rval = null ;
12701270
12711271 // Try to bind to the unspecified IPv6 address, see if IPv6 is available
12721272 if ( ! address && typeof fd !== 'number' ) {
@@ -1286,7 +1286,7 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) {
12861286 rval = createServerHandle ( address , port , addressType , fd , flags ) ;
12871287
12881288 if ( typeof rval === 'number' ) {
1289- var error = uvExceptionWithHostPort ( rval , 'listen' , address , port ) ;
1289+ const error = uvExceptionWithHostPort ( rval , 'listen' , address , port ) ;
12901290 process . nextTick ( emitErrorNT , this , error ) ;
12911291 return ;
12921292 }
@@ -1303,7 +1303,7 @@ function setupListenHandle(address, port, addressType, backlog, fd, flags) {
13031303 const err = this . _handle . listen ( backlog || 511 ) ;
13041304
13051305 if ( err ) {
1306- var ex = uvExceptionWithHostPort ( err , 'listen' , address , port ) ;
1306+ const ex = uvExceptionWithHostPort ( err , 'listen' , address , port ) ;
13071307 this . _handle . close ( ) ;
13081308 this . _handle = null ;
13091309 defaultTriggerAsyncIdScope ( this [ async_id_symbol ] ,
@@ -1370,7 +1370,7 @@ function listenInCluster(server, address, port, addressType,
13701370 err = checkBindError ( err , port , handle ) ;
13711371
13721372 if ( err ) {
1373- var ex = exceptionWithHostPort ( err , 'bind' , address , port ) ;
1373+ const ex = exceptionWithHostPort ( err , 'bind' , address , port ) ;
13741374 return server . emit ( 'error' , ex ) ;
13751375 }
13761376
@@ -1385,7 +1385,7 @@ function listenInCluster(server, address, port, addressType,
13851385
13861386Server . prototype . listen = function ( ...args ) {
13871387 const normalized = normalizeArgs ( args ) ;
1388- var options = normalized [ 0 ] ;
1388+ let options = normalized [ 0 ] ;
13891389 const cb = normalized [ 1 ] ;
13901390
13911391 if ( this . _handle ) {
@@ -1427,7 +1427,7 @@ Server.prototype.listen = function(...args) {
14271427 // ([port][, host][, backlog][, cb]) where port is specified
14281428 // or (options[, cb]) where options.port is specified
14291429 // or if options.port is normalized as 0 before
1430- var backlog ;
1430+ let backlog ;
14311431 if ( typeof options . port === 'number' || typeof options . port === 'string' ) {
14321432 if ( ! isLegalPort ( options . port ) ) {
14331433 throw new ERR_SOCKET_BAD_PORT ( options . port ) ;
@@ -1448,7 +1448,7 @@ Server.prototype.listen = function(...args) {
14481448 // (path[, backlog][, cb]) or (options[, cb])
14491449 // where path or options.path is a UNIX domain socket or Windows pipe
14501450 if ( options . path && isPipeName ( options . path ) ) {
1451- var pipeName = this . _pipeName = options . path ;
1451+ const pipeName = this . _pipeName = options . path ;
14521452 backlog = options . backlog || backlogFromArgs ;
14531453 listenInCluster ( this , pipeName , - 1 , - 1 ,
14541454 backlog , undefined , options . exclusive ) ;
@@ -1506,8 +1506,8 @@ ObjectDefineProperty(Server.prototype, 'listening', {
15061506
15071507Server . prototype . address = function ( ) {
15081508 if ( this . _handle && this . _handle . getsockname ) {
1509- var out = { } ;
1510- var err = this . _handle . getsockname ( out ) ;
1509+ const out = { } ;
1510+ const err = this . _handle . getsockname ( out ) ;
15111511 if ( err ) {
15121512 throw errnoException ( err , 'address' ) ;
15131513 }
@@ -1569,8 +1569,8 @@ Server.prototype.getConnections = function(cb) {
15691569 }
15701570
15711571 // Poll workers
1572- var left = this . _workers . length ;
1573- var total = this . _connections ;
1572+ let left = this . _workers . length ;
1573+ let total = this . _connections ;
15741574
15751575 function oncount ( err , count ) {
15761576 if ( err ) {
@@ -1582,7 +1582,7 @@ Server.prototype.getConnections = function(cb) {
15821582 if ( -- left === 0 ) return end ( null , total ) ;
15831583 }
15841584
1585- for ( var n = 0 ; n < this . _workers . length ; n ++ ) {
1585+ for ( let n = 0 ; n < this . _workers . length ; n ++ ) {
15861586 this . _workers [ n ] . getConnections ( oncount ) ;
15871587 }
15881588
@@ -1607,7 +1607,7 @@ Server.prototype.close = function(cb) {
16071607 }
16081608
16091609 if ( this . _usingWorkers ) {
1610- var left = this . _workers . length ;
1610+ let left = this . _workers . length ;
16111611 const onWorkerClose = ( ) => {
16121612 if ( -- left !== 0 ) return ;
16131613
@@ -1620,7 +1620,7 @@ Server.prototype.close = function(cb) {
16201620 this . _connections ++ ;
16211621
16221622 // Poll workers
1623- for ( var n = 0 ; n < this . _workers . length ; n ++ )
1623+ for ( let n = 0 ; n < this . _workers . length ; n ++ )
16241624 this . _workers [ n ] . close ( onWorkerClose ) ;
16251625 } else {
16261626 this . _emitCloseIfDrained ( ) ;
@@ -1690,11 +1690,11 @@ Server.prototype.unref = function() {
16901690 return this ;
16911691} ;
16921692
1693- var _setSimultaneousAccepts ;
1694- var warnSimultaneousAccepts = true ;
1693+ let _setSimultaneousAccepts ;
1694+ let warnSimultaneousAccepts = true ;
16951695
16961696if ( process . platform === 'win32' ) {
1697- var simultaneousAccepts ;
1697+ let simultaneousAccepts ;
16981698
16991699 _setSimultaneousAccepts = function ( handle ) {
17001700 if ( warnSimultaneousAccepts ) {
0 commit comments