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

Unified Diff: mojo/public/cpp/bindings/lib/array_internal.h

Issue 1618963006: Mojo C++ bindings: support enum validation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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/cpp/bindings/lib/array_internal.h
diff --git a/mojo/public/cpp/bindings/lib/array_internal.h b/mojo/public/cpp/bindings/lib/array_internal.h
index d351b3423b56dd7b0b23f3667e31e1c1b57d042d..1b70517798137788b5c00271463042d6a1e6cce2 100644
--- a/mojo/public/cpp/bindings/lib/array_internal.h
+++ b/mojo/public/cpp/bindings/lib/array_internal.h
@@ -173,8 +173,30 @@ struct ArraySerializationHelper<T, false> {
<< "Primitive type should be non-nullable";
MOJO_DCHECK(!validate_params->element_validate_params)
<< "Primitive type should not have array validate params";
+
+ for (uint32_t i = 0; i < header->num_elements; ++i) {
+ if (!ValidateCaller<ElementType>::Run(elements[i]))
+ return false;
+ }
+
return true;
}
+
+ private:
+ template <typename U, bool is_enum = IsEnumDataType<U>::value>
+ struct ValidateCaller {};
+
+ template <typename U>
+ struct ValidateCaller<U, false> {
+ static bool Run(const ElementType& element) { return true; }
+ };
+
+ template <typename U>
+ struct ValidateCaller<U, true> {
+ static bool Run(const ElementType& element) {
+ return ValidateEnum(element);
+ }
+ };
};
template <>

Powered by Google App Engine
This is Rietveld 408576698