New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 614223 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Aug 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Array.prototype.sort changes order when sort comparator returns 0

Reported by nbi...@gmail.com, May 24 2016

Issue description

Using a sort comparator, array.sort will change the order of the list if the comparator returns 0.

Chrome version 50.0, windows


<html>

<script>
var countries = ["Afghanistan", "Algeria", "Albania", "American Samoa", "Andean Region", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Cayman Islands", "Central African Republic", "Central America", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo, Dem. Rep.", "Congo, Rep.", "Costa Rica", "Cote d\"Ivoire", "Croatia", "Cuba", "Curacao", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt, Arab Rep.", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Faeroe Islands", "Fiji", "Finland", "France", "French Polynesia", "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hong Kong SAR, China", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Rep.", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Dem. Rep.", "Korea, Rep.", "Kosovo", "Kuwait", "Kyrgyz Republic", "Lao PDR", "Latin America and the Caribbean", "Latvia", "Lebenon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao SAR, China", "Macedonia, FYR", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia, Fed. Sts.", "Middle East (developing only)", "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russian Federation", "Rwanda", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten (Dutch part)", "Slovak Republic", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Sudan", "Southern Cone", "Spain", "Sri Lanka", "St. Kitts and Nevis", "St. Lucia", "St. Martin (French part)", "St. Vincent and the Grenadines", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela, RB", "Vietnam", "Virgin Islands (U.S.)", "West Bank and Gaza", "Yemen, Rep.", "Zambia", "Zimbabwe"];
    
countries.sort(function(a, b) {
  return 0;
});
console.log(countries); // Lebanon, Afghanistan, ...
</script>

</html>
 

Comment 1 Deleted

I have same bug https://jsfiddle.net/159mz60v/
Chrome 50.0.2661.102 (64 bit)
4.2.0-16-generic GNU/Linux

This issue should be merged into https://bugs.chromium.org/p/v8/issues/detail?id=90
Components: Blink
Labels: Needs-Feedback
nbilyk@Could you please check and confirm whether we can merge this issue into bug https://bugs.chromium.org/p/v8/issues/detail?id=90 as per comment 3?

Comment 5 by nbi...@gmail.com, May 24 2016

ssamanoori - Hehe, yes, it appears to be the same issue, and under some hot debate. :)

I'll add my opinion to the commentary - 
The other browsers I've tried that example on all stable sort, and that means if I would like a stable sort, in chrome and only chrome I would need to implement my own, and while not difficult, would not have the benefit of native performance. 
Project Member

Comment 6 by sheriffbot@chromium.org, May 25 2016

Labels: -Needs-Feedback Needs-Review
Owner: ssamanoori@chromium.org
Thank you for providing more feedback. Adding requester "ssamanoori@chromium.org" for another review and adding "Needs-Review" label for tracking.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Status: Assigned (was: Unconfirmed)
Based on the current discussion, I am changing the label.
Components: -Blink Infra>Client>V8
Labels: -Needs-Review
Owner: ----
Status: Unconfirmed (was: Assigned)
Status: Untriaged (was: Unconfirmed)
Components: -Infra>Client>V8 Blink>JavaScript
Cc: yangguo@chromium.org adamk@chromium.org dehrenberg@chromium.org
Components: -Blink>JavaScript Blink>JavaScript>Language
Status: WontFix (was: Untriaged)
I think this is working as intended. The sort algorithm does not need to be stable and if everything is equal (as in your sort function) it works correctly.
We seem to get a lot of complaints about this property of our sort. What kind of benefit do we bring to users by differing from browsers on sort stability?
We seem to get a lot of complaints about this property of our sort. What kind of benefit do we bring to users by differing from browsers on sort stability?
I think it's unwise to try to conform to a non-spec'ed standard such that users can start relying on that. We are seeing that with Date.parse.

Sign in to add a comment