Skip to content

Commit 3ebe589

Browse files
committed
add a bugfix for the WebKit Array.prototype.{ groupBy, groupByToMap } implementation
https://bugs.webkit.org/show_bug.cgi?id=236541
1 parent 94c7055 commit 3ebe589

File tree

9 files changed

+29
-14
lines changed

9 files changed

+29
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Changelog
22
##### Unreleased
3+
- Added a [bug](https://bugs.webkit.org/show_bug.cgi?id=236541)fix for the WebKit `Array.prototype.{ groupBy, groupByToMap }` implementation
34
- `atob` / `btoa` marked as [fixed](https://github.com/nodejs/node/pull/41478) in NodeJS 17.5
45
- Added Electron 18.0 compat data mapping
56

packages/core-js/internals/array-method-is-strict.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var fails = require('../internals/fails');
44
module.exports = function (METHOD_NAME, argument) {
55
var method = [][METHOD_NAME];
66
return !!method && fails(function () {
7-
// eslint-disable-next-line no-useless-call,no-throw-literal -- required for testing
8-
method.call(null, argument || function () { throw 1; }, 1);
7+
// eslint-disable-next-line no-useless-call -- required for testing
8+
method.call(null, argument || function () { return 1; }, 1);
99
});
1010
};

packages/core-js/modules/esnext.array.group-by-to-map.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var uncurryThis = require('../internals/function-uncurry-this');
66
var IndexedObject = require('../internals/indexed-object');
77
var toObject = require('../internals/to-object');
88
var lengthOfArrayLike = require('../internals/length-of-array-like');
9+
var arrayMethodIsStrict = require('../internals/array-method-is-strict');
910
var addToUnscopables = require('../internals/add-to-unscopables');
1011

1112
var Map = getBuiltIn('Map');
@@ -17,7 +18,8 @@ var push = uncurryThis([].push);
1718

1819
// `Array.prototype.groupByToMap` method
1920
// https://github.com/tc39/proposal-array-grouping
20-
$({ target: 'Array', proto: true }, {
21+
// https://bugs.webkit.org/show_bug.cgi?id=236541
22+
$({ target: 'Array', proto: true, forced: !arrayMethodIsStrict('groupByToMap') }, {
2123
groupByToMap: function groupByToMap(callbackfn /* , thisArg */) {
2224
var O = toObject(this);
2325
var self = IndexedObject(O);

packages/core-js/modules/esnext.array.group-by.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict';
22
var $ = require('../internals/export');
33
var $groupBy = require('../internals/array-group-by');
4+
var arrayMethodIsStrict = require('../internals/array-method-is-strict');
45
var addToUnscopables = require('../internals/add-to-unscopables');
56

67
// `Array.prototype.groupBy` method
78
// https://github.com/tc39/proposal-array-grouping
8-
$({ target: 'Array', proto: true }, {
9+
// https://bugs.webkit.org/show_bug.cgi?id=236541
10+
$({ target: 'Array', proto: true, forced: !arrayMethodIsStrict('groupBy') }, {
911
groupBy: function groupBy(callbackfn /* , thisArg */) {
1012
var thisArg = arguments.length > 1 ? arguments[1] : undefined;
1113
return $groupBy(this, callbackfn, thisArg);

tests/compat/tests.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,10 +1275,20 @@ GLOBAL.tests = {
12751275
return [].findLastIndex;
12761276
},
12771277
'esnext.array.group-by': function () {
1278-
return [].groupBy;
1278+
try {
1279+
// https://bugs.webkit.org/show_bug.cgi?id=236541
1280+
Array.prototype.groupBy.call(null, function () { /* empty */ });
1281+
return false;
1282+
} catch (error) { /* empty */ }
1283+
return Array.prototype.groupBy;
12791284
},
12801285
'esnext.array.group-by-to-map': function () {
1281-
return [].groupByToMap;
1286+
try {
1287+
// https://bugs.webkit.org/show_bug.cgi?id=236541
1288+
Array.prototype.groupByToMap.call(null, function () { /* empty */ });
1289+
return false;
1290+
} catch (error) { /* empty */ }
1291+
return Array.prototype.groupByToMap;
12821292
},
12831293
'esnext.array.is-template-object': function () {
12841294
return Array.isTemplateObject;

tests/pure/esnext.array.group-by-to-map.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ QUnit.test('Array#groupByToMap', assert => {
2525
);
2626
assert.deepEqual(from(groupByToMap(Array(3), it => it)), [[undefined, [undefined, undefined, undefined]]], '#3');
2727
if (STRICT) {
28-
assert.throws(() => groupByToMap(null, () => { /* empty */ }), TypeError);
29-
assert.throws(() => groupByToMap(undefined, () => { /* empty */ }), TypeError);
28+
assert.throws(() => groupByToMap(null, () => { /* empty */ }), TypeError, 'null this -> TypeError');
29+
assert.throws(() => groupByToMap(undefined, () => { /* empty */ }), TypeError, 'undefined this -> TypeError');
3030
}
3131
array = [1];
3232
// eslint-disable-next-line object-shorthand -- constructor

tests/pure/esnext.array.group-by.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ QUnit.test('Array#groupBy', assert => {
2424
);
2525
assert.deepEqual(groupBy(Array(3), it => it), { undefined: [undefined, undefined, undefined] }, '#3');
2626
if (STRICT) {
27-
assert.throws(() => groupBy(null, () => { /* empty */ }), TypeError);
28-
assert.throws(() => groupBy(undefined, () => { /* empty */ }), TypeError);
27+
assert.throws(() => groupBy(null, () => { /* empty */ }), TypeError, 'null this -> TypeError');
28+
assert.throws(() => groupBy(undefined, () => { /* empty */ }), TypeError, 'undefined this -> TypeError');
2929
}
3030
array = [1];
3131
// eslint-disable-next-line object-shorthand -- constructor

tests/tests/esnext.array.group-by-to-map.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ QUnit.test('Array#groupByToMap', assert => {
2727
);
2828
assert.deepEqual(from(Array(3).groupByToMap(it => it)), [[undefined, [undefined, undefined, undefined]]], '#3');
2929
if (STRICT) {
30-
assert.throws(() => groupByToMap.call(null, () => { /* empty */ }), TypeError);
31-
assert.throws(() => groupByToMap.call(undefined, () => { /* empty */ }), TypeError);
30+
assert.throws(() => groupByToMap.call(null, () => { /* empty */ }), TypeError, 'null this -> TypeError');
31+
assert.throws(() => groupByToMap.call(undefined, () => { /* empty */ }), TypeError, 'undefined this -> TypeError');
3232
}
3333
array = [1];
3434
// eslint-disable-next-line object-shorthand -- constructor

tests/tests/esnext.array.group-by.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ QUnit.test('Array#groupBy', assert => {
2727
);
2828
assert.deepEqual(Array(3).groupBy(it => it), { undefined: [undefined, undefined, undefined] }, '#3');
2929
if (STRICT) {
30-
assert.throws(() => groupBy.call(null, () => { /* empty */ }), TypeError);
31-
assert.throws(() => groupBy.call(undefined, () => { /* empty */ }), TypeError);
30+
assert.throws(() => groupBy.call(null, () => { /* empty */ }), TypeError, 'null this -> TypeError');
31+
assert.throws(() => groupBy.call(undefined, () => { /* empty */ }), TypeError, 'undefined this -> TypeError');
3232
}
3333
array = [1];
3434
// eslint-disable-next-line object-shorthand -- constructor

0 commit comments

Comments
 (0)