From dcc8ffd9c6fab3c82d3d6642a35a584aa0a3f64b Mon Sep 17 00:00:00 2001 From: Lian Duan Date: Thu, 25 Jul 2019 01:32:21 +0200 Subject: [PATCH] Fixed JS parsing of default map values (#6394) --- js/map.js | 8 ++++++-- src/google/protobuf/compiler/js/js_generator.cc | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/js/map.js b/js/map.js index b9a48afed..734b1566f 100644 --- a/js/map.js +++ b/js/map.js @@ -465,11 +465,15 @@ jspb.Map.prototype.serializeBinary = function( * entries with unset keys is required for maps to be backwards compatible * with the repeated message representation described here: goo.gl/zuoLAC * + * @param {V=} opt_defaultValue + * The default value for the type of map values. + * */ jspb.Map.deserializeBinary = function(map, reader, keyReaderFn, valueReaderFn, - opt_valueReaderCallback, opt_defaultKey) { + opt_valueReaderCallback, opt_defaultKey, + opt_defaultValue) { var key = opt_defaultKey; - var value = undefined; + var value = opt_defaultValue; while (reader.nextField()) { if (reader.isEndGroup()) { diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 88c9a0fb3..2a797e9b5 100644 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -3142,6 +3142,7 @@ void Generator::GenerateClassDeserializeBinaryField( printer->Print(", null"); } printer->Print(", $defaultKey$", "defaultKey", JSFieldDefault(key_field)); + printer->Print(", $defaultValue$", "defaultValue", JSFieldDefault(value_field)); printer->Print(");\n"); printer->Print(" });\n"); } else {