From 42a33c1bb869a8fd64525ae282a0ab1d859218a9 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Tue, 24 Dec 2013 16:33:03 +0400 Subject: [PATCH] domain: don't crash on "throw null" Signed-off-by: Trevor Norris --- lib/domain.js | 6 ++++-- test/simple/test-domain.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/domain.js b/lib/domain.js index bbedcbafcf2..f18cca6ebaa 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -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. diff --git a/test/simple/test-domain.js b/test/simple/test-domain.js index 5546d5eb7fe..25227585357 100644 --- a/test/simple/test-domain.js +++ b/test/simple/test-domain.js @@ -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++; + }); +});