diff --git a/ext/canvas/lib.rs b/ext/canvas/lib.rs index 347b12eb33..602a7d1801 100644 --- a/ext/canvas/lib.rs +++ b/ext/canvas/lib.rs @@ -20,6 +20,9 @@ pub enum CanvasError { /// This error will be mapped to DOMExceptionInvalidStateError. #[error("Cannot decode image '{0}'")] InvalidImage(String), + /// This error will be mapped to DOMExceptionInvalidStateError. + #[error("The chunk data is not big enough with the specified width: {0} and height: {1}.")] + NotBigEnoughChunk(u32, u32), #[error(transparent)] Lcms(#[from] lcms2::Error), #[error(transparent)] diff --git a/ext/canvas/op_create_image_bitmap.rs b/ext/canvas/op_create_image_bitmap.rs index d0e3a0e27a..45484d17c0 100644 --- a/ext/canvas/op_create_image_bitmap.rs +++ b/ext/canvas/op_create_image_bitmap.rs @@ -185,13 +185,11 @@ fn decode_bitmap_data( // > Returns the one-dimensional array containing the data in RGBA order, as integers in the range 0 to 255. // https://html.spec.whatwg.org/multipage/canvas.html#pixel-manipulation let image = match RgbaImage::from_raw(width, height, buf.into()) { - Some(image) => image.into(), - None => { - return Err(CanvasError::InvalidImage( - "The Chunk Data is not big enough with the specified width and height.".to_string() - )) - } - }; + Some(image) => image.into(), + None => { + return Err(CanvasError::NotBigEnoughChunk(width, height)); + } + }; (image, width, height, None, None) } diff --git a/runtime/errors.rs b/runtime/errors.rs index 73f7a822f3..3f0fbacecd 100644 --- a/runtime/errors.rs +++ b/runtime/errors.rs @@ -603,6 +603,7 @@ fn get_canvas_error(e: &CanvasError) -> &'static str { match e { CanvasError::UnsupportedColorType(_) => "TypeError", CanvasError::InvalidImage(_) => "DOMExceptionInvalidStateError", + CanvasError::NotBigEnoughChunk(_, _) => "DOMExceptionInvalidStateError", CanvasError::Lcms(_) => "TypeError", CanvasError::Image(_) => "TypeError", }