豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 0ad3e00

Browse files
committed
fix a modern Safari bug in Array.prototype.includes with sparse arrays and fromIndex
https://bugs.webkit.org/show_bug.cgi?id=309342
1 parent d7f511b commit 0ad3e00

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Minor performance optimization polyfills of methods from [`Map` upsert proposal](https://github.com/tc39/proposal-upsert)
1010
- Polyfills of methods from [`Map` upsert proposal](https://github.com/tc39/proposal-upsert) from the pure version made generic to make it work with polyfilled and native collections
1111
- Wrap `Symbol.for` in `Symbol.prototype.description` polyfill for correct handling of empty string descriptions
12+
- Fixed [a modern Safari bug](https://bugs.webkit.org/show_bug.cgi?id=309342) in `Array.prototype.includes` with sparse arrays and `fromIndex`
1213
- Fixed one more case (`Iterator.prototype.take`) of a V8 ~ Chromium < 126 [bug](https://issues.chromium.org/issues/336839115)
1314
- Forced replacement of `Iterator.{ concat, zip, zipKeyed }` in the pure version for ensuring proper wrapped `Iterator` instances as the result
1415
- Fixed proxying `.return()` on exhausted iterator from some methods of iterator helpers polyfill to the underlying iterator
@@ -97,6 +98,7 @@
9798
- [`Math.sumPrecise`](https://github.com/tc39/proposal-math-sum) marked as [shipped in V8 ~ Chrome 147](https://issues.chromium.org/issues/374310075#comment16)
9899
- [`Iterator.concat`](https://github.com/tc39/proposal-iterator-sequencing) marked as [shipped in V8 ~ Chrome 146](https://issues.chromium.org/issues/434977727#comment7)
99100
- [`Iterator.concat`](https://github.com/tc39/proposal-iterator-sequencing) marked as shipped in Safari 26.4
101+
- Because of [a bug](https://bugs.webkit.org/show_bug.cgi?id=309342), `Array.prototype.includes` marked as not supported in modern Safari
100102
- Fixed compat data for `parseInt` and `parseFloat`
101103
- Added Deno [2.6.7](https://github.com/denoland/deno/releases/tag/v2.6.7), [2.7.0](https://github.com/denoland/deno/releases/tag/v2.7.0) and [2.7.2](https://github.com/denoland/deno/releases/tag/v2.7.2) compat data mapping
102104
- Added Electron 42 compat data mapping

packages/core-js-compat/src/data.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ export const data = {
314314
// FF99-101 broken on sparse arrays
315315
firefox: '102', // '48',
316316
rhino: '1.8.0',
317-
safari: '10.0',
317+
// Safari broken on sparse arrays with fromIndex
318+
// https://bugs.webkit.org/show_bug.cgi?id=309342
319+
// safari: '10.0',
318320
},
319321
'es.array.index-of': {
320322
chrome: '51',

packages/core-js/modules/es.array.includes.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ var BROKEN_ON_SPARSE = fails(function () {
1010
return !Array(1).includes();
1111
});
1212

13+
// Safari 26.4- bug
14+
var BROKEN_ON_SPARSE_WITH_FROM_INDEX = fails(function () {
15+
// eslint-disable-next-line no-sparse-arrays, es/no-array-prototype-includes -- detection
16+
return [, 1].includes(undefined, 1);
17+
});
18+
1319
// `Array.prototype.includes` method
1420
// https://tc39.es/ecma262/#sec-array.prototype.includes
15-
$({ target: 'Array', proto: true, forced: BROKEN_ON_SPARSE }, {
21+
$({ target: 'Array', proto: true, forced: BROKEN_ON_SPARSE || BROKEN_ON_SPARSE_WITH_FROM_INDEX }, {
1622
includes: function includes(el /* , fromIndex = 0 */) {
1723
return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
1824
}

tests/compat/tests.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,10 @@ GLOBAL.tests = {
526526
'es.array.from': SAFE_ITERATION_CLOSING_SUPPORT,
527527
'es.array.includes': function () {
528528
return Array(1).includes()
529-
&& Array.prototype[Symbol.unscopables].includes;
529+
&& Array.prototype[Symbol.unscopables].includes
530+
// https://bugs.webkit.org/show_bug.cgi?id=309342
531+
// eslint-disable-next-line no-sparse-arrays -- testing
532+
&& ![, 1].includes(undefined, 1);
530533
},
531534
'es.array.index-of': function () {
532535
try {

tests/unit-global/es.array.includes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ QUnit.test('Array#includes', assert => {
1818
assert.false(array.includes({}));
1919
assert.true(Array(1).includes(undefined));
2020
assert.true([NaN].includes(NaN));
21+
// https://bugs.webkit.org/show_bug.cgi?id=309342
22+
// eslint-disable-next-line no-sparse-arrays -- testing
23+
assert.false([, 1].includes(undefined, 1), '`Array#includes(undefined, fromIndex)` should not find holes before fromIndex');
2124
if (STRICT) {
2225
assert.throws(() => includes.call(null, 0), TypeError);
2326
assert.throws(() => includes.call(undefined, 0), TypeError);

tests/unit-pure/es.array.includes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ QUnit.test('Array#includes', assert => {
1515
assert.false(includes(array, {}));
1616
assert.true(includes(Array(1), undefined));
1717
assert.true(includes([NaN], NaN));
18+
// https://bugs.webkit.org/show_bug.cgi?id=309342
19+
// eslint-disable-next-line no-sparse-arrays -- testing
20+
assert.false(includes([, 1], undefined, 1), '`Array#includes(undefined, fromIndex)` should not find holes before fromIndex');
1821
if (STRICT) {
1922
assert.throws(() => includes(null, 0), TypeError);
2023
assert.throws(() => includes(undefined, 0), TypeError);

0 commit comments

Comments
 (0)