add HTMLImageElement.complete property

Per spec, complete returns true when the image has no src, is fully
fetched, or is broken. Since this is a headless browser that does
not fetch images, complete always returns true.
This commit is contained in:
egrs
2026-02-18 08:18:54 +01:00
parent db4a97743f
commit 433d254c70
2 changed files with 23 additions and 0 deletions

View File

@@ -98,6 +98,22 @@
}
</script>
<script id="complete">
{
// Image with no src is complete per spec
const img = document.createElement('img');
testing.expectEqual(true, img.complete);
// Image with src is also complete (headless browser, no actual fetch)
img.src = 'test.png';
testing.expectEqual(true, img.complete);
// Image constructor also complete
const img2 = new Image();
testing.expectEqual(true, img2.complete);
}
</script>
<script id="load-trigger-event">
{
const img = document.createElement("img");

View File

@@ -112,6 +112,12 @@ pub fn getNaturalHeight(_: *const Image) u32 {
return 0;
}
pub fn getComplete(_: *const Image) bool {
// Per spec, complete is true when: no src/srcset, image fully fetched,
// or image is broken. Since we don't fetch images, they are always complete.
return true;
}
pub const JsApi = struct {
pub const bridge = js.Bridge(Image);
@@ -131,6 +137,7 @@ pub const JsApi = struct {
pub const loading = bridge.accessor(Image.getLoading, Image.setLoading, .{});
pub const naturalWidth = bridge.accessor(Image.getNaturalWidth, null, .{});
pub const naturalHeight = bridge.accessor(Image.getNaturalHeight, null, .{});
pub const complete = bridge.accessor(Image.getComplete, null, .{});
};
pub const Build = struct {