From 8c0742f43759d35da99f2475f81a026c2818c66a Mon Sep 17 00:00:00 2001 From: Yosuke Furukawa Date: Tue, 27 Jan 2015 02:55:19 +0900 Subject: [PATCH] net: check close callback is function PR-URL: https://github.com/iojs/io.js/pull/609 Reviewed-By: Ben Noordhuis Reviewed-By: Evan Lucas --- lib/net.js | 2 +- ...n-close-server-callback-is-not-function.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-net-listen-close-server-callback-is-not-function.js diff --git a/lib/net.js b/lib/net.js index 1cd8b6da352..af8c3dd8feb 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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')); diff --git a/test/parallel/test-net-listen-close-server-callback-is-not-function.js b/test/parallel/test-net-listen-close-server-callback-is-not-function.js new file mode 100644 index 00000000000..f4eff779406 --- /dev/null +++ b/test/parallel/test-net-listen-close-server-callback-is-not-function.js @@ -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); +});