0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-03-09 21:47:00 -04:00

Move 'create_param_allocations' from OwnedIsolate to IsolateAnnex (#365)

This commit is contained in:
Bert Belder 2020-04-23 20:14:53 +02:00
parent cc626550b1
commit db5bbf6e43
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461
2 changed files with 15 additions and 17 deletions

View file

@ -145,9 +145,8 @@ impl Isolate {
crate::V8::assert_initialized(); crate::V8::assert_initialized();
let (raw_create_params, create_param_allocations) = params.finalize(); let (raw_create_params, create_param_allocations) = params.finalize();
let cxx_isolate = unsafe { v8__Isolate__New(&raw_create_params) }; let cxx_isolate = unsafe { v8__Isolate__New(&raw_create_params) };
let mut owned_isolate = let mut owned_isolate = OwnedIsolate::new(cxx_isolate);
OwnedIsolate::new(cxx_isolate, create_param_allocations); owned_isolate.create_annex(create_param_allocations);
owned_isolate.create_annex();
owned_isolate owned_isolate
} }
@ -160,8 +159,8 @@ impl Isolate {
IsolateHandle::new(self) IsolateHandle::new(self)
} }
fn create_annex(&mut self) { fn create_annex(&mut self, create_param_allocations: Box<dyn Any>) {
let annex_arc = Arc::new(IsolateAnnex::new(self)); let annex_arc = Arc::new(IsolateAnnex::new(self, create_param_allocations));
let annex_ptr = Arc::into_raw(annex_arc); let annex_ptr = Arc::into_raw(annex_arc);
unsafe { v8__Isolate__SetData(self, 0, annex_ptr as *mut c_void) } unsafe { v8__Isolate__SetData(self, 0, annex_ptr as *mut c_void) }
} }
@ -362,7 +361,8 @@ impl Isolate {
annex.isolate = null_mut(); annex.isolate = null_mut();
} }
// Clear slots. // Clear slots and drop owned objects that were taken out of `CreateParams`.
annex.create_param_allocations = Box::new(());
annex.slots.clear(); annex.slots.clear();
// Subtract one from the Arc<IsolateAnnex> reference count. // Subtract one from the Arc<IsolateAnnex> reference count.
@ -404,6 +404,7 @@ impl Isolate {
} }
pub(crate) struct IsolateAnnex { pub(crate) struct IsolateAnnex {
create_param_allocations: Box<dyn Any>,
slots: HashMap<TypeId, RefCell<Box<dyn Any>>>, slots: HashMap<TypeId, RefCell<Box<dyn Any>>>,
// The `isolate` and `isolate_mutex` fields are there so an `IsolateHandle` // The `isolate` and `isolate_mutex` fields are there so an `IsolateHandle`
// (which may outlive the isolate itself) can determine whether the isolate is // (which may outlive the isolate itself) can determine whether the isolate is
@ -417,8 +418,12 @@ pub(crate) struct IsolateAnnex {
} }
impl IsolateAnnex { impl IsolateAnnex {
fn new(isolate: &mut Isolate) -> Self { fn new(
isolate: &mut Isolate,
create_param_allocations: Box<dyn Any>,
) -> Self {
Self { Self {
create_param_allocations,
slots: HashMap::new(), slots: HashMap::new(),
isolate, isolate,
isolate_mutex: Mutex::new(()), isolate_mutex: Mutex::new(()),
@ -531,19 +536,12 @@ impl IsolateHandle {
/// Same as Isolate but gets disposed when it goes out of scope. /// Same as Isolate but gets disposed when it goes out of scope.
pub struct OwnedIsolate { pub struct OwnedIsolate {
cxx_isolate: NonNull<Isolate>, cxx_isolate: NonNull<Isolate>,
create_param_allocations: Box<dyn Any>,
} }
impl OwnedIsolate { impl OwnedIsolate {
pub(crate) fn new( pub(crate) fn new(cxx_isolate: *mut Isolate) -> Self {
cxx_isolate: *mut Isolate,
create_param_allocations: Box<dyn Any>,
) -> Self {
let cxx_isolate = NonNull::new(cxx_isolate).unwrap(); let cxx_isolate = NonNull::new(cxx_isolate).unwrap();
Self { Self { cxx_isolate }
cxx_isolate,
create_param_allocations,
}
} }
} }

View file

@ -133,6 +133,6 @@ impl SnapshotCreator {
// revisited after the libdeno integration is complete. // revisited after the libdeno integration is complete.
pub unsafe fn get_owned_isolate(&mut self) -> OwnedIsolate { pub unsafe fn get_owned_isolate(&mut self) -> OwnedIsolate {
let isolate_ptr = v8__SnapshotCreator__GetIsolate(self); let isolate_ptr = v8__SnapshotCreator__GetIsolate(self);
OwnedIsolate::new(isolate_ptr, Box::new(())) OwnedIsolate::new(isolate_ptr)
} }
} }