Skip to content

Commit

Permalink
LibWeb: Reject Promise in createImageBitmap for Not Implemented Types
Browse files Browse the repository at this point in the history
If we don't reject the Promise, it lasts forever,
so rejecting non implemented Promises is essential,
to not timeout in e.g. WPT tests

(cherry picked from commit aab5a9e944f8b1c1a9de321047556bbcaa282a56)
  • Loading branch information
Totto16 authored and nico committed Nov 12, 2024
1 parent d823e90 commit c1b0ac6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Blob [Success]: [object ImageBitmap]
ImageData [ Error ]: Error: Not Implemented: createImageBitmap() for non-blob types
HTMLImageElement [ Error ]: TypeError: No union types matched
SVGImageElement [ Error ]: TypeError: No union types matched
HTMLCanvasElement [ Error ]: TypeError: No union types matched
ImageBitmap [ Error ]: TypeError: No union types matched
HTMLVideoElement [ Error ]: TypeError: No union types matched
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script src="../include.js"></script>
<script>
let canvas = document.createElement("canvas");

canvas.width = 20;
canvas.height = 20;

let ctx = canvas.getContext("2d");
ctx.fillStyle = "rgb(255, 0, 0)";
ctx.fillRect(0, 0, 10, 10);

let imageData = ctx.getImageData(0, 0, 20, 20);

let img = document.createElement("img");

let svgImg = document.createElement("img");
svgImg = document.createElementNS("http://www.w3.org/2000/svg", "image");

let video = document.createElement("video");
let file = new Blob([
new Uint8Array([
255, 10, 8, 16, 0, 9, 8, 6, 1, 0, 40, 0, 75, 56, 73, 152, 108, 128, 253, 145, 96, 0,
]),
]);
let imageBitmap = createImageBitmap(file, 0, 0, 0, 0);

const types = [
[file, "Blob"],
[imageData, "ImageData"],
[img, "HTMLImageElement"],
[svgImg, "SVGImageElement"],
[canvas, "HTMLCanvasElement"],
[imageBitmap, "ImageBitmap"],
[video, "HTMLVideoElement"],
];

asyncTest(async done => {
for (const [type, name] of types) {
try {
const result = await createImageBitmap(type, 0, 0, 20, 20);
println(`${name.padEnd(17, " ")} [Success]: ${result}`);
} catch (err) {
println(`${name.padEnd(17, " ")} [ Error ]: ${err}`);
}
}

done();
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ JS::NonnullGCPtr<JS::Promise> WindowOrWorkerGlobalScopeMixin::create_image_bitma
dbgln("(STUBBED) createImageBitmap() for non-blob types");
(void)sx;
(void)sy;
p->reject(JS::Error::create(relevant_realm(*p), "Not Implemented: createImageBitmap() for non-blob types"sv));
});

// 7. Return p.
Expand Down

0 comments on commit c1b0ac6

Please sign in to comment.