Fix serialization of arrays and maps.

R=azani@chromium.org
BUG=#461

Review URL: https://codereview.chromium.org/1433023003 .
diff --git a/mojom/mojom_parser/bin/linux64/mojom_parser.sha1 b/mojom/mojom_parser/bin/linux64/mojom_parser.sha1
index 5a2ecf6..6043978 100644
--- a/mojom/mojom_parser/bin/linux64/mojom_parser.sha1
+++ b/mojom/mojom_parser/bin/linux64/mojom_parser.sha1
@@ -1 +1 @@
-aadd14494d73a70786c30ca6fb035ac3f3f7a045
\ No newline at end of file
+1cd55327af9377b47c19f07ced12f607668075d6
\ No newline at end of file
diff --git a/mojom/mojom_parser/serialization/serialization.go b/mojom/mojom_parser/serialization/serialization.go
index f114660..80a7241 100644
--- a/mojom/mojom_parser/serialization/serialization.go
+++ b/mojom/mojom_parser/serialization/serialization.go
@@ -308,8 +308,12 @@
 	case mojom.HandleTypeRef:
 		return translateHandleType(t)
 	case mojom.ArrayTypeRef:
+		return translateArrayType(&t)
+	case *mojom.ArrayTypeRef:
 		return translateArrayType(t)
 	case mojom.MapTypeRef:
+		return translateMapType(&t)
+	case *mojom.MapTypeRef:
 		return translateMapType(t)
 	case *mojom.UserTypeRef:
 		return translateUserTypeRef(t)
@@ -368,14 +372,14 @@
 	return &mojom_types.TypeHandleType{mojom_types.HandleType{handleType.Nullable(), kind}}
 }
 
-func translateArrayType(arrayType mojom.ArrayTypeRef) *mojom_types.TypeArrayType {
+func translateArrayType(arrayType *mojom.ArrayTypeRef) *mojom_types.TypeArrayType {
 	return &mojom_types.TypeArrayType{mojom_types.ArrayType{
 		Nullable:    arrayType.Nullable(),
 		FixedLength: int32(arrayType.FixedLength()),
 		ElementType: translateTypeRef(arrayType.ElementType())}}
 }
 
-func translateMapType(mapType mojom.MapTypeRef) *mojom_types.TypeMapType {
+func translateMapType(mapType *mojom.MapTypeRef) *mojom_types.TypeMapType {
 	return &mojom_types.TypeMapType{mojom_types.MapType{
 		Nullable:  mapType.Nullable(),
 		KeyType:   translateTypeRef(mapType.KeyType()),
diff --git a/mojom/mojom_parser/serialization/serialization_test.go b/mojom/mojom_parser/serialization/serialization_test.go
index 95fc401..9905f64 100644
--- a/mojom/mojom_parser/serialization/serialization_test.go
+++ b/mojom/mojom_parser/serialization/serialization_test.go
@@ -88,6 +88,122 @@
 	test := singleFileTest{}
 
 	////////////////////////////////////////////////////////////
+	// Test Case: array of int32
+	////////////////////////////////////////////////////////////
+	{
+
+		contents := `
+	struct Foo{
+	  array<int32> bar1;
+	  array<int32, 7> bar2;
+	  array<int32>? bar3;
+	  array<int32, 8>? bar4;
+	};`
+
+		test.addTestCase("", contents)
+
+		// DeclaredMojomObjects
+		test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TYPE_KEY:Foo"}
+
+		// ResolvedTypes
+
+		// struct Foo
+		test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
+			DeclData: test.newDeclData("Foo", "Foo"),
+			Fields: []mojom_types.StructField{
+				// field bar1 is not nullable and not fixed length
+				{
+					DeclData: test.newDeclData("bar1", ""),
+					Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{
+						false, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32}}},
+				},
+				// field bar2 is not nullable and fixed length of 7
+				{
+					DeclData: test.newDeclData("bar2", ""),
+					Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{
+						false, 7, &mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32}}},
+				},
+				// field bar3 is nullable and not fixed length
+				{
+					DeclData: test.newDeclData("bar3", ""),
+					Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{
+						true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32}}},
+				},
+				// field bar4 is nullable and fixed length of 8
+				{
+					DeclData: test.newDeclData("bar4", ""),
+					Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{
+						true, 8, &mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32}}},
+				},
+			},
+		}}
+
+		test.endTestCase()
+	}
+
+	////////////////////////////////////////////////////////////
+	// Test Case: map string to int32
+	////////////////////////////////////////////////////////////
+	{
+
+		contents := `
+	struct Foo{
+	  map<string,  int32>  bar1;
+	  map<string?, int32>  bar2;
+	  map<string,  int32>? bar3;
+	  map<string?, int32>? bar4;
+	};`
+
+		test.addTestCase("", contents)
+
+		// DeclaredMojomObjects
+		test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TYPE_KEY:Foo"}
+
+		// ResolvedTypes
+
+		// struct Foo
+		test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
+			DeclData: test.newDeclData("Foo", "Foo"),
+			Fields: []mojom_types.StructField{
+				// field bar1 is non-nullable with a non-nullable key.
+				{
+					DeclData: test.newDeclData("bar1", ""),
+					Type: &mojom_types.TypeMapType{mojom_types.MapType{
+						false,
+						&mojom_types.TypeStringType{mojom_types.StringType{false}},
+						&mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32}}},
+				},
+				// field bar2 is non-nullable with a nullable key.
+				{
+					DeclData: test.newDeclData("bar2", ""),
+					Type: &mojom_types.TypeMapType{mojom_types.MapType{
+						false,
+						&mojom_types.TypeStringType{mojom_types.StringType{true}},
+						&mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32}}},
+				},
+				// field bar3 is nullable with a non-nullable key.
+				{
+					DeclData: test.newDeclData("bar3", ""),
+					Type: &mojom_types.TypeMapType{mojom_types.MapType{
+						true,
+						&mojom_types.TypeStringType{mojom_types.StringType{false}},
+						&mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32}}},
+				},
+				// field bar4 is nullable with a nullable key.
+				{
+					DeclData: test.newDeclData("bar4", ""),
+					Type: &mojom_types.TypeMapType{mojom_types.MapType{
+						true,
+						&mojom_types.TypeStringType{mojom_types.StringType{true}},
+						&mojom_types.TypeSimpleType{mojom_types.SimpleType_InT32}}},
+				},
+			},
+		}}
+
+		test.endTestCase()
+	}
+
+	////////////////////////////////////////////////////////////
 	// Test Case
 	////////////////////////////////////////////////////////////
 	{