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

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

Issue 1387993002: mojo::Serialize*_() calls now propogate/return validation errors. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Cleaned up how serialization errors propagate, and addressed other comments from viettrungluu@ Created 5 years, 2 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/map_serialization.h
diff --git a/mojo/public/cpp/bindings/lib/map_serialization.h b/mojo/public/cpp/bindings/lib/map_serialization.h
index 8ef83b3a3a554947606e20eb0aa01beaa53d06a5..db023f739151e4b8e8fc0ffcda4b345205320879 100644
--- a/mojo/public/cpp/bindings/lib/map_serialization.h
+++ b/mojo/public/cpp/bindings/lib/map_serialization.h
@@ -128,45 +128,54 @@ template <typename MapKey,
typename MapValue,
typename DataKey,
typename DataValue>
-inline void SerializeMap_(
+inline internal::ValidationError SerializeMap_(
Map<MapKey, MapValue>* input,
internal::Buffer* buf,
internal::Map_Data<DataKey, DataValue>** output,
const internal::ArrayValidateParams* value_validate_params) {
- if (input && *input) {
+ if (!input->is_null()) {
viettrungluu 2015/10/08 15:51:25 I assume that |input| itself shouldn't be a null p
vardhan 2015/10/08 20:53:51 That's right, thought i'd fix it here.
internal::Map_Data<DataKey, DataValue>* result =
internal::Map_Data<DataKey, DataValue>::New(buf);
+
+ // We *must* serialize the keys before we allocate an Array_Data for the
+ // values.
internal::Array_Data<DataKey>* keys_data =
internal::Array_Data<DataKey>::New(input->size(), buf);
+ result->keys.ptr = keys_data;
+
+ internal::MapKeyIterator<MapKey, MapValue> key_iter(input);
+ const internal::ArrayValidateParams* key_validate_params =
+ internal::MapKeyValidateParamsFactory<DataKey>::Get();
+
+ auto keys_retval =
+ internal::ArraySerializer<MapKey, DataKey>::SerializeElements(
+ key_iter.begin(), input->size(), buf, result->keys.ptr,
+ key_validate_params);
+ if (keys_retval != internal::ValidationError::VALIDATION_ERROR_NONE)
+ return keys_retval;
+
+ // Now we try allocate an Array_Data for the values
+ internal::Array_Data<DataValue>* values_data =
+ internal::Array_Data<DataValue>::New(input->size(), buf);
+ result->values.ptr = values_data;
- if (result && keys_data) {
- result->keys.ptr = keys_data;
-
- // We *must* serialize the keys before we allocate an Array_Data for the
- // values.
- internal::MapKeyIterator<MapKey, MapValue> key_iter(input);
- const internal::ArrayValidateParams* key_validate_params =
- internal::MapKeyValidateParamsFactory<DataKey>::Get();
-
- internal::ArraySerializer<MapKey, DataKey>::SerializeElements(
- key_iter.begin(), input->size(), buf, result->keys.ptr,
- key_validate_params);
-
- // Now we try allocate an Array_Data for the values
- internal::Array_Data<DataValue>* values_data =
- internal::Array_Data<DataValue>::New(input->size(), buf);
- if (values_data) {
- result->values.ptr = values_data;
- internal::MapValueIterator<MapKey, MapValue> value_iter(input);
+ internal::MapValueIterator<MapKey, MapValue> value_iter(input);
+
+ auto values_retval =
internal::ArraySerializer<MapValue, DataValue>::SerializeElements(
value_iter.begin(), input->size(), buf, result->values.ptr,
value_validate_params);
- }
- }
+
+ if (values_retval != internal::ValidationError::VALIDATION_ERROR_NONE)
+ return values_retval;
+
*output = result;
} else {
+ // |input| could be a nullable map, in which case |output| is serialized as
+ // null, which is valid.
*output = nullptr;
}
+ return internal::ValidationError::VALIDATION_ERROR_NONE;
}
template <typename MapKey,
« no previous file with comments | « mojo/public/cpp/bindings/lib/control_message_proxy.cc ('k') | mojo/public/cpp/bindings/lib/map_serialization_forward.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698