Skip to content

Commit

Permalink
add a fix for FF99+ Array.prototype.includes broken on sparse arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 28, 2022
1 parent 0ea8a60 commit 66be5f0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Changelog
##### Unreleased
- Nothing
- Added a fix for FF99+ `Array.prototype.includes` broken on sparse arrays

##### 3.22.2 - 2022.04.21
- Fixed `URLSearchParams` in IE8- that was broken in the previous release
Expand Down
3 changes: 2 additions & 1 deletion packages/core-js-compat/src/data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ export const data = {
'es.array.includes': {
chrome: '53',
edge: '14',
firefox: '48',
// FF99+ broken on sparse arrays

This comment has been minimized.

Copy link
@ljharb

ljharb May 3, 2022

shouldn't people on FF 48-98 not need the polyfill tho?

This comment has been minimized.

Copy link
@zloirock

zloirock May 3, 2022

Author Owner

Since in all tools it possible define only lower bar and it's not possible define ranges - they need it too.

This comment has been minimized.

Copy link
@ljharb

ljharb May 3, 2022

gotcha, seems like an unfortunate tooling limitation

// firefox: '48',
safari: '10.0',
},
'es.array.index-of': {
Expand Down
8 changes: 7 additions & 1 deletion packages/core-js/modules/es.array.includes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
'use strict';
var $ = require('../internals/export');
var $includes = require('../internals/array-includes').includes;
var fails = require('../internals/fails');
var addToUnscopables = require('../internals/add-to-unscopables');

// FF99+ bug
var BROKEN_ON_SPARSE = fails(function () {
return !Array(1).includes();
});

// `Array.prototype.includes` method
// https://tc39.es/ecma262/#sec-array.prototype.includes
$({ target: 'Array', proto: true }, {
$({ target: 'Array', proto: true, forced: BROKEN_ON_SPARSE }, {
includes: function includes(el /* , fromIndex = 0 */) {
return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ GLOBAL.tests = {
},
'es.array.from': SAFE_ITERATION_CLOSING_SUPPORT,
'es.array.includes': function () {
return Array.prototype[Symbol.unscopables].includes;
return Array(1).includes()
&& Array.prototype[Symbol.unscopables].includes;
},
'es.array.index-of': function () {
try {
Expand Down

0 comments on commit 66be5f0

Please sign in to comment.