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

Make Array.prototype.sort stable -- version that builds #1526

Merged
merged 3 commits into from
Jul 17, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion rhino/src/main/java/org/mozilla/javascript/NativeArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,15 @@ public int compare(final Object x, final Object y) {
working[i] = getRawElem(o, i);
}

Sorting.get().hybridSort(working, comparator);
// Java's 'Arrays.sort' is guaranteed to be stable so we can use it; however,
// if the comparator is not consistent, it throws an IllegalArgumentException.
// In case where the comparator is not consistent, the ECMAScript specification states
// that sort order is implementation-defined, so we can just return the original array.
try {
Arrays.sort(working, comparator);
} catch (IllegalArgumentException e) {
return o;
}

// copy the working array back into thisObj
for (int i = 0; i < length; ++i) {
Expand Down
129 changes: 0 additions & 129 deletions rhino/src/main/java/org/mozilla/javascript/Sorting.java

This file was deleted.

195 changes: 0 additions & 195 deletions rhino/src/test/java/org/mozilla/javascript/tests/SortingTest.java

This file was deleted.

2 changes: 0 additions & 2 deletions tests/testsrc/test262.properties
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ built-ins/Array 146/2670 (5.47%)
prototype/slice/target-array-with-non-configurable-property.js
prototype/some/15.4.4.17-5-1-s.js non-strict
prototype/sort/S15.4.4.11_A8.js non-strict
prototype/sort/stability-2048-elements.js
prototype/sort/stability-513-elements.js
prototype/splice/clamps-length-to-integer-limit.js
prototype/splice/create-ctor-non-object.js
prototype/splice/create-ctor-poisoned.js
Expand Down
Loading