mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-02-02 12:49:57 -05:00
Make get_data and set_data private (#384)
This commit is contained in:
parent
56c3d9f9c0
commit
defb39b101
2 changed files with 5 additions and 32 deletions
|
@ -188,26 +188,23 @@ impl Isolate {
|
||||||
|
|
||||||
/// Associate embedder-specific data with the isolate. |slot| has to be
|
/// Associate embedder-specific data with the isolate. |slot| has to be
|
||||||
/// between 0 and GetNumberOfDataSlots() - 1.
|
/// between 0 and GetNumberOfDataSlots() - 1.
|
||||||
pub unsafe fn set_data(&mut self, slot: u32, ptr: *mut c_void) {
|
unsafe fn set_data(&mut self, slot: u32, ptr: *mut c_void) {
|
||||||
v8__Isolate__SetData(self, slot + 1, ptr)
|
v8__Isolate__SetData(self, slot + 1, ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve embedder-specific data from the isolate.
|
/// Retrieve embedder-specific data from the isolate.
|
||||||
/// Returns NULL if SetData has never been called for the given |slot|.
|
/// Returns NULL if SetData has never been called for the given |slot|.
|
||||||
pub fn get_data(&self, slot: u32) -> *mut c_void {
|
fn get_data(&self, slot: u32) -> *mut c_void {
|
||||||
unsafe { v8__Isolate__GetData(self, slot + 1) }
|
unsafe { v8__Isolate__GetData(self, slot + 1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the maximum number of available embedder data slots. Valid slots
|
/// Returns the maximum number of available embedder data slots. Valid slots
|
||||||
/// are in the range of 0 - GetNumberOfDataSlots() - 1.
|
/// are in the range of 0 - GetNumberOfDataSlots() - 1.
|
||||||
pub fn get_number_of_data_slots(&self) -> u32 {
|
fn get_number_of_data_slots(&self) -> u32 {
|
||||||
unsafe { v8__Isolate__GetNumberOfDataSlots(self) - 1 }
|
unsafe { v8__Isolate__GetNumberOfDataSlots(self) - 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Safe alternative to Isolate::get_data
|
/// Get mutable reference to embedder data.
|
||||||
///
|
|
||||||
/// Warning: will be renamed to get_data_mut() after original unsafe version
|
|
||||||
/// is removed.
|
|
||||||
pub fn get_slot_mut<T: 'static>(&self) -> Option<RefMut<T>> {
|
pub fn get_slot_mut<T: 'static>(&self) -> Option<RefMut<T>> {
|
||||||
let cell = self.get_annex().slots.get(&TypeId::of::<T>())?;
|
let cell = self.get_annex().slots.get(&TypeId::of::<T>())?;
|
||||||
let ref_mut = cell.try_borrow_mut().ok()?;
|
let ref_mut = cell.try_borrow_mut().ok()?;
|
||||||
|
@ -218,10 +215,7 @@ impl Isolate {
|
||||||
Some(ref_mut)
|
Some(ref_mut)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Safe alternative to Isolate::get_data
|
/// Get reference to embedder data.
|
||||||
///
|
|
||||||
/// Warning: will be renamed to get_data() after original unsafe version is
|
|
||||||
/// removed.
|
|
||||||
pub fn get_slot<T: 'static>(&self) -> Option<Ref<T>> {
|
pub fn get_slot<T: 'static>(&self) -> Option<Ref<T>> {
|
||||||
let cell = self.get_annex().slots.get(&TypeId::of::<T>())?;
|
let cell = self.get_annex().slots.get(&TypeId::of::<T>())?;
|
||||||
let r = cell.try_borrow().ok()?;
|
let r = cell.try_borrow().ok()?;
|
||||||
|
@ -231,8 +225,6 @@ impl Isolate {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Safe alternative to Isolate::set_data
|
|
||||||
///
|
|
||||||
/// Use with Isolate::get_slot and Isolate::get_slot_mut to associate state
|
/// Use with Isolate::get_slot and Isolate::get_slot_mut to associate state
|
||||||
/// with an Isolate.
|
/// with an Isolate.
|
||||||
///
|
///
|
||||||
|
@ -244,9 +236,6 @@ impl Isolate {
|
||||||
/// Returns true if value was set without replacing an existing value.
|
/// Returns true if value was set without replacing an existing value.
|
||||||
///
|
///
|
||||||
/// The value will be dropped when the isolate is dropped.
|
/// The value will be dropped when the isolate is dropped.
|
||||||
///
|
|
||||||
/// Warning: will be renamed to set_data() after original unsafe version is
|
|
||||||
/// removed.
|
|
||||||
pub fn set_slot<T: 'static>(&mut self, value: T) -> bool {
|
pub fn set_slot<T: 'static>(&mut self, value: T) -> bool {
|
||||||
self
|
self
|
||||||
.get_annex_mut()
|
.get_annex_mut()
|
||||||
|
|
|
@ -2800,22 +2800,6 @@ fn context_from_object_template() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn get_and_set_data() {
|
|
||||||
let _setup_guard = setup();
|
|
||||||
let mut isolate = v8::Isolate::new(Default::default());
|
|
||||||
let nslots = isolate.get_number_of_data_slots();
|
|
||||||
assert!(nslots > 0);
|
|
||||||
for slot in 0..nslots {
|
|
||||||
let b = Box::new(123 as i32);
|
|
||||||
let ptr = Box::into_raw(b);
|
|
||||||
unsafe { isolate.set_data(slot, ptr as *mut std::ffi::c_void) };
|
|
||||||
let ptr = isolate.get_data(slot) as *mut i32;
|
|
||||||
let b = unsafe { Box::from_raw(ptr) };
|
|
||||||
assert_eq!(*b, 123);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn take_heap_snapshot() {
|
fn take_heap_snapshot() {
|
||||||
let _setup_guard = setup();
|
let _setup_guard = setup();
|
||||||
|
|
Loading…
Add table
Reference in a new issue