Skip to content

Commit

Permalink
reduthis pattern creates a reference to a reference
Browse files Browse the repository at this point in the history
  • Loading branch information
six-shot authored and mrobinson committed Mar 27, 2024
1 parent ccc4ac1 commit 09fd39b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions components/script/dom/bindings/refcounted.rs
Expand Up @@ -82,14 +82,14 @@ impl TrustedPromise {
/// lifetime.
#[allow(crown::unrooted_must_root)]
pub fn new(promise: Rc<Promise>) -> TrustedPromise {
LIVE_REFERENCES.with(|ref r| {
LIVE_REFERENCES.with(|r| {
let r = r.borrow();
let live_references = r.as_ref().unwrap();
let ptr = &*promise as *const Promise;
live_references.addref_promise(promise);
TrustedPromise {
dom_object: ptr,
owner_thread: (&*live_references) as *const _ as *const libc::c_void,
owner_thread: (live_references) as *const _ as *const libc::c_void,
}
})
}
Expand All @@ -98,12 +98,12 @@ impl TrustedPromise {
/// a different thread than the original value from which this `TrustedPromise` was
/// obtained.
pub fn root(self) -> Rc<Promise> {
LIVE_REFERENCES.with(|ref r| {
LIVE_REFERENCES.with(|r| {
let r = r.borrow();
let live_references = r.as_ref().unwrap();
assert_eq!(
self.owner_thread,
(&*live_references) as *const _ as *const libc::c_void
(live_references) as *const _ as *const libc::c_void
);
// Borrow-check error requires the redundant `let promise = ...; promise` here.
let promise = match live_references
Expand Down Expand Up @@ -176,7 +176,7 @@ impl<T: DomObject> Trusted<T> {
fn add_live_reference(
ptr: *const libc::c_void,
) -> (Arc<TrustedReference>, *const LiveDOMReferences) {
LIVE_REFERENCES.with(|ref r| {
LIVE_REFERENCES.with(|r| {
let r = r.borrow();
let live_references = r.as_ref().unwrap();
let refcount = unsafe { live_references.addref(ptr) };
Expand All @@ -197,7 +197,7 @@ impl<T: DomObject> Trusted<T> {
/// obtained.
pub fn root(&self) -> DomRoot<T> {
fn validate(owner_thread: *const LiveDOMReferences) {
assert!(LIVE_REFERENCES.with(|ref r| {
assert!(LIVE_REFERENCES.with(|r| {
let r = r.borrow();
let live_references = r.as_ref().unwrap();
owner_thread == live_references
Expand Down Expand Up @@ -230,7 +230,7 @@ pub struct LiveDOMReferences {
impl LiveDOMReferences {
/// Set up the thread-local data required for storing the outstanding DOM references.
pub fn initialize() {
LIVE_REFERENCES.with(|ref r| {
LIVE_REFERENCES.with(|r| {
*r.borrow_mut() = Some(LiveDOMReferences {
reflectable_table: RefCell::new(HashMap::new()),
promise_table: RefCell::new(HashMap::new()),
Expand All @@ -239,7 +239,7 @@ impl LiveDOMReferences {
}

pub fn destruct() {
LIVE_REFERENCES.with(|ref r| {
LIVE_REFERENCES.with(|r| {
*r.borrow_mut() = None;
});
}
Expand Down

0 comments on commit 09fd39b

Please sign in to comment.