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

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

Issue 803173009: Mojo JS Bindings: Eliminate foo$ Stub and Proxy class members (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years 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 unified diff | Download patch
OLDNEW
1 {%- for method in interface.methods %} 1 {%- for method in interface.methods %}
2 var k{{interface.name}}_{{method.name}}_Name = {{method.ordinal}}; 2 var k{{interface.name}}_{{method.name}}_Name = {{method.ordinal}};
3 {%- endfor %} 3 {%- endfor %}
4 4
5 function {{interface.name}}Proxy(receiver) { 5 function {{interface.name}}Proxy(receiver) {
esprehn 2014/12/29 22:00:44 class {{interface.name}}Proxy extends bindings.Pro
hansmuller1 2014/12/29 23:14:11 I hadn't been using classes in the generated code
6 connection.initProxyInstance(this, {{interface.name}}, receiver); 6 bindings.ProxyBase.call(this, receiver);
7 } 7 }
8 {{interface.name}}Proxy.prototype = Object.create(bindings.ProxyBase.prototype );
esprehn 2014/12/29 22:00:44 Use class, then you don't need this at all.
hansmuller1 2014/12/29 23:14:11 Acknowledged.
8 9
9 {%- for method in interface.methods %} 10 {%- for method in interface.methods %}
10 {{interface.name}}Proxy.prototype.{{method.name|stylize_method}} = function( 11 {{interface.name}}Proxy.prototype.{{method.name|stylize_method}} = function(
11 {%- for parameter in method.parameters -%} 12 {%- for parameter in method.parameters -%}
12 {{parameter.name}}{% if not loop.last %}, {% endif %} 13 {{parameter.name}}{% if not loop.last %}, {% endif %}
13 {%- endfor -%} 14 {%- endfor -%}
14 ) { 15 ) {
15 var params = new {{interface.name}}_{{method.name}}_Params(); 16 var params = new {{interface.name}}_{{method.name}}_Params();
16 {%- for parameter in method.parameters %} 17 {%- for parameter in method.parameters %}
17 params.{{parameter.name}} = {{parameter|js_proxy_method_parameter_value}}; 18 params.{{parameter.name}} = {{parameter|js_proxy_method_parameter_value}};
(...skipping 20 matching lines...) Expand all
38 reader.decodeStruct({{interface.name}}_{{method.name}}_ResponseParam s); 39 reader.decodeStruct({{interface.name}}_{{method.name}}_ResponseParam s);
39 resolve(responseParams); 40 resolve(responseParams);
40 }).catch(function(result) { 41 }).catch(function(result) {
41 reject(Error("Connection error: " + result)); 42 reject(Error("Connection error: " + result));
42 }); 43 });
43 }.bind(this)); 44 }.bind(this));
44 {%- endif %} 45 {%- endif %}
45 }; 46 };
46 {%- endfor %} 47 {%- endfor %}
47 48
48 function {{interface.name}}Stub(delegate) { 49 function {{interface.name}}Stub(delegate) {
esprehn 2014/12/29 22:00:44 class {{interface.name}}Stub extends StubBase {
hansmuller1 2014/12/29 23:14:11 Oops, that's a mistake.The super class does the de
49 this.delegate$ = delegate; 50 bindings.StubBase.call(this, delegate);
51 this.delegate$ = delegate;
50 } 52 }
53 {{interface.name}}Stub.prototype = Object.create(bindings.StubBase.prototype);
esprehn 2014/12/29 22:00:44 don't need this with class.
hansmuller1 2014/12/29 23:14:11 Acknowledged.
51 54
52 {%- for method in interface.methods %} 55 {%- for method in interface.methods %}
53 {% macro stub_method_parameters() -%} 56 {%- set js_method_name = method.name|stylize_method %}
54 {%- for parameter in method.parameters -%} 57 {%- set delegate_expr = "bindings.StubBindings(this).delegate" %}
55 {{parameter.name}}{% if not loop.last %}, {% endif %} 58 {{interface.name}}Stub.prototype.{{js_method_name}} = function({{method.parame ters|map(attribute='name')|join(', ')}}) {
56 {%- endfor %} 59 return {{delegate_expr}} && {{delegate_expr}}.{{js_method_name}} && {{delega te_expr}}.{{js_method_name}}({{method.parameters|map('js_stub_method_parameter_v alue')|join(', ')}});
57 {%- endmacro %}
58 {{interface.name}}Stub.prototype.{{method.name|stylize_method}} = function({{s tub_method_parameters()}}) {
59 if (this.delegate$.{{method.name|stylize_method}})
60 return this.delegate$.{{method.name|stylize_method}}({{method.parameters|m ap('js_stub_method_parameter_value')|join(',')}});
61 } 60 }
62 {%- endfor %} 61 {%- endfor %}
63 62
64 {{interface.name}}Stub.prototype.accept = function(message) { 63 {{interface.name}}Stub.prototype.accept = function(message) {
65 var reader = new codec.MessageReader(message); 64 var reader = new codec.MessageReader(message);
66 switch (reader.messageName) { 65 switch (reader.messageName) {
67 {%- for method in interface.methods %} 66 {%- for method in interface.methods %}
68 {%- if method.response_parameters == None %} 67 {%- if method.response_parameters == None %}
69 case k{{interface.name}}_{{method.name}}_Name: 68 case k{{interface.name}}_{{method.name}}_Name:
70 var params = reader.decodeStruct({{interface.name}}_{{method.name}}_Params ); 69 var params = reader.decodeStruct({{interface.name}}_{{method.name}}_Params );
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 {%- from "enum_definition.tmpl" import enum_def -%} 180 {%- from "enum_definition.tmpl" import enum_def -%}
182 {%- for enum in interface.enums %} 181 {%- for enum in interface.enums %}
183 {{ enum_def("%s.%s"|format(interface.name, enum.name), enum) }} 182 {{ enum_def("%s.%s"|format(interface.name, enum.name), enum) }}
184 {%- endfor %} 183 {%- endfor %}
185 {{interface.name}}Stub.prototype.validator = validate{{interface.name}}Request ; 184 {{interface.name}}Stub.prototype.validator = validate{{interface.name}}Request ;
186 {%- if interface|has_callbacks %} 185 {%- if interface|has_callbacks %}
187 {{interface.name}}Proxy.prototype.validator = validate{{interface.name}}Respon se; 186 {{interface.name}}Proxy.prototype.validator = validate{{interface.name}}Respon se;
188 {%- else %} 187 {%- else %}
189 {{interface.name}}Proxy.prototype.validator = null; 188 {{interface.name}}Proxy.prototype.validator = null;
190 {%- endif %} 189 {%- endif %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698