From 41f29a19c4456fa2e4f474a1c0f39ef99914182d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 31 Dec 2020 08:30:30 +0100 Subject: [PATCH] Isolate::thread_safe_handle() no longer requires mutable reference (#562) --- src/handle.rs | 2 +- src/isolate.rs | 10 +++++----- tests/test_api.rs | 22 ++++------------------ 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/handle.rs b/src/handle.rs index f31675d9..3f379cd4 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -409,6 +409,6 @@ impl HandleHost { } fn get_isolate_handle(self) -> IsolateHandle { - unsafe { self.get_isolate().as_mut().thread_safe_handle() } + unsafe { self.get_isolate().as_ref() }.thread_safe_handle() } } diff --git a/src/isolate.rs b/src/isolate.rs index 91aedceb..b6e783ad 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -267,22 +267,22 @@ impl Isolate { CreateParams::default() } - pub fn thread_safe_handle(&mut self) -> IsolateHandle { + pub fn thread_safe_handle(&self) -> IsolateHandle { IsolateHandle::new(self) } /// See [`IsolateHandle::terminate_execution`] - pub fn terminate_execution(&mut self) -> bool { + pub fn terminate_execution(&self) -> bool { self.thread_safe_handle().terminate_execution() } /// See [`IsolateHandle::cancel_terminate_execution`] - pub fn cancel_terminate_execution(&mut self) -> bool { + pub fn cancel_terminate_execution(&self) -> bool { self.thread_safe_handle().cancel_terminate_execution() } /// See [`IsolateHandle::is_execution_terminating`] - pub fn is_execution_terminating(&mut self) -> bool { + pub fn is_execution_terminating(&self) -> bool { self.thread_safe_handle().is_execution_terminating() } @@ -672,7 +672,7 @@ impl IsolateHandle { self.0.isolate } - fn new(isolate: &mut Isolate) -> Self { + fn new(isolate: &Isolate) -> Self { Self(isolate.get_annex_arc()) } diff --git a/tests/test_api.rs b/tests/test_api.rs index 6f10f990..72cc3529 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -733,30 +733,16 @@ fn throw_exception() { #[test] fn isolate_termination_methods() { let _setup_guard = setup(); - let mut isolate = v8::Isolate::new(Default::default()); - let handle = isolate.thread_safe_handle(); - assert_eq!(false, isolate.terminate_execution()); - assert_eq!(false, isolate.cancel_terminate_execution()); + let isolate = v8::Isolate::new(Default::default()); assert_eq!(false, isolate.is_execution_terminating()); - static CALL_COUNT: AtomicUsize = AtomicUsize::new(0); - extern "C" fn callback( - _isolate: &mut v8::Isolate, - data: *mut std::ffi::c_void, - ) { - assert_eq!(data, std::ptr::null_mut()); - CALL_COUNT.fetch_add(1, Ordering::SeqCst); - } - assert_eq!( - false, - handle.request_interrupt(callback, std::ptr::null_mut()) - ); - assert_eq!(CALL_COUNT.load(Ordering::SeqCst), 0); + assert_eq!(true, isolate.terminate_execution()); + assert_eq!(true, isolate.cancel_terminate_execution()); } #[test] fn thread_safe_handle_drop_after_isolate() { let _setup_guard = setup(); - let mut isolate = v8::Isolate::new(Default::default()); + let isolate = v8::Isolate::new(Default::default()); let handle = isolate.thread_safe_handle(); // We can call it twice. let handle_ = isolate.thread_safe_handle();