mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Format script component
This commit is contained in:
parent
2ca7a13473
commit
c37a345dc9
357 changed files with 25485 additions and 18076 deletions
|
@ -28,11 +28,12 @@ pub struct ImageData {
|
|||
|
||||
impl ImageData {
|
||||
#[allow(unsafe_code)]
|
||||
pub fn new(global: &GlobalScope,
|
||||
width: u32,
|
||||
height: u32,
|
||||
mut data: Option<Vec<u8>>)
|
||||
-> Fallible<DomRoot<ImageData>> {
|
||||
pub fn new(
|
||||
global: &GlobalScope,
|
||||
width: u32,
|
||||
height: u32,
|
||||
mut data: Option<Vec<u8>>,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
let len = width * height * 4;
|
||||
unsafe {
|
||||
let cx = global.get_cx();
|
||||
|
@ -50,11 +51,12 @@ impl ImageData {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn new_with_jsobject(global: &GlobalScope,
|
||||
width: u32,
|
||||
mut opt_height: Option<u32>,
|
||||
opt_jsobject: Option<*mut JSObject>)
|
||||
-> Fallible<DomRoot<ImageData>> {
|
||||
unsafe fn new_with_jsobject(
|
||||
global: &GlobalScope,
|
||||
width: u32,
|
||||
mut opt_height: Option<u32>,
|
||||
opt_jsobject: Option<*mut JSObject>,
|
||||
) -> Fallible<DomRoot<ImageData>> {
|
||||
assert!(opt_jsobject.is_some() || opt_height.is_some());
|
||||
|
||||
if width == 0 {
|
||||
|
@ -65,8 +67,9 @@ impl ImageData {
|
|||
if let Some(jsobject) = opt_jsobject {
|
||||
let cx = global.get_cx();
|
||||
typedarray!(in(cx) let array_res: Uint8ClampedArray = jsobject);
|
||||
let array = array_res
|
||||
.map_err(|_| Error::Type("Argument to Image data is not an Uint8ClampedArray".to_owned()))?;
|
||||
let array = array_res.map_err(|_| {
|
||||
Error::Type("Argument to Image data is not an Uint8ClampedArray".to_owned())
|
||||
})?;
|
||||
|
||||
let byte_len = array.as_slice().len() as u32;
|
||||
if byte_len % 4 != 0 {
|
||||
|
@ -108,7 +111,11 @@ impl ImageData {
|
|||
(*imagedata).data.set(array.get());
|
||||
}
|
||||
|
||||
Ok(reflect_dom_object(imagedata, global, ImageDataBinding::Wrap))
|
||||
Ok(reflect_dom_object(
|
||||
imagedata,
|
||||
global,
|
||||
ImageDataBinding::Wrap,
|
||||
))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#pixel-manipulation:dom-imagedata-3
|
||||
|
@ -120,12 +127,13 @@ impl ImageData {
|
|||
// https://html.spec.whatwg.org/multipage/#pixel-manipulation:dom-imagedata-4
|
||||
#[allow(unsafe_code)]
|
||||
#[allow(unused_variables)]
|
||||
pub unsafe fn Constructor_(cx: *mut JSContext,
|
||||
global: &GlobalScope,
|
||||
jsobject: *mut JSObject,
|
||||
width: u32,
|
||||
opt_height: Option<u32>)
|
||||
-> Fallible<DomRoot<Self>> {
|
||||
pub unsafe fn Constructor_(
|
||||
cx: *mut JSContext,
|
||||
global: &GlobalScope,
|
||||
jsobject: *mut JSObject,
|
||||
width: u32,
|
||||
opt_height: Option<u32>,
|
||||
) -> Fallible<DomRoot<Self>> {
|
||||
Self::new_with_jsobject(global, width, opt_height, Some(jsobject))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue