Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix js message pivot selection #6813

Merged
merged 4 commits into from Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -1217,6 +1217,7 @@ js_EXTRA_DIST= \
js/test_bootstrap.js \
js/testbinary.proto \
js/testempty.proto \
js/testlargenumbers.proto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is missing a \

js/experimental/runtime/testing/jasmine_protobuf.js \
js/experimental/runtime/testing/ensure_custom_equality_test.js \
js/experimental/runtime/testing/binary/test_message.js \
Expand Down
1 change: 1 addition & 0 deletions js/gulpfile.js
Expand Up @@ -37,6 +37,7 @@ var group1Protos = [
'testbinary.proto',
'testempty.proto',
'test.proto',
'testlargenumbers.proto',
];

var group2Protos = [
Expand Down
5 changes: 4 additions & 1 deletion js/message.js
Expand Up @@ -1112,8 +1112,11 @@ jspb.Message.setFieldIgnoringDefault_ = function(
goog.asserts.assertInstanceof(msg, jspb.Message);
if (value !== defaultValue) {
jspb.Message.setField(msg, fieldNumber, value);
} else {
} else if (fieldNumber < msg.pivot_) {
msg.array[jspb.Message.getIndex_(msg, fieldNumber)] = null;
} else {
jspb.Message.maybeInitEmptyExtensionObject_(msg);
delete msg.extensionObject_[fieldNumber];
}
return msg;
};
Expand Down
34 changes: 34 additions & 0 deletions js/message_test.js
Expand Up @@ -118,6 +118,8 @@ goog.require('proto.jspb.test.ExtensionMessage');
goog.require('proto.jspb.test.TestExtensionsMessage');

goog.require('proto.jspb.test.TestAllowAliasEnum');
// CommonJS-LoadFromFile: testlargenumbers_pb proto.jspb.test
goog.require('proto.jspb.test.MessageWithLargeFieldNumbers');

describe('Message test suite', function() {
var stubs = new goog.testing.PropertyReplacer();
Expand Down Expand Up @@ -1075,4 +1077,36 @@ describe('Message test suite', function() {
assertEquals(12, package2Message.getA());
});


it('testMessageWithLargeFieldNumbers', function() {
var message = new proto.jspb.test.MessageWithLargeFieldNumbers;

message.setAString('string');
assertEquals('string', message.getAString());

message.setAString('');
assertEquals('', message.getAString());

message.setAString('new string');
assertEquals('new string', message.getAString());

message.setABoolean(true);
assertEquals(true, message.getABoolean());

message.setABoolean(false);
assertEquals(false, message.getABoolean());

message.setABoolean(true);
assertEquals(true, message.getABoolean());

message.setAInt(42);
assertEquals(42, message.getAInt());

message.setAInt(0);
assertEquals(0, message.getAInt());

message.setAInt(42);
assertEquals(42, message.getAInt());
});

});
40 changes: 40 additions & 0 deletions js/testlargenumbers.proto
@@ -0,0 +1,40 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax = "proto3";

package jspb.test;


message MessageWithLargeFieldNumbers {
string a_string = 1;
bool a_boolean = 900;
int32 a_int = 5000;
}