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

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

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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
deleted file mode 100644
index 62b497cb2622f3a0494a27f710a95e79aeec5a19..0000000000000000000000000000000000000000
--- a/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl
+++ /dev/null
@@ -1,120 +0,0 @@
-{#--- Begin #}
- 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)}}
-{%- endfor %}
-
-{#--- Constants #}
-{% for constant in struct.constants %}
- {{struct.name}}.{{constant.name}} = {{constant.value|expression_to_text}};
-{%- endfor %}
-
-{#--- 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) {
- var err;
-{% macro check_err() -%}
- if (err !== validator.validationError.NONE)
- return err;
-{%- endmacro %}
- err = messageValidator.validateStructHeader(offset, {{struct.name}}.encodedSize, {{struct.packed.packed_fields|length}});
- {{check_err()}}
-
-{%- for packed_field in struct.packed.packed_fields %}
-{%- set field_name = packed_field.field.name %}
-{%- if packed_field.field|is_string_pointer_field %}
- // validate {{struct.name}}.{{field_name}}
- err = messageValidator.validateStringPointer({{packed_field|validate_string_params}})
- {{check_err()}}
-{%- elif packed_field.field|is_array_pointer_field %}
- // validate {{struct.name}}.{{field_name}}
- err = messageValidator.validateArrayPointer({{packed_field|validate_array_params}});
- {{check_err()}}
-{%- elif packed_field.field|is_struct_pointer_field %}
- // validate {{struct.name}}.{{field_name}}
- err = messageValidator.validateStructPointer({{packed_field|validate_struct_params}});
- {{check_err()}}
-{%- elif packed_field.field|is_map_pointer_field %}
- // validate {{struct.name}}.{{field_name}}
- err = messageValidator.validateMapPointer({{packed_field|validate_map_params}});
- {{check_err()}}
-{%- elif packed_field.field|is_handle_field %}
- // validate {{struct.name}}.{{field_name}}
- err = messageValidator.validateHandle({{packed_field|validate_handle_params}})
- {{check_err()}}
-{%- endif %}
-{%- endfor %}
-
- return validator.validationError.NONE;
- };
-
-{#--- 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.readUint32();
- var numberOfFields = decoder.readUint32();
-{%- for byte in struct.bytes %}
-{%- if byte.packed_fields|length > 1 %}
- packed = decoder.readUint8();
-{%- 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.writeUint32({{struct.name}}.encodedSize);
- encoder.writeUint32({{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.writeUint8(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 %}
- };

Powered by Google App Engine
This is Rietveld 408576698