mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-25 16:49:29 -05:00
chore: Add Debug for ExternalReference (#1272)
This commit is contained in:
parent
226c662da6
commit
4110d1bf4e
2 changed files with 13 additions and 2 deletions
|
@ -11,6 +11,7 @@ use crate::NamedGetterCallback;
|
|||
use crate::NamedSetterCallback;
|
||||
use crate::PropertyEnumeratorCallback;
|
||||
use std::ffi::c_void;
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub union ExternalReference<'s> {
|
||||
|
@ -26,6 +27,13 @@ pub union ExternalReference<'s> {
|
|||
pub pointer: *mut c_void,
|
||||
}
|
||||
|
||||
impl<'s> Debug for ExternalReference<'s> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
// SAFETY: All union fields are the same size
|
||||
unsafe { (self.pointer).fmt(f) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ExternalReferences {
|
||||
null_terminated: Vec<intptr_t>,
|
||||
|
|
|
@ -5309,7 +5309,7 @@ fn external_references() {
|
|||
let external_ptr = Box::into_raw(vec![0_u8, 1, 2, 3, 4].into_boxed_slice())
|
||||
as *mut [u8] as *mut c_void;
|
||||
// Push them to the external reference table.
|
||||
let refs = v8::ExternalReferences::new(&[
|
||||
let refs = [
|
||||
v8::ExternalReference {
|
||||
function: fn_callback.map_fn_to(),
|
||||
},
|
||||
|
@ -5319,7 +5319,10 @@ fn external_references() {
|
|||
v8::ExternalReference {
|
||||
pointer: external_ptr,
|
||||
},
|
||||
]);
|
||||
];
|
||||
// Exercise the Debug impl
|
||||
println!("{refs:?}");
|
||||
let refs = v8::ExternalReferences::new(&refs);
|
||||
// TODO(piscisaureus): leaking the `ExternalReferences` collection shouldn't
|
||||
// be necessary. The reference needs to remain valid for the lifetime of the
|
||||
// `SnapshotCreator` or `Isolate` that uses it, which would be the case here
|
||||
|
|
Loading…
Reference in a new issue