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

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: Removed a console import 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..ff0ff4dbae7319d413172226a53f9c1684943fab 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) {
Matt Perry 2014/08/13 19:31:01 I wonder if we should add an {{interface.name}} ob
hansmuller 2014/08/13 21:23:40 That seems reasonable. Currently we put interface
Matt Perry 2014/08/13 21:30:44 That's right. (Though maybe they need to be on the
hansmuller 2014/08/13 21:53:21 I assume so however I haven't seen a JS use case.
+{%- if interface.methods %}
Matt Perry 2014/08/13 19:31:01 nit: this would be slightly clearer to me if you i
hansmuller 2014/08/13 21:23:40 Good point, I'll swap them.
+ var message = messageValidator.message;
+ var paramsClass = null;
+ switch (message.getName()) {
+{%- for method in interface.methods %}
+ case k{{interface.name}}_{{method.name}}_Name:
+{%- if method.response_parameters == None %}
+ if (!message.expectsResponse() && !message.isResponse())
+ paramsClass = {{interface.name}}_{{method.name}}_Params;
+{%- else %}
+ if (message.expectsResponse())
Matt Perry 2014/08/13 19:31:01 is it not an error if the message expects a respon
hansmuller 2014/08/13 21:23:40 I believe that the previous clause covers the firs
+ paramsClass = {{interface.name}}_{{method.name}}_Params;
+{%- endif %}
+ break;
+{%- endfor %}
+ }
+ if (paramsClass === null)
+ return validator.validationError.NONE;
+ return paramsClass.validate(messageValidator, codec.kMessageHeaderSize);
+{%- else %}
+ return validator.validationError.NONE;
+{%- endif %}
+ }
+
+ function validate{{interface.name}}Response(messageValidator) {
+{%- if interface|has_callbacks %}
Matt Perry 2014/08/13 19:31:01 ditto line 114
hansmuller 2014/08/13 21:23:40 Done.
+ 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);
+{%- else %}
+ return validator.validationError.NONE;
+{%- endif %}
+ }
+
{#--- Enums #}
{% from "enum_definition.tmpl" import enum_def -%}
{% for enum in interface.enums %}

Powered by Google App Engine
This is Rietveld 408576698