mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
This clamps the interval of repeating timers to 4ms after they have run 5 times. This prevents CPU spinning for `setInterval()` calls with low timeouts.
24 lines
752 B
HTML
24 lines
752 B
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
asyncTest(done => {
|
|
// With 4ms clamping after nesting level 5, running for 100ms should yield
|
|
// roughly 5-6 unclamped calls plus approximately 25 clamped calls.
|
|
// Without clamping, we'd get thousands of calls.
|
|
// We test that the count is bounded, proving clamping is working.
|
|
const testDurationMilliseconds = 100;
|
|
let callCount = 0;
|
|
|
|
const id = setInterval(() => {
|
|
callCount++;
|
|
}, 0);
|
|
|
|
setTimeout(() => {
|
|
clearInterval(id);
|
|
|
|
println(`Callback count bounded (< 100 in 100ms): ${callCount < 100}`);
|
|
done();
|
|
}, testDurationMilliseconds);
|
|
});
|
|
</script>
|