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:
parent
c4d2244a09
commit
6df7bdd954
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user