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

Commit 6df7bdd

Browse files
committedDec 18, 2011
child_process: make .send() throw if message is undefined
JSON.stringify(undefined) returns "undefined" but JSON.parse() doesn't know how to parse that.
1 parent c4d2244 commit 6df7bdd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

Diff for: ‎lib/child_process.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ function setupChannel(target, channel) {
111111
};
112112

113113
target.send = function(message, sendHandle) {
114-
if (!target._channel) throw new Error('channel closed');
114+
if (typeof message === 'undefined') {
115+
throw new TypeError('message cannot be undefined');
116+
}
117+
118+
if (!target._channel) throw new Error("channel closed");
115119

116120
// For overflow protection don't write if channel queue is too deep.
117121
if (channel.writeQueueSize > 1024 * 1024) {

Diff for: ‎test/simple/test-child-process-fork.js

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ n.on('message', function(m) {
3535
messageCount++;
3636
});
3737

38+
// https://github.com/joyent/node/issues/2355 - JSON.stringify(undefined)
39+
// returns "undefined" but JSON.parse() cannot parse that...
40+
assert.throws(function() { n.send(undefined); }, TypeError);
41+
assert.throws(function() { n.send(); }, TypeError);
42+
3843
n.send({ hello: 'world' });
3944

4045
var childExitCode = -1;

0 commit comments

Comments
 (0)
This repository has been archived.