diff --git a/lib/child_process.js b/lib/child_process.js index a34313f61ed..55412b94949 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -111,7 +111,11 @@ function setupChannel(target, channel) { }; target.send = function(message, sendHandle) { - if (!target._channel) throw new Error('channel closed'); + if (typeof message === 'undefined') { + throw new TypeError('message cannot be undefined'); + } + + if (!target._channel) throw new Error("channel closed"); // For overflow protection don't write if channel queue is too deep. if (channel.writeQueueSize > 1024 * 1024) { diff --git a/test/simple/test-child-process-fork.js b/test/simple/test-child-process-fork.js index 4860732b71f..41cc28c72e4 100644 --- a/test/simple/test-child-process-fork.js +++ b/test/simple/test-child-process-fork.js @@ -35,6 +35,11 @@ n.on('message', function(m) { messageCount++; }); +// https://github.com/joyent/node/issues/2355 - JSON.stringify(undefined) +// returns "undefined" but JSON.parse() cannot parse that... +assert.throws(function() { n.send(undefined); }, TypeError); +assert.throws(function() { n.send(); }, TypeError); + n.send({ hello: 'world' }); var childExitCode = -1;