child_process: make .send() throw if message is undefined

JSON.stringify(undefined) returns "undefined" but JSON.parse() doesn't know how
to parse that.
This commit is contained in:
Ben Noordhuis 2011-12-18 01:26:00 +01:00
parent c4d2244a09
commit 6df7bdd954
2 changed files with 10 additions and 1 deletions

View File

@ -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) {

View File

@ -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;