-
Notifications
You must be signed in to change notification settings - Fork 649
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
Add support for ES2023 Array
non-mutating methods
#1286
Conversation
(fwiw after ES6, only the year should be used; so instead of ES14, it should be ES2023) |
Array
non-mutating methodsArray
non-mutating methods
cc14ad0
to
32af68f
Compare
@tmikov has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
32af68f
to
641e4cb
Compare
@robik has updated the pull request. You must reimport the pull request before landing. |
@tmikov has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@robik thank you very much for this PR. We are reviewing it - it looks generally good, we might have some minor comments. |
@robik there are some issues in toSorted(), caused partially by Hermes being non-spec compliant. Could you split this into two PRs - one containing everything but toSorted(), which we can probably land faster, and then toSorted(), which might require more time to sort out (pun intended). |
641e4cb
to
d2d3bc4
Compare
@robik has updated the pull request. You must reimport the pull request before landing. |
1 similar comment
@robik has updated the pull request. You must reimport the pull request before landing. |
Thanks! I'm ready for the review 🫡
Sure! I've moved toSorted() implementation to new PR #1298 |
1acb0c6
to
fbc68c3
Compare
@robik has updated the pull request. You must reimport the pull request before landing. |
@tmikov has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@robik thanks a lot! This looks good, we are landing it. |
Summary: Original Author: [email protected] Original Git: b30f0e4 Original Reviewed By: avp Original Revision: D53206784 ### Overview This PR implements partial support for new `Array.prototype` non-mutating methods introduced in ES2023. These are: - [`Array.prototype.toReversed()`](https://262.ecma-international.org/14.0/#sec-array.prototype.toreversed) - [`Array.prototype.toSpliced(start, skipCount, ...items)`](https://262.ecma-international.org/14.0/#sec-array.prototype.tospliced) - [`Array.prototype.with(index, value)`](https://262.ecma-international.org/14.0/#sec-array.prototype.with) `Array.prototype.toSorted()` is implemented in separate PR #1298 as per request. Other Array methods introduced in ES14 seem to already be implemented (`findLast`, `findLastIndex`). Implementation for `TypedArray` methods are not included in this PR and will be provided in another one. ### Motivation Aforementioned methods see support in all major browsers for quite some time [^toReversed][^toSorted][^toSpliced][^with]. Adding support brings hermes closer to full ES2023 coverage and will improve interoperability with browsers. It also should provide slight performance gains across all applications upon adoption. <img width="1438" alt="obraz" src="https://github.com/facebook/hermes/assets/681837/e6f405b7-0645-4d27-8ca7-54f2c0aaf5d6"> [^toReversed]: https://caniuse.com/?search=toReversed [^toSorted]: https://caniuse.com/?search=toSorted [^toSpliced]: https://caniuse.com/?search=toSpliced [^with]: https://caniuse.com/?search=array.with - [x] Implementation - [x] Add tests - [x] Format changes - [ ] Add documentation somewhere? ### Implementation/review notes This is my first contribution to this project. While I have some experience in C++ and have spent some time studying hermes codebase, there might be some slight misusages of your APIs (most notably handles and memory management) and breaking code-style. If so, please let me know and I will try fix them promptly 🙂 Most of the code was inspired/taken from already existing mutating functions. I also tried to apply optimisations that I've noticed in some of the methods (most notably fast path for array element accessing). Pull Request resolved: #1286 Pulled By: tmikov Reviewed By: avp Differential Revision: D54092069 fbshipit-source-id: cc4b58cf9d832538ff22df954e6655075a709aa3
Summary
Overview
This PR implements partial support for new
Array.prototype
non-mutating methods introduced in ES2023. These are:Array.prototype.toReversed()
Array.prototype.toSpliced(start, skipCount, ...items)
Array.prototype.with(index, value)
Array.prototype.toSorted()
is implemented in separate PR #1298 as per request.Other Array methods introduced in ES14 seem to already be implemented (
findLast
,findLastIndex
).Implementation for
TypedArray
methods are not included in this PR and will be provided in another one.Motivation
Aforementioned methods see support in all major browsers for quite some time 1234. Adding support brings hermes closer to full ES2023 coverage and will improve interoperability with browsers. It also should provide slight performance gains across all applications upon adoption.
Tasks
Implementation/review notes
This is my first contribution to this project. While I have some experience in C++ and have spent some time studying hermes codebase, there might be some slight misusages of your APIs (most notably handles and memory management) and breaking code-style. If so, please let me know and I will try fix them promptly 🙂
Most of the code was inspired/taken from already existing mutating functions. I also tried to apply optimisations that I've noticed in some of the methods (most notably fast path for array element accessing).
Test Plan
Code is annotated with algorithm steps from EcmaScript specification for easier verification and maintenance.
I also added tests to verify that methods work as intended. There might be some more edge cases that might be covered based on your experience.
Quick test:
Fixes #1078
Footnotes
https://caniuse.com/?search=toReversed ↩
https://caniuse.com/?search=toSorted ↩
https://caniuse.com/?search=toSpliced ↩
https://caniuse.com/?search=array.with ↩