mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-02-08 07:16:31 -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::NamedSetterCallback;
|
||||||
use crate::PropertyEnumeratorCallback;
|
use crate::PropertyEnumeratorCallback;
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub union ExternalReference<'s> {
|
pub union ExternalReference<'s> {
|
||||||
|
@ -26,6 +27,13 @@ pub union ExternalReference<'s> {
|
||||||
pub pointer: *mut c_void,
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ExternalReferences {
|
pub struct ExternalReferences {
|
||||||
null_terminated: Vec<intptr_t>,
|
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())
|
let external_ptr = Box::into_raw(vec![0_u8, 1, 2, 3, 4].into_boxed_slice())
|
||||||
as *mut [u8] as *mut c_void;
|
as *mut [u8] as *mut c_void;
|
||||||
// Push them to the external reference table.
|
// Push them to the external reference table.
|
||||||
let refs = v8::ExternalReferences::new(&[
|
let refs = [
|
||||||
v8::ExternalReference {
|
v8::ExternalReference {
|
||||||
function: fn_callback.map_fn_to(),
|
function: fn_callback.map_fn_to(),
|
||||||
},
|
},
|
||||||
|
@ -5319,7 +5319,10 @@ fn external_references() {
|
||||||
v8::ExternalReference {
|
v8::ExternalReference {
|
||||||
pointer: external_ptr,
|
pointer: external_ptr,
|
||||||
},
|
},
|
||||||
]);
|
];
|
||||||
|
// Exercise the Debug impl
|
||||||
|
println!("{refs:?}");
|
||||||
|
let refs = v8::ExternalReferences::new(&refs);
|
||||||
// TODO(piscisaureus): leaking the `ExternalReferences` collection shouldn't
|
// TODO(piscisaureus): leaking the `ExternalReferences` collection shouldn't
|
||||||
// be necessary. The reference needs to remain valid for the lifetime of the
|
// 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
|
// `SnapshotCreator` or `Isolate` that uses it, which would be the case here
|
||||||
|
|
Loading…
Add table
Reference in a new issue