Skip to content

Commit

Permalink
deps: V8: cherry-pick 217457d0a560
Browse files Browse the repository at this point in the history
Original commit message:

    [set-methods] Handle SetLike with infinite size

    This CL adds a check for identifying SetLikes with infinite sizes in
    methods dependent on the size of `other`s.

    Bug: 351332634
    Change-Id: I5c6d9c0cc7f3f5fae5cedc72a44bc21c917c84b8
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5684652
    Reviewed-by: Shu-yu Guo <[email protected]>
    Commit-Queue: Rezvan Mahdavi Hezaveh <[email protected]>
    Cr-Commit-Position: refs/heads/main@{#94897}

Refs: v8/v8@217457d
PR-URL: #54883
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
  • Loading branch information
targos committed Sep 19, 2024
1 parent 67ecb10 commit 1de5512
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.19',
'v8_embedder_string': '-node.20',

##### V8 defaults for Node.js #####

Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/builtins/set-difference.tq
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ transitioning javascript builtin SetPrototypeDifference(
}
} label SlowPath {
// 6. If thisSize ≤ otherRec.[[Size]], then
if (thisSize <= Convert<int32>(otherRec.size)) {
if (otherRec.size == V8_INFINITY ||
thisSize <= Convert<int32>(otherRec.size)) {
// a. Let index be 0.
let thisIter = collections::NewOrderedHashSetIterator(table.GetTable());

Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/builtins/set-intersection.tq
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ transitioning javascript builtin SetPrototypeIntersection(
}
} label SlowPath {
// 6. If thisSize ≤ otherRec.[[Size]], then
if (thisSize <= Convert<int32>(otherRec.size)) {
if (otherRec.size == V8_INFINITY ||
thisSize <= Convert<int32>(otherRec.size)) {
// a. Let index be 0.
let thisIter = collections::NewOrderedHashSetIterator(table.GetTable());

Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/builtins/set-is-disjoint-from.tq
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ transitioning javascript builtin SetPrototypeIsDisjointFrom(
}
} label SlowPath {
// 5. If thisSize ≤ otherRec.[[Size]], then
if (thisSize <= Convert<int32>(otherRec.size)) {
if (otherRec.size == V8_INFINITY ||
thisSize <= Convert<int32>(otherRec.size)) {
// a. Let index be 0.
let thisIter = collections::NewOrderedHashSetIterator(table.GetTable());

Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/builtins/set-is-subset-of.tq
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ transitioning javascript builtin SetPrototypeIsSubsetOf(
const thisSize = table.LoadSize();

// 5. If thisSize > otherRec.[[Size]], return false.
if (thisSize > Convert<int32>(otherRec.size)) {
if (!(otherRec.size == V8_INFINITY) &&
thisSize > Convert<int32>(otherRec.size)) {
return False;
}

Expand Down
3 changes: 2 additions & 1 deletion deps/v8/src/builtins/set-is-superset-of.tq
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ transitioning javascript builtin SetPrototypeIsSupersetOf(
const thisSize = table.LoadSize();

// 5. If thisSize < otherRec.[[Size]], return false.
if (thisSize < Convert<int32>(otherRec.size)) {
if (otherRec.size == V8_INFINITY ||
thisSize < Convert<int32>(otherRec.size)) {
return False;
}

Expand Down
41 changes: 40 additions & 1 deletion deps/v8/test/mjsunit/harmony/set-difference.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,43 @@
assertThrows(() => {
new Set().difference(setLike);
}, RangeError, "'-1' is an invalid size");
})()
})();

(function TestDifferenceSetLikeWithInfiniteSize() {
let setLike = {
size: Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

const firstSet = new Set();
firstSet.add(42);
firstSet.add(43);

const resultSet = new Set();

const resultArray = Array.from(resultSet);
const differenceArray = Array.from(firstSet.difference(setLike));

assertEquals(resultArray, differenceArray);
})();

(function TestDifferenceSetLikeWithNegativeInfiniteSize() {
let setLike = {
size: -Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

assertThrows(() => {
new Set().difference(setLike);
}, RangeError, '\'-Infinity\' is an invalid size');
})();
37 changes: 37 additions & 0 deletions deps/v8/test/mjsunit/harmony/set-intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,40 @@

assertEquals([43], Array.from(firstSet.intersection(evil)));
})();

(function TestIntersectionSetLikeWithInfiniteSize() {
let setLike = {
size: Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

const firstSet = new Set();
firstSet.add(42);
firstSet.add(43);

const resultArray = [42, 43];
const intersectionArray = Array.from(firstSet.intersection(setLike));

assertEquals(resultArray, intersectionArray);
})();

(function TestIntersectionSetLikeWithNegativeInfiniteSize() {
let setLike = {
size: -Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

assertThrows(() => {
new Set().intersection(setLike);
}, RangeError, '\'-Infinity\' is an invalid size');
})();
34 changes: 34 additions & 0 deletions deps/v8/test/mjsunit/harmony/set-is-disjoint-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,37 @@

assertFalse(firstSet.isDisjointFrom(evil));
})();

(function TestIsDisjointFromSetLikeWithInfiniteSize() {
let setLike = {
size: Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

const firstSet = new Set();
firstSet.add(42);
firstSet.add(43);

assertEquals(firstSet.isDisjointFrom(setLike), false);
})();

(function TestIsDisjointFromSetLikeWithNegativeInfiniteSize() {
let setLike = {
size: -Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

assertThrows(() => {
new Set().isDisjointFrom(setLike);
}, RangeError, '\'-Infinity\' is an invalid size');
})();
34 changes: 34 additions & 0 deletions deps/v8/test/mjsunit/harmony/set-is-subset-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,37 @@

assertEquals(firstSet.isSubsetOf(setLike), true);
})();

(function TestIsSubsetOfSetLikeWithInfiniteSize() {
let setLike = {
size: Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

const firstSet = new Set();
firstSet.add(42);
firstSet.add(43);

assertEquals(firstSet.isSubsetOf(setLike), true);
})();

(function TestIsSubsetOfSetLikeWithNegativeInfiniteSize() {
let setLike = {
size: -Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

assertThrows(() => {
new Set().isSubsetOf(setLike);
}, RangeError, '\'-Infinity\' is an invalid size');
})();
34 changes: 34 additions & 0 deletions deps/v8/test/mjsunit/harmony/set-is-superset-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,37 @@

assertTrue(firstSet.isSupersetOf(evil));
})();

(function TestIsSupersetOfSetLikeWithInfiniteSize() {
let setLike = {
size: Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

const firstSet = new Set();
firstSet.add(42);
firstSet.add(43);

assertEquals(firstSet.isSupersetOf(setLike), false);
})();

(function TestIsSupersetOfSetLikeWithNegativeInfiniteSize() {
let setLike = {
size: -Infinity,
has(v) {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
};

assertThrows(() => {
new Set().isSupersetOf(setLike);
}, RangeError, '\'-Infinity\' is an invalid size');
})();

0 comments on commit 1de5512

Please sign in to comment.