| Index: third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl
|
| diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5a328f9e2b1555aaa39c9eda7298cf40edab99fe
|
| --- /dev/null
|
| +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl
|
| @@ -0,0 +1,43 @@
|
| +{%- macro validate_not_null_ptr(field_expr, field, object_name) %}
|
| +if (!{{field_expr}}->offset) {
|
| + ReportValidationError(
|
| + mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
|
| + "null {{field.name}} field in {{object_name}}");
|
| + return false;
|
| +}
|
| +{%- endmacro %}
|
| +
|
| +{%- macro validate_encoded_ptr(field_expr) %}
|
| +if (!mojo::internal::ValidateEncodedPointer(&{{field_expr}}->offset)) {
|
| + ReportValidationError(mojo::internal::VALIDATION_ERROR_ILLEGAL_POINTER);
|
| + return false;
|
| +}
|
| +{%- endmacro %}
|
| +
|
| +{%- macro validate_array_or_string(field_expr, field) -%}
|
| +if (!{{field.kind|cpp_wrapper_type}}::Data_::Validate<
|
| + {{field.kind|get_array_validate_params}}>(
|
| + mojo::internal::DecodePointerRaw(&{{field_expr}}->offset),
|
| + bounds_checker)) {
|
| + return false;
|
| +}
|
| +{%- endmacro %}
|
| +
|
| +{%- macro validate_union_field(field, union) %}
|
| +{%- set field_expr = "(reinterpret_cast<const "
|
| + ~ field.kind|cpp_field_type
|
| + ~ "*>(&object->data.f_"
|
| + ~ field.name
|
| + ~ "))" -%}
|
| +{%- if field.kind|is_object_kind -%}
|
| +{%- if not field.kind|is_nullable_kind -%}
|
| +{{ validate_not_null_ptr(field_expr, field, union.name) }}
|
| +{%- endif %}
|
| +{{ validate_encoded_ptr(field_expr) }}
|
| +{%- endif %}
|
| +
|
| +{%- if field.kind|is_array_kind or field.kind|is_string_kind -%}
|
| +{{ validate_array_or_string(field_expr, field) }}
|
| +{%- endif %}
|
| +return true;
|
| +{%- endmacro %}
|
|
|