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

Unified Diff: mojo/public/tools/bindings/generators/mojom_cpp_generator.py

Issue 2036623002: Validate map keys in C++ Mojo bindings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 4 years, 7 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
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/tools/bindings/generators/mojom_cpp_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
index d8e0491cc309d0f8475e7eab1b2139925e9b03b6..357c831e640c58bae140d72dd43a522efcf8dc0f 100644
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py
@@ -383,16 +383,21 @@ def GetArrayValidateParamsCtorArgs(kind):
if mojom.IsStringKind(kind):
expected_num_elements = 0
element_is_nullable = False
+ key_validate_params = "nullptr"
element_validate_params = "nullptr"
enum_validate_func = "nullptr"
elif mojom.IsMapKind(kind):
expected_num_elements = 0
- element_is_nullable = mojom.IsNullableKind(kind.value_kind)
- element_validate_params = GetNewArrayValidateParams(kind.value_kind)
+ element_is_nullable = False
+ key_validate_params = GetNewArrayValidateParams(mojom.Array(
+ kind=kind.key_kind))
+ element_validate_params = GetNewArrayValidateParams(mojom.Array(
+ kind=kind.value_kind))
enum_validate_func = "nullptr"
- else:
+ else: # mojom.IsArrayKind(kind)
expected_num_elements = generator.ExpectedArraySize(kind) or 0
element_is_nullable = mojom.IsNullableKind(kind.kind)
+ key_validate_params = "nullptr"
element_validate_params = GetNewArrayValidateParams(kind.kind)
if mojom.IsEnumKind(kind.kind):
enum_validate_func = ("%s::Validate" %
@@ -401,9 +406,12 @@ def GetArrayValidateParamsCtorArgs(kind):
enum_validate_func = "nullptr"
if enum_validate_func == "nullptr":
- return "%d, %s, %s" % (expected_num_elements,
- "true" if element_is_nullable else "false",
- element_validate_params)
+ if key_validate_params == "nullptr":
+ return "%d, %s, %s" % (expected_num_elements,
+ "true" if element_is_nullable else "false",
+ element_validate_params)
+ else:
+ return "%s, %s" % (key_validate_params, element_validate_params)
else:
return "%d, %s" % (expected_num_elements, enum_validate_func)
@@ -415,13 +423,6 @@ def GetNewArrayValidateParams(kind):
return "new mojo::internal::ArrayValidateParams(%s)" % (
GetArrayValidateParamsCtorArgs(kind))
-def GetMapValidateParamsCtorArgs(value_kind):
- # Unlike GetArrayValidateParams, we are given the wrapped kind, instead of
- # the raw array kind. So we wrap the return value of GetArrayValidateParams.
- element_is_nullable = mojom.IsNullableKind(value_kind)
- return "0, %s, %s" % ("true" if element_is_nullable else "false",
- GetNewArrayValidateParams(value_kind))
-
class Generator(generator.Generator):
cpp_filters = {
@@ -435,7 +436,6 @@ class Generator(generator.Generator):
"default_value": DefaultValue,
"expression_to_text": ExpressionToText,
"get_array_validate_params_ctor_args": GetArrayValidateParamsCtorArgs,
- "get_map_validate_params_ctor_args": GetMapValidateParamsCtorArgs,
"get_name_for_kind": GetNameForKind,
"get_pad": pack.GetPad,
"get_qualified_name_for_kind": GetQualifiedNameForKind,
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698