clippy: Add safety documentation and clean up unsafe methods (#33748)

This change:

1. Adds safety documentation where it was missing.
2. Limits the scope of unsafe code in some cases to where it is actually
   unsafe.
3. Converts some free functions to associated functions and methods,
   thereby making them more likely to be called safely.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-10-16 01:11:31 -07:00 committed by GitHub
parent ed959d7a1a
commit 30abb99287
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 409 additions and 347 deletions

View file

@ -76,6 +76,10 @@ impl Reflector {
}
/// Initialize the reflector. (May be called only once.)
///
/// # Safety
///
/// The provided [`JSObject`] pointer must point to a valid [`JSObject`].
pub unsafe fn set_jsobject(&self, object: *mut JSObject) {
assert!(self.object.get().is_null());
assert!(!object.is_null());
@ -123,6 +127,10 @@ impl DomObject for Reflector {
/// A trait to initialize the `Reflector` for a DOM object.
pub trait MutDomObject: DomObject {
/// Initializes the Reflector
///
/// # Safety
///
/// The provided [`JSObject`] pointer must point to a valid [`JSObject`].
unsafe fn init_reflector(&self, obj: *mut JSObject);
}