0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-21 15:04:33 -05:00

chore: Add Debug for ExternalReference (#1272)

This commit is contained in:
Matt Mastracci 2023-07-11 10:09:29 -06:00 committed by GitHub
parent 226c662da6
commit 4110d1bf4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -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>,

View file

@ -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