diff --git a/index.js b/index.js index 7820e64..7fd75ce 100644 --- a/index.js +++ b/index.js @@ -190,7 +190,7 @@ var compile = function(schema, cache, root, reporter, opts) { validate('for (var %s = %d; %s < %s.length; %s++) {', i, node.items.length, i, name, i) visit(name+'['+i+']', node.additionalItems, reporter, filter) validate('}') - } + } } if (node.format && fmts[node.format]) { @@ -395,7 +395,7 @@ var compile = function(schema, cache, root, reporter, opts) { node.anyOf.forEach(function(sch, i) { if (i === 0) { validate('var %s = errors', prev) - } else { + } else { validate('if (errors !== %s) {', prev) ('errors = %s', prev) } @@ -446,7 +446,7 @@ var compile = function(schema, cache, root, reporter, opts) { if (node.maxProperties !== undefined) { if (type !== 'object') validate('if (%s) {', types.object(name)) - + validate('if (Object.keys(%s).length > %d) {', name, node.maxProperties) error('has more properties than allowed') validate('}') @@ -456,7 +456,7 @@ var compile = function(schema, cache, root, reporter, opts) { if (node.minProperties !== undefined) { if (type !== 'object') validate('if (%s) {', types.object(name)) - + validate('if (Object.keys(%s).length < %d) {', name, node.minProperties) error('has less properties than allowed') validate('}') @@ -466,7 +466,7 @@ var compile = function(schema, cache, root, reporter, opts) { if (node.maxItems !== undefined) { if (type !== 'array') validate('if (%s) {', types.array(name)) - + validate('if (%s.length > %d) {', name, node.maxItems) error('has more items than allowed') validate('}') @@ -476,7 +476,7 @@ var compile = function(schema, cache, root, reporter, opts) { if (node.minItems !== undefined) { if (type !== 'array') validate('if (%s) {', types.array(name)) - + validate('if (%s.length < %d) {', name, node.minItems) error('has less items than allowed') validate('}') @@ -543,13 +543,14 @@ var compile = function(schema, cache, root, reporter, opts) { validate = validate.toFunction(scope) validate.errors = null - validate.__defineGetter__('error', function() { - if (!validate.errors) return '' - return validate.errors - .map(function(err) { - return err.field+' '+err.message - }) - .join('\n') + Object.defineProperty(validate, 'error', { + get: function() { + if (!validate.errors) + return ''; + return validate.errors.map(function(err) { + return err.field + ' ' + err.message; + }).join('\n'); + } }) validate.toJSON = function() {