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

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

Issue 226263002: Mojo: Move mojo/public/bindings to mojo/public/tools/bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 9 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/bindings/generators/js_templates/struct_definition.tmpl
diff --git a/mojo/public/bindings/generators/js_templates/struct_definition.tmpl b/mojo/public/bindings/generators/js_templates/struct_definition.tmpl
deleted file mode 100644
index 1686820a7e7f71967f1cdd53adcd013cf641cf58..0000000000000000000000000000000000000000
--- a/mojo/public/bindings/generators/js_templates/struct_definition.tmpl
+++ /dev/null
@@ -1,118 +0,0 @@
-{%- macro set_default(module, kind, value, depth) -%}
-{#--- Strings ---#}
-{%- if kind|is_string_kind -%}
-{{caller(value|expression_to_text(module))}}
-{#--- 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(module))}}
-{%- endif %}
-{%- 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. #}
-{%- from "enum_definition.tmpl" import enum_def %}
-{% for enum in struct.enums %}
- var {{enum_def("%s_%s"|format(struct.name, enum.name), enum, module)}}
-{% endfor %}
-
-{#--- Constructor #}
- function {{struct.name}}() {
-{%- 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 %}
- }
-
-{#--- 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 #}
-
- {{struct.name}}.encodedSize = codec.kStructHeaderSize + {{struct.packed|payload_size}};
-
- {{struct.name}}.decode = function(decoder) {
- var packed;
- var val = new {{struct.name}}();
- var numberOfBytes = decoder.read32();
- var numberOfFields = decoder.read32();
-{%- for byte in struct.bytes %}
-{%- if byte.packed_fields|length > 1 %}
- packed = decoder.read8();
-{%- for packed_field in byte.packed_fields %}
- val.{{packed_field.field.name}} = (packed >> {{packed_field.bit}}) & 1 ? true : false;
-{%- endfor %}
-{%- else %}
-{%- for packed_field in byte.packed_fields %}
- val.{{packed_field.field.name}} = decoder.{{packed_field.field.kind|decode_snippet}};
-{%- endfor %}
-{%- endif %}
-{%- if byte.is_padding %}
- decoder.skip(1);
-{%- endif %}
-{%- endfor %}
- return val;
- };
-
- {{struct.name}}.encode = function(encoder, val) {
- var packed;
- encoder.write32({{struct.name}}.encodedSize);
- encoder.write32({{struct.packed.packed_fields|length}});
-
-{%- for byte in struct.bytes %}
-{%- if byte.packed_fields|length > 1 %}
- packed = 0;
-{%- for packed_field in byte.packed_fields %}
- packed |= (val.{{packed_field.field.name}} & 1) << {{packed_field.bit}}
-{%- endfor %}
- encoder.write8(packed);
-{%- else %}
-{%- for packed_field in byte.packed_fields %}
- encoder.{{packed_field.field.kind|encode_snippet}}val.{{packed_field.field.name}});
-{%- endfor %}
-{%- endif %}
-{%- if byte.is_padding %}
- encoder.skip(1);
-{%- endif %}
-{%- endfor %}
- };
« no previous file with comments | « mojo/public/bindings/generators/js_templates/module.js.tmpl ('k') | mojo/public/bindings/generators/mojom_cpp_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698