mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 15:04:33 -05:00
Add methods for termination to Isolate (#561)
This commit adds following methods to Isolate: - terminate_execution - cancel_terminate_execution - is_execution_terminating
This commit is contained in:
parent
810c108170
commit
cf7bb2d001
2 changed files with 38 additions and 0 deletions
|
@ -271,6 +271,21 @@ impl Isolate {
|
|||
IsolateHandle::new(self)
|
||||
}
|
||||
|
||||
/// See [`IsolateHandle::terminate_execution`]
|
||||
pub fn terminate_execution(&mut self) -> bool {
|
||||
self.thread_safe_handle().terminate_execution()
|
||||
}
|
||||
|
||||
/// See [`IsolateHandle::cancel_terminate_execution`]
|
||||
pub fn cancel_terminate_execution(&mut self) -> bool {
|
||||
self.thread_safe_handle().cancel_terminate_execution()
|
||||
}
|
||||
|
||||
/// See [`IsolateHandle::is_execution_terminating`]
|
||||
pub fn is_execution_terminating(&mut self) -> bool {
|
||||
self.thread_safe_handle().is_execution_terminating()
|
||||
}
|
||||
|
||||
pub(crate) fn create_annex(
|
||||
&mut self,
|
||||
create_param_allocations: Box<dyn Any>,
|
||||
|
|
|
@ -730,6 +730,29 @@ 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());
|
||||
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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thread_safe_handle_drop_after_isolate() {
|
||||
let _setup_guard = setup();
|
||||
|
|
Loading…
Reference in a new issue