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

Commit

Permalink
child_process: make .send() throw if message is undefined
Browse files Browse the repository at this point in the history
JSON.stringify(undefined) returns "undefined" but JSON.parse() doesn't know how
to parse that.
  • Loading branch information
bnoordhuis committed Dec 18, 2011
1 parent c4d2244 commit 6df7bdd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions test/simple/test-child-process-fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6df7bdd

Please sign in to comment.