ladybird/Libraries/LibJS/Tests/array-shrink-during-find-crash.js
Linus Groh c14fedd562 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.
2020-04-28 13:08:19 +02:00

25 lines
444 B
JavaScript

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);
}