| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 101db80 commit f3696f6
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -374,7 +374,7 @@ function connectionListener(socket) { | |||
| 374 | 374 | parser = null; | |
| 375 | 375 | ||
| 376 | 376 | var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade'; | |
| 377 | - if (self.listenerCount(eventName) > 0) { | ||
| 377 | + if (EventEmitter.listenerCount(self, eventName) > 0) { | ||
| 378 | 378 | debug('SERVER have listener for %s', eventName); | |
| 379 | 379 | var bodyHead = d.slice(bytesParsed, d.length); | |
| 380 | 380 | ||
@@ -497,7 +497,7 @@ function connectionListener(socket) { | |||
| 497 | 497 | (req.httpVersionMajor == 1 && req.httpVersionMinor == 1) && | |
| 498 | 498 | continueExpression.test(req.headers['expect'])) { | |
| 499 | 499 | res._expect_continue = true; | |
| 500 | - if (self.listenerCount('checkContinue') > 0) { | ||
| 500 | + if (EventEmitter.listenerCount(self, 'checkContinue') > 0) { | ||
| 501 | 501 | self.emit('checkContinue', req, res); | |
| 502 | 502 | } else { | |
| 503 | 503 | res.writeContinue(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -537,7 +537,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { | |||
| 537 | 537 | debug('onerror', er); | |
| 538 | 538 | unpipe(); | |
| 539 | 539 | dest.removeListener('error', onerror); | |
| 540 | - if (dest.listenerCount('error') === 0) | ||
| 540 | + if (EE.listenerCount(dest, 'error') === 0) | ||
| 541 | 541 | dest.emit('error', er); | |
| 542 | 542 | } | |
| 543 | 543 | // This is a brutally ugly hack to make sure that our error handler | |
@@ -586,7 +586,7 @@ function pipeOnDrain(src) { | |||
| 586 | 586 | debug('pipeOnDrain', state.awaitDrain); | |
| 587 | 587 | if (state.awaitDrain) | |
| 588 | 588 | state.awaitDrain--; | |
| 589 | - if (state.awaitDrain === 0 && src.listenerCount('data')) { | ||
| 589 | + if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) { | ||
| 590 | 590 | state.flowing = true; | |
| 591 | 591 | flow(src); | |
| 592 | 592 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -395,10 +395,15 @@ EventEmitter.prototype.listeners = function listeners(type) { | |||
| 395 | 395 | }; | |
| 396 | 396 | ||
| 397 | 397 | EventEmitter.listenerCount = function(emitter, type) { | |
| 398 | - return emitter.listenerCount(type); | ||
| 398 | + if (typeof emitter.listenerCount === 'function') { | ||
| 399 | + return emitter.listenerCount(type); | ||
| 400 | + } else { | ||
| 401 | + return listenerCount.call(emitter, type); | ||
| 402 | + } | ||
| 399 | 403 | }; | |
| 400 | 404 | ||
| 401 | - EventEmitter.prototype.listenerCount = function listenerCount(type) { | ||
| 405 | + EventEmitter.prototype.listenerCount = listenerCount; | ||
| 406 | + function listenerCount(type) { | ||
| 402 | 407 | const events = this._events; | |
| 403 | 408 | ||
| 404 | 409 | if (events) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,7 +70,7 @@ Stream.prototype.pipe = function(dest, options) { | |||
| 70 | 70 | // don't leave dangling pipes when there are errors. | |
| 71 | 71 | function onerror(er) { | |
| 72 | 72 | cleanup(); | |
| 73 | - if (this.listenerCount('error') === 0) { | ||
| 73 | + if (EE.listenerCount(this, 'error') === 0) { | ||
| 74 | 74 | throw er; // Unhandled stream error in pipe. | |
| 75 | 75 | } | |
| 76 | 76 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const stream = require('stream'); | ||
| 4 | + | ||
| 5 | + const r = new stream.Stream(); | ||
| 6 | + r.listenerCount = undefined; | ||
| 7 | + | ||
| 8 | + const w = new stream.Stream(); | ||
| 9 | + w.listenerCount = undefined; | ||
| 10 | + | ||
| 11 | + w.on('pipe', function() { | ||
| 12 | + r.emit('error', new Error('Readable Error')); | ||
| 13 | + w.emit('error', new Error('Writable Error')); | ||
| 14 | + }); | ||
| 15 | + r.on('error', common.mustCall(noop)); | ||
| 16 | + w.on('error', common.mustCall(noop)); | ||
| 17 | + r.pipe(w); | ||
| 18 | + | ||
| 19 | + function noop() {}; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments