0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00

use an unique variant of CanvasError

- https://github.com/denoland/deno/pull/25517#discussion_r1855116556
This commit is contained in:
Hajime-san 2024-11-26 19:51:28 +09:00
parent 332fc416e8
commit d764f628f5
3 changed files with 9 additions and 7 deletions

View file

@ -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)]

View file

@ -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)
}

View file

@ -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",
}