mozjs
mozjs copied to clipboard
Documentation for Heap::handle is unclear
https://github.com/servo/mozjs/blob/d6c3bd9a9a86a53c627355241b015fa7768ed688/mozjs-sys/src/jsgc.rs#L333-L348
I no longer remember when "if you know what you're doing applies", but we have a lot of usages in Servo which makes me nervous.
IIUC this is only safe when done on RootedGuard<Heap<T>> (or similar, something that ensures that heap is rooted), so we could just do
impl RootedGuard<Heap<T>> {
pub fn handle(&self) -> JS::Handle<T> {
JS::Handle::from_marked_location(self.ptr.get() as *const _)
}
}
From my understanding, it's also safe if you have any Heap<T>, as long as it's traced, eg via a custom trace op or a global tracer.