LibWeb: Set width/height of ImageBitmap when deserializing or receiving

This commit is contained in:
Luke Wilde 2025-10-28 16:45:41 +00:00 committed by Jelle Raaijmakers
parent 3ca4ff6037
commit 498e59f71d
3 changed files with 50 additions and 2 deletions

View File

@ -84,7 +84,7 @@ WebIDL::ExceptionOr<void> ImageBitmap::serialization_steps(HTML::TransferDataEnc
WebIDL::ExceptionOr<void> ImageBitmap::deserialization_steps(HTML::TransferDataDecoder& serialized, HTML::DeserializationMemory&)
{
// 1. Set value's bitmap data to serialized.[[BitmapData]].
m_bitmap = TRY(deserialize_bitmap(this->realm(), serialized));
set_bitmap(TRY(deserialize_bitmap(this->realm(), serialized)));
return {};
}
@ -107,7 +107,7 @@ WebIDL::ExceptionOr<void> ImageBitmap::transfer_steps(HTML::TransferDataEncoder&
WebIDL::ExceptionOr<void> ImageBitmap::transfer_receiving_steps(HTML::TransferDataDecoder& data_holder)
{
// 1. Set value's bitmap data to dataHolder.[[BitmapData]].
m_bitmap = TRY(deserialize_bitmap(this->realm(), data_holder));
set_bitmap(TRY(deserialize_bitmap(this->realm(), data_holder)));
return {};
}

View File

@ -0,0 +1,15 @@
before cloning:
original imageBitmap width: 120
original imageBitmap height: 120
after cloning, before transferring:
original imageBitmap width: 120
original imageBitmap height: 120
cloned imageBitmap width: 120
cloned imageBitmap height: 120
after cloning, after transferring:
original imageBitmap width: 0
original imageBitmap height: 0
cloned imageBitmap width: 120
cloned imageBitmap height: 120
transferred imageBitmap width: 120
transferred imageBitmap height: 120

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
asyncTest((done) => {
const image = document.createElement("img");
image.onload = async () => {
const printDimensions = (name, imageBitmapToPrint) => {
println(`${name} imageBitmap width: ${imageBitmapToPrint.width}`);
println(`${name} imageBitmap height: ${imageBitmapToPrint.height}`);
};
const imageBitmap = await createImageBitmap(image);
println("before cloning:");
printDimensions("original", imageBitmap);
println("after cloning, before transferring:");
const clonedImageBitmap = structuredClone(imageBitmap);
printDimensions("original", imageBitmap);
printDimensions("cloned", clonedImageBitmap);
println("after cloning, after transferring:");
const transferredImageBitmap = structuredClone(imageBitmap, { transfer: [imageBitmap] });
printDimensions("original", imageBitmap);
printDimensions("cloned", clonedImageBitmap);
printDimensions("transferred", transferredImageBitmap);
done();
};
image.src = "../../../Assets/120.png";
});
</script>