summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSakthipriyan Vairamani <thechargingvolcano@gmail.com>2015-08-12 00:01:50 +0530
committerSakthipriyan Vairamani <thechargingvolcano@gmail.com>2015-08-20 03:17:08 +0530
commit8f58fb92fff904a6ca58fd0df9ee5a1816e5b84e (patch)
treea3eb0aea4cfa4d7f3cbb85adefe60ca621901f89 /lib
parentd98eed51f782ea44c3fd7823b2912f7fb30ab185 (diff)
downloadandroid-node-v8-8f58fb92fff904a6ca58fd0df9ee5a1816e5b84e.tar.gz
android-node-v8-8f58fb92fff904a6ca58fd0df9ee5a1816e5b84e.tar.bz2
android-node-v8-8f58fb92fff904a6ca58fd0df9ee5a1816e5b84e.zip
events: deprecate static listenerCount function
As per the discussion in #734, this patch deprecates the usage of `EventEmitter.listenerCount` static function in the docs, and introduces the `listenerCount` function in the prototype of `EventEmitter` itself. PR-URL: https://github.com/nodejs/node/pull/2349 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/_http_client.js2
-rw-r--r--lib/_http_server.js4
-rw-r--r--lib/_stream_readable.js4
-rw-r--r--lib/_tls_wrap.js9
-rw-r--r--lib/events.js22
-rw-r--r--lib/fs.js2
-rw-r--r--lib/readline.js8
-rw-r--r--lib/stream.js2
8 files changed, 28 insertions, 25 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js
index 50d1052b44..e705117ab6 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -322,7 +322,7 @@ function socketOnData(d) {
var bodyHead = d.slice(bytesParsed, d.length);
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
- if (EventEmitter.listenerCount(req, eventName) > 0) {
+ if (req.listenerCount(eventName) > 0) {
req.upgradeOrConnect = true;
// detach the socket
diff --git a/lib/_http_server.js b/lib/_http_server.js
index 1a4bd7555a..6769f4a152 100644
--- a/lib/_http_server.js
+++ b/lib/_http_server.js
@@ -343,7 +343,7 @@ function connectionListener(socket) {
parser = null;
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
- if (EventEmitter.listenerCount(self, eventName) > 0) {
+ if (self.listenerCount(eventName) > 0) {
debug('SERVER have listener for %s', eventName);
var bodyHead = d.slice(bytesParsed, d.length);
@@ -467,7 +467,7 @@ function connectionListener(socket) {
(req.httpVersionMajor == 1 && req.httpVersionMinor == 1) &&
continueExpression.test(req.headers['expect'])) {
res._expect_continue = true;
- if (EventEmitter.listenerCount(self, 'checkContinue') > 0) {
+ if (self.listenerCount('checkContinue') > 0) {
self.emit('checkContinue', req, res);
} else {
res.writeContinue();
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 7be7723e52..11069985a4 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -533,7 +533,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
debug('onerror', er);
unpipe();
dest.removeListener('error', onerror);
- if (EE.listenerCount(dest, 'error') === 0)
+ if (dest.listenerCount('error') === 0)
dest.emit('error', er);
}
// This is a brutally ugly hack to make sure that our error handler
@@ -582,7 +582,7 @@ function pipeOnDrain(src) {
debug('pipeOnDrain', state.awaitDrain);
if (state.awaitDrain)
state.awaitDrain--;
- if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) {
+ if (state.awaitDrain === 0 && src.listenerCount('data')) {
state.flowing = true;
flow(src);
}
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js
index b5d1899480..df86512c77 100644
--- a/lib/_tls_wrap.js
+++ b/lib/_tls_wrap.js
@@ -5,7 +5,6 @@ const crypto = require('crypto');
const net = require('net');
const tls = require('tls');
const util = require('util');
-const listenerCount = require('events').listenerCount;
const common = require('_tls_common');
const StreamWrap = require('_stream_wrap').StreamWrap;
const Buffer = require('buffer').Buffer;
@@ -116,7 +115,7 @@ function requestOCSP(self, hello, ctx, cb) {
if (ctx.context)
ctx = ctx.context;
- if (listenerCount(self.server, 'OCSPRequest') === 0) {
+ if (self.server.listenerCount('OCSPRequest') === 0) {
return cb(null);
} else {
self.server.emit('OCSPRequest',
@@ -396,11 +395,11 @@ TLSSocket.prototype._init = function(socket, wrap) {
ssl.handshakes = 0;
if (this.server) {
- if (listenerCount(this.server, 'resumeSession') > 0 ||
- listenerCount(this.server, 'newSession') > 0) {
+ if (this.server.listenerCount('resumeSession') > 0 ||
+ this.server.listenerCount('newSession') > 0) {
ssl.enableSessionCallbacks();
}
- if (listenerCount(this.server, 'OCSPRequest') > 0)
+ if (this.server.listenerCount('OCSPRequest') > 0)
ssl.enableCertCb();
}
} else {
diff --git a/lib/events.js b/lib/events.js
index 3ea798b3bd..722b64537e 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -395,19 +395,23 @@ EventEmitter.prototype.listeners = function listeners(type) {
};
EventEmitter.listenerCount = function(emitter, type) {
- var evlistener;
- var ret = 0;
- var events = emitter._events;
+ return emitter.listenerCount(type);
+};
+
+EventEmitter.prototype.listenerCount = function listenerCount(type) {
+ const events = this._events;
if (events) {
- evlistener = events[type];
- if (typeof evlistener === 'function')
- ret = 1;
- else if (evlistener)
- ret = evlistener.length;
+ const evlistener = events[type];
+
+ if (typeof evlistener === 'function') {
+ return 1;
+ } else if (evlistener) {
+ return evlistener.length;
+ }
}
- return ret;
+ return 0;
};
// About 1.5x faster than the two-arg version of Array#splice().
diff --git a/lib/fs.js b/lib/fs.js
index 138a90e2f2..9bfd14cd29 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1354,7 +1354,7 @@ fs.unwatchFile = function(filename, listener) {
stat.removeAllListeners('change');
}
- if (EventEmitter.listenerCount(stat, 'change') === 0) {
+ if (stat.listenerCount('change') === 0) {
stat.stop();
statWatchers.delete(filename);
}
diff --git a/lib/readline.js b/lib/readline.js
index 02fa9d08f6..6164bcc85f 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -683,7 +683,7 @@ Interface.prototype._ttyWrite = function(s, key) {
switch (key.name) {
case 'c':
- if (EventEmitter.listenerCount(this, 'SIGINT') > 0) {
+ if (this.listenerCount('SIGINT') > 0) {
this.emit('SIGINT');
} else {
// This readline instance is finished
@@ -746,7 +746,7 @@ Interface.prototype._ttyWrite = function(s, key) {
case 'z':
if (process.platform == 'win32') break;
- if (EventEmitter.listenerCount(this, 'SIGTSTP') > 0) {
+ if (this.listenerCount('SIGTSTP') > 0) {
this.emit('SIGTSTP');
} else {
process.once('SIGCONT', (function(self) {
@@ -907,7 +907,7 @@ function emitKeypressEvents(stream) {
stream[ESCAPE_DECODER].next();
function onData(b) {
- if (EventEmitter.listenerCount(stream, 'keypress') > 0) {
+ if (stream.listenerCount('keypress') > 0) {
var r = stream[KEYPRESS_DECODER].write(b);
if (r) {
for (var i = 0; i < r.length; i++) {
@@ -936,7 +936,7 @@ function emitKeypressEvents(stream) {
}
}
- if (EventEmitter.listenerCount(stream, 'keypress') > 0) {
+ if (stream.listenerCount('keypress') > 0) {
stream.on('data', onData);
} else {
stream.on('newListener', onNewListener);
diff --git a/lib/stream.js b/lib/stream.js
index 8d3535dc4d..2e0cdfc313 100644
--- a/lib/stream.js
+++ b/lib/stream.js
@@ -70,7 +70,7 @@ Stream.prototype.pipe = function(dest, options) {
// don't leave dangling pipes when there are errors.
function onerror(er) {
cleanup();
- if (EE.listenerCount(this, 'error') === 0) {
+ if (this.listenerCount('error') === 0) {
throw er; // Unhandled stream error in pipe.
}
}