Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
domain: don't crash on "throw null"
Browse files Browse the repository at this point in the history
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
rlidwka authored and trevnorris committed Apr 2, 2014
1 parent 006d427 commit 42a33c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/domain.js
Expand Up @@ -85,8 +85,10 @@ Domain.prototype._errorHandler = function errorHandler(er) {
if (this._disposed)
return true;

er.domain = this;
er.domainThrown = true;
if (!util.isPrimitive(er)) {
er.domain = this;
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
15 changes: 15 additions & 0 deletions test/simple/test-domain.js
Expand Up @@ -261,3 +261,18 @@ assert.equal(result, 'return value');
var fst = fs.createReadStream('stream for nonexistent file')
d.add(fst)
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++;
});
});

0 comments on commit 42a33c1

Please sign in to comment.