domain,events: support non-object 'error' argument
Fix a TypeError when emitting an 'error' argument with a non-object argument (like a string) when domains are active. Fixes: https://github.com/nodejs/help/issues/501 PR-URL: https://github.com/nodejs/node/pull/11438 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
3f02b47b8a
commit
4f638f6fd7
@ -153,9 +153,11 @@ EventEmitter.prototype.emit = function emit(type) {
|
|||||||
if (domain) {
|
if (domain) {
|
||||||
if (!er)
|
if (!er)
|
||||||
er = new Error('Uncaught, unspecified "error" event');
|
er = new Error('Uncaught, unspecified "error" event');
|
||||||
|
if (typeof er === 'object' && er !== null) {
|
||||||
er.domainEmitter = this;
|
er.domainEmitter = this;
|
||||||
er.domain = domain;
|
er.domain = domain;
|
||||||
er.domainThrown = false;
|
er.domainThrown = false;
|
||||||
|
}
|
||||||
domain.emit('error', er);
|
domain.emit('error', er);
|
||||||
} else if (er instanceof Error) {
|
} else if (er instanceof Error) {
|
||||||
throw er; // Unhandled 'error' event
|
throw er; // Unhandled 'error' event
|
||||||
|
@ -3,12 +3,33 @@ const common = require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const events = require('events');
|
const events = require('events');
|
||||||
const domain = require('domain');
|
const domain = require('domain');
|
||||||
const e = new events.EventEmitter();
|
|
||||||
|
|
||||||
const d = domain.create();
|
{
|
||||||
d.add(e);
|
const e = new events.EventEmitter();
|
||||||
d.on('error', common.mustCall(function(er) {
|
const d = domain.create();
|
||||||
|
d.add(e);
|
||||||
|
d.on('error', common.mustCall(function(er) {
|
||||||
assert(er instanceof Error, 'error created');
|
assert(er instanceof Error, 'error created');
|
||||||
}));
|
}));
|
||||||
|
e.emit('error');
|
||||||
|
}
|
||||||
|
|
||||||
e.emit('error');
|
for (const arg of [false, null, undefined]) {
|
||||||
|
const e = new events.EventEmitter();
|
||||||
|
const d = domain.create();
|
||||||
|
d.add(e);
|
||||||
|
d.on('error', common.mustCall(function(er) {
|
||||||
|
assert(er instanceof Error, 'error created');
|
||||||
|
}));
|
||||||
|
e.emit('error', arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const arg of [42, 'fortytwo', true]) {
|
||||||
|
const e = new events.EventEmitter();
|
||||||
|
const d = domain.create();
|
||||||
|
d.add(e);
|
||||||
|
d.on('error', common.mustCall(function(er) {
|
||||||
|
assert.strictEqual(er, arg);
|
||||||
|
}));
|
||||||
|
e.emit('error', arg);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user