| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 instance, schema, path) { | 398 instance, schema, path) { |
| 399 | 399 |
| 400 // Forbid NaN, +Infinity, and -Infinity. Our APIs don't use them, and | 400 // Forbid NaN, +Infinity, and -Infinity. Our APIs don't use them, and |
| 401 // JSON serialization encodes them as 'null'. Re-evaluate supporting | 401 // JSON serialization encodes them as 'null'. Re-evaluate supporting |
| 402 // them if we add an API that could reasonably take them as a parameter. | 402 // them if we add an API that could reasonably take them as a parameter. |
| 403 if (isNaN(instance) || | 403 if (isNaN(instance) || |
| 404 instance == Number.POSITIVE_INFINITY || | 404 instance == Number.POSITIVE_INFINITY || |
| 405 instance == Number.NEGATIVE_INFINITY ) | 405 instance == Number.NEGATIVE_INFINITY ) |
| 406 this.addError(path, "numberFiniteNotNan", [instance]); | 406 this.addError(path, "numberFiniteNotNan", [instance]); |
| 407 | 407 |
| 408 if (schema.minimum && instance < schema.minimum) | 408 if (typeof schema.minimum != 'undefined' && instance < schema.minimum) |
| 409 this.addError(path, "numberMinValue", [schema.minimum]); | 409 this.addError(path, "numberMinValue", [schema.minimum]); |
| 410 | 410 |
| 411 if (schema.maximum && instance > schema.maximum) | 411 if (typeof schema.maximum != 'undefined' && instance > schema.maximum) |
| 412 this.addError(path, "numberMaxValue", [schema.maximum]); | 412 this.addError(path, "numberMaxValue", [schema.maximum]); |
| 413 | 413 |
| 414 if (schema.maxDecimal && instance * Math.pow(10, schema.maxDecimal) % 1) | 414 if (typeof schema.maxDecimal != 'undefined' && |
| 415 instance * Math.pow(10, schema.maxDecimal) % 1) { |
| 415 this.addError(path, "numberMaxDecimal", [schema.maxDecimal]); | 416 this.addError(path, "numberMaxDecimal", [schema.maxDecimal]); |
| 417 } |
| 416 }; | 418 }; |
| 417 | 419 |
| 418 /** | 420 /** |
| 419 * Validates the primitive type of an instance and populates the errors | 421 * Validates the primitive type of an instance and populates the errors |
| 420 * property. Returns true if the instance validates, false otherwise. | 422 * property. Returns true if the instance validates, false otherwise. |
| 421 */ | 423 */ |
| 422 chromeHidden.JSONSchemaValidator.prototype.validateType = function( | 424 chromeHidden.JSONSchemaValidator.prototype.validateType = function( |
| 423 instance, schema, path) { | 425 instance, schema, path) { |
| 424 var actualType = chromeHidden.JSONSchemaValidator.getType(instance); | 426 var actualType = chromeHidden.JSONSchemaValidator.getType(instance); |
| 425 if (schema.type != actualType && !(schema.type == "number" && | 427 if (schema.type != actualType && !(schema.type == "number" && |
| (...skipping 12 matching lines...) Expand all Loading... |
| 438 */ | 440 */ |
| 439 chromeHidden.JSONSchemaValidator.prototype.addError = function( | 441 chromeHidden.JSONSchemaValidator.prototype.addError = function( |
| 440 path, key, replacements) { | 442 path, key, replacements) { |
| 441 this.errors.push({ | 443 this.errors.push({ |
| 442 path: path, | 444 path: path, |
| 443 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) | 445 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) |
| 444 }); | 446 }); |
| 445 }; | 447 }; |
| 446 | 448 |
| 447 })(); | 449 })(); |
| OLD | NEW |