Merge pull request #1580 from egrs/image-complete

add HTMLImageElement.complete property
This commit is contained in:
Karl Seguin
2026-02-18 19:02:07 +08:00
committed by GitHub
2 changed files with 25 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,14 @@ pub fn getNaturalHeight(_: *const Image) u32 {
return 0;
}
pub fn getComplete(_: *const Image) bool {
// Per spec, complete is true when: no src/srcset, src is empty,
// image is fully available, or image is broken (with no pending request).
// Since we never fetch images, they are in the "broken" state, which has
// complete=true. This is consistent with naturalWidth/naturalHeight=0.
return true;
}
pub const JsApi = struct {
pub const bridge = js.Bridge(Image);
@@ -131,6 +139,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 {