Bug 227939 - Implement Array.prototype.findLast and Array.prototype.findLastIndex
Summary: Implement Array.prototype.findLast and Array.prototype.findLastIndex
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-07-13 20:05 PDT by Devin Rousso
Modified: 2021-07-14 20:13 PDT (History)
11 users (show)

See Also:


Attachments
[Patch] WIP (11.13 KB, patch)
2021-07-13 21:02 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (42.75 KB, patch)
2021-07-14 13:01 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (42.85 KB, patch)
2021-07-14 14:27 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (42.81 KB, patch)
2021-07-14 17:47 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2021-07-13 20:05:28 PDT
`Array.prototype.findLast` and `Array.prototype.findLastIndex` just advanced to TC39 stage 3

Proposal: <https://github.com/tc39/proposal-array-find-from-last>
Spec: <https://tc39.es/proposal-array-find-from-last/index.html>

```
const array = [{ value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }];

array.find(n => n.value % 2 === 1); // { value: 1 }
array.findIndex(n => n.value % 2 === 1); // 0

array.findLast(n => n.value % 2 === 1); // { value: 3 }
array.findLastIndex(n => n.value % 2 === 1); // 2
```
Comment 1 Devin Rousso 2021-07-13 21:02:24 PDT
Created attachment 433476 [details]
[Patch] WIP
Comment 2 Yusuke Suzuki 2021-07-13 22:52:07 PDT
Comment on attachment 433476 [details]
[Patch] WIP

View in context: https://bugs.webkit.org/attachment.cgi?id=433476&action=review

r=me

> Source/JavaScriptCore/builtins/ArrayPrototype.js:269
> +        var kValue = array[i];

I like the name like `element` instead of `kValue` even though it is derived from the spec's name since the name is not suitable for WebKit's coding style.
Comment 3 Yusuke Suzuki 2021-07-13 22:52:37 PDT
Comment on attachment 433476 [details]
[Patch] WIP

Can you add tests in JSTests/stress?
Comment 4 Devin Rousso 2021-07-14 13:01:29 PDT
Created attachment 433521 [details]
Patch
Comment 5 Devin Rousso 2021-07-14 14:27:08 PDT
Created attachment 433528 [details]
Patch
Comment 6 Devin Rousso 2021-07-14 17:47:11 PDT
Created attachment 433547 [details]
Patch
Comment 7 EWS 2021-07-14 20:12:00 PDT
Committed r279937 (239681@main): <https://commits.webkit.org/239681@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 433547 [details].
Comment 8 Radar WebKit Bug Importer 2021-07-14 20:13:17 PDT
<rdar://problem/80610784>