Fix rooting of external array buffer pointer (#31342)

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2024-02-14 03:34:05 +01:00 committed by GitHub
parent b2d2e896d6
commit a4db81cbd0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -183,16 +183,18 @@ where
let mapping_slice_ptr =
mapping.lock().unwrap().borrow_mut()[offset as usize..m_end as usize].as_mut_ptr();
let array_buffer = NewExternalArrayBuffer(
// rooted! is needed to ensure memory safety and prevent potential garbage collection issues.
// https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples/blob/esr78/docs/GC%20Rooting%20Guide.md#performance-tweaking
rooted!(in(*cx) let array_buffer = NewExternalArrayBuffer(
*cx,
range_size as usize,
mapping_slice_ptr as _,
Some(free_func),
Arc::into_raw(mapping) as _,
);
));
HeapTypedArray {
internal: Heap::boxed(array_buffer),
internal: Heap::boxed(*array_buffer),
phantom: PhantomData::default(),
}
}