Chromium Code Reviews| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 this.addError(path, "invalidChoice"); | 310 this.addError(path, "invalidChoice"); |
| 311 }; | 311 }; |
| 312 | 312 |
| 313 /** | 313 /** |
| 314 * Validates an instance against a schema with an enum type. Populates the | 314 * Validates an instance against a schema with an enum type. Populates the |
| 315 * |errors| property, and returns a boolean indicating whether the instance | 315 * |errors| property, and returns a boolean indicating whether the instance |
| 316 * validates. | 316 * validates. |
| 317 */ | 317 */ |
| 318 JSONSchemaValidator.prototype.validateEnum = function(instance, schema, path) { | 318 JSONSchemaValidator.prototype.validateEnum = function(instance, schema, path) { |
| 319 for (var i = 0; i < schema.enum.length; i++) { | 319 for (var i = 0; i < schema.enum.length; i++) { |
| 320 if (instance === schema.enum[i]) | 320 if (instance === (schema.enum[i].name || schema.enum[i])) |
|
not at google - send to devlin
2013/10/28 18:00:25
add function like enumToString; instance == enumTo
Sam McNally
2013/10/29 00:39:02
Done.
| |
| 321 return true; | 321 return true; |
| 322 } | 322 } |
| 323 | 323 |
| 324 this.addError(path, "invalidEnum", [schema.enum.join(", ")]); | 324 this.addError(path, "invalidEnum", [schema.enum.map(function(enumValue) { |
| 325 return enumValue.name || enumValue; | |
| 326 }).join(", ")]); | |
| 325 return false; | 327 return false; |
| 326 }; | 328 }; |
| 327 | 329 |
| 328 /** | 330 /** |
| 329 * Validates an instance against an object schema and populates the errors | 331 * Validates an instance against an object schema and populates the errors |
| 330 * property. | 332 * property. |
| 331 */ | 333 */ |
| 332 JSONSchemaValidator.prototype.validateObject = | 334 JSONSchemaValidator.prototype.validateObject = |
| 333 function(instance, schema, path) { | 335 function(instance, schema, path) { |
| 334 if (schema.properties) { | 336 if (schema.properties) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 }; | 509 }; |
| 508 | 510 |
| 509 /** | 511 /** |
| 510 * Resets errors to an empty list so you can call 'validate' again. | 512 * Resets errors to an empty list so you can call 'validate' again. |
| 511 */ | 513 */ |
| 512 JSONSchemaValidator.prototype.resetErrors = function() { | 514 JSONSchemaValidator.prototype.resetErrors = function() { |
| 513 this.errors = []; | 515 this.errors = []; |
| 514 }; | 516 }; |
| 515 | 517 |
| 516 exports.JSONSchemaValidator = JSONSchemaValidator; | 518 exports.JSONSchemaValidator = JSONSchemaValidator; |
| OLD | NEW |