net: check close callback is function

PR-URL: https://github.com/iojs/io.js/pull/609
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Evan Lucas <evanlucas@me.com>
pull/694/head
Yosuke Furukawa 2015-01-27 02:55:19 +09:00 committed by Ben Noordhuis
parent 207e48c934
commit 8c0742f437
2 changed files with 21 additions and 1 deletions

View File

@ -1368,7 +1368,7 @@ Server.prototype.close = function(cb) {
self._emitCloseIfDrained();
}
if (cb) {
if (typeof cb === 'function') {
if (!this._handle) {
this.once('close', function() {
cb(new Error('Not running'));

View File

@ -0,0 +1,20 @@
var assert = require('assert');
var common = require('../common');
var net = require('net');
var server = net.createServer(assert.fail);
var closeEvents = 0;
server.on('close', function() {
++closeEvents;
});
server.listen(common.PORT, function() {
assert(false);
});
server.close('bad argument');
process.on('exit', function() {
assert.equal(closeEvents, 1);
});