Make ImageData::new return Fallible instead of panic

This commit is contained in:
Lucjan Suski 2017-03-20 21:16:55 +01:00
parent 17098ddc8f
commit c83ac31e71
2 changed files with 12 additions and 8 deletions

View file

@ -28,7 +28,11 @@ pub struct ImageData {
impl ImageData {
#[allow(unsafe_code)]
pub fn new(global: &GlobalScope, width: u32, height: u32, mut data: Option<Vec<u8>>) -> Root<ImageData> {
pub fn new(global: &GlobalScope,
width: u32,
height: u32,
mut data: Option<Vec<u8>>)
-> Fallible<Root<ImageData>> {
let len = width * height * 4;
unsafe {
let cx = global.get_cx();
@ -41,7 +45,7 @@ impl ImageData {
None => CreateWith::Length(len),
};
Uint8ClampedArray::create(cx, data, js_object.handle_mut()).unwrap();
Self::new_with_jsobject(global, width, Some(height), Some(js_object.get())).unwrap()
Self::new_with_jsobject(global, width, Some(height), Some(js_object.get()))
}
}