Skip to content

Commit

Permalink
[Fix] polyfill: also detect Chrome/v8 bug with setlike size of 2**31
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 10, 2024
1 parent 5902bcb commit 6344598
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = function getPolyfill() {
}
};

new Set([1]).intersection(setLike);
setLike.size = 2147483648; // 2 ** 31
new Set([1]).intersection(setLike);

if (!called) {
Expand Down
35 changes: 29 additions & 6 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,36 @@ module.exports = function (intersection, t) {
}
};

var result = intersection(set, setLike);
var result;
st.doesNotThrow(
function () { result = intersection(set, setLike); },
'`keys` function is not invoked'
);
st.ok(result instanceof $Set, 'returns a Set');
setEqual(
st,
result,
new $Set([1, 2]),
'returns the intersection of the Set and the setLike'
if (result) {
setEqual(
st,
result,
new $Set([1, 2]),
'returns the intersection of the Set and the setLike'
);
}

st.end();
});

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 () { intersection(new $Set([1]), setLike); },
'2**31: `keys` function is not invoked'
);

st.end();
Expand Down

0 comments on commit 6344598

Please sign in to comment.