Skip to content

Commit 5b908c2

Browse files
committed
add a fix of Safari bug with double call of constructor in Array.fromAsync
https://bugs.webkit.org/show_bug.cgi?id=271703
1 parent 92f8618 commit 5b908c2

File tree

6 files changed

+44
-4
lines changed

6 files changed

+44
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
- Added [`URL.parse`](https://url.spec.whatwg.org/#dom-url-parse), [url/825](https://github.com/whatwg/url/pull/825)
2020
- [`RegExp.escape`](https://github.com/tc39/proposal-regex-escaping) [moved to hex-escape semantics](https://github.com/tc39/proposal-regex-escaping/pull/67)
2121
- 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)
22+
- Engines bugs fixes:
23+
- Added a fix of [Safari bug with double call of constructor in `Array.fromAsync`](https://bugs.webkit.org/show_bug.cgi?id=271703)
2224
- Compat data improvements:
2325
- [`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)
2426
- `URL.canParse` fixed and marked as supported [from Bun 1.1.0](https://github.com/oven-sh/bun/pull/9710)

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1982,11 +1982,13 @@ export const data = {
19821982
// bun: '1.0.23',
19831983
},
19841984
'esnext.array.from-async': {
1985-
bun: '0.3.0',
1985+
// https://bugs.webkit.org/show_bug.cgi?id=271703
1986+
bun: '1.1.2', // bun: '0.3.0',
19861987
chrome: '121',
19871988
deno: '1.38',
19881989
firefox: '115',
1989-
safari: '16.4',
1990+
// https://bugs.webkit.org/show_bug.cgi?id=271703
1991+
// safari: '16.4',
19901992
},
19911993
// TODO: Remove from `core-js@4`
19921994
'esnext.array.at': null,
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
'use strict';
22
var $ = require('../internals/export');
33
var fromAsync = require('../internals/array-from-async');
4+
var fails = require('../internals/fails');
5+
6+
var nativeFromAsync = Array.fromAsync;
7+
// https://bugs.webkit.org/show_bug.cgi?id=271703
8+
var INCORRECT_CONSTRUCTURING = !nativeFromAsync || fails(function () {
9+
var counter = 0;
10+
nativeFromAsync.call(function () {
11+
counter++;
12+
return [];
13+
}, { length: 0 });
14+
return counter !== 1;
15+
});
416

517
// `Array.fromAsync` method
618
// https://github.com/tc39/proposal-array-from-async
7-
$({ target: 'Array', stat: true }, {
19+
$({ target: 'Array', stat: true, forced: INCORRECT_CONSTRUCTURING }, {
820
fromAsync: fromAsync
921
});

tests/compat/tests.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,13 @@ GLOBAL.tests = {
15251525
&& SuppressedError(1, 2, 3, { cause: 4 }).cause !== 4;
15261526
},
15271527
'esnext.array.from-async': function () {
1528-
return Array.fromAsync;
1528+
// https://bugs.webkit.org/show_bug.cgi?id=271703
1529+
var counter = 0;
1530+
Array.fromAsync.call(function () {
1531+
counter++;
1532+
return [];
1533+
}, { length: 0 });
1534+
return counter === 1;
15291535
},
15301536
'esnext.array.filter-reject': function () {
15311537
return [].filterReject;

tests/unit-global/esnext.array.from-async.js

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ QUnit.test('Array.fromAsync', assert => {
1010
assert.looksNative(fromAsync);
1111
assert.nonEnumerable(Array, 'fromAsync');
1212

13+
let counter = 0;
14+
// eslint-disable-next-line prefer-arrow-callback -- constructor
15+
fromAsync.call(function () {
16+
counter++;
17+
return [];
18+
}, { length: 0 });
19+
20+
assert.same(counter, 1, 'proper number of constructor calling');
21+
1322
function C() { /* empty */ }
1423

1524
return fromAsync(createAsyncIterable([1, 2, 3]), it => it ** 2).then(it => {

tests/unit-pure/esnext.array.from-async.js

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ QUnit.test('Array.fromAsync', assert => {
99
assert.arity(fromAsync, 1);
1010
assert.name(fromAsync, 'fromAsync');
1111

12+
let counter = 0;
13+
// eslint-disable-next-line prefer-arrow-callback -- constructor
14+
fromAsync.call(function () {
15+
counter++;
16+
return [];
17+
}, { length: 0 });
18+
19+
assert.same(counter, 1, 'proper number of constructor calling');
20+
1221
function C() { /* empty */ }
1322

1423
return fromAsync(createAsyncIterable([1, 2, 3]), it => it ** 2).then(it => {

0 commit comments

Comments
 (0)