mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 19:47:17 +02:00
LibWeb: Avoid spin_until in HTMLImageElement::decode_image
Improve performance of overlapping decodes. Reject on src changes during the operation.
This commit is contained in:
committed by
Jelle Raaijmakers
parent
49eb9d7a7a
commit
34742681de
Notes:
github-actions[bot]
2026-02-23 09:12:10 +00:00
Author: https://github.com/jonbgamble Commit: https://github.com/LadybirdBrowser/ladybird/commit/34742681de4 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8075 Reviewed-by: https://github.com/gmta ✅
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
// Test: decode() must reject if the image's current request changes after decode begins.
|
||||
asyncTest(async done => {
|
||||
const server = httpTestServer();
|
||||
const slowImageUrl = await server.createEcho("GET", "/decode-mutation-slow.svg", {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "image/svg+xml",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
},
|
||||
body: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><rect width="16" height="16" fill="green"/></svg>',
|
||||
delay_ms: 300,
|
||||
});
|
||||
|
||||
const image = document.createElement("img");
|
||||
image.src = slowImageUrl;
|
||||
document.body.appendChild(image);
|
||||
|
||||
const decodePromise = image.decode();
|
||||
|
||||
await Promise.resolve();
|
||||
image.src = "../../../Assets/120.png?mutated=1";
|
||||
|
||||
const timeoutPromise = timeout(3000).then(() => {
|
||||
throw new Error("Timed out waiting for decode result");
|
||||
});
|
||||
|
||||
try {
|
||||
await Promise.race([decodePromise, timeoutPromise]);
|
||||
println("FAIL: decode resolved after current request changed");
|
||||
} catch (error) {
|
||||
if (String(error).includes("Timed out"))
|
||||
println("FAIL: timed out waiting for decode rejection");
|
||||
else
|
||||
println("PASS");
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user