1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:25:08 +00:00

LibJS: Add bounds check to Array.prototype.{find,findIndex}

The number of iterations is limited to the initial array size, but we
still need to check if the array did shrink since then before accessing
each element.

Fixes #1992.
This commit is contained in:
Linus Groh 2020-04-28 00:26:00 +01:00 committed by Andreas Kling
parent 92671be906
commit c14fedd562
2 changed files with 31 additions and 0 deletions

View file

@ -0,0 +1,25 @@
load("test-common.js");
try {
var a, callbackCalled;
callbackCalled = 0;
a = [1, 2, 3, 4, 5];
a.find(() => {
callbackCalled++;
a.pop();
});
assert(callbackCalled === 3);
callbackCalled = 0;
a = [1, 2, 3, 4, 5];
a.findIndex(() => {
callbackCalled++;
a.pop();
});
assert(callbackCalled === 3);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}