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 ad47748ae0c5bd90f3becc5baefb23e8e9946df5..94c6d366778bbb233d77615f5bde16414d215501 100644 |
--- a/chrome/renderer/resources/extensions/json_schema.js |
+++ b/chrome/renderer/resources/extensions/json_schema.js |
@@ -144,6 +144,52 @@ chromeHidden.JSONSchemaValidator.prototype.addTypes = function(typeOrTypeList) { |
} |
/** |
+ * Returns a list of strings of the types that this schema accepts. |
+ */ |
+chromeHidden.JSONSchemaValidator.prototype.getAllTypesForSchema = function( |
+ schema) { |
+ var schema_types = []; |
+ if (schema.type) |
+ schema_types.push(schema.type); |
+ if (schema.choices) { |
+ for (var i = 0; i < schema.choices.length; i++) |
+ schema_types.push(schema.choices[i].type); |
+ } |
+ if (schema['$ref']) { |
+ var ref_types = this.getAllTypesForSchema(this.types[schema['$ref']]); |
+ schema_types = schema_types.concat(ref_types); |
+ } |
+ return schema_types; |
+}; |
+ |
+/** |
+ * Returns true if |schema| would accept an argument of type |type|. |
+ */ |
+chromeHidden.JSONSchemaValidator.prototype.isValidSchemaType = function( |
+ type, schema) { |
+ schema_types = this.getAllTypesForSchema(schema); |
+ for (var i = 0; i < schema_types.length; i++) { |
+ if (schema_types[i] == "any" || type == schema_types[i]) |
+ return true; |
+ } |
+ return type == "any"; |
+}; |
+ |
+/** |
+ * Returns true if there is a non-null argument that both |schema1| and |
+ * |schema2| would accept. |
+ */ |
+chromeHidden.JSONSchemaValidator.prototype.checkSchemaOverlap = function( |
+ schema1, schema2) { |
+ var schema1_types = this.getAllTypesForSchema(schema1); |
+ for (var i = 0; i < schema1_types.length; i++) { |
+ if (this.isValidSchemaType(schema1_types[i], schema2)) |
+ return true; |
+ } |
+ return false; |
+}; |
+ |
+/** |
* Validates an instance against a schema. The instance can be any JavaScript |
* value and will be validated recursively. When this method returns, the |
* |errors| property will contain a list of errors, if any. |
@@ -448,4 +494,13 @@ chromeHidden.JSONSchemaValidator.prototype.addError = function( |
}); |
}; |
+/** |
+ * Adds an error message. |key| is an index into the |messages| object. |
+ * |replacements| is an array of values to replace '*' characters in the |
+ * message. |
Matt Perry
2012/02/24 02:00:12
Comment needs updating.
Matt Tytel
2012/02/24 02:29:36
Done.
|
+ */ |
+chromeHidden.JSONSchemaValidator.prototype.resetErrors = function() { |
+ this.errors = []; |
+}; |
+ |
})(); |