0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-02-02 04:37:35 -05:00

Isolate::thread_safe_handle() no longer requires mutable reference (#562)

This commit is contained in:
Bartek Iwańczuk 2020-12-31 08:30:30 +01:00 committed by GitHub
parent f22a00e726
commit 41f29a19c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 24 deletions

View file

@ -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()
}
}

View file

@ -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())
}

View file

@ -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();