Bug 236541

Summary: `Array#{ groupBy, groupByToMap }` should throw a `TypeError` when `this` is `null` or `undefined`
Product: WebKit Reporter: zloirock <zloirock>
Component: JavaScriptCoreAssignee: Yusuke Suzuki <ysuzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: ashvayka, ews-watchlist, joepeck, keith_miller, mark.lam, msaboff, saam, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=235549
Attachments:
Description Flags
Patch none

Description zloirock 2022-02-12 10:07:56 PST
(tested in playwright)

Array.prototype.groupBy.call(null, () => { /* empty */ }) // should be a TypeError
Array.prototype.groupByToMap.call(null, () => { /* empty */ }) // should be a TypeError
Comment 1 Alexey Shvayka 2022-02-14 09:31:55 PST
(In reply to zloirock from comment #0)
> (tested in playwright)
> 
> Array.prototype.groupBy.call(null, () => { /* empty */ }) // should be a
> TypeError
> Array.prototype.groupByToMap.call(null, () => { /* empty */ }) // should be
> a TypeError

Wow, that's a nice catch, thank you.
We've missed "use strict".
Comment 2 Yusuke Suzuki 2022-02-14 09:42:33 PST
Created attachment 451916 [details]
Patch
Comment 3 Alexey Shvayka 2022-02-14 09:45:08 PST
Comment on attachment 451916 [details]
Patch

I wish we could mandate "use strict" for built-ins with exception of Reflect.has, which we need to be sloppy mode JS built-in for inlining + caching.
Comment 4 EWS 2022-02-14 16:15:42 PST
Committed r289780 (247248@main): <https://commits.webkit.org/247248@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 451916 [details].
Comment 5 Radar WebKit Bug Importer 2022-02-14 16:16:18 PST
<rdar://problem/88934440>