diff options
author | Ms2ger <Ms2ger@gmail.com> | 2017-02-15 13:49:19 +0100 |
---|---|---|
committer | Ms2ger <Ms2ger@gmail.com> | 2017-02-15 16:27:29 +0100 |
commit | 67c572af37ac6dd170414b3dfc34dfdf21da8015 (patch) | |
tree | 3a7ba9bc7d788777c1937deba20f56520dfc9ebe /components/script/dom/imagedata.rs | |
parent | 9702d6920a7cf6506fa26c042eb4b9f7cd061713 (diff) | |
download | servo-67c572af37ac6dd170414b3dfc34dfdf21da8015.tar.gz servo-67c572af37ac6dd170414b3dfc34dfdf21da8015.zip |
Update js.
Fixes #15553.
Diffstat (limited to 'components/script/dom/imagedata.rs')
-rw-r--r-- | components/script/dom/imagedata.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/components/script/dom/imagedata.rs b/components/script/dom/imagedata.rs index 6edf2e309b2..4de2e9ced92 100644 --- a/components/script/dom/imagedata.rs +++ b/components/script/dom/imagedata.rs @@ -11,7 +11,7 @@ use dom::globalscope::GlobalScope; use euclid::size::Size2D; use js::jsapi::{Heap, JSContext, JSObject}; use js::rust::Runtime; -use js::typedarray::Uint8ClampedArray; +use js::typedarray::{Uint8ClampedArray, CreateWith}; use std::default::Default; use std::ptr; use std::vec::Vec; @@ -26,19 +26,26 @@ pub struct ImageData { impl ImageData { #[allow(unsafe_code)] - pub fn new(global: &GlobalScope, width: u32, height: u32, data: Option<Vec<u8>>) -> Root<ImageData> { + pub fn new(global: &GlobalScope, width: u32, height: u32, mut data: Option<Vec<u8>>) -> Root<ImageData> { let imagedata = box ImageData { reflector_: Reflector::new(), width: width, height: height, data: Heap::default(), }; + let len = width * height * 4; unsafe { let cx = global.get_cx(); rooted!(in (cx) let mut js_object = ptr::null_mut()); - let data = data.as_ref().map(|d| &d[..]); - Uint8ClampedArray::create(cx, width * height * 4, data, js_object.handle_mut()).unwrap(); + let data = match data { + Some(ref mut d) => { + d.resize(len as usize, 0); + CreateWith::Slice(&d[..]) + }, + None => CreateWith::Length(len), + }; + Uint8ClampedArray::create(cx, data, js_object.handle_mut()).unwrap(); (*imagedata).data.set(js_object.get()); } |