Skip to content

Commit

Permalink
domain: don't crash on "throw null"
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Dec 24, 2013
1 parent 055f7e9 commit 34f5c3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/domain.js
Expand Up @@ -56,8 +56,10 @@ var listenerObj = {
if (domain._disposed)
return true;

er.domain = domain;
er.domainThrown = true;
if (util.isObject(er) || util.isFunction(er)) {
er.domain = domain;
er.domainThrown = true;
}
// wrap this in a try/catch so we don't get infinite throwing
try {
// One of three things will happen here.
Expand Down
17 changes: 17 additions & 0 deletions test/simple/test-domain.js
Expand Up @@ -261,3 +261,20 @@ assert.equal(result, 'return value');
var fst = fs.createReadStream('stream for nonexistent file')
d.add(fst)
expectCaught++;


;[42, /*NaN,*/ null, undefined, 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++;
});
});

0 comments on commit 34f5c3c

Please sign in to comment.