diff --git a/CHANGELOG.md b/CHANGELOG.md index 73e3be69310e..19a5f82cfc33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - [`RegExp.escape`](https://github.com/tc39/proposal-regex-escaping) [moved to hex-escape semantics](https://github.com/tc39/proposal-regex-escaping/pull/67) - Some minor updates of [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management) Stage 3 proposal like [explicit-resource-management/217](https://github.com/tc39/proposal-explicit-resource-management/pull/217) - Engines bugs fixes: + - Added a fix of [Safari `{ Object, Map }.groupBy` bug that does not support iterable primitives](https://bugs.webkit.org/show_bug.cgi?id=271524) - Added a fix of [Safari bug with double call of constructor in `Array.fromAsync`](https://bugs.webkit.org/show_bug.cgi?id=271703) - Compat data improvements: - [`URL.parse`](https://url.spec.whatwg.org/#dom-url-parse) added and marked as supported [from FF 126](https://bugzilla.mozilla.org/show_bug.cgi?id=1887611) diff --git a/packages/core-js-compat/src/data.mjs b/packages/core-js-compat/src/data.mjs index 1d6a3e56fa47..531d2622dcef 100644 --- a/packages/core-js-compat/src/data.mjs +++ b/packages/core-js-compat/src/data.mjs @@ -606,10 +606,12 @@ export const data = { safari: '10.0', }, 'es.map.group-by': { - bun: '1.0.19', + // https://bugs.webkit.org/show_bug.cgi?id=271524 + bun: '1.1.2', // bun: '1.0.19', chrome: '117', firefox: '119', - safari: '17.4', + // https://bugs.webkit.org/show_bug.cgi?id=271524 + // safari: '17.4', }, 'es.math.acosh': { chrome: '54', @@ -972,10 +974,12 @@ export const data = { safari: '9.0', }, 'es.object.group-by': { - bun: '1.0.19', + // https://bugs.webkit.org/show_bug.cgi?id=271524 + bun: '1.1.2', // bun: '1.0.19', chrome: '117', firefox: '119', - safari: '17.4', + // https://bugs.webkit.org/show_bug.cgi?id=271524 + // safari: '17.4', }, 'es.object.has-own': { chrome: '93', diff --git a/packages/core-js/modules/es.map.group-by.js b/packages/core-js/modules/es.map.group-by.js index badc33250ac9..2fbfe468e228 100644 --- a/packages/core-js/modules/es.map.group-by.js +++ b/packages/core-js/modules/es.map.group-by.js @@ -6,6 +6,7 @@ var requireObjectCoercible = require('../internals/require-object-coercible'); var iterate = require('../internals/iterate'); var MapHelpers = require('../internals/map-helpers'); var IS_PURE = require('../internals/is-pure'); +var fails = require('../internals/fails'); var Map = MapHelpers.Map; var has = MapHelpers.has; @@ -13,9 +14,15 @@ var get = MapHelpers.get; var set = MapHelpers.set; var push = uncurryThis([].push); +var DOES_NOT_WORK_WITH_PRIMITIVES = IS_PURE || fails(function () { + return Map.groupBy('ab', function (it) { + return it; + }).get('a').length !== 1; +}); + // `Map.groupBy` method // https://github.com/tc39/proposal-array-grouping -$({ target: 'Map', stat: true, forced: IS_PURE }, { +$({ target: 'Map', stat: true, forced: IS_PURE || DOES_NOT_WORK_WITH_PRIMITIVES }, { groupBy: function groupBy(items, callbackfn) { requireObjectCoercible(items); aCallable(callbackfn); diff --git a/packages/core-js/modules/es.object.group-by.js b/packages/core-js/modules/es.object.group-by.js index aa2464c3456a..18799c3e3a14 100644 --- a/packages/core-js/modules/es.object.group-by.js +++ b/packages/core-js/modules/es.object.group-by.js @@ -6,13 +6,22 @@ var aCallable = require('../internals/a-callable'); var requireObjectCoercible = require('../internals/require-object-coercible'); var toPropertyKey = require('../internals/to-property-key'); var iterate = require('../internals/iterate'); +var fails = require('../internals/fails'); +// eslint-disable-next-line es/no-object-map-groupby -- testing +var nativeGroupBy = Object.groupBy; var create = getBuiltIn('Object', 'create'); var push = uncurryThis([].push); +var DOES_NOT_WORK_WITH_PRIMITIVES = !nativeGroupBy || fails(function () { + return nativeGroupBy('ab', function (it) { + return it; + }).a.length !== 1; +}); + // `Object.groupBy` method // https://github.com/tc39/proposal-array-grouping -$({ target: 'Object', stat: true }, { +$({ target: 'Object', stat: true, forced: DOES_NOT_WORK_WITH_PRIMITIVES }, { groupBy: function groupBy(items, callbackfn) { requireObjectCoercible(items); aCallable(callbackfn); diff --git a/tests/compat/tests.js b/tests/compat/tests.js index b7d5c2b19a9f..4fc6952b7545 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -704,7 +704,10 @@ GLOBAL.tests = { && map[Symbol.toStringTag]; }], 'es.map.group-by': function () { - return Map.groupBy; + // https://bugs.webkit.org/show_bug.cgi?id=271524 + return Map.groupBy('ab', function (it) { + return it; + }).get('a').length === 1; }, 'es.math.acosh': function () { // V8 bug: https://code.google.com/p/v8/issues/detail?id=3509 @@ -893,7 +896,10 @@ GLOBAL.tests = { return Object.getPrototypeOf('qwe'); }, 'es.object.group-by': function () { - return Object.groupBy; + // https://bugs.webkit.org/show_bug.cgi?id=271524 + return Object.groupBy('ab', function (it) { + return it; + }).a.length === 1; }, 'es.object.has-own': function () { return Object.hasOwn; diff --git a/tests/unit-global/es.map.group-by.js b/tests/unit-global/es.map.group-by.js index 1cbcdf1607cd..0c40c50d3cc0 100644 --- a/tests/unit-global/es.map.group-by.js +++ b/tests/unit-global/es.map.group-by.js @@ -16,6 +16,7 @@ QUnit.test('Map.groupBy', assert => { assert.deepEqual(toArray(groupBy([1, 2], it => it ** 2)), [[1, [1]], [4, [2]]]); assert.deepEqual(toArray(groupBy([1, 2, 1], it => it ** 2)), [[1, [1, 1]], [4, [2]]]); assert.deepEqual(toArray(groupBy(createIterable([1, 2]), it => it ** 2)), [[1, [1]], [4, [2]]]); + assert.deepEqual(toArray(groupBy('qwe', it => it)), [['q', ['q']], ['w', ['w']], ['e', ['e']]], 'iterable string'); const element = {}; groupBy([element], function (it, i) { diff --git a/tests/unit-global/es.object.group-by.js b/tests/unit-global/es.object.group-by.js index 4a84a61e7546..fd8f0f97d920 100644 --- a/tests/unit-global/es.object.group-by.js +++ b/tests/unit-global/es.object.group-by.js @@ -15,6 +15,7 @@ QUnit.test('Object.groupBy', assert => { assert.deepEqual(entries(groupBy([1, 2], it => it ** 2)), [['1', [1]], ['4', [2]]]); assert.deepEqual(entries(groupBy([1, 2, 1], it => it ** 2)), [['1', [1, 1]], ['4', [2]]]); assert.deepEqual(entries(groupBy(createIterable([1, 2]), it => it ** 2)), [['1', [1]], ['4', [2]]]); + assert.deepEqual(entries(groupBy('qwe', it => it)), [['q', ['q']], ['w', ['w']], ['e', ['e']]], 'iterable string'); const element = {}; groupBy([element], function (it, i) { diff --git a/tests/unit-pure/es.map.group-by.js b/tests/unit-pure/es.map.group-by.js index c73069ff8e27..d512477e9438 100644 --- a/tests/unit-pure/es.map.group-by.js +++ b/tests/unit-pure/es.map.group-by.js @@ -16,6 +16,7 @@ QUnit.test('Map.groupBy', assert => { assert.deepEqual(from(groupBy([1, 2], it => it ** 2)), [[1, [1]], [4, [2]]]); assert.deepEqual(from(groupBy([1, 2, 1], it => it ** 2)), [[1, [1, 1]], [4, [2]]]); assert.deepEqual(from(groupBy(createIterable([1, 2]), it => it ** 2)), [[1, [1]], [4, [2]]]); + assert.deepEqual(from(groupBy('qwe', it => it)), [['q', ['q']], ['w', ['w']], ['e', ['e']]], 'iterable string'); const element = {}; groupBy([element], function (it, i) { diff --git a/tests/unit-pure/es.object.group-by.js b/tests/unit-pure/es.object.group-by.js index bd0acf78a960..c3fbeb140eed 100644 --- a/tests/unit-pure/es.object.group-by.js +++ b/tests/unit-pure/es.object.group-by.js @@ -14,6 +14,7 @@ QUnit.test('Object.groupBy', assert => { assert.deepEqual(entries(groupBy([1, 2], it => it ** 2)), [['1', [1]], ['4', [2]]]); assert.deepEqual(entries(groupBy([1, 2, 1], it => it ** 2)), [['1', [1, 1]], ['4', [2]]]); assert.deepEqual(entries(groupBy(createIterable([1, 2]), it => it ** 2)), [['1', [1]], ['4', [2]]]); + assert.deepEqual(entries(groupBy('qwe', it => it)), [['q', ['q']], ['w', ['w']], ['e', ['e']]], 'iterable string'); const element = {}; groupBy([element], function (it, i) {