mirror of
https://github.com/servo/servo.git
synced 2025-06-14 19:34:29 +00:00
* Upgrade rustc to 1.83 Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix crown (change copied from linked clippy function) Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix named lifetime lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Bump shell.nix Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix non-local impl warnings Signed-off-by: Nico Burns <nico@nicoburns.com> * Format with 1.83 formatting changes Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix manual non-local impl Signed-off-by: Nico Burns <nico@nicoburns.com> * More fixes for crown Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix tidy Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix needless_return lints Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix doc comment lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix missing wait lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Allow needless_lifetimes lint Signed-off-by: Nico Burns <nico@nicoburns.com> * more doc comments Signed-off-by: Nico Burns <nico@nicoburns.com> * More needless_returns Signed-off-by: Nico Burns <nico@nicoburns.com> * is_empty lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix needless_lifetime lints Signed-off-by: Nico Burns <nico@nicoburns.com> * fix div_ceil lint Signed-off-by: Nico Burns <nico@nicoburns.com> * Allow non-minimal bool Signed-off-by: Nico Burns <nico@nicoburns.com> * Non-local impl in constellation Signed-off-by: Nico Burns <nico@nicoburns.com> * Missing wait in constellation Signed-off-by: Nico Burns <nico@nicoburns.com> * fmt Signed-off-by: Nico Burns <nico@nicoburns.com> * remove useless lints table Signed-off-by: Nico Burns <nico@nicoburns.com> * Fixup comments Signed-off-by: Nico Burns <nico@nicoburns.com> * Allow non-local definition in sandboxing code to simplify feature flagging Signed-off-by: Nico Burns <nico@nicoburns.com> * Remove wait calls and allow zombie_processes lint Signed-off-by: Nico Burns <nico@nicoburns.com> --------- Signed-off-by: Nico Burns <nico@nicoburns.com>
52 lines
1.7 KiB
Rust
52 lines
1.7 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
//! Generic finalizer implementations for DOM binding implementations.
|
|
|
|
use std::any::type_name;
|
|
use std::mem;
|
|
|
|
use js::glue::JS_GetReservedSlot;
|
|
use js::jsapi::JSObject;
|
|
use js::jsval::UndefinedValue;
|
|
|
|
use crate::dom::bindings::utils::finalize_global as do_finalize_global;
|
|
use crate::dom::bindings::weakref::{WeakBox, WeakReferenceable, DOM_WEAK_SLOT};
|
|
|
|
pub unsafe fn finalize_common<T>(this: *const T) {
|
|
if !this.is_null() {
|
|
// The pointer can be null if the object is the unforgeable holder of that interface.
|
|
let _ = Box::from_raw(this as *mut T);
|
|
}
|
|
debug!("{} finalize: {:p}", type_name::<T>(), this);
|
|
}
|
|
|
|
pub unsafe fn finalize_global<T>(obj: *mut JSObject, this: *const T) {
|
|
do_finalize_global(obj);
|
|
finalize_common::<T>(this);
|
|
}
|
|
|
|
pub unsafe fn finalize_weak_referenceable<T: WeakReferenceable>(
|
|
obj: *mut JSObject,
|
|
this: *const T,
|
|
) {
|
|
let mut slot = UndefinedValue();
|
|
JS_GetReservedSlot(obj, DOM_WEAK_SLOT, &mut slot);
|
|
let weak_box_ptr = slot.to_private() as *mut WeakBox<T>;
|
|
if !weak_box_ptr.is_null() {
|
|
let count = {
|
|
let weak_box = &*weak_box_ptr;
|
|
assert!(weak_box.value.get().is_some());
|
|
assert!(weak_box.count.get() > 0);
|
|
weak_box.value.set(None);
|
|
let count = weak_box.count.get() - 1;
|
|
weak_box.count.set(count);
|
|
count
|
|
};
|
|
if count == 0 {
|
|
mem::drop(Box::from_raw(weak_box_ptr));
|
|
}
|
|
}
|
|
finalize_common::<T>(this);
|
|
}
|