From 57332c05e9962b20a4954fed3ebdc9eb5cda895b Mon Sep 17 00:00:00 2001 From: Brendan Ashworth Date: Mon, 29 Dec 2014 12:03:24 -0800 Subject: [PATCH 1/2] dgram: change Socket.bind() to return itself This commit changes `lib/dgram.js` Sockets to, when they are bound to a port / IP, return themselves. This is done in order to allow chaining of methods and be in accordance with the `lib/net.js` library. --- lib/dgram.js | 4 +++- test/parallel/test-dgram-bind.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/dgram.js b/lib/dgram.js index defa144bd1deec..6b1772e6128dba 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; }; 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 From 6a2f4b5325bb8173fab302ece511819071060081 Mon Sep 17 00:00:00 2001 From: Brendan Ashworth Date: Mon, 29 Dec 2014 12:12:30 -0800 Subject: [PATCH 2/2] dgram: changes Socket.close() to return itself This commit adds a return statement to the dgram.Socket.close() function that returns itself after it finishes. This follows along the functionality of the more popular and, dare I say, father-library `lib/net.js`. --- lib/dgram.js | 2 ++ test/parallel/test-dgram-close.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/dgram.js b/lib/dgram.js index 6b1772e6128dba..ac7a054a4c4681 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -358,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-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