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

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

Issue 524703004: Mojo: validate nullability in Java serialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Ben's comments. Created 6 years, 3 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/java_templates/struct_definition.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_java_generator.py
diff --git a/mojo/public/tools/bindings/generators/mojom_java_generator.py b/mojo/public/tools/bindings/generators/mojom_java_generator.py
index 91e8b8e0a578702157417f1d12783112ac468802..6b338e3871c5f34ddd487b4a7448c14e2ec54e48 100644
--- a/mojo/public/tools/bindings/generators/mojom_java_generator.py
+++ b/mojo/public/tools/bindings/generators/mojom_java_generator.py
@@ -165,20 +165,9 @@ def GetArrayNullabilityFlags(kind):
return " | ".join(flags_to_set)
-@contextfilter
-def DecodeMethod(context, kind, offset, bit):
- def _DecodeMethodName(kind):
- if mojom.IsAnyArrayKind(kind):
- return _DecodeMethodName(kind.kind) + 's'
- if mojom.IsEnumKind(kind):
- return _DecodeMethodName(mojom.INT32)
- if mojom.IsInterfaceRequestKind(kind):
- return "readInterfaceRequest"
- if mojom.IsInterfaceKind(kind):
- return "readServiceInterface"
- return _spec_to_decode_method[kind.spec]
- methodName = _DecodeMethodName(kind)
- params = [ str(offset) ]
+def AppendEncodeDecodeParams(initial_params, context, kind, bit):
+ """ Appends standard parameters shared between encode and decode calls. """
+ params = list(initial_params)
if (kind == mojom.BOOL):
params.append(str(bit))
if mojom.IsReferenceKind(kind):
@@ -196,23 +185,29 @@ def DecodeMethod(context, kind, offset, bit):
params.append('%s.MANAGER' % GetJavaType(context, kind))
if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind):
params.append('%s.MANAGER' % GetJavaType(context, kind.kind))
+ return params
+
+
+@contextfilter
+def DecodeMethod(context, kind, offset, bit):
+ def _DecodeMethodName(kind):
+ if mojom.IsAnyArrayKind(kind):
+ return _DecodeMethodName(kind.kind) + 's'
+ if mojom.IsEnumKind(kind):
+ return _DecodeMethodName(mojom.INT32)
+ if mojom.IsInterfaceRequestKind(kind):
+ return "readInterfaceRequest"
+ if mojom.IsInterfaceKind(kind):
+ return "readServiceInterface"
+ return _spec_to_decode_method[kind.spec]
+ methodName = _DecodeMethodName(kind)
+ params = AppendEncodeDecodeParams([ str(offset) ], context, kind, bit)
return '%s(%s)' % (methodName, ', '.join(params))
@contextfilter
def EncodeMethod(context, kind, variable, offset, bit):
- params = [ variable, str(offset) ]
- if (kind == mojom.BOOL):
- params.append(str(bit))
- if mojom.IsAnyArrayKind(kind):
- if mojom.IsFixedArrayKind(kind):
- params.append(str(kind.length))
- else:
- params.append(
- "org.chromium.mojo.bindings.BindingsHelper.UNSPECIFIED_ARRAY_LENGTH");
- if mojom.IsInterfaceKind(kind):
- params.append('%s.MANAGER' % GetJavaType(context, kind))
- if mojom.IsAnyArrayKind(kind) and mojom.IsInterfaceKind(kind.kind):
- params.append('%s.MANAGER' % GetJavaType(context, kind.kind))
+ params = AppendEncodeDecodeParams(
+ [ variable, str(offset) ], context, kind, bit)
return 'encode(%s)' % ', '.join(params)
def GetPackage(module):
« no previous file with comments | « mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698