refactor: add CanGc as argument to create_buffer_source_with_length (#35596)

Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Yerkebulan Tulibergenov 2025-02-21 22:17:24 -08:00 committed by GitHub
parent d72c9f3501
commit 89d7f874b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 9 deletions

View file

@ -52,6 +52,7 @@ pub(crate) enum BufferSource {
pub(crate) fn new_initialized_heap_buffer_source<T>( pub(crate) fn new_initialized_heap_buffer_source<T>(
init: HeapTypedArrayInit, init: HeapTypedArrayInit,
can_gc: CanGc,
) -> Result<HeapBufferSource<T>, ()> ) -> Result<HeapBufferSource<T>, ()>
where where
T: TypedArrayElement + TypedArrayElementCreator, T: TypedArrayElement + TypedArrayElementCreator,
@ -65,7 +66,7 @@ where
HeapTypedArrayInit::Info { len, cx } => { HeapTypedArrayInit::Info { len, cx } => {
rooted!(in (*cx) let mut array = ptr::null_mut::<JSObject>()); rooted!(in (*cx) let mut array = ptr::null_mut::<JSObject>());
let typed_array_result = let typed_array_result =
create_buffer_source_with_length::<T>(cx, len as usize, array.handle_mut()); create_buffer_source_with_length::<T>(cx, len as usize, array.handle_mut(), can_gc);
if typed_array_result.is_err() { if typed_array_result.is_err() {
return Err(()); return Err(());
} }
@ -371,6 +372,7 @@ fn create_buffer_source_with_length<T>(
cx: JSContext, cx: JSContext,
len: usize, len: usize,
dest: MutableHandleObject, dest: MutableHandleObject,
_can_gc: CanGc,
) -> Result<TypedArray<T, *mut JSObject>, ()> ) -> Result<TypedArray<T, *mut JSObject>, ()>
where where
T: TypedArrayElement + TypedArrayElementCreator, T: TypedArrayElement + TypedArrayElementCreator,

View file

@ -67,6 +67,7 @@ impl ImageData {
) -> Fallible<DomRoot<ImageData>> { ) -> Fallible<DomRoot<ImageData>> {
let heap_typed_array = match new_initialized_heap_buffer_source::<ClampedU8>( let heap_typed_array = match new_initialized_heap_buffer_source::<ClampedU8>(
HeapTypedArrayInit::Buffer(BufferSource::ArrayBufferView(Heap::boxed(jsobject))), HeapTypedArrayInit::Buffer(BufferSource::ArrayBufferView(Heap::boxed(jsobject))),
can_gc,
) { ) {
Ok(heap_typed_array) => heap_typed_array, Ok(heap_typed_array) => heap_typed_array,
Err(_) => return Err(Error::JSFailed), Err(_) => return Err(Error::JSFailed),
@ -121,11 +122,10 @@ impl ImageData {
let cx = GlobalScope::get_cx(); let cx = GlobalScope::get_cx();
let len = width * height * 4; let len = width * height * 4;
let heap_typed_array = let heap_typed_array = match new_initialized_heap_buffer_source::<ClampedU8>(
match new_initialized_heap_buffer_source::<ClampedU8>(HeapTypedArrayInit::Info { HeapTypedArrayInit::Info { len, cx },
len, can_gc,
cx, ) {
}) {
Ok(heap_typed_array) => heap_typed_array, Ok(heap_typed_array) => heap_typed_array,
Err(_) => return Err(Error::JSFailed), Err(_) => return Err(Error::JSFailed),
}; };