Chromium Code Reviews| Index: chrome/renderer/resources/extensions/json_schema.js |
| diff --git a/chrome/renderer/resources/extensions/json_schema.js b/chrome/renderer/resources/extensions/json_schema.js |
| index 7770185283aa6bf0e6c0dd9cc28595467b959313..02c301f072549c6411fedf83d2c04bac6a68cb20 100644 |
| --- a/chrome/renderer/resources/extensions/json_schema.js |
| +++ b/chrome/renderer/resources/extensions/json_schema.js |
| @@ -40,7 +40,8 @@ |
| // TODO(cduvall): Make this file not depend on chromeHidden. |
| var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| -var loadRefDependency = require('utils').loadRefDependency; |
| +var loadTypeSchema = require('utils').loadTypeSchema; |
| +var CHECK = requireNative('logging').CHECK; |
| function isInstanceOfClass(instance, className) { |
| if (!instance) |
| @@ -176,13 +177,21 @@ chromeHidden.JSONSchemaValidator.prototype.getAllTypesForSchema = |
| schemaTypes = schemaTypes.concat(choiceTypes); |
| } |
| } |
| - if (schema['$ref']) { |
| - var refTypes = this.getAllTypesForSchema(this.types[schema['$ref']]); |
| - schemaTypes = schemaTypes.concat(refTypes); |
| + var ref = schema['$ref']; |
| + if (ref) { |
| + var type = this.getOrAddType(ref); |
| + CHECK(type, 'Could not find type ' + ref); |
| + schemaTypes = schemaTypes.concat(this.getAllTypesForSchema(type)); |
| } |
| return schemaTypes; |
| }; |
| +chromeHidden.JSONSchemaValidator.prototype.getOrAddType = function(typeName) { |
| + if (!this.types[typeName]) |
| + this.types[typeName] = loadTypeSchema(typeName); |
| + return this.types[typeName]; |
| +}; |
| + |
| /** |
| * Returns true if |schema| would accept an argument of type |type|. |
| */ |
| @@ -243,12 +252,12 @@ chromeHidden.JSONSchemaValidator.prototype.validate = |
| // If the schema has a $ref property, the instance must validate against |
| // that schema too. It must be present in this.types to be referenced. |
| - if (schema["$ref"]) { |
| - loadRefDependency(schema["$ref"]); |
| - if (!this.types[schema["$ref"]]) |
| - this.addError(path, "unknownSchemaReference", [ schema["$ref"] ]); |
| + var ref = schema["$ref"]; |
| + if (ref) { |
| + if (!this.getOrAddType(ref)) |
| + this.addError(path, "unknownSchemaReference", [ ref ]); |
| else |
| - this.validate(instance, this.types[schema["$ref"]], path) |
| + this.validate(instance, this.types[ref], path) |
|
not at google - send to devlin
2013/03/21 01:36:55
accessing this.types[ref] here kind of defeats the
cduvall
2013/03/21 17:16:07
Done.
|
| } |
| // If the schema has a choices property, the instance must validate against at |