| 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 df3ee17e4049a351c3bc56d3df361a58629aa820..d77b28b80eaf9bc739eff75e89cde43aa6e471d0 100644
|
| --- a/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl
|
| +++ b/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl
|
| @@ -1,26 +1,35 @@
|
| {#--- Begin #}
|
| - function {{struct.name}}() {
|
| + function {{struct.name}}(values) {
|
| this.initDefaults_();
|
| + this.initFields_(values);
|
| }
|
|
|
| {#--- Enums #}
|
| {%- from "enum_definition.tmpl" import enum_def %}
|
| {% for enum in struct.enums %}
|
| {{enum_def("%s.%s"|format(struct.name, enum.name), enum, module)}}
|
| -{% endfor %}
|
| +{%- endfor %}
|
|
|
| {#--- Constants #}
|
| {% for constant in struct.constants %}
|
| {{struct.name}}.{{constant.name}} = {{constant.value|expression_to_text}};
|
| -{% endfor %}
|
| +{%- endfor %}
|
|
|
| -{#--- Set up defaults #}
|
| +{#--- initDefaults() #}
|
| {{struct.name}}.prototype.initDefaults_ = function() {
|
| {%- for packed_field in struct.packed.packed_fields %}
|
| this.{{packed_field.field.name}} = {{packed_field.field|default_value}};
|
| {%- endfor %}
|
| };
|
|
|
| +{#--- initFields() #}
|
| + {{struct.name}}.prototype.initFields_ = function(fields) {
|
| + for(var field in fields) {
|
| + if (this.hasOwnProperty(field))
|
| + this[field] = fields[field];
|
| + }
|
| + };
|
| +
|
| {#--- Validation #}
|
|
|
| {{struct.name}}.validate = function(messageValidator, offset) {
|
|
|