diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-09-12 15:09:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-12 15:09:47 -0700 |
commit | 2bd55a9fbcd2815b3332bf309bc20f59eef0b36b (patch) | |
tree | 049577e28c1ee1b2f29fc71c22d06ec6016cae45 /src/google | |
parent | 6a4ffb2f90ef7bbd3f20f2a1db4948630ad37dc8 (diff) |
Fix js conformance tests. (#3604)
* Fix js conformance tests.
* Remove old incorrect compatibility tests
Diffstat (limited to 'src/google')
-rwxr-xr-x | src/google/protobuf/compiler/js/js_generator.cc | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 73d32762..a25de76c 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2876,6 +2876,29 @@ void Generator::GenerateClassDeserializeBinaryField( "Group" : "Message", "grpfield", (field->type() == FieldDescriptor::TYPE_GROUP) ? (SimpleItoa(field->number()) + ", ") : ""); + } else if (field->is_repeated() && + field->cpp_type() != FieldDescriptor::CPPTYPE_STRING) { + printer->Print( + " if (reader.getWireType() == 2) {\n" + " var value = /** @type {$fieldtype_packed$} */ " + "(reader.readPacked$reader$());\n" + " msg.set$list_name$(value);\n" + " } else {\n" + " var value = /** @type {$fieldtype$} */ " + "(reader.read$reader$());\n" + " msg.add$name$(value);\n" + " }\n", + "fieldtype_packed", JSFieldTypeAnnotation(options, field, false, true, + /* singular_if_not_packed */ false, + BYTES_U8), + "fieldtype", JSFieldTypeAnnotation(options, field, false, true, + /* singular_if_not_packed */ true, + BYTES_U8), + "reader", JSBinaryReaderMethodType(field), + "list_name", JSGetterName(options, field), + "name", JSGetterName(options, field, + BYTES_DEFAULT, /* drop_list = */ true) + ); } else { printer->Print( " var value = /** @type {$fieldtype$} */ " @@ -2887,14 +2910,15 @@ void Generator::GenerateClassDeserializeBinaryField( JSBinaryReadWriteMethodName(field, /* is_writer = */ false)); } - if (field->is_repeated() && !field->is_packed()) { + if (field->is_repeated() && + (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE || + field->cpp_type() == FieldDescriptor::CPPTYPE_STRING)) { printer->Print( " msg.add$name$(value);\n", "name", JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true)); - } else { - // Singular fields, and packed repeated fields, receive a |value| either - // as the field's value or as the array of all the field's values; set - // this as the field's value directly. + } else if (!field->is_repeated()) { + // Singular fields, receive a |value| as the field's value ; set this as + // the field's value directly. printer->Print( " msg.set$name$(value);\n", "name", JSGetterName(options, field)); |