mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-25 15:29:43 -05:00
Explicitly drop slots when disposing an isolate (#364)
This commit is contained in:
parent
ce54d39929
commit
cc626550b1
2 changed files with 20 additions and 11 deletions
|
@ -352,7 +352,22 @@ impl Isolate {
|
||||||
/// Disposes the isolate. The isolate must not be entered by any
|
/// Disposes the isolate. The isolate must not be entered by any
|
||||||
/// thread to be disposable.
|
/// thread to be disposable.
|
||||||
unsafe fn dispose(&mut self) {
|
unsafe fn dispose(&mut self) {
|
||||||
IsolateHandle::dispose_isolate(self);
|
let annex = self.get_annex_mut();
|
||||||
|
|
||||||
|
// Set the `isolate` pointer inside the annex struct to null, so any
|
||||||
|
// IsolateHandle that outlives the isolate will know that it can't call
|
||||||
|
// methods on the isolate.
|
||||||
|
{
|
||||||
|
let _lock = annex.isolate_mutex.lock().unwrap();
|
||||||
|
annex.isolate = null_mut();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear slots.
|
||||||
|
annex.slots.clear();
|
||||||
|
|
||||||
|
// Subtract one from the Arc<IsolateAnnex> reference count.
|
||||||
|
Arc::from_raw(annex);
|
||||||
|
self.set_data(0, null_mut());
|
||||||
|
|
||||||
// No test case in rusty_v8 show this, but there have been situations in
|
// No test case in rusty_v8 show this, but there have been situations in
|
||||||
// deno where dropping Annex before the states causes a segfault.
|
// deno where dropping Annex before the states causes a segfault.
|
||||||
|
@ -429,16 +444,6 @@ impl IsolateHandle {
|
||||||
Self(isolate.get_annex_arc())
|
Self(isolate.get_annex_arc())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispose_isolate(isolate: &mut Isolate) {
|
|
||||||
let annex = isolate.get_annex_mut();
|
|
||||||
{
|
|
||||||
let _lock = annex.isolate_mutex.lock().unwrap();
|
|
||||||
annex.isolate = null_mut();
|
|
||||||
}
|
|
||||||
unsafe { Arc::from_raw(annex) };
|
|
||||||
unsafe { isolate.set_data(0, null_mut()) };
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Forcefully terminate the current thread of JavaScript execution
|
/// Forcefully terminate the current thread of JavaScript execution
|
||||||
/// in the given isolate.
|
/// in the given isolate.
|
||||||
///
|
///
|
||||||
|
|
|
@ -128,6 +128,9 @@ impl DerefMut for EsIsolate {
|
||||||
fn slots_layer1() {
|
fn slots_layer1() {
|
||||||
let drop_count = Rc::new(AtomicUsize::new(0));
|
let drop_count = Rc::new(AtomicUsize::new(0));
|
||||||
let mut core_isolate = CoreIsolate::new(drop_count.clone());
|
let mut core_isolate = CoreIsolate::new(drop_count.clone());
|
||||||
|
// The existence of a IsolateHandle that outlives the isolate should not
|
||||||
|
// inhibit dropping of slot contents.
|
||||||
|
let isolate_handle = core_isolate.thread_safe_handle();
|
||||||
assert!(core_isolate.execute("1 + 1"));
|
assert!(core_isolate.execute("1 + 1"));
|
||||||
assert!(!core_isolate.execute("throw 'foo'"));
|
assert!(!core_isolate.execute("throw 'foo'"));
|
||||||
assert_eq!(0, core_isolate.get_i());
|
assert_eq!(0, core_isolate.get_i());
|
||||||
|
@ -138,6 +141,7 @@ fn slots_layer1() {
|
||||||
core_isolate.run_microtasks();
|
core_isolate.run_microtasks();
|
||||||
drop(core_isolate);
|
drop(core_isolate);
|
||||||
assert_eq!(drop_count.load(Ordering::SeqCst), 1);
|
assert_eq!(drop_count.load(Ordering::SeqCst), 1);
|
||||||
|
drop(isolate_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue