File tree Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ use std::ffi::CStr;
12
12
use std:: marker:: PhantomData ;
13
13
use std:: mem:: MaybeUninit ;
14
14
use std:: ops:: { Deref , DerefMut } ;
15
- use std:: ptr;
15
+ use std:: ptr:: { self , NonNull } ;
16
16
use std:: slice;
17
17
use std:: str;
18
18
use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
@@ -303,10 +303,9 @@ pub struct Runtime {
303
303
304
304
impl Runtime {
305
305
/// Get the `JSContext` for this thread.
306
- pub fn get ( ) -> * mut JSContext {
306
+ pub fn get ( ) -> Option < NonNull < JSContext > > {
307
307
let cx = CONTEXT . with ( |context| context. get ( ) ) ;
308
- assert ! ( !cx. is_null( ) ) ;
309
- cx
308
+ NonNull :: new ( cx)
310
309
}
311
310
312
311
/// Create a [`ThreadSafeJSContext`] that can detect when this `Runtime` is destroyed.
Original file line number Diff line number Diff line change @@ -40,15 +40,15 @@ fn runtime() {
40
40
let ( sender, receiver) = channel ( ) ;
41
41
thread:: spawn ( move || {
42
42
let runtime = unsafe { Runtime :: create_with_parent ( parent) } ;
43
- assert ! ( ! Runtime :: get( ) . is_null ( ) ) ;
43
+ assert ! ( Runtime :: get( ) . is_some ( ) ) ;
44
44
drop ( runtime) ;
45
45
let _ = sender. send ( ( ) ) ;
46
46
} ) ;
47
47
let _ = receiver. recv ( ) ;
48
48
}
49
49
50
50
unsafe extern "C" fn finalize ( _fop : * mut GCContext , _object : * mut JSObject ) {
51
- assert ! ( ! Runtime :: get( ) . is_null ( ) ) ;
51
+ assert ! ( Runtime :: get( ) . is_some ( ) ) ;
52
52
}
53
53
54
54
static CLASS_OPS : JSClassOps = JSClassOps {
You can’t perform that action at this time.
0 commit comments