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:
parent
92671be906
commit
c14fedd562
2 changed files with 31 additions and 0 deletions
25
Libraries/LibJS/Tests/array-shrink-during-find-crash.js
Normal file
25
Libraries/LibJS/Tests/array-shrink-during-find-crash.js
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue