OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 //============================================================================== |
11 // This file contains a class that implements a subset of JSON Schema. | 11 // This file contains a class that implements a subset of JSON Schema. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 unexpectedProperty: "Unexpected property.", | 68 unexpectedProperty: "Unexpected property.", |
69 arrayMinItems: "Array must have at least * items.", | 69 arrayMinItems: "Array must have at least * items.", |
70 arrayMaxItems: "Array must not have more than * items.", | 70 arrayMaxItems: "Array must not have more than * items.", |
71 itemRequired: "Item is required.", | 71 itemRequired: "Item is required.", |
72 stringMinLength: "String must be at least * characters long.", | 72 stringMinLength: "String must be at least * characters long.", |
73 stringMaxLength: "String must not be more than * characters long.", | 73 stringMaxLength: "String must not be more than * characters long.", |
74 stringPattern: "String must match the pattern: *.", | 74 stringPattern: "String must match the pattern: *.", |
75 numberFiniteNotNan: "Value must not be *.", | 75 numberFiniteNotNan: "Value must not be *.", |
76 numberMinValue: "Value must not be less than *.", | 76 numberMinValue: "Value must not be less than *.", |
77 numberMaxValue: "Value must not be greater than *.", | 77 numberMaxValue: "Value must not be greater than *.", |
| 78 numberIntValue: "Value must fit in a 32-bit signed integer.", |
78 numberMaxDecimal: "Value must not have more than * decimal places.", | 79 numberMaxDecimal: "Value must not have more than * decimal places.", |
79 invalidType: "Expected '*' but got '*'.", | 80 invalidType: "Expected '*' but got '*'.", |
80 invalidChoice: "Value does not match any valid type choices.", | 81 invalidChoice: "Value does not match any valid type choices.", |
81 invalidPropertyType: "Missing property type.", | 82 invalidPropertyType: "Missing property type.", |
82 schemaRequired: "Schema value required.", | 83 schemaRequired: "Schema value required.", |
83 unknownSchemaReference: "Unknown schema reference: *.", | 84 unknownSchemaReference: "Unknown schema reference: *.", |
84 notInstance: "Object must be an instance of *." | 85 notInstance: "Object must be an instance of *." |
85 }; | 86 }; |
86 | 87 |
87 /** | 88 /** |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 instance == Number.POSITIVE_INFINITY || | 404 instance == Number.POSITIVE_INFINITY || |
404 instance == Number.NEGATIVE_INFINITY ) | 405 instance == Number.NEGATIVE_INFINITY ) |
405 this.addError(path, "numberFiniteNotNan", [instance]); | 406 this.addError(path, "numberFiniteNotNan", [instance]); |
406 | 407 |
407 if (schema.minimum && instance < schema.minimum) | 408 if (schema.minimum && instance < schema.minimum) |
408 this.addError(path, "numberMinValue", [schema.minimum]); | 409 this.addError(path, "numberMinValue", [schema.minimum]); |
409 | 410 |
410 if (schema.maximum && instance > schema.maximum) | 411 if (schema.maximum && instance > schema.maximum) |
411 this.addError(path, "numberMaxValue", [schema.maximum]); | 412 this.addError(path, "numberMaxValue", [schema.maximum]); |
412 | 413 |
| 414 // Check for integer values outside of -2^31..2^31-1. |
| 415 if (schema.type === "integer" && (instance | 0) !== instance) |
| 416 this.addError(path, "numberIntValue", []); |
| 417 |
413 if (schema.maxDecimal && instance * Math.pow(10, schema.maxDecimal) % 1) | 418 if (schema.maxDecimal && instance * Math.pow(10, schema.maxDecimal) % 1) |
414 this.addError(path, "numberMaxDecimal", [schema.maxDecimal]); | 419 this.addError(path, "numberMaxDecimal", [schema.maxDecimal]); |
415 }; | 420 }; |
416 | 421 |
417 /** | 422 /** |
418 * Validates the primitive type of an instance and populates the errors | 423 * Validates the primitive type of an instance and populates the errors |
419 * property. Returns true if the instance validates, false otherwise. | 424 * property. Returns true if the instance validates, false otherwise. |
420 */ | 425 */ |
421 chromeHidden.JSONSchemaValidator.prototype.validateType = function( | 426 chromeHidden.JSONSchemaValidator.prototype.validateType = function( |
422 instance, schema, path) { | 427 instance, schema, path) { |
(...skipping 14 matching lines...) Expand all Loading... |
437 */ | 442 */ |
438 chromeHidden.JSONSchemaValidator.prototype.addError = function( | 443 chromeHidden.JSONSchemaValidator.prototype.addError = function( |
439 path, key, replacements) { | 444 path, key, replacements) { |
440 this.errors.push({ | 445 this.errors.push({ |
441 path: path, | 446 path: path, |
442 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) | 447 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) |
443 }); | 448 }); |
444 }; | 449 }; |
445 | 450 |
446 })(); | 451 })(); |
OLD | NEW |