Skip to content

Commit d8af813

Browse files
committed
f
Signed-off-by: sagudev <[email protected]>
1 parent 49a44c4 commit d8af813

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

mozjs/src/context.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use std::marker::PhantomData;
6-
use std::ops::Deref;
6+
use std::ops::{Deref, DerefMut};
77
use std::ptr::NonNull;
88

99
pub use crate::jsapi::JSContext as RawJSContext;
@@ -170,8 +170,20 @@ impl Deref for JSContext {
170170
/// This exists to make migration to [JSContext] easier,
171171
/// but it will be eventually removed as it is **unsafe**.
172172
///
173-
/// Use [JSContext::raw_cx] instead.
173+
/// Use [JSContext::raw_cx_no_gc] instead.
174174
fn deref(&'_ self) -> &'_ Self::Target {
175175
unsafe { std::mem::transmute::<&NonNull<RawJSContext>, &*mut RawJSContext>(&self.ptr) }
176176
}
177177
}
178+
179+
impl DerefMut for JSContext {
180+
/// This exists to make migration to [JSContext] easier,
181+
/// but it will be eventually removed as it is **unsafe**.
182+
///
183+
/// Use [JSContext::raw_cx] instead.
184+
fn deref_mut(&'_ mut self) -> &'_ mut Self::Target {
185+
unsafe {
186+
std::mem::transmute::<&mut NonNull<RawJSContext>, &mut *mut RawJSContext>(&mut self.ptr)
187+
}
188+
}
189+
}

mozjs/src/rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ pub struct Runtime {
307307
impl Runtime {
308308
/// Get the `JSContext` for this thread.
309309
///
310-
/// This will eventually be removed for in favour of [JSContext]
310+
/// This will eventually be removed for in favour of [crate::context::JSContext]
311311
pub fn get() -> Option<NonNull<JSContext>> {
312312
CONTEXT.with(|context| context.get())
313313
}

0 commit comments

Comments
 (0)