| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 36b4ddd commit 213dcd7
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -361,14 +361,13 @@ IncomingMessage.prototype._dump = function _dump() { | |||
| 361 | 361 | } | |
| 362 | 362 | }; | |
| 363 | 363 | ||
| 364 | - function onError(instance, error, cb) { | ||
| 364 | + function onError(self, error, cb) { | ||
| 365 | 365 | // This is to keep backward compatible behavior. | |
| 366 | - // An error is emitted only if there are listeners attached to | ||
| 367 | - // the event. | ||
| 368 | - if (instance.listenerCount('error') > 0) { | ||
| 369 | - cb(error); | ||
| 370 | - } else { | ||
| 366 | + // An error is emitted only if there are listeners attached to the event. | ||
| 367 | + if (self.listenerCount('error') === 0) { | ||
| 371 | 368 | cb(); | |
| 369 | + } else { | ||
| 370 | + cb(error); | ||
| 372 | 371 | } | |
| 373 | 372 | } | |
| 374 | 373 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const { createServer, get } = require('http'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + const server = createServer(common.mustCall((req, res) => { | ||
| 8 | + res.writeHead(200); | ||
| 9 | + res.write('Part of res.'); | ||
| 10 | + })); | ||
| 11 | + | ||
| 12 | + function onUncaught(error) { | ||
| 13 | + assert.strictEqual(error.message, 'Destroy test'); | ||
| 14 | + server.close(); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + process.on('uncaughtException', common.mustCall(onUncaught)); | ||
| 18 | + | ||
| 19 | + server.listen(0, () => { | ||
| 20 | + get({ | ||
| 21 | + port: server.address().port | ||
| 22 | + }, common.mustCall((res) => { | ||
| 23 | + res.destroy(new Error('Destroy test')); | ||
| 24 | + })); | ||
| 25 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const { createServer, get } = require('http'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + const server = createServer(common.mustCall((req, res) => { | ||
| 8 | + req.destroy(new Error('Destroy test')); | ||
| 9 | + })); | ||
| 10 | + | ||
| 11 | + function onUncaught(error) {} | ||
| 12 | + | ||
| 13 | + process.on('uncaughtException', common.mustNotCall(onUncaught)); | ||
| 14 | + | ||
| 15 | + server.listen(0, common.mustCall(() => { | ||
| 16 | + get({ | ||
| 17 | + port: server.address().port | ||
| 18 | + }, (res) => { | ||
| 19 | + res.resume(); | ||
| 20 | + }).on('error', (error) => { | ||
| 21 | + assert.strictEqual(error.message, 'socket hang up'); | ||
| 22 | + assert.strictEqual(error.code, 'ECONNRESET'); | ||
| 23 | + server.close(); | ||
| 24 | + }); | ||
| 25 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments