pub struct TypedArray<T: TypedArrayElement, S: JSObjectStorage> {
object: S,
computed: Cell<ArrayData<T::Element>>,
}Expand description
A typed array wrapper.
Fields§
§object: S§computed: Cell<ArrayData<T::Element>>Implementations§
Source§impl<T: TypedArrayElement, S: JSObjectStorage> TypedArray<T, S>
impl<T: TypedArrayElement, S: JSObjectStorage> TypedArray<T, S>
Sourcepub fn from(object: *mut JSObject) -> Result<Self, ()>
pub fn from(object: *mut JSObject) -> Result<Self, ()>
Create a typed array representation that wraps an existing JS reflector. This operation will fail if attempted on a JS object that does not match the expected typed array details.
fn data(&self) -> Option<NonNull<[T::Element]>>
Sourcepub unsafe fn underlying_object(&self) -> &S
pub unsafe fn underlying_object(&self) -> &S
§Unsafety
Returned wrapped pointer to the underlying JSObject is meant to be
read-only, modifying it can lead to Undefined Behaviour and violation
of TypedArray API guarantees.
Practically, this exists only to implement JSTraceable trait in Servo
for Box<Heap<*mut JSObject>> variant.
Sourcepub fn to_vec(&self) -> Option<Vec<T::Element>>
pub fn to_vec(&self) -> Option<Vec<T::Element>>
Retrieves an owned data that’s represented by the typed array. Returns None if the underlying buffer is detached.
Sourcepub fn as_slice_safe<'a>(&self, _no_gc: &'a NoGC) -> Option<&'a [T::Element]>
pub fn as_slice_safe<'a>(&self, _no_gc: &'a NoGC) -> Option<&'a [T::Element]>
Returns None if the underlying array buffer is detached. Otherwise, returns Some with the slice data.
Sourcepub unsafe fn as_mut_slice(&mut self) -> Option<&mut [T::Element]>
👎Deprecated: use as_mut_slice_safe instead
pub unsafe fn as_mut_slice(&mut self) -> Option<&mut [T::Element]>
pub fn as_mut_slice_safe<'a>( &mut self, _no_gc: &'a NoGC, ) -> Option<&'a mut [T::Element]>
Return a boolean flag which denotes whether the underlying buffer is a SharedArrayBuffer.
Source§impl<T: TypedArrayElementCreator + TypedArrayElement, S: JSObjectStorage> TypedArray<T, S>
impl<T: TypedArrayElementCreator + TypedArrayElement, S: JSObjectStorage> TypedArray<T, S>
Sourcepub unsafe fn create(
cx: *mut JSContext,
with: CreateWith<'_, T::Element>,
result: MutableHandleObject<'_>,
) -> Result<(), ()>
pub unsafe fn create( cx: *mut JSContext, with: CreateWith<'_, T::Element>, result: MutableHandleObject<'_>, ) -> Result<(), ()>
Create a new JS typed array, optionally providing initial data that will be copied into the newly-allocated buffer. Returns the new JS reflector.
unsafe fn update_raw(data: &[T::Element], result: *mut JSObject)
Source§impl<S: JSObjectStorage> TypedArray<ArrayBufferViewU8, S>
impl<S: JSObjectStorage> TypedArray<ArrayBufferViewU8, S>
pub fn get_array_type(&self) -> Type
Trait Implementations§
Source§impl<T> CustomTrace for TypedArray<T, *mut JSObject>where
T: TypedArrayElement,
impl<T> CustomTrace for TypedArray<T, *mut JSObject>where
T: TypedArrayElement,
Source§impl<T: TypedArrayElement, S: JSObjectStorage> FromJSValConvertible for TypedArray<T, S>
impl<T: TypedArrayElement, S: JSObjectStorage> FromJSValConvertible for TypedArray<T, S>
Source§fn safe_from_jsval(
_cx: &mut JSContext,
value: HandleValue<'_>,
_option: (),
) -> Result<ConversionResult<Self>, ()>
fn safe_from_jsval( _cx: &mut JSContext, value: HandleValue<'_>, _option: (), ) -> Result<ConversionResult<Self>, ()>
val to type Self.
Optional configuration of type T can be passed as the option
argument.
If it returns Err(()), a JSAPI exception is pending.
If it returns Ok(Failure(reason)), there is no pending JSAPI exception.Source§impl<T: TypedArrayElement, S: JSObjectStorage> ToJSValConvertible for TypedArray<T, S>
impl<T: TypedArrayElement, S: JSObjectStorage> ToJSValConvertible for TypedArray<T, S>
Source§unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue<'_>)
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue<'_>)
self to a JSVal. JSAPI failure causes a panic.Source§fn safe_to_jsval(&self, cx: &mut JSContext, rval: MutableHandleValue<'_>)
fn safe_to_jsval(&self, cx: &mut JSContext, rval: MutableHandleValue<'_>)
self to a JSVal. JSAPI failure causes a panic.