RefCell<Option<Heap<T>>> is easy to misuse
Author: jdmCreated Feb 11, 2020Updated Sep 17, 2026
LabelsA-content/bindingsI-safety
Code like this is subtly incorrect:
// Cache the Js value.
let heap_val = Heap::default();
heap_val.set(frozen_types);
*self.frozen_supported_performance_entry_types.borrow_mut() = Some(heap_val);Moving around Heap values invalidates pointers; the correct way to use this is to set the Some(Heap::default()), then use borrow_mut().as_ref().unwrap().set(...) to update the value after it has settled in memory.
Source: servo/servo