| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // ----------------------------------------------------------------------------- | 5 // ----------------------------------------------------------------------------- |
| 6 // NOTE: If you change this file you need to touch renderer_resources.grd to | 6 // NOTE: If you change this file you need to touch renderer_resources.grd to |
| 7 // have your change take effect. | 7 // have your change take effect. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 | 9 |
| 10 //============================================================================== | 10 //============================================================================== |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // There are also these departures from the JSON Schema proposal: | 31 // There are also these departures from the JSON Schema proposal: |
| 32 // - function and undefined types are supported | 32 // - function and undefined types are supported |
| 33 // - null counts as 'unspecified' for optional values | 33 // - null counts as 'unspecified' for optional values |
| 34 // - added the 'choices' property, to allow specifying a list of possible types | 34 // - added the 'choices' property, to allow specifying a list of possible types |
| 35 // for a value | 35 // for a value |
| 36 // - by default an "object" typed schema does not allow additional properties. | 36 // - by default an "object" typed schema does not allow additional properties. |
| 37 // if present, "additionalProperties" is to be a schema against which all | 37 // if present, "additionalProperties" is to be a schema against which all |
| 38 // additional properties will be validated. | 38 // additional properties will be validated. |
| 39 //============================================================================== | 39 //============================================================================== |
| 40 | 40 |
| 41 // TODO: Make this file not depend on chromeHidden. |
| 41 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 42 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 43 var loadRefDependency = require('utils').loadRefDependency; |
| 44 |
| 45 var DCHECK = requireNative('logging').DCHECK; |
| 42 | 46 |
| 43 function isInstanceOfClass(instance, className) { | 47 function isInstanceOfClass(instance, className) { |
| 44 if (!instance) | 48 if (!instance) |
| 45 return false; | 49 return false; |
| 46 | 50 |
| 47 if (Object.prototype.toString.call(instance) == "[object " + className + "]") | 51 if (Object.prototype.toString.call(instance) == "[object " + className + "]") |
| 48 return true; | 52 return true; |
| 49 | 53 |
| 50 return isInstanceOfClass(Object.getPrototypeOf(instance), className); | 54 return isInstanceOfClass(Object.getPrototypeOf(instance), className); |
| 51 } | 55 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 this.types[schema.id] = schema; | 237 this.types[schema.id] = schema; |
| 234 | 238 |
| 235 // If the schema has an extends property, the instance must validate against | 239 // If the schema has an extends property, the instance must validate against |
| 236 // that schema too. | 240 // that schema too. |
| 237 if (schema.extends) | 241 if (schema.extends) |
| 238 this.validate(instance, schema.extends, path); | 242 this.validate(instance, schema.extends, path); |
| 239 | 243 |
| 240 // If the schema has a $ref property, the instance must validate against | 244 // If the schema has a $ref property, the instance must validate against |
| 241 // that schema too. It must be present in this.types to be referenced. | 245 // that schema too. It must be present in this.types to be referenced. |
| 242 if (schema["$ref"]) { | 246 if (schema["$ref"]) { |
| 247 loadRefDependency(schema["$ref"]); |
| 243 if (!this.types[schema["$ref"]]) | 248 if (!this.types[schema["$ref"]]) |
| 244 this.addError(path, "unknownSchemaReference", [ schema["$ref"] ]); | 249 this.addError(path, "unknownSchemaReference", [ schema["$ref"] ]); |
| 245 else | 250 else |
| 246 this.validate(instance, this.types[schema["$ref"]], path) | 251 this.validate(instance, this.types[schema["$ref"]], path) |
| 247 } | 252 } |
| 248 | 253 |
| 249 // If the schema has a choices property, the instance must validate against at | 254 // If the schema has a choices property, the instance must validate against at |
| 250 // least one of the items in that array. | 255 // least one of the items in that array. |
| 251 if (schema.choices) { | 256 if (schema.choices) { |
| 252 this.validateChoices(instance, schema, path); | 257 this.validateChoices(instance, schema, path); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) | 506 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) |
| 502 }); | 507 }); |
| 503 }; | 508 }; |
| 504 | 509 |
| 505 /** | 510 /** |
| 506 * Resets errors to an empty list so you can call 'validate' again. | 511 * Resets errors to an empty list so you can call 'validate' again. |
| 507 */ | 512 */ |
| 508 chromeHidden.JSONSchemaValidator.prototype.resetErrors = function() { | 513 chromeHidden.JSONSchemaValidator.prototype.resetErrors = function() { |
| 509 this.errors = []; | 514 this.errors = []; |
| 510 }; | 515 }; |
| OLD | NEW |