diff --git a/components/script/dom/bindings/typedarrays.rs b/components/script/dom/bindings/typedarrays.rs index c5582ccc5f3..bc49c4678c1 100644 --- a/components/script/dom/bindings/typedarrays.rs +++ b/components/script/dom/bindings/typedarrays.rs @@ -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(), } }