Skip to content

Commit e4d4f9a

Browse files
authored
Remove DerefMut impl for Mutable Handle (#573)
* Remove DerefMut impl for MutableHandle Signed-off-by: Greg Morenz <[email protected]> * Add access methods to MutableHandle Signed-off-by: Greg Morenz <[email protected]> --------- Signed-off-by: Greg Morenz <[email protected]>
1 parent 36f1e77 commit e4d4f9a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

mozjs/src/gc/root.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ impl<'a, T> MutableHandle<'a, T> {
236236
unsafe { *self.ptr = v }
237237
}
238238

239+
/// Safety: GC must not run during the lifetime of the returned reference.
240+
pub unsafe fn as_mut<'b>(&'b mut self) -> &'b mut T
241+
where
242+
'a: 'b,
243+
{
244+
&mut *(self.ptr)
245+
}
246+
239247
/// Creates a copy of this object, with a shorter lifetime, that holds a
240248
/// mutable borrow on the original object. When you write code that wants
241249
/// to use a `MutableHandle` more than once, you will typically need to
@@ -261,6 +269,13 @@ impl<'a, T> MutableHandle<'a, T> {
261269
}
262270
}
263271

272+
impl<'a, T> MutableHandle<'a, Option<T>> {
273+
pub fn take(&mut self) -> Option<T> {
274+
// Safety: No GC occurs during take call
275+
unsafe { self.as_mut().take() }
276+
}
277+
}
278+
264279
impl<'a, T> Deref for MutableHandle<'a, T> {
265280
type Target = T;
266281

@@ -269,12 +284,6 @@ impl<'a, T> Deref for MutableHandle<'a, T> {
269284
}
270285
}
271286

272-
impl<'a, T> DerefMut for MutableHandle<'a, T> {
273-
fn deref_mut(&mut self) -> &mut T {
274-
unsafe { &mut *self.ptr }
275-
}
276-
}
277-
278287
impl HandleValue<'static> {
279288
pub fn null() -> Self {
280289
unsafe { Self::from_raw(RawHandleValue::null()) }

0 commit comments

Comments
 (0)