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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl

Issue 2064903002: Mojo: Report bindings validation errors via MojoNotifyBadMessage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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 unified diff | Download patch
OLDNEW
1 {%- import "validation_macros.tmpl" as validation_macros %} 1 {%- import "validation_macros.tmpl" as validation_macros %}
2 {%- set class_name = union.name ~ "_Data" %} 2 {%- set class_name = union.name ~ "_Data" %}
3 {%- set enum_name = union.name ~ "_Tag" -%} 3 {%- set enum_name = union.name ~ "_Tag" -%}
4 4
5 // static 5 // static
6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { 6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) {
7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); 7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}();
8 } 8 }
9 9
10 // static 10 // static
11 bool {{class_name}}::Validate(const void* data, 11 bool {{class_name}}::Validate(
12 mojo::internal::BoundsChecker* bounds_checker, 12 const void* data,
13 bool inlined) { 13 mojo::internal::ValidationContext* validation_context,
14 bool inlined) {
14 if (!data) 15 if (!data)
15 return true; 16 return true;
16 17
17 if (!ValidateUnionHeaderAndClaimMemory(data, inlined, bounds_checker)) 18 if (!ValidateUnionHeaderAndClaimMemory(data, inlined, validation_context))
18 return false; 19 return false;
19 20
20 const {{class_name}}* object = static_cast<const {{class_name}}*>(data); 21 const {{class_name}}* object = static_cast<const {{class_name}}*>(data);
21 ALLOW_UNUSED_LOCAL(object); 22 ALLOW_UNUSED_LOCAL(object);
22 23
23 switch (object->tag) { 24 switch (object->tag) {
24 {% for field in union.fields %} 25 {% for field in union.fields %}
25 case {{enum_name}}::{{field.name|upper}}: { 26 case {{enum_name}}::{{field.name|upper}}: {
26 {%- set field_expr = "object->data.f_" ~ field.name %} 27 {%- set field_expr = "object->data.f_" ~ field.name %}
27 {{validation_macros.validate_field(field, field_expr, union.name, false)|indent( 4)}} 28 {{validation_macros.validate_field(field, field_expr, union.name, false)|indent( 4)}}
28 return true; 29 return true;
29 } 30 }
30 {%- endfor %} 31 {%- endfor %}
31 default: { 32 default: {
32 ReportValidationError( 33 ReportValidationError(
34 validation_context,
33 mojo::internal::VALIDATION_ERROR_UNKNOWN_UNION_TAG, 35 mojo::internal::VALIDATION_ERROR_UNKNOWN_UNION_TAG,
34 "unknown tag in {{union.name}}"); 36 "unknown tag in {{union.name}}");
35 return false; 37 return false;
36 } 38 }
37 } 39 }
38 } 40 }
39 41
40 void {{class_name}}::set_null() { 42 void {{class_name}}::set_null() {
41 size = 0U; 43 size = 0U;
42 tag = static_cast<{{enum_name}}>(0); 44 tag = static_cast<{{enum_name}}>(0);
(...skipping 21 matching lines...) Expand all
64 {%- for field in union.fields %} 66 {%- for field in union.fields %}
65 case {{enum_name}}::{{field.name|upper}}: { 67 case {{enum_name}}::{{field.name|upper}}: {
66 {%- if field.kind|is_object_kind %} 68 {%- if field.kind|is_object_kind %}
67 mojo::internal::Decode(&data.f_{{field.name}}); 69 mojo::internal::Decode(&data.f_{{field.name}});
68 {%- endif %} 70 {%- endif %}
69 return; 71 return;
70 } 72 }
71 {%- endfor %} 73 {%- endfor %}
72 } 74 }
73 } 75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698