set.prototype.difference
Advanced tools
Comparing version
@@ -56,3 +56,3 @@ 'use strict'; | ||
return { '[[Set]]': obj, '[[Size]]': intSize, '[[Has]]': has, '[[Keys]]': keys }; // step 12 | ||
return { '[[SetObject]]': obj, '[[Size]]': intSize, '[[Has]]': has, '[[Keys]]': keys }; // step 12 | ||
}; |
@@ -8,2 +8,12 @@ # Changelog | ||
## [v1.1.6](https://github.com/es-shims/Set.prototype.difference/compare/v1.1.5...v1.1.6) - 2024-09-10 | ||
### Commits | ||
- [Fix] handle chrome/v8 bugs [`266d8aa`](https://github.com/es-shims/Set.prototype.difference/commit/266d8aa29af20e03b6ccf37454df238f663358c7) | ||
- [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `object-inspect`, `tape` [`7563c36`](https://github.com/es-shims/Set.prototype.difference/commit/7563c368cf3675fef9e1a6cbea7c8dc7cb8b3dde) | ||
- [Refactor] change internal slot name [`113b587`](https://github.com/es-shims/Set.prototype.difference/commit/113b587893d71f35873aed2536dd7ee851ef7c00) | ||
- [Tests] replace `aud` with `npm audit` [`eec956e`](https://github.com/es-shims/Set.prototype.difference/commit/eec956e04a9d2aa82665111a0497e061908606ab) | ||
- [Dev Deps] add missing peer dep [`b2219f3`](https://github.com/es-shims/Set.prototype.difference/commit/b2219f399ea9e0286b66f2dc043da12e36092450) | ||
## [v1.1.5](https://github.com/es-shims/Set.prototype.difference/compare/v1.1.4...v1.1.5) - 2024-04-06 | ||
@@ -10,0 +20,0 @@ |
@@ -46,3 +46,3 @@ 'use strict'; | ||
$setForEach(O, function (e) { // step 5.a | ||
var inOther = ToBoolean(Call(otherRec['[[Has]]'], otherRec['[[Set]]'], [e])); // step 5.a.i.1 | ||
var inOther = ToBoolean(Call(otherRec['[[Has]]'], otherRec['[[SetObject]]'], [e])); // step 5.a.i.1 | ||
if (!inOther) { // step 5.a.i.2 (kinda) | ||
@@ -53,3 +53,3 @@ $setAdd(result, e); // step 5.a.i.2.a (kinda) | ||
} else { // step 6 | ||
var keysIter = GetIteratorFromMethod(otherRec['[[Set]]'], otherRec['[[Keys]]']); // step 6.a | ||
var keysIter = GetIteratorFromMethod(otherRec['[[SetObject]]'], otherRec['[[Keys]]']); // step 6.a | ||
var resultSetData = []; | ||
@@ -56,0 +56,0 @@ $setForEach(O, function (e) { |
{ | ||
"name": "set.prototype.difference", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "An ESnext spec-compliant `Set.prototype.difference` shim/polyfill/replacement that works as far down as ES3", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
"test": "npm run tests-only", | ||
"posttest": "aud --production", | ||
"posttest": "npx npm@'>=10.2' audit --production", | ||
"version": "auto-changelog && git add CHANGELOG.md", | ||
@@ -64,6 +64,6 @@ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" | ||
"devDependencies": { | ||
"@es-shims/api": "^2.5.0", | ||
"@ljharb/eslint-config": "^21.1.0", | ||
"aud": "^2.0.4", | ||
"@es-shims/api": "^2.5.1", | ||
"@ljharb/eslint-config": "^21.1.1", | ||
"auto-changelog": "^2.4.0", | ||
"encoding": "^0.1.13", | ||
"es-get-iterator": "^1.1.3", | ||
@@ -81,5 +81,5 @@ "es-map": "^1.0.5", | ||
"nyc": "^10.3.2", | ||
"object-inspect": "^1.13.1", | ||
"object-inspect": "^1.13.2", | ||
"safe-publish-latest": "^2.0.0", | ||
"tape": "^5.7.5" | ||
"tape": "^5.8.1" | ||
}, | ||
@@ -86,0 +86,0 @@ "testling": { |
@@ -8,3 +8,22 @@ 'use strict'; | ||
module.exports = function getPolyfill() { | ||
return typeof Set.prototype.difference === 'function' ? Set.prototype.difference : implementation; | ||
if (typeof Set.prototype.difference === 'function') { | ||
var called = false; | ||
var setLike = { | ||
size: Infinity, | ||
has: function () {}, | ||
keys: function () { | ||
called = true; | ||
return [].values(); | ||
} | ||
}; | ||
new Set([1]).difference(setLike); | ||
setLike.size = 2147483648; // 2 ** 31 | ||
new Set([1]).difference(setLike); | ||
if (!called) { | ||
return Set.prototype.difference; | ||
} | ||
} | ||
return implementation; | ||
}; |
@@ -31,2 +31,5 @@ # set.prototype.difference <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
## Compatibility | ||
node v22 and equivalent versions of Chrome have Set difference, but has a bug with set-like arguments with non-SMI integer sizes. | ||
## Tests | ||
@@ -33,0 +36,0 @@ Simply clone the repo, `npm install`, and run `npm test` |
@@ -496,3 +496,26 @@ 'use strict'; | ||
t.test('works with a set-like of certain sizes', function (st) { | ||
var setLike = { | ||
size: Math.pow(2, 31), | ||
has: function () {}, | ||
keys: function () { | ||
throw new Error('Unexpected call to |keys| method'); | ||
} | ||
}; | ||
st.doesNotThrow( | ||
function () { difference(new $Set([1]), setLike); }, | ||
'2**31: `keys` function is not invoked' | ||
); | ||
setLike.size = Infinity; | ||
st.doesNotThrow( | ||
function () { difference(new $Set([1]), setLike); }, | ||
'∞: `keys` function is not invoked' | ||
); | ||
st.end(); | ||
}); | ||
return t.comment('tests completed'); | ||
}; |
37425
5.46%687
5.53%63
5%