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

Unified Diff: mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl

Issue 468713002: JavaScript bindings for Mojo message validation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Binding generator simplification for Arrays Created 6 years, 4 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: mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl b/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl
index d46f8eeac9ce86a90c5dc48f7c162ff9f61aac02..544b0e29354fec006bfe7437c87a65d408bb0130 100644
--- a/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl
@@ -108,6 +108,55 @@ params.{{parameter.name}}{% if not loop.last %}, {% endif -%}
}
};
+{#--- Validation #}
+
+ function validate{{interface.name}}Request(messageValidator) {
+{%- if not(interface.methods) %}
+ return validator.validationError.NONE;
+{%- else %}
+ var message = messageValidator.message;
+ var paramsClass = null;
+ switch (message.getName()) {
+{%- for method in interface.methods %}
yzshen1 2014/08/14 18:02:21 Please consider the following way of indentation:
hansmuller 2014/08/14 23:51:46 Done.
+ case k{{interface.name}}_{{method.name}}_Name:
+{%- if method.response_parameters == None %}
+ if (!message.expectsResponse() && !message.isResponse())
+ paramsClass = {{interface.name}}_{{method.name}}_Params;
+{%- else %}
yzshen1 2014/08/14 18:02:21 Inconsistent indent, this else corresponds to line
hansmuller 2014/08/14 23:51:45 Done.
+ if (message.expectsResponse())
+ paramsClass = {{interface.name}}_{{method.name}}_Params;
+{%- endif %}
+ break;
+{%- endfor %}
+ }
+ if (paramsClass === null)
+ return validator.validationError.NONE;
+ return paramsClass.validate(messageValidator, codec.kMessageHeaderSize);
yzshen1 2014/08/14 18:02:21 This is incorrect: The message header may contain
hansmuller 2014/08/14 23:51:45 Done.
+{%- endif %}
+ }
+
+ function validate{{interface.name}}Response(messageValidator) {
+{%- if not(interface|has_callbacks) %}
+ return validator.validationError.NONE;
+{%- else %}
+ var message = messageValidator.message;
+ var paramsClass = null;
+ switch (message.getName()) {
+{%- for method in interface.methods %}
+{%- if method.response_parameters != None %}
+ case k{{interface.name}}_{{method.name}}_Name:
+ if (message.isResponse())
+ paramsClass = {{interface.name}}_{{method.name}}_ResponseParams;
+ break;
+{%- endif %}
+{%- endfor %}
+ }
+ if (paramsClass === null)
+ return validator.validationError.NONE;
+ return paramsClass.validate(messageValidator, codec.kMessageWithRequestIDHeaderSize);
yzshen1 2014/08/14 18:02:21 - 80 chars? - The offset is incorrect, please see
hansmuller 2014/08/14 23:51:45 The existing templates don't strictly adhere to th
+{%- endif %}
+ }
+
{#--- Enums #}
{% from "enum_definition.tmpl" import enum_def -%}
{% for enum in interface.enums %}

Powered by Google App Engine
This is Rietveld 408576698