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

Unified Diff: mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl

Issue 268363003: Mojo: Add support for constants to the IDL compiler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: JS export constants Created 6 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl b/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl
index 6db102ce8e1c82b49e6eafe12407f6d715136a6c..0c79f24cd26820aa8ebb2a0e02f1fa92a625173b 100644
--- a/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl
@@ -40,15 +40,23 @@ tmp{{depth}}.{{subfield.name}} = {{result}};
{%- endmacro %}
{#--- Begin #}
-{#--- Enums. We must define these before the constructor because they
- may be used there. Later, we alias these to be class static variables. #}
+ function {{struct.name}}() {
+ this.initDefaults_();
+ }
+
+{#--- Enums #}
{%- from "enum_definition.tmpl" import enum_def %}
{% for enum in struct.enums %}
- var {{enum_def("%s_%s"|format(struct.name, enum.name), enum, module)}}
+ {{enum_def("%s.%s"|format(struct.name, enum.name), enum, module)}}
{% endfor %}
-{#--- Constructor #}
- function {{struct.name}}() {
+{#--- Constants #}
+{% for constant in struct.constants %}
+ {{struct.name}}.{{constant.name}} = {{constant.value|expression_to_text(module)}};
+{% endfor %}
+
+{#--- Set up defaults #}
+ {{struct.name}}.prototype.initDefaults_ = function() {
{%- for packed_field in struct.packed.packed_fields %}
{%- if packed_field.field.default %}
{%- filter indent(4) %}
@@ -60,12 +68,7 @@ this.{{packed_field.field.name}} = {{result}};
this.{{packed_field.field.name}} = {{packed_field.field|default_value}};
{%- endif %}
{%- endfor %}
- }
-
-{#--- Alias any Struct_Enum enums to Struct.Enum #}
-{% for enum in struct.enums %}
- {{struct.name}}.{{enum.name}} = {{struct.name}}_{{enum.name}};
-{%- endfor %}
+ };
{#--- Encoding and decoding #}

Powered by Google App Engine
This is Rietveld 408576698