Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/sockets/sock.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,24 @@ Socket.prototype.use = function(plugin){
/**
* Creates a new `Message` and write the `args`.
*
* Will throw if any of the provided `args` are `undefined`, given that
* JSON.stringify's result will be coerced to `'undefined'`, which JSON.parse
* cannot handle.
*
* @param {Array} args
* @return {Buffer}
* @api private
*/

Socket.prototype.pack = function(args){
var len = args.length;

for (var i = 0; i < len; i++) {
if (args[i] === undefined) {
throw new Error('cannot pack undefined');
}
}

var msg = new Message(args);
return msg.toBuffer();
};
Expand Down
13 changes: 12 additions & 1 deletion test/test.arg-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@ var done;
push.bind(4000);
push.send('foo', { bar: 'baz' }, ['some', 1], new Buffer('hello'));

assert.throws(function() {
push.send(undefined);
}, /undefined/, 'send should reject unserializable types');
assert.throws(function() {
push.send(null, undefined);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this test, should probably ensure that push.send(null) still works.

}, /undefined/, 'send should reject unserializable types');
assert.throws(function() {
push.send({ bar: 'baz' }, undefined);
}, /undefined/, 'send should reject unserializable types');

pull.connect(4000);
pull.on('message', function(a, b, c, d){
assert(!done, 'message already received');
assert('string' == typeof a);
b.should.eql({ bar: 'baz' });
c.should.eql(['some', 1]);
Expand All @@ -29,4 +40,4 @@ pull.on('message', function(a, b, c, d){

process.on('exit', function(){
assert(done);
});
});