Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome/renderer/resources/json_schema.js

Issue 5018002: Fixes a crash when entering a negative index with chrome.tabs.move .... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/tabs/basics/move.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 return message; 98 return message;
99 }; 99 };
100 100
101 /** 101 /**
102 * Classifies a value as one of the JSON schema primitive types. Note that we 102 * Classifies a value as one of the JSON schema primitive types. Note that we
103 * don't explicitly disallow 'function', because we want to allow functions in 103 * don't explicitly disallow 'function', because we want to allow functions in
104 * the input values. 104 * the input values.
105 */ 105 */
106 chromeHidden.JSONSchemaValidator.getType = function(value) { 106 chromeHidden.JSONSchemaValidator.getType = function(value) {
107 var s = typeof value; 107 var s = typeof value;
108 108 var maxInt = -1 >>> 1;
Aaron Boodman 2010/11/18 23:04:35 This is not the largest representable integer in J
109 if (s == "object") { 109 if (s == "object") {
110 if (value === null) { 110 if (value === null) {
111 return "null"; 111 return "null";
112 } else if (value instanceof Array || 112 } else if (value instanceof Array ||
113 Object.prototype.toString.call(value) == "[Object Array]") { 113 Object.prototype.toString.call(value) == "[Object Array]") {
114 return "array"; 114 return "array";
115 } 115 }
116 } else if (s == "number") { 116 } else if (s == "number") {
117 if (value % 1 == 0) { 117 if ((value % 1 == 0) && (Math.abs(value) <= maxInt)) {
118 return "integer"; 118 return "integer";
119 } 119 }
120 } 120 }
121 121
122 return s; 122 return s;
123 }; 123 };
124 124
125 /** 125 /**
126 * Add types that may be referenced by validated schemas that reference them 126 * Add types that may be referenced by validated schemas that reference them
127 * with "$ref": <typeId>. Each type must be a valid schema and define an 127 * with "$ref": <typeId>. Each type must be a valid schema and define an
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 373 }
374 } 374 }
375 } 375 }
376 }; 376 };
377 377
378 /** 378 /**
379 * Validates a string and populates the errors property. 379 * Validates a string and populates the errors property.
380 */ 380 */
381 chromeHidden.JSONSchemaValidator.prototype.validateString = function( 381 chromeHidden.JSONSchemaValidator.prototype.validateString = function(
382 instance, schema, path) { 382 instance, schema, path) {
383 if (schema.minLength && instance.length < schema.minLength) 383 if ('minLength' in schema && instance.length < schema.minLength)
384 this.addError(path, "stringMinLength", [schema.minLength]); 384 this.addError(path, "stringMinLength", [schema.minLength]);
385 385
386 if (schema.maxLength && instance.length > schema.maxLength) 386 if ('maxLength' in schema && instance.length > schema.maxLength)
387 this.addError(path, "stringMaxLength", [schema.maxLength]); 387 this.addError(path, "stringMaxLength", [schema.maxLength]);
388 388
389 if (schema.pattern && !schema.pattern.test(instance)) 389 if (schema.pattern && !schema.pattern.test(instance))
390 this.addError(path, "stringPattern", [schema.pattern]); 390 this.addError(path, "stringPattern", [schema.pattern]);
391 }; 391 };
392 392
393 /** 393 /**
394 * Validates a number and populates the errors property. The instance is 394 * Validates a number and populates the errors property. The instance is
395 * assumed to be a number. 395 * assumed to be a number.
396 */ 396 */
397 chromeHidden.JSONSchemaValidator.prototype.validateNumber = function( 397 chromeHidden.JSONSchemaValidator.prototype.validateNumber = function(
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 ('minimum' in schema && 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 ('maximum' in schema && 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 (schema.maxDecimal && instance * Math.pow(10, schema.maxDecimal) % 1)
415 this.addError(path, "numberMaxDecimal", [schema.maxDecimal]); 415 this.addError(path, "numberMaxDecimal", [schema.maxDecimal]);
416 }; 416 };
417 417
418 /** 418 /**
419 * Validates the primitive type of an instance and populates the errors 419 * Validates the primitive type of an instance and populates the errors
420 * property. Returns true if the instance validates, false otherwise. 420 * property. Returns true if the instance validates, false otherwise.
421 */ 421 */
(...skipping 16 matching lines...) Expand all
438 */ 438 */
439 chromeHidden.JSONSchemaValidator.prototype.addError = function( 439 chromeHidden.JSONSchemaValidator.prototype.addError = function(
440 path, key, replacements) { 440 path, key, replacements) {
441 this.errors.push({ 441 this.errors.push({
442 path: path, 442 path: path,
443 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) 443 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements)
444 }); 444 });
445 }; 445 };
446 446
447 })(); 447 })();
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/tabs/basics/move.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698