Skip to content

Commit 09c96b2

Browse files
committed
detect and fix early Set methods implementations
1 parent ce0913b commit 09c96b2

File tree

4 files changed

+55
-39
lines changed

4 files changed

+55
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- `DataView.prototype.setUint8Clamped`
4040
- Used strict mode in some missed cases, [#1269](https://github.com/zloirock/core-js/issues/1269)
4141
- Fixed [a Chromium 117 bug](https://bugs.chromium.org/p/v8/issues/detail?id=14222) in `value` argument of `URLSearchParams.prototype.{ has, delete }`
42+
- Fixed early WebKit `Set` methods implementation by the actual spec
4243
- Fixed incorrect `Symbol.{ dispose, asyncDispose }` descriptors from [NodeJS 20.4](https://github.com/nodejs/node/issues/48699) / transpilers helpers / userland code
4344
- Fixed forced polyfilling of some iterator helpers that should return wrapped iterator in the pure version
4445
- Fixed and exposed [`AsyncIteratorPrototype` `core-js/configurator` option](https://github.com/zloirock/core-js#asynciterator-helpers), [#1268](https://github.com/zloirock/core-js/issues/1268)

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,8 +2200,6 @@ export const data = {
22002200
'esnext.set.delete-all': {
22012201
},
22022202
'esnext.set.difference.v2': {
2203-
bun: '0.6.0',
2204-
safari: '17.0',
22052203
},
22062204
// TODO: Remove from `core-js@4`
22072205
'esnext.set.difference': {
@@ -2215,29 +2213,21 @@ export const data = {
22152213
'esnext.set.from': {
22162214
},
22172215
'esnext.set.intersection.v2': {
2218-
bun: '0.5.7',
2219-
safari: '17.0',
22202216
},
22212217
// TODO: Remove from `core-js@4`
22222218
'esnext.set.intersection': {
22232219
},
22242220
'esnext.set.is-disjoint-from.v2': {
2225-
bun: '0.5.7',
2226-
safari: '17.0',
22272221
},
22282222
// TODO: Remove from `core-js@4`
22292223
'esnext.set.is-disjoint-from': {
22302224
},
22312225
'esnext.set.is-subset-of.v2': {
2232-
bun: '0.5.7',
2233-
safari: '17.0',
22342226
},
22352227
// TODO: Remove from `core-js@4`
22362228
'esnext.set.is-subset-of': {
22372229
},
22382230
'esnext.set.is-superset-of.v2': {
2239-
bun: '0.5.7',
2240-
safari: '17.0',
22412231
},
22422232
// TODO: Remove from `core-js@4`
22432233
'esnext.set.is-superset-of': {
@@ -2253,15 +2243,11 @@ export const data = {
22532243
'esnext.set.some': {
22542244
},
22552245
'esnext.set.symmetric-difference.v2': {
2256-
bun: '0.5.7',
2257-
safari: '17.0',
22582246
},
22592247
// TODO: Remove from `core-js@4`
22602248
'esnext.set.symmetric-difference': {
22612249
},
22622250
'esnext.set.union.v2': {
2263-
bun: '0.5.7',
2264-
safari: '17.0',
22652251
},
22662252
// TODO: Remove from `core-js@4`
22672253
'esnext.set.union': {

packages/core-js/internals/set-method-accept-set-like.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22
var getBuiltIn = require('../internals/get-built-in');
33

4-
var createEmptySetLike = function () {
4+
var createSetLike = function (size) {
55
return {
6-
size: 0,
6+
size: size,
77
has: function () {
88
return false;
99
},
@@ -18,10 +18,17 @@ var createEmptySetLike = function () {
1818
};
1919

2020
module.exports = function (name) {
21+
var Set = getBuiltIn('Set');
2122
try {
22-
var Set = getBuiltIn('Set');
23-
new Set()[name](createEmptySetLike());
24-
return true;
23+
new Set()[name](createSetLike(0));
24+
try {
25+
// late spec change, early Safari implementation does not pass it
26+
// https://github.com/tc39/proposal-set-methods/pull/88
27+
new Set()[name](createSetLike(-1));
28+
return false;
29+
} catch (error2) {
30+
return true;
31+
}
2532
} catch (error) {
2633
return false;
2734
}

tests/compat/tests.js

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,40 @@ function createStringTrimMethodTest(METHOD_NAME) {
223223
};
224224
}
225225

226+
function createSetLike(size) {
227+
return {
228+
size: size,
229+
has: function () {
230+
return false;
231+
},
232+
keys: function () {
233+
return {
234+
next: function () {
235+
return { done: true };
236+
}
237+
};
238+
}
239+
};
240+
}
241+
242+
function createSetMethodTest(METHOD_NAME) {
243+
return function () {
244+
try {
245+
new Set()[METHOD_NAME](createSetLike(0));
246+
try {
247+
// late spec change, early Safari implementation does not pass it
248+
// https://github.com/tc39/proposal-set-methods/pull/88
249+
new Set()[METHOD_NAME](createSetLike(-1));
250+
return false;
251+
} catch (error2) {
252+
return true;
253+
}
254+
} catch (error) {
255+
return false;
256+
}
257+
};
258+
}
259+
226260
function NATIVE_RAW_JSON() {
227261
var unsafeInt = '9007199254740993';
228262
var raw = JSON.rawJSON(unsafeInt);
@@ -1731,9 +1765,7 @@ GLOBAL.tests = {
17311765
'esnext.set.delete-all': function () {
17321766
return Set.prototype.deleteAll;
17331767
},
1734-
'esnext.set.difference.v2': function () {
1735-
return Set.prototype.difference;
1736-
},
1768+
'esnext.set.difference.v2': createSetMethodTest('difference'),
17371769
'esnext.set.every': function () {
17381770
return Set.prototype.every;
17391771
},
@@ -1746,18 +1778,12 @@ GLOBAL.tests = {
17461778
'esnext.set.from': function () {
17471779
return Set.from;
17481780
},
1749-
'esnext.set.intersection.v2': function () {
1781+
'esnext.set.intersection.v2': [createSetMethodTest('intersection'), function () {
17501782
return Array.from(new Set([1, 2, 3]).intersection(new Set([3, 2]))) == '3,2';
1751-
},
1752-
'esnext.set.is-disjoint-from.v2': function () {
1753-
return Set.prototype.isDisjointFrom;
1754-
},
1755-
'esnext.set.is-subset-of.v2': function () {
1756-
return Set.prototype.isSubsetOf;
1757-
},
1758-
'esnext.set.is-superset-of.v2': function () {
1759-
return Set.prototype.isSupersetOf;
1760-
},
1783+
}],
1784+
'esnext.set.is-disjoint-from.v2': createSetMethodTest('isDisjointFrom'),
1785+
'esnext.set.is-subset-of.v2': createSetMethodTest('isSubsetOf'),
1786+
'esnext.set.is-superset-of.v2': createSetMethodTest('isSupersetOf'),
17611787
'esnext.set.join': function () {
17621788
return Set.prototype.join;
17631789
},
@@ -1773,12 +1799,8 @@ GLOBAL.tests = {
17731799
'esnext.set.some': function () {
17741800
return Set.prototype.some;
17751801
},
1776-
'esnext.set.symmetric-difference.v2': function () {
1777-
return Set.prototype.symmetricDifference;
1778-
},
1779-
'esnext.set.union.v2': function () {
1780-
return Set.prototype.union;
1781-
},
1802+
'esnext.set.symmetric-difference.v2': createSetMethodTest('symmetricDifference'),
1803+
'esnext.set.union.v2': createSetMethodTest('union'),
17821804
'esnext.string.code-points': function () {
17831805
return String.prototype.codePoints;
17841806
},

0 commit comments

Comments
 (0)