chromium/mojo/public/tools/bindings/generators/js_templates/lite/struct_definition.tmpl

{%  for constant in struct.constants %}
/**
 * @const { {{constant.kind|lite_closure_type_with_nullability}} }
 * @export
 */
{{module.namespace}}.{{struct.name}}_{{constant.name}} =
    {{constant|constant_value}};
{%  endfor %}

{%- from "lite/enum_definition.tmpl" import enum_def with context %}
{%  for enum in struct.enums %}
{{enum_def("%s.%sSpec"|format(module.namespace, struct.name),
           "%s.%s"|format(module.namespace, struct.name), enum)}}
{%  endfor %}

mojo.internal.Struct(
    {{module.namespace}}.{{struct.name}}Spec.$,
    '{{struct.name}}',
    [
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %}
      mojo.internal.StructField(
        '{{packed_field.field.name}}', {{packed_field.offset}},
        {% if packed_field.field.kind|is_bool_kind %}{{packed_field.bit}}
        {%- else %}0{% endif %},
        {{packed_field.field.kind|lite_js_type}},
        {{packed_field.field|lite_default_value}},
{%-   if packed_field.field.kind.is_nullable %}
        true, /* nullable */
{%-   else %}
        false, /* nullable */
{%-   endif %}
        0 /* minVersion */,
{%-   if packed_field|is_nullable_value_kind_packed_field %}
{%-     set name = packed_field.original_field.name %}
{%-     set isPrimary = packed_field|is_primary_nullable_value_kind_packed_field %}
        {
{%-     if isPrimary %}
          isPrimary: true,
          linkedValueFieldName: "{{packed_field.linked_value_packed_field.field.name}}",
{%-     else %}
          isPrimary: false,
{%-     endif %}
          originalFieldName: "{{name}}",
        }
{%-   endif %}
      ),{%- endfor %}
    ],
    [
{%-   for info in struct.versions -%}
      [{{info.version}}, {{info.num_bytes}}],
{%-   endfor -%}
    ]);

{% if generate_struct_deserializers %}
{{module.namespace}}.{{struct.name}}_Deserialize =
    mojo.internal.createStructDeserializer({{module.namespace}}.{{struct.name}}Spec.$);
{% endif %}

{%  if generate_closure_exports -%}
goog.provide('{{module.namespace}}.{{struct.name}}');
{%- endif %}

/** @record */
{{module.namespace}}.{{struct.name}} = class {
  constructor() {
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %}
{%-   if packed_field|is_nullable_value_kind_packed_field %}
{%-     if packed_field|is_primary_nullable_value_kind_packed_field %}
{%-       set original_field = packed_field.original_field %}
{%-       set name = original_field.name %}
{%-       set kind = original_field.kind %}
    /** @export { {{original_field.kind|lite_closure_field_type}} } */
    this.{{name}};
{%-     endif %}
{%-   else %}
    /** @export { {{packed_field.field.kind|lite_closure_field_type}} } */
    this.{{packed_field.field.name}};
{%-   endif %}
{%- endfor %}
  }
};