From 11340c9ca3b97e4d9605aee60f7106695bf74df9 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 23 Apr 2020 16:46:53 -0400 Subject: [PATCH] There should be a single entry point for creating IsolateHandle (#361) --- src/global.rs | 4 ++-- src/isolate.rs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/global.rs b/src/global.rs index 1c984db2..ffae9336 100644 --- a/src/global.rs +++ b/src/global.rs @@ -59,7 +59,7 @@ impl Global { Self { value: other_value .map(|v| unsafe { transmute(v8__Global__New(isolate, transmute(v))) }), - isolate_handle: other_value.map(|_| IsolateHandle::new(isolate)), + isolate_handle: other_value.map(|_| isolate.thread_safe_handle()), } } @@ -104,7 +104,7 @@ impl Global { ) }, } - self.isolate_handle = other_value.map(|_| IsolateHandle::new(isolate)); + self.isolate_handle = other_value.map(|_| isolate.thread_safe_handle()); } /// If non-empty, destroy the underlying storage cell diff --git a/src/isolate.rs b/src/isolate.rs index 3fb73c6e..6e783924 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -431,6 +431,12 @@ impl IsolateAnnex { } } +/// IsolateHandle is a thread-safe reference to an Isolate. It's main use is to +/// terminate execution of a running isolate from another thread. +/// +/// It is created with Isolate::thread_safe_handle(). +/// +/// IsolateHandle is Cloneable, Send, and Sync. #[derive(Clone)] pub struct IsolateHandle(Arc); @@ -445,7 +451,7 @@ impl IsolateHandle { self.0.isolate } - pub(crate) fn new(isolate: &mut Isolate) -> Self { + fn new(isolate: &mut Isolate) -> Self { Self(isolate.get_annex_arc()) }