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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 this.validate(instance[prop], schema.properties[prop], propPath); | 273 this.validate(instance[prop], schema.properties[prop], propPath); |
274 } else if (!schema.properties[prop].optional) { | 274 } else if (!schema.properties[prop].optional) { |
275 this.addError(propPath, "propertyRequired"); | 275 this.addError(propPath, "propertyRequired"); |
276 } | 276 } |
277 } | 277 } |
278 } | 278 } |
279 | 279 |
280 // If "instanceof" property is set, check that this object inherits from | 280 // If "instanceof" property is set, check that this object inherits from |
281 // the specified constructor (function). | 281 // the specified constructor (function). |
282 if (schema.isInstanceOf) { | 282 if (schema.isInstanceOf) { |
283 var isInstance = function() { | 283 if (Object.prototype.toString.call(instance) != |
arv (Not doing code reviews)
2012/03/02 19:58:28
It seems a bit cleaner to get the substring here
Aaron Boodman
2012/03/02 22:54:26
Disagree. I think the intention of the code is muc
| |
284 var constructor = this[schema.isInstanceOf]; | 284 "[object " + schema.isInstanceOf + "]") { |
285 if (constructor) { | |
286 return (instance instanceof constructor); | |
287 } | |
288 | |
289 // Special-case constructors that can not always be found on the global | |
290 // object, but for which we to allow validation. | |
291 var allowedNamedConstructors = { | |
292 "Window": true, | |
293 "ImageData": true | |
294 } | |
295 if (!allowedNamedConstructors[schema.isInstanceOf]) { | |
296 throw "Attempt to validate against an instance ctor that could not be" + | |
297 "found: " + schema.isInstanceOf; | |
298 } | |
299 return (schema.isInstanceOf == instance.constructor.name) | |
300 }(); | |
301 | |
302 if (!isInstance) | |
303 this.addError(propPath, "notInstance", [schema.isInstanceOf]); | 285 this.addError(propPath, "notInstance", [schema.isInstanceOf]); |
286 } | |
304 } | 287 } |
305 | 288 |
306 // Exit early from additional property check if "type":"any" is defined. | 289 // Exit early from additional property check if "type":"any" is defined. |
307 if (schema.additionalProperties && | 290 if (schema.additionalProperties && |
308 schema.additionalProperties.type && | 291 schema.additionalProperties.type && |
309 schema.additionalProperties.type == "any") { | 292 schema.additionalProperties.type == "any") { |
310 return; | 293 return; |
311 } | 294 } |
312 | 295 |
313 // By default, additional properties are not allowed on instance objects. This | 296 // By default, additional properties are not allowed on instance objects. This |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 */ | 427 */ |
445 chromeHidden.JSONSchemaValidator.prototype.addError = function( | 428 chromeHidden.JSONSchemaValidator.prototype.addError = function( |
446 path, key, replacements) { | 429 path, key, replacements) { |
447 this.errors.push({ | 430 this.errors.push({ |
448 path: path, | 431 path: path, |
449 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) | 432 message: chromeHidden.JSONSchemaValidator.formatError(key, replacements) |
450 }); | 433 }); |
451 }; | 434 }; |
452 | 435 |
453 })(); | 436 })(); |
OLD | NEW |