check for present of callback in args correctly

This commit is contained in:
Ryan X. Charles 2014-04-15 12:21:24 -03:00
parent 5cc25e3e59
commit 9f39da9ff8
1 changed files with 9 additions and 2 deletions

11
API.js
View File

@ -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;