diff --git a/lib/dgram.js b/lib/dgram.js index defa144bd1deec..ac7a054a4c4681 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -170,7 +170,7 @@ Socket.prototype.bind = function(port /*, address, callback*/) { if (port instanceof UDP) { replaceHandle(self, port); startListening(self); - return; + return self; } var address; @@ -231,6 +231,8 @@ Socket.prototype.bind = function(port /*, address, callback*/) { startListening(self); } }); + + return self; }; @@ -356,6 +358,8 @@ Socket.prototype.close = function() { this._handle.close(); this._handle = null; this.emit('close'); + + return this; }; diff --git a/test/parallel/test-dgram-bind.js b/test/parallel/test-dgram-bind.js index 8ee67637fcb6ce..1fe615bb757916 100644 --- a/test/parallel/test-dgram-bind.js +++ b/test/parallel/test-dgram-bind.js @@ -29,4 +29,6 @@ socket.on('listening', function () { socket.close(); }); -socket.bind(); // should not throw +var result = socket.bind(); // should not throw + +assert.strictEqual(result, socket); // should have returned itself diff --git a/test/parallel/test-dgram-close.js b/test/parallel/test-dgram-close.js index 77af6f13b8011e..1eed54c91f4106 100644 --- a/test/parallel/test-dgram-close.js +++ b/test/parallel/test-dgram-close.js @@ -32,7 +32,7 @@ buf.fill(42); var socket = dgram.createSocket('udp4'); var handle = socket._handle; socket.send(buf, 0, buf.length, common.PORT, 'localhost'); -socket.close(); +assert.strictEqual(socket.close(), socket); socket = null; // Verify that accessing handle after closure doesn't throw