Skip to content
Browse files

be agnostic about whether built-ins are 'function' or 'object'

  • Loading branch information...
1 parent 598a4db commit b89c660ce610a8266235fe508aa2fdaaf420d209 @bronson committed Oct 6, 2011
Showing with 7 additions and 10 deletions.
  1. +7 −10 lib/valid.js
View
17 lib/valid.js
@@ -298,25 +298,19 @@ Valid.JsonField = function(path, value, schema) {
if(value !== schema) this.JsonError(path, "must equal " + this.Escape(schema));
break;
- case 'function':
- if(isRegExp(schema)) {
- var reresult = Valid.match(schema).check(value);
- if(reresult) this.JsonError(path, reresult);
- } else {
- var fresult = schema.call(this, value);
- if(fresult) this.JsonError(path, fresult);
- }
- break;
-
case 'null': // usually typeof null === 'object'
case 'object':
+ case 'function': // seems random what impls return for built-in objects
if(schema === null) {
if(value !== null) this.JsonError(path, "must be null");
} else if(schema._queue && typeof schema.GetChain === 'function') { // try to detect a Valid chain
var vresult = schema.check(value);
if(vresult) this.JsonError(path, vresult);
} else if(value === null) {
this.JsonError(path, "can't be null");
+ } else if(isRegExp(schema)) {
+ var reresult = Valid.match(schema).check(value);
+ if(reresult) this.JsonError(path, reresult);
} else if(schema instanceof Array) {
if(value instanceof Array) {
if(value.length !== schema.length) this.JsonError(path, " must have " + value.length + " items, not " + schema.length);
@@ -327,6 +321,9 @@ Valid.JsonField = function(path, value, schema) {
} else {
this.JsonError(path, "must be an array");
}
+ } else if(typeof schema === 'function') {
+ var fresult = schema.call(this, value);
+ if(fresult) this.JsonError(path, fresult);
} else {
this.JsonObject(path, value, schema);
}

0 comments on commit b89c660

Please sign in to comment.
Something went wrong with that request. Please try again.