down integration from internal
diff --git a/js/binary/writer.js b/js/binary/writer.js
index 287d29c..ae1c29b 100644
--- a/js/binary/writer.js
+++ b/js/binary/writer.js
@@ -800,6 +800,38 @@
/**
+ * Writes a message set extension to the buffer.
+ * @param {number} field The field number for the extension.
+ * @param {?MessageType} value The extension message object to write. Note that
+ * message set can only have extensions with type of optional message.
+ * @param {function(!MessageTypeNonNull, !jspb.BinaryWriter)} writerCallback
+ * Will be invoked with the value to write and the writer to write it with.
+ * @template MessageType
+ * Use go/closure-ttl to declare a non-nullable version of MessageType. Replace
+ * the null in blah|null with none. This is necessary because the compiler will
+ * infer MessageType to be nullable if the value parameter is nullable.
+ * @template MessageTypeNonNull :=
+ * cond(isUnknown(MessageType), unknown(),
+ * mapunion(MessageType, (X) =>
+ * cond(eq(X, 'null'), none(), X)))
+ * =:
+ */
+jspb.BinaryWriter.prototype.writeMessageSet = function(
+ field, value, writerCallback) {
+ if (value == null) return;
+ // The wire format for a message set is defined by
+ // google3/net/proto/message_set.proto
+ this.writeFieldHeader_(1, jspb.BinaryConstants.WireType.START_GROUP);
+ this.writeFieldHeader_(2, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeSignedVarint32(field);
+ var bookmark = this.beginDelimited_(3);
+ writerCallback(value, this);
+ this.endDelimited_(bookmark);
+ this.writeFieldHeader_(1, jspb.BinaryConstants.WireType.END_GROUP);
+};
+
+
+/**
* Writes a group message to the buffer.
*
* @param {number} field The field number.
diff --git a/js/message.js b/js/message.js
index 1ca9fac..eb54678 100644
--- a/js/message.js
+++ b/js/message.js
@@ -183,9 +183,6 @@
* calling fromObject. Enabling this might disable the JSCompiler's ability
* to dead code eliminate fields used in protocol buffers that are never
* used in an application.
- * NOTE: By default no protos actually have a fromObject method. You need to
- * add the jspb.generate_from_object options to the proto definition to
- * activate the feature.
* By default this is enabled for test code only.
*/
goog.define('jspb.Message.GENERATE_FROM_OBJECT', !goog.DISALLOW_TEST_ONLY_CODE);
@@ -703,20 +700,7 @@
* @protected
*/
jspb.Message.getRepeatedField = function(msg, fieldNumber) {
- if (fieldNumber < msg.pivot_) {
- var index = jspb.Message.getIndex_(msg, fieldNumber);
- var val = msg.array[index];
- if (val === jspb.Message.EMPTY_LIST_SENTINEL_) {
- return msg.array[index] = [];
- }
- return val;
- }
-
- var val = msg.extensionObject_[fieldNumber];
- if (val === jspb.Message.EMPTY_LIST_SENTINEL_) {
- return msg.extensionObject_[fieldNumber] = [];
- }
- return val;
+ return /** @type {!Array} */ (jspb.Message.getField(msg, fieldNumber));
};
diff --git a/js/test.proto b/js/test.proto
index bc1a9b6..1c0d255 100644
--- a/js/test.proto
+++ b/js/test.proto
@@ -106,6 +106,13 @@
}
}
+message MineField {
+ // document.cookie is a banned property in a couple of conformance check
+ // configs at Google. Verify that having a field called cookie doesn't confuse
+ // the compiler and break the build.
+ optional string cookie = 1;
+}
+
message IsExtension {
extend HasExtensions {
optional IsExtension ext_field = 100;
@@ -261,7 +268,6 @@
}
message TestMapFieldsNoBinary {
-
map<string, string> map_string_string = 1;
map<string, int32> map_string_int32 = 2;
map<string, int64> map_string_int64 = 3;
@@ -285,7 +291,6 @@
}
message MapValueMessageNoBinary {
-
optional int32 foo = 1;
}