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

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: sync Created 5 years, 11 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 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) {
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 );
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 21 matching lines...) Expand all
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) {
49 this.delegate$ = delegate; 50 bindings.StubBase.call(this, delegate);
50 } 51 }
52 {{interface.name}}Stub.prototype = Object.create(bindings.StubBase.prototype);
51 53
52 {%- for method in interface.methods %} 54 {%- for method in interface.methods %}
53 {% macro stub_method_parameters() -%} 55 {%- set js_method_name = method.name|stylize_method %}
54 {%- for parameter in method.parameters -%} 56 {%- set delegate_expr = "bindings.StubBindings(this).delegate" %}
55 {{parameter.name}}{% if not loop.last %}, {% endif %} 57 {{interface.name}}Stub.prototype.{{js_method_name}} = function({{method.parame ters|map(attribute='name')|join(', ')}}) {
56 {%- endfor %} 58 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 } 59 }
62 {%- endfor %} 60 {%- endfor %}
63 61
64 {{interface.name}}Stub.prototype.accept = function(message) { 62 {{interface.name}}Stub.prototype.accept = function(message) {
65 var reader = new codec.MessageReader(message); 63 var reader = new codec.MessageReader(message);
66 switch (reader.messageName) { 64 switch (reader.messageName) {
67 {%- for method in interface.methods %} 65 {%- for method in interface.methods %}
68 {%- if method.response_parameters == None %} 66 {%- if method.response_parameters == None %}
69 case k{{interface.name}}_{{method.name}}_Name: 67 case k{{interface.name}}_{{method.name}}_Name:
70 var params = reader.decodeStruct({{interface.name}}_{{method.name}}_Params ); 68 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 -%} 179 {%- from "enum_definition.tmpl" import enum_def -%}
182 {%- for enum in interface.enums %} 180 {%- for enum in interface.enums %}
183 {{ enum_def("%s.%s"|format(interface.name, enum.name), enum) }} 181 {{ enum_def("%s.%s"|format(interface.name, enum.name), enum) }}
184 {%- endfor %} 182 {%- endfor %}
185 {{interface.name}}Stub.prototype.validator = validate{{interface.name}}Request ; 183 {{interface.name}}Stub.prototype.validator = validate{{interface.name}}Request ;
186 {%- if interface|has_callbacks %} 184 {%- if interface|has_callbacks %}
187 {{interface.name}}Proxy.prototype.validator = validate{{interface.name}}Respon se; 185 {{interface.name}}Proxy.prototype.validator = validate{{interface.name}}Respon se;
188 {%- else %} 186 {%- else %}
189 {{interface.name}}Proxy.prototype.validator = null; 187 {{interface.name}}Proxy.prototype.validator = null;
190 {%- endif %} 188 {%- endif %}
OLDNEW
« no previous file with comments | « mojo/public/sky/BUILD.gn ('k') | mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698