Browse Source

dgram: 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>
v1.8.0-commit
Yosuke Furukawa 10 years ago
committed by Ben Noordhuis
parent
commit
207e48c934
  1. 2
      lib/dgram.js
  2. 21
      test/parallel/test-dgram-close-is-not-callback.js

2
lib/dgram.js

@ -341,7 +341,7 @@ function afterSend(err) {
Socket.prototype.close = function(callback) { Socket.prototype.close = function(callback) {
if (callback) if (typeof callback === 'function')
this.on('close', callback); this.on('close', callback);
this._healthCheck(); this._healthCheck();
this._stopReceiving(); this._stopReceiving();

21
test/parallel/test-dgram-close-is-not-callback.js

@ -0,0 +1,21 @@
var assert = require('assert');
var common = require('../common');
var dgram = require('dgram');
var buf = new Buffer(1024);
buf.fill(42);
var socket = dgram.createSocket('udp4');
var closeEvents = 0;
socket.send(buf, 0, buf.length, common.PORT, 'localhost');
// if close callback is not function, ignore the argument.
socket.close('bad argument');
socket.on('close', function() {
++closeEvents;
});
process.on('exit', function() {
assert.equal(closeEvents, 1);
});
Loading…
Cancel
Save