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

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

Issue 317073005: Mojom: Add 'default' keyword for initializing structs to non-null value. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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 ca9e43c13fb0eb217bdcb65dd4162c63e9ffd63b..ae1ccb079afc63819a9862ec795f04743362f059 100644
--- a/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl
@@ -1,44 +1,3 @@
-{%- macro set_default(module, kind, value, depth) -%}
-{#--- Strings ---#}
-{%- if kind|is_string_kind -%}
-{{caller(value|expression_to_text)}}
-{#--- Arrays ---#}
-{%- elif kind|is_array_kind %}
-{%- set _ = value|verify_token_type("ARRAY") %}
-{
- var tmp{{depth}} = [];
-{%- for element in value[1] %}
-{%- filter indent(2) %}
-{%- call(result) set_default(module, kind.kind, element, depth+1) %}
-tmp{{depth}}[{{loop.index0}}] = {{result}};
-{%- endcall %}
-{%- endfilter %}
-{%- endfor -%}
- {{caller("tmp" ~ depth)|indent(2)}}
-}
-{#--- Objects ---#}
-{%- elif kind|is_object_kind %}
-{%- set _ = value|verify_token_type("OBJECT") %}
-{
- var tmp{{depth}} = new {{kind|js_type}}();
-{%- set struct = kinds[kind.spec] %}
-{%- for element in value[1] %}
-{#- Use struct.packed_fields to order struct values by ordinal number #}
-{%- set subfield = struct.fields[loop.index0] %}
-{%- filter indent(2) %}
-{%- call(result) set_default(module, subfield.kind, element, depth+1) %}
-tmp{{depth}}.{{subfield.name}} = {{result}};
-{%- endcall %}
-{%- endfilter %}
-{%- endfor -%}
- {{caller("tmp" ~ depth)|indent(2)}}
-}
-{#--- POD types ---#}
-{%- else -%}
-{{caller(value|expression_to_text)}}
-{%- endif %}
-{%- endmacro %}
-
{#--- Begin #}
function {{struct.name}}() {
this.initDefaults_();
@@ -58,15 +17,7 @@ tmp{{depth}}.{{subfield.name}} = {{result}};
{#--- Set up defaults #}
{{struct.name}}.prototype.initDefaults_ = function() {
{%- for packed_field in struct.packed.packed_fields %}
-{%- if packed_field.field.default %}
-{%- filter indent(4) %}
-{%- call(result) set_default(module, packed_field.field.kind, packed_field.field.default, 0) %}
-this.{{packed_field.field.name}} = {{result}};
-{%- endcall %}
-{%- endfilter %}
-{%- else %}
this.{{packed_field.field.name}} = {{packed_field.field|default_value}};
-{%- endif %}
{%- endfor %}
};

Powered by Google App Engine
This is Rietveld 408576698