servo / rust-mozjs

DEPRECATED - moved to servo/mozjs instead.
Mozilla Public License 2.0
293 stars 122 forks source link

Add a debug mode for Heap<T> that can detect some invalid moves of Heap objects #417

Open jdm opened 6 years ago

jdm commented 6 years ago

If we add a Cell<*mut Self> member to Heap<T> that is conditionally compiled, initialize it to null, and set it to self as *const Self whenever Heap::set is invoked, we can assert that the cell value is either null or equal to self as *const Self. This will automatically assert any time that a Heap value is set to a non-default value, moved (thus invalidating the pointer stored by SM), and set once more. This can't flag any moves that occur when no mutation follows, but it's better than nothing.