Skip to content

Commit

Permalink
[Fix] node v22 and equivalent Chrome versions have a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 10, 2024
1 parent 047c8e0 commit 2024f8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var shimmedResult = set1.intersection(set2);
assert.deepEqual(shimmedResult, new Set([2]));
```

## Compatibility
node v22 and equivalent versions of Chrome have Set intersection, but has a bug with set-like arguments with non-SMI integer sizes.

## Tests
Simply clone the repo, `npm install`, and run `npm test`

Expand Down
19 changes: 18 additions & 1 deletion polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,22 @@ var Set = require('es-set/polyfill')();
var implementation = require('./implementation');

module.exports = function getPolyfill() {
return typeof Set.prototype.intersection === 'function' ? Set.prototype.intersection : implementation;
if (typeof Set.prototype.intersection === 'function') {
var called = false;
var setLike = {
size: Infinity,
has: function () {},
keys: function () {
called = true;
return [].values();
}
};

new Set([1]).intersection(setLike);

if (!called) {
return Set.prototype.intersection;
}
}
return implementation;
};

0 comments on commit 2024f8c

Please sign in to comment.