Add AsHandleValue trait to Heap<Value> and make Heap values rooted (#38024)

Encapsulates the unsafe conversion from Heap<Value> to HandleValue<'a>,
and reducing repetitive unsafe code at call.

fix #37258
This commit is contained in:
Taym Haddadi 2025-08-04 18:42:53 +02:00 committed by GitHub
parent 9416251cab
commit 04ec710e60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 204 additions and 146 deletions

View file

@ -154,7 +154,7 @@ pub(crate) struct PipeTo {
/// The error potentially passed to shutdown,
/// stored here because we must keep it across a microtask.
#[ignore_malloc_size_of = "mozjs"]
shutdown_error: Rc<RefCell<Option<Heap<JSVal>>>>,
shutdown_error: Rc<RefCell<Option<RootedTraceableBox<Heap<JSVal>>>>>,
/// The promise returned by a shutdown action.
/// We keep it to only continue when it is not pending anymore.
@ -376,7 +376,7 @@ impl PipeTo {
/// Setting shutdown error in a way that ensures it isn't
/// moved after it has been set.
fn set_shutdown_error(&self, error: SafeHandleValue) {
*self.shutdown_error.borrow_mut() = Some(Heap::default());
*self.shutdown_error.borrow_mut() = Some(RootedTraceableBox::new(Heap::default()));
let Some(ref heap) = *self.shutdown_error.borrow() else {
unreachable!("Option set to Some(heap) above.");
};