domain: don't crash on "throw null"

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
pull/5010/head
Alex Kocharin 2013-12-24 16:33:03 +04:00 committed by Trevor Norris
parent 006d42786e
commit 42a33c1bb8
2 changed files with 19 additions and 2 deletions

View File

@ -85,8 +85,10 @@ Domain.prototype._errorHandler = function errorHandler(er) {
if (this._disposed) if (this._disposed)
return true; return true;
er.domain = this; if (!util.isPrimitive(er)) {
er.domainThrown = true; er.domain = this;
er.domainThrown = true;
}
// wrap this in a try/catch so we don't get infinite throwing // wrap this in a try/catch so we don't get infinite throwing
try { try {
// One of three things will happen here. // One of three things will happen here.

View File

@ -261,3 +261,18 @@ assert.equal(result, 'return value');
var fst = fs.createReadStream('stream for nonexistent file') var fst = fs.createReadStream('stream for nonexistent file')
d.add(fst) d.add(fst)
expectCaught++; expectCaught++;
[42, null, , false, function(){}, 'string'].forEach(function(something) {
var d = new domain.Domain();
d.run(function() {
process.nextTick(function() {
throw something;
});
expectCaught++;
});
d.on('error', function(er) {
assert.strictEqual(something, er);
caught++;
});
});