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 85d95d6a62822f6658c9c4e993c07bff4ee9f0be..c3c6525c13dbcf41d397c28d6f8451d1f86b05bd 100644 |
--- a/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl |
+++ b/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl |
@@ -1,53 +1,59 @@ |
{%- for method in interface.methods %} |
- var k{{interface.name}}_{{method.name}}_Name = {{method.ordinal}}; |
+{%- set interface_method_identifier = interface.stylized_name ~ "_" ~ |
+ method.name|to_camel %} |
+ var k{{interface_method_identifier}}_Name = {{method.ordinal}}; |
{%- endfor %} |
- function {{interface.name}}Ptr(handleOrPtrInfo) { |
- this.ptr = new bindings.InterfacePtrController({{interface.name}}, |
+ function {{interface.stylized_name}}Ptr(handleOrPtrInfo) { |
+ this.ptr = new bindings.InterfacePtrController({{interface.stylized_name}}, |
handleOrPtrInfo); |
} |
- function Associated{{interface.name}}Ptr(associatedInterfacePtrInfo) { |
+ function Associated{{interface.stylized_name}}Ptr( |
+ associatedInterfacePtrInfo) { |
this.ptr = new associatedBindings.AssociatedInterfacePtrController( |
- {{interface.name}}, associatedInterfacePtrInfo); |
+ {{interface.stylized_name}}, associatedInterfacePtrInfo); |
} |
- Associated{{interface.name}}Ptr.prototype = |
- Object.create({{interface.name}}Ptr.prototype); |
- Associated{{interface.name}}Ptr.prototype.constructor = |
- Associated{{interface.name}}Ptr; |
+ Associated{{interface.stylized_name}}Ptr.prototype = |
+ Object.create({{interface.stylized_name}}Ptr.prototype); |
+ Associated{{interface.stylized_name}}Ptr.prototype.constructor = |
+ Associated{{interface.stylized_name}}Ptr; |
- function {{interface.name}}Proxy(receiver) { |
+ function {{interface.stylized_name}}Proxy(receiver) { |
this.receiver_ = receiver; |
} |
{%- for method in interface.methods %} |
- {{interface.name}}Ptr.prototype.{{method.name|stylize_method}} = function() { |
- return {{interface.name}}Proxy.prototype.{{method.name|stylize_method}} |
+ {{interface.stylized_name}}Ptr.prototype.{{method.stylized_name}} = |
+ function() { |
+ return {{interface.stylized_name}}Proxy.prototype.{{method.stylized_name}} |
.apply(this.ptr.getProxy(), arguments); |
}; |
- {{interface.name}}Proxy.prototype.{{method.name|stylize_method}} = function( |
+ {{interface.stylized_name}}Proxy.prototype.{{method.stylized_name}} = |
+ function( |
{%- for parameter in method.parameters -%} |
-{{parameter.name}}{% if not loop.last %}, {% endif %} |
+{{parameter.stylized_name}}{% if not loop.last %}, {% endif %} |
{%- endfor -%} |
) { |
- var params = new {{interface.name}}_{{method.name}}_Params(); |
+ var params = new {{interface_method_identifier}}_Params(); |
{%- for parameter in method.parameters %} |
- params.{{parameter.name}} = {{parameter.name}}; |
+ params.{{parameter.stylized_name}} = {{parameter.stylized_name}}; |
{%- endfor %} |
{%- if method.response_parameters == None %} |
{%- if method|method_passes_associated_kinds and not use_new_js_bindings %} |
var builder = new codec.MessageV2Builder( |
- k{{interface.name}}_{{method.name}}_Name, |
- codec.align({{interface.name}}_{{method.name}}_Params.encodedSize)); |
- builder.setPayload({{interface.name}}_{{method.name}}_Params, params); |
+ k{{interface_method_identifier}}_Name, |
+ codec.align( |
+ {{interface_method_identifier}}_Params.encodedSize)); |
+ builder.setPayload({{interface_method_identifier}}_Params, params); |
{%- else %} |
var builder = new codec.MessageV0Builder( |
- k{{interface.name}}_{{method.name}}_Name, |
- codec.align({{interface.name}}_{{method.name}}_Params.encodedSize)); |
- builder.encodeStruct({{interface.name}}_{{method.name}}_Params, params); |
+ k{{interface_method_identifier}}_Name, |
+ codec.align({{interface_method_identifier}}_Params.encodedSize)); |
+ builder.encodeStruct({{interface_method_identifier}}_Params, params); |
{%- endif %} |
var message = builder.finish(); |
this.receiver_.accept(message); |
@@ -55,22 +61,22 @@ |
return new Promise(function(resolve, reject) { |
{%- if method|method_passes_associated_kinds and not use_new_js_bindings %} |
var builder = new codec.MessageV2Builder( |
- k{{interface.name}}_{{method.name}}_Name, |
- codec.align({{interface.name}}_{{method.name}}_Params.encodedSize), |
+ k{{interface_method_identifier}}_Name, |
+ codec.align({{interface_method_identifier}}_Params.encodedSize), |
codec.kMessageExpectsResponse, 0); |
- builder.setPayload({{interface.name}}_{{method.name}}_Params, params); |
+ builder.setPayload({{interface_method_identifier}}_Params, params); |
{%- else %} |
var builder = new codec.MessageV1Builder( |
- k{{interface.name}}_{{method.name}}_Name, |
- codec.align({{interface.name}}_{{method.name}}_Params.encodedSize), |
+ k{{interface_method_identifier}}_Name, |
+ codec.align({{interface_method_identifier}}_Params.encodedSize), |
codec.kMessageExpectsResponse, 0); |
- builder.encodeStruct({{interface.name}}_{{method.name}}_Params, params); |
+ builder.encodeStruct({{interface_method_identifier}}_Params, params); |
{%- endif %} |
var message = builder.finish(); |
this.receiver_.acceptAndExpectResponse(message).then(function(message) { |
var reader = new codec.MessageReader(message); |
var responseParams = |
- reader.decodeStruct({{interface.name}}_{{method.name}}_ResponseParams); |
+ reader.decodeStruct({{interface_method_identifier}}_ResponseParams); |
resolve(responseParams); |
}).catch(function(result) { |
reject(Error("Connection error: " + result)); |
@@ -80,27 +86,30 @@ |
}; |
{%- endfor %} |
- function {{interface.name}}Stub(delegate) { |
+ function {{interface.stylized_name}}Stub(delegate) { |
this.delegate_ = delegate; |
} |
{%- for method in interface.methods %} |
-{%- set js_method_name = method.name|stylize_method %} |
- {{interface.name}}Stub.prototype.{{js_method_name}} = function({{method.parameters|map(attribute='name')|join(', ')}}) { |
- return this.delegate_ && this.delegate_.{{js_method_name}} && this.delegate_.{{js_method_name}}({{method.parameters|map(attribute='name')|join(', ')}}); |
+ {{interface.stylized_name}}Stub.prototype.{{method.stylized_name}} = |
+ function( |
+ {{method.parameters|map(attribute='stylized_name')|join(', ')}}) { |
+ return this.delegate_ && this.delegate_.{{method.stylized_name}} && |
+ this.delegate_.{{method.stylized_name}}( |
+ {{method.parameters|map(attribute='stylized_name')|join(', ')}}); |
} |
{%- endfor %} |
- {{interface.name}}Stub.prototype.accept = function(message) { |
+ {{interface.stylized_name}}Stub.prototype.accept = function(message) { |
var reader = new codec.MessageReader(message); |
switch (reader.messageName) { |
{%- for method in interface.methods %} |
{%- if method.response_parameters == None %} |
- case k{{interface.name}}_{{method.name}}_Name: |
- var params = reader.decodeStruct({{interface.name}}_{{method.name}}_Params); |
- this.{{method.name|stylize_method}}( |
+ case k{{interface_method_identifier}}_Name: |
+ var params = reader.decodeStruct({{interface_method_identifier}}_Params); |
+ this.{{method.stylized_name}}( |
{%- for parameter in method.parameters -%} |
- params.{{parameter.name}}{% if not loop.last %}, {% endif %} |
+ params.{{parameter.stylized_name}}{% if not loop.last %}, {% endif %} |
{%- endfor %}); |
return true; |
{%- endif %} |
@@ -110,37 +119,39 @@ |
} |
}; |
- {{interface.name}}Stub.prototype.acceptWithResponder = |
+ {{interface.stylized_name}}Stub.prototype.acceptWithResponder = |
function(message, responder) { |
var reader = new codec.MessageReader(message); |
switch (reader.messageName) { |
{%- for method in interface.methods %} |
{%- if method.response_parameters != None %} |
- case k{{interface.name}}_{{method.name}}_Name: |
- var params = reader.decodeStruct({{interface.name}}_{{method.name}}_Params); |
- this.{{method.name|stylize_method}}( |
+ case k{{interface_method_identifier}}_Name: |
+ var params = reader.decodeStruct({{interface_method_identifier}}_Params); |
+ this.{{method.stylized_name}}( |
{%- for parameter in method.parameters -%} |
-params.{{parameter.name}}{% if not loop.last %}, {% endif -%} |
+params.{{parameter.stylized_name}}{% if not loop.last %}, {% endif -%} |
{%- endfor %}).then(function(response) { |
var responseParams = |
- new {{interface.name}}_{{method.name}}_ResponseParams(); |
+ new {{interface_method_identifier}}_ResponseParams(); |
{%- for parameter in method.response_parameters %} |
- responseParams.{{parameter.name}} = response.{{parameter.name}}; |
+ responseParams.{{parameter.stylized_name}} = |
+ response.{{parameter.stylized_name}}; |
{%- endfor %} |
{%- if method|method_passes_associated_kinds and not use_new_js_bindings %} |
var builder = new codec.MessageV2Builder( |
- k{{interface.name}}_{{method.name}}_Name, |
- codec.align({{interface.name}}_{{method.name}}_ResponseParams |
+ k{{interface_method_identifier}}_Name, |
+ codec.align({{interface_method_identifier}}_ResponseParams |
.encodedSize), |
codec.kMessageIsResponse, reader.requestID); |
- builder.setPayload({{interface.name}}_{{method.name}}_ResponseParams, |
+ builder.setPayload({{interface_method_identifier}}_ResponseParams, |
responseParams); |
{%- else %} |
var builder = new codec.MessageV1Builder( |
- k{{interface.name}}_{{method.name}}_Name, |
- codec.align({{interface.name}}_{{method.name}}_ResponseParams.encodedSize), |
+ k{{interface_method_identifier}}_Name, |
+ codec.align({{interface_method_identifier}}_ResponseParams |
+ .encodedSize), |
codec.kMessageIsResponse, reader.requestID); |
- builder.encodeStruct({{interface.name}}_{{method.name}}_ResponseParams, |
+ builder.encodeStruct({{interface_method_identifier}}_ResponseParams, |
responseParams); |
{%- endif %} |
var message = builder.finish(); |
@@ -156,7 +167,7 @@ params.{{parameter.name}}{% if not loop.last %}, {% endif -%} |
{#--- Validation #} |
- function validate{{interface.name}}Request(messageValidator) { |
+ function validate{{interface.stylized_name}}Request(messageValidator) { |
{%- if not(interface.methods) %} |
return validator.validationError.NONE; |
{%- else %} |
@@ -164,13 +175,13 @@ params.{{parameter.name}}{% if not loop.last %}, {% endif -%} |
var paramsClass = null; |
switch (message.getName()) { |
{%- for method in interface.methods %} |
- case k{{interface.name}}_{{method.name}}_Name: |
+ case k{{interface_method_identifier}}_Name: |
{%- if method.response_parameters == None %} |
if (!message.expectsResponse() && !message.isResponse()) |
- paramsClass = {{interface.name}}_{{method.name}}_Params; |
+ paramsClass = {{interface_method_identifier}}_Params; |
{%- else %} |
if (message.expectsResponse()) |
- paramsClass = {{interface.name}}_{{method.name}}_Params; |
+ paramsClass = {{interface_method_identifier}}_Params; |
{%- endif %} |
break; |
{%- endfor %} |
@@ -181,7 +192,7 @@ params.{{parameter.name}}{% if not loop.last %}, {% endif -%} |
{%- endif %} |
} |
- function validate{{interface.name}}Response(messageValidator) { |
+ function validate{{interface.stylized_name}}Response(messageValidator) { |
{%- if not(interface|has_callbacks) %} |
return validator.validationError.NONE; |
{%- else %} |
@@ -190,9 +201,9 @@ params.{{parameter.name}}{% if not loop.last %}, {% endif -%} |
switch (message.getName()) { |
{%- for method in interface.methods %} |
{%- if method.response_parameters != None %} |
- case k{{interface.name}}_{{method.name}}_Name: |
+ case k{{interface_method_identifier}}_Name: |
if (message.isResponse()) |
- paramsClass = {{interface.name}}_{{method.name}}_ResponseParams; |
+ paramsClass = {{interface_method_identifier}}_ResponseParams; |
break; |
{%- endif %} |
{%- endfor %} |
@@ -203,31 +214,35 @@ params.{{parameter.name}}{% if not loop.last %}, {% endif -%} |
{%- endif %} |
} |
- var {{interface.name}} = { |
- name: '{{namespace|replace(".","::")}}::{{interface.name}}', |
+ var {{interface.stylized_name}} = { |
+ name: '{{module.namespace|replace(".","::")}}::{{interface.name}}', |
kVersion: {{interface.version}}, |
- ptrClass: {{interface.name}}Ptr, |
- proxyClass: {{interface.name}}Proxy, |
- stubClass: {{interface.name}}Stub, |
- validateRequest: validate{{interface.name}}Request, |
+ ptrClass: {{interface.stylized_name}}Ptr, |
+ proxyClass: {{interface.stylized_name}}Proxy, |
+ stubClass: {{interface.stylized_name}}Stub, |
+ validateRequest: validate{{interface.stylized_name}}Request, |
{%- if interface|has_callbacks %} |
- validateResponse: validate{{interface.name}}Response, |
+ validateResponse: validate{{interface.stylized_name}}Response, |
{%- else %} |
validateResponse: null, |
{%- endif %} |
}; |
{#--- Interface Constants #} |
{%- for constant in interface.constants %} |
- {{interface.name}}.{{constant.name}} = {{constant.value|expression_to_text}}, |
+ {{interface.stylized_name}}.{{constant.stylized_name}} = |
+ {{constant.value|expression_to_text}}, |
{%- endfor %} |
{#--- Interface Enums #} |
{%- from "enum_definition.tmpl" import enum_def -%} |
{%- for enum in interface.enums %} |
- {{ enum_def("%s.%s"|format(interface.name, enum.name), enum) }} |
+ {{ enum_def("%s.%s"|format(interface.stylized_name, enum.stylized_name), |
+ enum) }} |
{%- endfor %} |
- {{interface.name}}Stub.prototype.validator = validate{{interface.name}}Request; |
+ {{interface.stylized_name}}Stub.prototype.validator = |
+ validate{{interface.stylized_name}}Request; |
{%- if interface|has_callbacks %} |
- {{interface.name}}Proxy.prototype.validator = validate{{interface.name}}Response; |
+ {{interface.stylized_name}}Proxy.prototype.validator = |
+ validate{{interface.stylized_name}}Response; |
{%- else %} |
- {{interface.name}}Proxy.prototype.validator = null; |
+ {{interface.stylized_name}}Proxy.prototype.validator = null; |
{%- endif %} |