Skip to content

Documentation for Heap::handle is unclear #536

Open
@jdm

Description

@jdm

mozjs/mozjs-sys/src/jsgc.rs

Lines 333 to 348 in d6c3bd9

/// Retrieves a Handle to the underlying value.
///
/// # Safety
///
/// This is only safe to do on a rooted object (which Heap is not, it needs
/// to be additionally rooted), like RootedGuard, so use this only if you
/// know what you're doing.
///
/// # Notes
///
/// Since Heap values need to be informed when a change to underlying
/// value is made (e.g. via `get()`), this does not allow to create
/// MutableHandle objects, which can bypass this and lead to crashes.
pub unsafe fn handle(&self) -> JS::Handle<T> {
JS::Handle::from_marked_location(self.ptr.get() as *const _)
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions