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

Unified Diff: chrome/renderer/resources/extensions/json_schema.js

Issue 9317072: Allow omitting optional parameters for Extensions API functions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moved functions to json_schema.js and fixed naming conventions. Created 8 years, 10 months 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 side-by-side diff with in-line comments
Download patch
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 = [];
+};
+
})();

Powered by Google App Engine
This is Rietveld 408576698