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

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

Issue 2855263002: Mojo bindings: support generating identifers using different style rules for different target langu…
Patch Set: . Created 3 years, 7 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
« no previous file with comments | « no previous file | mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 {%- macro enum_def(enum_name, enum) -%} 1 {%- macro enum_def(enum_name, enum) -%}
2 {{enum_name}} = {}; 2 {{enum_name}} = {};
3 {%- set prev_enum = 0 %} 3 {%- set prev_enum = 0 %}
4 {%- for field in enum.fields %} 4 {%- for field in enum.fields %}
5 {%- if field.value %} 5 {%- if field.value %}
6 {{enum_name}}.{{field.name}} = {{field.value|expression_to_text}}; 6 {{enum_name}}.{{field.stylized_name}} = {{field.value|expression_to_text}};
7 {%- elif loop.first %} 7 {%- elif loop.first %}
8 {{enum_name}}.{{field.name}} = 0; 8 {{enum_name}}.{{field.stylized_name}} = 0;
9 {%- else %} 9 {%- else %}
10 {{enum_name}}.{{field.name}} = {{enum_name}}.{{enum.fields[loop.index0 - 1].na me}} + 1; 10 {{enum_name}}.{{field.stylized_name}} =
11 {{enum_name}}.{{enum.fields[loop.index0 - 1].stylized_name}} + 1;
11 {%- endif %} 12 {%- endif %}
12 {%- endfor %} 13 {%- endfor %}
13 14
14 {{enum_name}}.isKnownEnumValue = function(value) { 15 {{enum_name}}.isKnownEnumValue = function(value) {
15 {%- if enum.fields %} 16 {%- if enum.fields %}
16 switch (value) { 17 switch (value) {
17 {%- for enum_field in enum.fields|groupby('numeric_value') %} 18 {%- for enum_field in enum.fields|groupby('numeric_value') %}
18 case {{enum_field[0]}}: 19 case {{enum_field[0]}}:
19 {%- endfor %} 20 {%- endfor %}
20 return true; 21 return true;
21 } 22 }
22 {%- endif %} 23 {%- endif %}
23 return false; 24 return false;
24 }; 25 };
25 26
26 {{enum_name}}.validate = function(enumValue) { 27 {{enum_name}}.validate = function(enumValue) {
27 var isExtensible = {% if enum.extensible %}true{% else %}false{% endif %}; 28 var isExtensible = {% if enum.extensible %}true{% else %}false{% endif %};
28 if (isExtensible || this.isKnownEnumValue(enumValue)) 29 if (isExtensible || this.isKnownEnumValue(enumValue))
29 return validator.validationError.NONE; 30 return validator.validationError.NONE;
30 31
31 return validator.validationError.UNKNOWN_ENUM_VALUE; 32 return validator.validationError.UNKNOWN_ENUM_VALUE;
32 }; 33 };
33 {%- endmacro %} 34 {%- endmacro %}
OLDNEW
« no previous file with comments | « no previous file | mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698