From 9f39da9ff8b45be696ecffcc221877fef8620024 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Tue, 15 Apr 2014 12:21:24 -0300 Subject: [PATCH] check for present of callback in args correctly --- API.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/API.js b/API.js index 43bdb0da0..c56c66128 100644 --- a/API.js +++ b/API.js @@ -54,9 +54,8 @@ API.prototype._command = function(command, args, callback) { if (!API._checkArgTypes(command, args)) { var argTypes = API.prototype[command].argTypes; API._coerceArgTypes(args, argTypes) - if (!API._checkArgTypes(command, args)) { + if (!API._checkArgTypes(command, args)) throw new Error('Invalid arguments'); - } } if (typeof self[command] == 'function') { @@ -72,6 +71,14 @@ API.prototype._command = function(command, args, callback) { API._checkArgTypes = function(command, args) { var f = API.prototype[command]; + + if (f.argTypes.length != args.length) { + + //if the function doesn't have a callback + if (!(f.argTypes.length == args.length + 1 && f.argTypes[f.argTypes.length-1][1] == 'function')) + return false; + } + for (var i in args) { if (typeof args[i] != f.argTypes[i][1]) return false;