mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
WebIDL: Use Uint8ClampedArray instead of raw JSObject in bindings (#31317)
* WebIDL: Use Uint8ClampedArray instead of raw JSObject in bindings Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * fmt Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * introduce new_initialized_heap_typed_array function Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Remove unsed unsafe_code Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Use doc comments for ImageData Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Use get_internal instead of acquire_data Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Handle JS errors in ImageData GetData and new_initialized_heap_typed_array Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Fix wrong assert that causes CRASH in test Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Early return for error Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Address review comments Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> --------- Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
parent
7e9be5ae9f
commit
328c376ff1
6 changed files with 118 additions and 55 deletions
|
@ -5,14 +5,14 @@
|
|||
// check-tidy: no specs after this line
|
||||
|
||||
use std::borrow::ToOwned;
|
||||
use std::ptr::NonNull;
|
||||
use std::ptr::{self, NonNull};
|
||||
use std::rc::Rc;
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsapi::{Heap, JSObject, JS_NewPlainObject, JS_NewUint8ClampedArray};
|
||||
use js::jsapi::{Heap, JSObject, JS_NewPlainObject};
|
||||
use js::jsval::{JSVal, NullValue};
|
||||
use js::rust::{CustomAutoRooterGuard, HandleObject, HandleValue};
|
||||
use js::typedarray;
|
||||
use js::typedarray::{self, Uint8ClampedArray};
|
||||
use script_traits::serializable::BlobImpl;
|
||||
use script_traits::MsDuration;
|
||||
use servo_config::prefs;
|
||||
|
@ -41,6 +41,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject,
|
|||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::str::{ByteString, DOMString, USVString};
|
||||
use crate::dom::bindings::trace::RootedTraceableBox;
|
||||
use crate::dom::bindings::typedarrays::create_typed_array;
|
||||
use crate::dom::bindings::weakref::MutableWeakRef;
|
||||
use crate::dom::blob::Blob;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
|
@ -209,12 +210,12 @@ impl TestBindingMethods for TestBinding {
|
|||
ByteStringOrLong::ByteString(ByteString::new(vec![]))
|
||||
}
|
||||
fn SetUnion9Attribute(&self, _: ByteStringOrLong) {}
|
||||
#[allow(unsafe_code)]
|
||||
fn ArrayAttribute(&self, cx: SafeJSContext) -> NonNull<JSObject> {
|
||||
unsafe {
|
||||
rooted!(in(*cx) let array = JS_NewUint8ClampedArray(*cx, 16));
|
||||
NonNull::new(array.get()).expect("got a null pointer")
|
||||
}
|
||||
fn ArrayAttribute(&self, cx: SafeJSContext) -> Uint8ClampedArray {
|
||||
let data: [u8; 16] = [0; 16];
|
||||
|
||||
rooted!(in (*cx) let mut array = ptr::null_mut::<JSObject>());
|
||||
create_typed_array(cx, &data, array.handle_mut())
|
||||
.expect("Creating ClampedU8 array should never fail")
|
||||
}
|
||||
fn AnyAttribute(&self, _: SafeJSContext) -> JSVal {
|
||||
NullValue()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue