Mojo: Require nullable outputs for optional fields
This makes it so optional mojom values can only be read from their DataView into a destination type that supports nullability when read with the common Read[FieldName] methods. Attempting to violate this constraint will result in a compile-time assertion failure at the site of the Read[FieldName] call. Prior to this change, such instances were non-obvious and could instead result in surprising runtime behavior. Types that support nullability include anything wrapped with base::Optional, or any type for which there exists an appropriate {Struct,Union,Array,String}Traits definition with a SetToNull method. Pre-existing violations of the new constraint are corrected here either by making fields non-optional, deserializing to a base::Optional, or doing something more specialized to fix traits logic. Finally, this also removes the IsNull and SetToNull methods from StringTraits<std::string> since: (a) optional string fields are generated as base::Optional<std::string> and (b) it was not intentional for null strings and empty strings to be treated as equivalent in meaning. Fixed: 1124639 Change-Id: I0569b4b8420b4b416bd889417d9723307a880454 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404478 Commit-Queue: Ken Rockot <rockot@google.com> Reviewed-by:danakj <danakj@chromium.org> Reviewed-by:
Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/master@{#807146}
Showing
Please register or sign in to comment