mirror of https://github.com/lukechilds/node.git
Browse Source
This PR simplifies Server.prototype.listen, removing some redundancy and inconsistency. Because listen and connect have a similar function signature, normalizeConnectArgs can be reused for listen. listenAfterLookup renamed to lookupAndListen for consistency with lookupAndConnect, and moved out of Server.prototype.listen. PR-URL: https://github.com/nodejs/node/pull/4039 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Glen Keane <glenkeane.94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>v7.x
Jan Schär
8 years ago
committed by
Matteo Collina
3 changed files with 98 additions and 92 deletions
@ -1,28 +1,45 @@ |
|||||
'use strict'; |
'use strict'; |
||||
var common = require('../common'); |
const common = require('../common'); |
||||
var assert = require('assert'); |
const assert = require('assert'); |
||||
var net = require('net'); |
const net = require('net'); |
||||
|
|
||||
function close() { this.close(); } |
function close() { this.close(); } |
||||
net.Server().listen({ port: undefined }, close); |
|
||||
net.Server().listen({ port: '' + common.PORT }, close); |
|
||||
|
|
||||
[ 'nan', |
// From lib/net.js
|
||||
-1, |
function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; } |
||||
123.456, |
|
||||
0x10000, |
function isPipeName(s) { |
||||
1 / 0, |
return typeof s === 'string' && toNumber(s) === false; |
||||
-1 / 0, |
} |
||||
'+Infinity', |
|
||||
'-Infinity' |
const listenVariants = [ |
||||
].forEach(function(port) { |
(port, cb) => net.Server().listen({port}, cb), |
||||
assert.throws(function() { |
(port, cb) => net.Server().listen(port, cb) |
||||
net.Server().listen({ port: port }, common.fail); |
]; |
||||
}, /"port" argument must be >= 0 and < 65536/i); |
|
||||
}); |
listenVariants.forEach((listenVariant, i) => { |
||||
|
listenVariant(undefined, common.mustCall(close)); |
||||
|
listenVariant('0', common.mustCall(close)); |
||||
|
|
||||
|
[ |
||||
|
'nan', |
||||
|
-1, |
||||
|
123.456, |
||||
|
0x10000, |
||||
|
1 / 0, |
||||
|
-1 / 0, |
||||
|
'+Infinity', |
||||
|
'-Infinity' |
||||
|
].forEach((port) => { |
||||
|
if (i === 1 && isPipeName(port)) { |
||||
|
// skip this, because listen(port) can also be listen(path)
|
||||
|
return; |
||||
|
} |
||||
|
assert.throws(() => listenVariant(port, common.fail), |
||||
|
/"port" argument must be >= 0 and < 65536/i); |
||||
|
}); |
||||
|
|
||||
[null, true, false].forEach(function(port) { |
[null, true, false].forEach((port) => |
||||
assert.throws(function() { |
assert.throws(() => listenVariant(port, common.fail), |
||||
net.Server().listen({ port: port }, common.fail); |
/invalid listen argument/i)); |
||||
}, /invalid listen argument/i); |
|
||||
}); |
}); |
||||
|
Loading…
Reference in new issue