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>
This commit is contained in:
Родитель
207e48c934
Коммит
8c0742f437
|
@ -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'));
|
||||
|
|
|
@ -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);
|
||||
});
|
Загрузка…
Ссылка в новой задаче