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

ES2019 stable Array.sort() #1151

Closed
gbrail opened this issue Jan 7, 2022 · 9 comments · Fixed by #1526
Closed

ES2019 stable Array.sort() #1151

gbrail opened this issue Jan 7, 2022 · 9 comments · Fixed by #1526
Labels
Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec good first issue Great place to start if you're looking to start an open source "resume"
Milestone

Comments

@gbrail
Copy link
Collaborator

gbrail commented Jan 7, 2022

The greater JavaScript community got excited a while back because "all major JavaScript implementations" have implemented a stable sort for Array.sort().

Rhino, however, has its own sorting implementation in the "Sorting" class that's not stable, as it uses a hybrid quicksort / insertion sort. I realize that this is no longer the state of the art.

(Rhino cannot use the "Collections.sort()" functionality in Java because it does not handle misbehaved comparators in a way that is compatible with the JavaScript specs.)

A great project for an eager computer scientist would be to improve this sorting algorithm.

@gbrail gbrail added the good first issue Great place to start if you're looking to start an open source "resume" label Jan 7, 2022
@p-bakker p-bakker added this to the ES2019 milestone Jan 7, 2022
@p-bakker p-bakker added the Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec label Jan 7, 2022
@angelinakap2
Copy link

Hello @gbrail, I have some experience in coding in JavaScript and am interested in open-source contribution for my Intro to Software Engineering class. Could I possibly be assigned to this code?

@tuchida
Copy link
Contributor

tuchida commented Jan 22, 2022

@angelinakap2 Thank you for your interest.
Rhino is open source, so anyone can create a Pull Request. If you create a Pull Request for this issue, I will review it.

@gbrail
Copy link
Collaborator Author

gbrail commented Jan 22, 2022 via email

@p-bakker
Copy link
Collaborator

Some links that might contain interesting/relevant info:

As for testing: as stable sorting was introduced in ES20219 and we're running agfainst a version of the test262 suite authored in 2020, the functional tests of the stable sorting algorithm ought to be covered by the version of the test262 suite we're running against (assuming such tests are included in the test262 suite). Any tests for the refinements to the algorithm in ES2021 wont be in the version of the test262 suite we're running against (and while we cant upgrade the version of the test262 suite we run against in our CI, you can try to locally run the tests related to the (stable) sorting algorithm from test262 master)

@p-bakker p-bakker changed the title Make Array.sort() stable ES2019 stable Array.sort() Jan 29, 2022
@DanielRosenwasser
Copy link
Contributor

Hey all, I have a PR over at #1494; however, I might have jumped the gun a bit and done a quick implementation using Arrays.sort, not having read this line:

Rhino cannot use the "Collections.sort()" functionality in Java because it does not handle misbehaved comparators in a way that is compatible with the JavaScript specs

Can you give some specifics on what sort of misbehavior can occur there? Because as far as I can tell, the current implementation already performs a copy and ignores external mutations.

@DanielRosenwasser
Copy link
Contributor

Also - the context is that we'd eventually like to merge in microsoft/TypeScript#55728, and while we generally expect a Node.js runtime, we don't want to break anyone building anything custom with Rhino. 😄

@gbrail
Copy link
Collaborator Author

gbrail commented Jun 18, 2024 via email

@gbrail
Copy link
Collaborator Author

gbrail commented Jun 18, 2024

Here's the original issue. It's possible that Arrays.sort is a lot more flexible in more recent versions of Java:

#255

@DanielRosenwasser
Copy link
Contributor

Well let me know if you feel like the current approach is fine - I'm okay with implementing a separate merge sort or something if you'd like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec good first issue Great place to start if you're looking to start an open source "resume"
Projects
None yet
5 participants