#[derive(Debug)] all the things (#468)

This commit implements Debug trait for most public structs.
This commit is contained in:
Moritz Gunz 2020-11-18 15:17:25 +01:00 committed by GitHub
parent 2a9e2e6409
commit efe0e76a75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 187 additions and 20 deletions

View File

@ -100,6 +100,7 @@ extern "C" {
/// namespace array_buffer, which will contain only the Allocator we opt in Rust
/// to allow it to live in the top level: v8::Allocator
#[repr(C)]
#[derive(Debug)]
pub struct Allocator(Opaque);
impl Shared for Allocator {
@ -169,6 +170,7 @@ pub unsafe extern "C" fn backing_store_deleter_callback(
/// default. Use Isolate::CreateParams::array_buffer_allocator_shared when
/// creating the Isolate to make it hold a reference to the allocator itself.
#[repr(C)]
#[derive(Debug)]
pub struct BackingStore([usize; 6]);
unsafe impl Send for BackingStore {}

View File

@ -195,6 +195,7 @@ impl Error for DataError {}
/// The superclass of objects that can reside on V8's heap.
#[repr(C)]
#[derive(Debug)]
pub struct Data(Opaque);
impl_from! { AccessorSignature for Data }
@ -312,6 +313,7 @@ impl_partial_eq! { Symbol for Data use identity }
/// An AccessorSignature specifies which receivers are valid parameters
/// to an accessor callback.
#[repr(C)]
#[derive(Debug)]
pub struct AccessorSignature(Opaque);
impl_deref! { Data for AccessorSignature }
@ -323,6 +325,7 @@ impl_partial_eq! { AccessorSignature for AccessorSignature use identity }
/// A sandboxed execution context with its own set of built-in objects
/// and functions.
#[repr(C)]
#[derive(Debug)]
pub struct Context(Opaque);
impl_deref! { Data for Context }
@ -333,6 +336,7 @@ impl_partial_eq! { Context for Context use identity }
/// An error message.
#[repr(C)]
#[derive(Debug)]
pub struct Message(Opaque);
impl_deref! { Data for Message }
@ -343,6 +347,7 @@ impl_partial_eq! { Message for Message use identity }
/// A compiled JavaScript module.
#[repr(C)]
#[derive(Debug)]
pub struct Module(Opaque);
impl_deref! { Data for Module }
@ -357,6 +362,7 @@ impl_partial_eq! { Module for Module use identity }
/// This is passed back to the embedder as part of
/// HostImportModuleDynamicallyCallback for module loading.
#[repr(C)]
#[derive(Debug)]
pub struct PrimitiveArray(Opaque);
impl_deref! { Data for PrimitiveArray }
@ -369,6 +375,7 @@ impl_partial_eq! { PrimitiveArray for PrimitiveArray use identity }
///
/// This is an experimental feature. Use at your own risk.
#[repr(C)]
#[derive(Debug)]
pub struct Private(Opaque);
impl_deref! { Data for Private }
@ -381,6 +388,7 @@ impl_partial_eq! { Private for Private use identity }
/// A compiled JavaScript script, tied to a Context which was active when the
/// script was compiled.
#[repr(C)]
#[derive(Debug)]
pub struct Script(Opaque);
impl_deref! { Data for Script }
@ -394,6 +402,7 @@ impl_partial_eq! { Script for Script use identity }
/// This is passed back to the embedder as part of
/// HostImportModuleDynamicallyCallback for module loading.
#[repr(C)]
#[derive(Debug)]
pub struct ScriptOrModule(Opaque);
impl_deref! { Data for ScriptOrModule }
@ -409,6 +418,7 @@ impl_partial_eq! { ScriptOrModule for ScriptOrModule use identity }
/// from a FunctionTemplate that inherits directly or indirectly from the
/// signature's FunctionTemplate.
#[repr(C)]
#[derive(Debug)]
pub struct Signature(Opaque);
impl_deref! { Data for Signature }
@ -419,6 +429,7 @@ impl_partial_eq! { Signature for Signature use identity }
/// A single JavaScript stack frame.
#[repr(C)]
#[derive(Debug)]
pub struct StackFrame(Opaque);
impl_deref! { Data for StackFrame }
@ -431,6 +442,7 @@ impl_partial_eq! { StackFrame for StackFrame use identity }
/// snapshot of the execution stack and the information remains valid after
/// execution continues.
#[repr(C)]
#[derive(Debug)]
pub struct StackTrace(Opaque);
impl_deref! { Data for StackTrace }
@ -441,6 +453,7 @@ impl_partial_eq! { StackTrace for StackTrace use identity }
/// The superclass of object and function templates.
#[repr(C)]
#[derive(Debug)]
pub struct Template(Opaque);
impl_deref! { Data for Template }
@ -559,6 +572,7 @@ impl_partial_eq! { ObjectTemplate for Template use identity }
/// include/v8-fast-api-calls.h. Please note that this feature is still
/// experimental.
#[repr(C)]
#[derive(Debug)]
pub struct FunctionTemplate(Opaque);
impl_deref! { Template for FunctionTemplate }
@ -574,6 +588,7 @@ impl_partial_eq! { FunctionTemplate for FunctionTemplate use identity }
/// Properties added to an ObjectTemplate are added to each object
/// created from the ObjectTemplate.
#[repr(C)]
#[derive(Debug)]
pub struct ObjectTemplate(Opaque);
impl_deref! { Template for ObjectTemplate }
@ -586,6 +601,7 @@ impl_partial_eq! { ObjectTemplate for ObjectTemplate use identity }
/// A compiled JavaScript module, not yet tied to a Context.
#[repr(C)]
#[derive(Debug)]
pub struct UnboundModuleScript(Opaque);
impl_deref! { Data for UnboundModuleScript }
@ -596,6 +612,7 @@ impl_partial_eq! { UnboundModuleScript for UnboundModuleScript use identity }
/// A compiled JavaScript script, not yet tied to a Context.
#[repr(C)]
#[derive(Debug)]
pub struct UnboundScript(Opaque);
impl_deref! { Data for UnboundScript }
@ -606,6 +623,7 @@ impl_partial_eq! { UnboundScript for UnboundScript use identity }
/// The superclass of all JavaScript values and objects.
#[repr(C)]
#[derive(Debug)]
pub struct Value(Opaque);
impl_deref! { Data for Value }
@ -708,6 +726,7 @@ impl_partial_eq! { Uint32 for Value use same_value_zero }
/// A JavaScript value that wraps a C++ void*. This type of value is mainly used
/// to associate C++ data structures with JavaScript objects.
#[repr(C)]
#[derive(Debug)]
pub struct External(Opaque);
impl_deref! { Value for External }
@ -720,6 +739,7 @@ impl_partial_eq! { External for External use identity }
/// A JavaScript object (ECMA-262, 4.3.3)
#[repr(C)]
#[derive(Debug)]
pub struct Object(Opaque);
impl_deref! { Value for Object }
@ -794,6 +814,7 @@ impl_partial_eq! { WasmModuleObject for Object use identity }
/// An instance of the built-in array constructor (ECMA-262, 15.4.2).
#[repr(C)]
#[derive(Debug)]
pub struct Array(Opaque);
impl_deref! { Object for Array }
@ -808,6 +829,7 @@ impl_partial_eq! { Array for Array use identity }
/// An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
#[repr(C)]
#[derive(Debug)]
pub struct ArrayBuffer(Opaque);
impl_deref! { Object for ArrayBuffer }
@ -823,6 +845,7 @@ impl_partial_eq! { ArrayBuffer for ArrayBuffer use identity }
/// A base class for an instance of one of "views" over ArrayBuffer,
/// including TypedArrays and DataView (ES6 draft 15.13).
#[repr(C)]
#[derive(Debug)]
pub struct ArrayBufferView(Opaque);
impl_deref! { Object for ArrayBufferView }
@ -863,6 +886,7 @@ impl_partial_eq! { Uint8ClampedArray for ArrayBufferView use identity }
/// An instance of DataView constructor (ES6 draft 15.13.7).
#[repr(C)]
#[derive(Debug)]
pub struct DataView(Opaque);
impl_deref! { ArrayBufferView for DataView }
@ -880,6 +904,7 @@ impl_partial_eq! { DataView for DataView use identity }
/// A base class for an instance of TypedArray series of constructors
/// (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct TypedArray(Opaque);
impl_deref! { ArrayBufferView for TypedArray }
@ -918,6 +943,7 @@ impl_partial_eq! { Uint8ClampedArray for TypedArray use identity }
/// An instance of BigInt64Array constructor.
#[repr(C)]
#[derive(Debug)]
pub struct BigInt64Array(Opaque);
impl_deref! { TypedArray for BigInt64Array }
@ -936,6 +962,7 @@ impl_partial_eq! { BigInt64Array for BigInt64Array use identity }
/// An instance of BigUint64Array constructor.
#[repr(C)]
#[derive(Debug)]
pub struct BigUint64Array(Opaque);
impl_deref! { TypedArray for BigUint64Array }
@ -954,6 +981,7 @@ impl_partial_eq! { BigUint64Array for BigUint64Array use identity }
/// An instance of Float32Array constructor (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct Float32Array(Opaque);
impl_deref! { TypedArray for Float32Array }
@ -972,6 +1000,7 @@ impl_partial_eq! { Float32Array for Float32Array use identity }
/// An instance of Float64Array constructor (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct Float64Array(Opaque);
impl_deref! { TypedArray for Float64Array }
@ -990,6 +1019,7 @@ impl_partial_eq! { Float64Array for Float64Array use identity }
/// An instance of Int16Array constructor (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct Int16Array(Opaque);
impl_deref! { TypedArray for Int16Array }
@ -1008,6 +1038,7 @@ impl_partial_eq! { Int16Array for Int16Array use identity }
/// An instance of Int32Array constructor (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct Int32Array(Opaque);
impl_deref! { TypedArray for Int32Array }
@ -1026,6 +1057,7 @@ impl_partial_eq! { Int32Array for Int32Array use identity }
/// An instance of Int8Array constructor (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct Int8Array(Opaque);
impl_deref! { TypedArray for Int8Array }
@ -1044,6 +1076,7 @@ impl_partial_eq! { Int8Array for Int8Array use identity }
/// An instance of Uint16Array constructor (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct Uint16Array(Opaque);
impl_deref! { TypedArray for Uint16Array }
@ -1062,6 +1095,7 @@ impl_partial_eq! { Uint16Array for Uint16Array use identity }
/// An instance of Uint32Array constructor (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct Uint32Array(Opaque);
impl_deref! { TypedArray for Uint32Array }
@ -1080,6 +1114,7 @@ impl_partial_eq! { Uint32Array for Uint32Array use identity }
/// An instance of Uint8Array constructor (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct Uint8Array(Opaque);
impl_deref! { TypedArray for Uint8Array }
@ -1098,6 +1133,7 @@ impl_partial_eq! { Uint8Array for Uint8Array use identity }
/// An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
#[repr(C)]
#[derive(Debug)]
pub struct Uint8ClampedArray(Opaque);
impl_deref! { TypedArray for Uint8ClampedArray }
@ -1116,6 +1152,7 @@ impl_partial_eq! { Uint8ClampedArray for Uint8ClampedArray use identity }
/// A BigInt object (https://tc39.github.io/proposal-bigint)
#[repr(C)]
#[derive(Debug)]
pub struct BigIntObject(Opaque);
impl_deref! { Object for BigIntObject }
@ -1130,6 +1167,7 @@ impl_partial_eq! { BigIntObject for BigIntObject use identity }
/// A Boolean object (ECMA-262, 4.3.15).
#[repr(C)]
#[derive(Debug)]
pub struct BooleanObject(Opaque);
impl_deref! { Object for BooleanObject }
@ -1144,6 +1182,7 @@ impl_partial_eq! { BooleanObject for BooleanObject use identity }
/// An instance of the built-in Date constructor (ECMA-262, 15.9).
#[repr(C)]
#[derive(Debug)]
pub struct Date(Opaque);
impl_deref! { Object for Date }
@ -1158,6 +1197,7 @@ impl_partial_eq! { Date for Date use identity }
/// A JavaScript function object (ECMA-262, 15.3).
#[repr(C)]
#[derive(Debug)]
pub struct Function(Opaque);
impl_deref! { Object for Function }
@ -1172,6 +1212,7 @@ impl_partial_eq! { Function for Function use identity }
/// An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1).
#[repr(C)]
#[derive(Debug)]
pub struct Map(Opaque);
impl_deref! { Object for Map }
@ -1186,6 +1227,7 @@ impl_partial_eq! { Map for Map use identity }
/// A Number object (ECMA-262, 4.3.21).
#[repr(C)]
#[derive(Debug)]
pub struct NumberObject(Opaque);
impl_deref! { Object for NumberObject }
@ -1200,6 +1242,7 @@ impl_partial_eq! { NumberObject for NumberObject use identity }
/// An instance of the built-in Promise constructor (ES6 draft).
#[repr(C)]
#[derive(Debug)]
pub struct Promise(Opaque);
impl_deref! { Object for Promise }
@ -1213,6 +1256,7 @@ impl_partial_eq! { Object for Promise use identity }
impl_partial_eq! { Promise for Promise use identity }
#[repr(C)]
#[derive(Debug)]
pub struct PromiseResolver(Opaque);
impl_deref! { Object for PromiseResolver }
@ -1226,6 +1270,7 @@ impl_partial_eq! { PromiseResolver for PromiseResolver use identity }
/// An instance of the built-in Proxy constructor (ECMA-262, 6th Edition,
/// 26.2.1).
#[repr(C)]
#[derive(Debug)]
pub struct Proxy(Opaque);
impl_deref! { Object for Proxy }
@ -1240,6 +1285,7 @@ impl_partial_eq! { Proxy for Proxy use identity }
/// An instance of the built-in RegExp constructor (ECMA-262, 15.10).
#[repr(C)]
#[derive(Debug)]
pub struct RegExp(Opaque);
impl_deref! { Object for RegExp }
@ -1254,6 +1300,7 @@ impl_partial_eq! { RegExp for RegExp use identity }
/// An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1).
#[repr(C)]
#[derive(Debug)]
pub struct Set(Opaque);
impl_deref! { Object for Set }
@ -1268,6 +1315,7 @@ impl_partial_eq! { Set for Set use identity }
/// An instance of the built-in SharedArrayBuffer constructor.
#[repr(C)]
#[derive(Debug)]
pub struct SharedArrayBuffer(Opaque);
impl_deref! { Object for SharedArrayBuffer }
@ -1282,6 +1330,7 @@ impl_partial_eq! { SharedArrayBuffer for SharedArrayBuffer use identity }
/// A String object (ECMA-262, 4.3.18).
#[repr(C)]
#[derive(Debug)]
pub struct StringObject(Opaque);
impl_deref! { Object for StringObject }
@ -1296,6 +1345,7 @@ impl_partial_eq! { StringObject for StringObject use identity }
/// A Symbol object (ECMA-262 edition 6).
#[repr(C)]
#[derive(Debug)]
pub struct SymbolObject(Opaque);
impl_deref! { Object for SymbolObject }
@ -1309,6 +1359,7 @@ impl_partial_eq! { Object for SymbolObject use identity }
impl_partial_eq! { SymbolObject for SymbolObject use identity }
#[repr(C)]
#[derive(Debug)]
pub struct WasmModuleObject(Opaque);
impl_deref! { Object for WasmModuleObject }
@ -1323,6 +1374,7 @@ impl_partial_eq! { WasmModuleObject for WasmModuleObject use identity }
/// The superclass of primitive values. See ECMA-262 4.3.2.
#[repr(C)]
#[derive(Debug)]
pub struct Primitive(Opaque);
impl_deref! { Value for Primitive }
@ -1352,6 +1404,7 @@ impl_partial_eq! { Uint32 for Primitive use same_value_zero }
/// A JavaScript BigInt value (https://tc39.github.io/proposal-bigint)
#[repr(C)]
#[derive(Debug)]
pub struct BigInt(Opaque);
impl_deref! { Primitive for BigInt }
@ -1366,6 +1419,7 @@ impl_partial_eq! { BigInt for BigInt use strict_equals }
/// A primitive boolean value (ECMA-262, 4.3.14). Either the true
/// or false value.
#[repr(C)]
#[derive(Debug)]
pub struct Boolean(Opaque);
impl_deref! { Primitive for Boolean }
@ -1380,6 +1434,7 @@ impl_partial_eq! { Boolean for Boolean use identity }
/// A superclass for symbols and strings.
#[repr(C)]
#[derive(Debug)]
pub struct Name(Opaque);
impl_deref! { Primitive for Name }
@ -1397,6 +1452,7 @@ impl_partial_eq! { Symbol for Name use identity }
/// A JavaScript string value (ECMA-262, 4.3.17).
#[repr(C)]
#[derive(Debug)]
pub struct String(Opaque);
impl_deref! { Name for String }
@ -1412,6 +1468,7 @@ impl_partial_eq! { String for String use strict_equals }
/// A JavaScript symbol (ECMA-262 edition 6)
#[repr(C)]
#[derive(Debug)]
pub struct Symbol(Opaque);
impl_deref! { Name for Symbol }
@ -1428,6 +1485,7 @@ impl_partial_eq! { Symbol for Symbol use identity }
/// A JavaScript number value (ECMA-262, 4.3.20)
#[repr(C)]
#[derive(Debug)]
pub struct Number(Opaque);
impl_deref! { Primitive for Number }
@ -1447,6 +1505,7 @@ impl_partial_eq! { Uint32 for Number use same_value_zero }
/// A JavaScript value representing a signed integer.
#[repr(C)]
#[derive(Debug)]
pub struct Integer(Opaque);
impl_deref! { Number for Integer }
@ -1466,6 +1525,7 @@ impl_partial_eq! { Uint32 for Integer use strict_equals }
/// A JavaScript value representing a 32-bit signed integer.
#[repr(C)]
#[derive(Debug)]
pub struct Int32(Opaque);
impl_deref! { Integer for Int32 }
@ -1483,6 +1543,7 @@ impl_partial_eq! { Int32 for Int32 use strict_equals }
/// A JavaScript value representing a 32-bit unsigned integer.
#[repr(C)]
#[derive(Debug)]
pub struct Uint32(Opaque);
impl_deref! { Integer for Uint32 }

View File

@ -260,6 +260,7 @@ impl Message {
/// Create new error objects by calling the corresponding error object
/// constructor with the message.
#[derive(Debug)]
pub struct Exception;
impl Exception {

View File

@ -11,6 +11,7 @@ pub union ExternalReference<'s> {
pub message: MessageCallback,
}
#[derive(Debug)]
pub struct ExternalReferences {
null_terminated: Vec<intptr_t>,
}

View File

@ -67,6 +67,7 @@ extern "C" {
// outlive the FunctionCallbackInfo/PropertyCallbackInfo object from which it
// is derived.
#[repr(C)]
#[derive(Debug)]
pub struct ReturnValue<'cb>(*mut Value, PhantomData<&'cb ()>);
/// In V8 ReturnValue<> has a type parameter, but
@ -103,6 +104,7 @@ impl<'cb> ReturnValue<'cb> {
/// including the receiver, the number and values of arguments, and
/// the holder of the function.
#[repr(C)]
#[derive(Debug)]
pub struct FunctionCallbackInfo {
// The layout of this struct must match that of `class FunctionCallbackInfo`
// as defined in v8.h.
@ -114,12 +116,14 @@ pub struct FunctionCallbackInfo {
/// The information passed to a property callback about the context
/// of the property access.
#[repr(C)]
#[derive(Debug)]
pub struct PropertyCallbackInfo {
// The layout of this struct must match that of `class PropertyCallbackInfo`
// as defined in v8.h.
args: *mut Opaque,
}
#[derive(Debug)]
pub struct FunctionCallbackArguments<'s> {
info: *const FunctionCallbackInfo,
phantom: PhantomData<&'s ()>,
@ -164,6 +168,7 @@ impl<'s> FunctionCallbackArguments<'s> {
}
}
#[derive(Debug)]
pub struct PropertyCallbackArguments<'s> {
info: *const PropertyCallbackInfo,
phantom: PhantomData<&'s ()>,

View File

@ -51,6 +51,7 @@ extern "C" {
/// never empty. In situations where empty handles are needed, use
/// Option<Local>.
#[repr(C)]
#[derive(Debug)]
pub struct Local<'s, T>(NonNull<T>, PhantomData<&'s ()>);
impl<'s, T> Local<'s, T> {
@ -118,6 +119,7 @@ impl<'s, T> Deref for Local<'s, T> {
/// A global handle contains a reference to a storage cell within
/// the V8 engine which holds an object value and which is updated by
/// the garbage collector whenever the object is moved.
#[derive(Debug)]
pub struct Global<T> {
data: NonNull<T>,
isolate_handle: IsolateHandle,
@ -300,7 +302,7 @@ where
}
}
#[derive(Copy, Clone)]
#[derive(Copy, Debug, Clone)]
pub struct HandleInfo<T> {
data: NonNull<T>,
host: HandleHost,
@ -312,7 +314,7 @@ impl<T> HandleInfo<T> {
}
}
#[derive(Copy, Clone)]
#[derive(Copy, Debug, Clone)]
enum HandleHost {
// Note: the `HandleHost::Scope` variant does not indicate that the handle
// it applies to is not associated with an `Isolate`. It only means that

View File

@ -23,6 +23,7 @@ use crate::support::UniqueRef;
use crate::Context;
use crate::Isolate;
use crate::Local;
use std::fmt::{self, Debug, Formatter};
extern "C" {
fn v8_inspector__V8Inspector__Channel__BASE__CONSTRUCT(
@ -176,6 +177,7 @@ pub unsafe extern "C" fn v8_inspector__V8InspectorClient__BASE__consoleAPIMessag
}
#[repr(C)]
#[derive(Debug)]
pub struct Channel {
_cxx_vtable: CxxVTable,
}
@ -305,6 +307,15 @@ impl ChannelBase {
}
}
impl Debug for ChannelBase {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("ChannelBase")
.field("cxx_base", &self.cxx_base)
.field("offset_within_embedder", &self.offset_within_embedder)
.finish()
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -318,6 +329,7 @@ mod tests {
// Using repr(C) to preserve field ordering and test that everything works
// when the ChannelBase field is not the first element of the struct.
#[repr(C)]
#[derive(Debug)]
pub struct TestChannel {
field1: i32,
base: ChannelBase,
@ -379,6 +391,7 @@ mod tests {
}
#[repr(C)]
#[derive(Debug)]
pub struct V8InspectorClient {
_cxx_vtable: CxxVTable,
}
@ -553,7 +566,17 @@ impl V8InspectorClientBase {
}
}
impl Debug for V8InspectorClientBase {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("V8InspectorClientBase")
.field("cxx_base", &self.cxx_base)
.field("offset_within_embedder", &self.offset_within_embedder)
.finish()
}
}
#[repr(C)]
#[derive(Debug)]
pub struct V8InspectorSession(Opaque);
impl V8InspectorSession {
@ -587,6 +610,7 @@ impl Drop for V8InspectorSession {
// case, but currently to obtain a `UniquePtr<StringBuffer>` is by making a
// copy using `StringBuffer::create()`.
#[repr(C)]
#[derive(Debug)]
pub struct StringBuffer {
_cxx_vtable: CxxVTable,
}
@ -615,7 +639,6 @@ impl Drop for StringBuffer {
}
unsafe impl Send for StringBuffer {}
use std::fmt;
use std::iter::ExactSizeIterator;
use std::iter::IntoIterator;
use std::marker::PhantomData;
@ -631,7 +654,7 @@ use std::string;
// `u8` have the same size. This is assumption is checked in 'support.h'.
// TODO: find/open upstream issue to allow #[repr(bool)] support.
#[derive(Clone, Copy)]
#[derive(Clone, Debug, Copy)]
#[repr(u8)]
pub enum StringView<'a> {
// Do not reorder!
@ -648,8 +671,8 @@ impl StringView<'static> {
impl fmt::Display for StringView<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::U16(v) => v.fmt(f),
Self::U8(v) => v.fmt(f),
Self::U16(v) => write!(f, "{}", v),
Self::U8(v) => write!(f, "{}", v),
}
}
}
@ -795,7 +818,7 @@ impl<'a, T> Deref for CharacterArray<'a, T> {
}
}
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub struct StringViewIterator<'a> {
view: StringView<'a>,
pos: usize,
@ -829,6 +852,7 @@ fn string_view_display() {
}
#[repr(C)]
#[derive(Debug)]
pub struct V8Inspector(Opaque);
impl V8Inspector {
@ -892,6 +916,7 @@ impl Drop for V8Inspector {
}
#[repr(C)]
#[derive(Debug)]
pub struct V8StackTrace {
_cxx_vtable: CxxVTable,
}

View File

@ -21,6 +21,7 @@ use std::any::TypeId;
use std::collections::HashMap;
use std::ffi::c_void;
use std::fmt::{self, Debug, Formatter};
use std::mem::MaybeUninit;
use std::ops::Deref;
use std::ops::DerefMut;
@ -122,6 +123,7 @@ pub type NearHeapLimitCallback = extern "C" fn(
/// get heap statistics from V8.
// Must be >= sizeof(v8::HeapStatistics), see v8__HeapStatistics__CONSTRUCT().
#[repr(C)]
#[derive(Debug)]
pub struct HeapStatistics([usize; 16]);
extern "C" {
@ -227,13 +229,14 @@ extern "C" {
fn v8__HeapStatistics__does_zap_garbage(s: *const HeapStatistics) -> usize;
}
#[repr(C)]
/// Isolate represents an isolated instance of the V8 engine. V8 isolates have
/// completely separate states. Objects from one isolate must not be used in
/// other isolates. The embedder can create multiple isolates and use them in
/// parallel in multiple threads. An isolate can be entered by at most one
/// thread at any given time. The Locker/Unlocker API must be used to
/// synchronize.
#[repr(C)]
#[derive(Debug)]
pub struct Isolate(Opaque);
impl Isolate {
@ -625,13 +628,22 @@ impl IsolateAnnex {
}
}
impl Debug for IsolateAnnex {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("IsolateAnnex")
.field("isolate", &self.isolate)
.field("isolate_mutex", &self.isolate_mutex)
.finish()
}
}
/// IsolateHandle is a thread-safe reference to an Isolate. It's main use is to
/// terminate execution of a running isolate from another thread.
///
/// It is created with Isolate::thread_safe_handle().
///
/// IsolateHandle is Cloneable, Send, and Sync.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct IsolateHandle(Arc<IsolateAnnex>);
unsafe impl Send for IsolateHandle {}
@ -734,6 +746,7 @@ impl IsolateHandle {
}
/// Same as Isolate but gets disposed when it goes out of scope.
#[derive(Debug)]
pub struct OwnedIsolate {
cxx_isolate: NonNull<Isolate>,
}

View File

@ -17,7 +17,7 @@ use std::ptr::null;
/// Initial configuration parameters for a new Isolate.
#[must_use]
#[derive(Default)]
#[derive(Debug, Default)]
pub struct CreateParams {
raw: raw::CreateParams,
allocations: CreateParamAllocations,
@ -157,7 +157,7 @@ impl CreateParams {
}
}
#[derive(Default)]
#[derive(Debug, Default)]
struct CreateParamAllocations {
// Owner of the snapshot data buffer itself.
snapshot_blob_data: Option<Allocation<[u8]>>,
@ -172,6 +172,7 @@ pub(crate) mod raw {
use super::*;
#[repr(C)]
#[derive(Debug)]
pub(crate) struct CreateParams {
pub code_event_handler: *const Opaque, // JitCodeEventHandler
pub constraints: ResourceConstraints,
@ -206,6 +207,7 @@ pub(crate) mod raw {
}
#[repr(C)]
#[derive(Debug)]
pub(crate) struct StartupData {
pub data: *const char,
pub raw_size: int,
@ -221,6 +223,7 @@ pub(crate) mod raw {
}
#[repr(C)]
#[derive(Debug)]
pub(crate) struct ResourceConstraints {
code_range_size_: usize,
max_old_generation_size_: usize,

View File

@ -169,8 +169,9 @@ extern "C" {
fn v8__Location__GetColumnNumber(this: *const Location) -> int;
}
#[repr(C)]
/// A location in JavaScript source.
#[repr(C)]
#[derive(Debug)]
pub struct Location([usize; 1]);
impl Location {

View File

@ -19,6 +19,7 @@ pub fn new_default_platform() -> UniquePtr<Platform> {
}
#[repr(C)]
#[derive(Debug)]
pub struct Platform(Opaque);
impl Drop for Platform {

View File

@ -1,3 +1,4 @@
use std::fmt::{self, Debug, Formatter};
use std::mem::drop;
use std::mem::forget;
use std::mem::ManuallyDrop;
@ -31,6 +32,7 @@ pub unsafe extern "C" fn v8__Task__BASE__Run(this: &mut Task) {
}
#[repr(C)]
#[derive(Debug)]
pub struct Task {
_cxx_vtable: CxxVTable,
}
@ -161,6 +163,15 @@ impl TaskBase {
}
}
impl Debug for TaskBase {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("TaskBase")
.field("cxx_base", &self.cxx_base)
.field("offset_within_embedder", &self.offset_within_embedder)
.finish()
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -200,7 +200,7 @@ pub enum PromiseRejectEvent {
PromiseResolveAfterResolved,
}
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct PromiseRejectMessage<'msg>([usize; 3], PhantomData<&'msg ()>);

View File

@ -109,6 +109,7 @@ use crate::Value;
/// Stack-allocated class which sets the execution context for all operations
/// executed within a local scope. After entering a context, all code compiled
/// and run is compiled and run in this context.
#[derive(Debug)]
pub struct ContextScope<'s, P> {
data: NonNull<data::ScopeData>,
_phantom: PhantomData<&'s mut P>,
@ -143,6 +144,7 @@ impl<'s, P: param::NewContextScope<'s>> ContextScope<'s, P> {
/// garbage collector will no longer track the object stored in the
/// handle and may deallocate it. The behavior of accessing a handle
/// for which the handle scope has been deleted is undefined.
#[derive(Debug)]
pub struct HandleScope<'s, C = Context> {
data: NonNull<data::ScopeData>,
_phantom: PhantomData<&'s mut C>,
@ -289,6 +291,7 @@ impl<'s> HandleScope<'s> {
// eventually remove it. Blocker at the time of writing is that there are some
// tests that enter an `EscapableHandleScope` without creating a `ContextScope`
// at all. These tests need to updated first.
#[derive(Debug)]
pub struct EscapableHandleScope<'s, 'e: 's, C = Context> {
data: NonNull<data::ScopeData>,
_phantom:
@ -324,6 +327,7 @@ impl<'s, 'e: 's, C> EscapableHandleScope<'s, 'e, C> {
}
/// An external exception handler.
#[derive(Debug)]
pub struct TryCatch<'s, P> {
data: NonNull<data::ScopeData>,
_phantom: PhantomData<&'s mut P>,
@ -502,6 +506,7 @@ where
/// - `&FunctionCallbackInfo`
/// - `&PropertyCallbackInfo`
/// - `&PromiseRejectMessage`
#[derive(Debug)]
pub struct CallbackScope<'s, C = Context> {
data: NonNull<data::ScopeData>,
_phantom: PhantomData<&'s mut HandleScope<'s, C>>,
@ -949,6 +954,7 @@ mod getter {
pub(crate) mod data {
use super::*;
#[derive(Debug)]
pub struct ScopeData {
// The first four fields are always valid - even when the `Box<ScopeData>`
// struct is free (does not contain data related to an actual scope).
@ -1436,6 +1442,7 @@ pub(crate) mod data {
}
}
#[derive(Debug)]
enum ScopeTypeSpecificData {
None,
ContextScope {
@ -1499,10 +1506,11 @@ pub(crate) mod data {
mod raw {
use super::*;
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
#[repr(transparent)]
pub(super) struct Address(NonZeroUsize);
#[derive(Debug)]
pub(super) struct ContextScope {
entered_context: NonNull<Context>,
}
@ -1523,6 +1531,7 @@ mod raw {
}
#[repr(C)]
#[derive(Debug)]
pub(super) struct HandleScope([usize; 3]);
impl HandleScope {
@ -1551,6 +1560,7 @@ mod raw {
}
#[repr(transparent)]
#[derive(Debug)]
pub(super) struct EscapeSlot(NonNull<raw::Address>);
impl EscapeSlot {
@ -1580,6 +1590,7 @@ mod raw {
}
#[repr(C)]
#[derive(Debug)]
pub(super) struct TryCatch([usize; 6]);
impl TryCatch {

View File

@ -13,6 +13,7 @@ use crate::Value;
/// The origin, within a file, of a script.
#[repr(C)]
#[derive(Debug)]
pub struct ScriptOrigin<'s>([usize; 7], PhantomData<&'s ()>);
extern "C" {

View File

@ -24,8 +24,9 @@ extern "C" {
) -> *const Module;
}
#[repr(C)]
/// Source code which can be then compiled to a UnboundScript or Script.
#[repr(C)]
#[derive(Debug)]
pub struct Source([usize; 8]);
impl Source {
@ -46,6 +47,7 @@ impl Drop for Source {
}
#[repr(C)]
#[derive(Debug)]
pub enum CompileOptions {
NoCompileOptions = 0,
ConsumeCodeCache,
@ -54,6 +56,7 @@ pub enum CompileOptions {
/// The reason for which we are not requesting or providing a code cache.
#[repr(C)]
#[derive(Debug)]
pub enum NoCacheReason {
NoReason = 0,
BecauseCachingDisabled,

View File

@ -46,6 +46,7 @@ extern "C" {
// TODO(piscisaureus): merge this struct with
// `isolate_create_params::raw::StartupData`.
#[repr(C)]
#[derive(Debug)]
pub struct StartupData {
data: *const char,
raw_size: int,
@ -79,6 +80,7 @@ impl Drop for StartupData {
}
#[repr(C)]
#[derive(Debug)]
pub enum FunctionCodeHandling {
Clear,
Keep,
@ -86,6 +88,7 @@ pub enum FunctionCodeHandling {
/// Helper class to create a snapshot data blob.
#[repr(C)]
#[derive(Debug)]
pub struct SnapshotCreator([usize; 1]);
impl SnapshotCreator {

View File

@ -35,6 +35,7 @@ extern "C" {
}
#[repr(C)]
#[derive(Debug)]
pub enum NewStringType {
Normal,
Internalized,

View File

@ -7,6 +7,7 @@ use std::convert::identity;
use std::convert::AsMut;
use std::convert::AsRef;
use std::convert::TryFrom;
use std::fmt::{self, Debug, Formatter};
use std::hash::BuildHasher;
use std::hash::Hasher;
use std::marker::PhantomData;
@ -40,6 +41,7 @@ pub type Opaque = [u8; 0];
/// Pointer to object allocated on the C++ heap. The pointer may be null.
#[repr(transparent)]
#[derive(Debug)]
pub struct UniquePtr<T: ?Sized>(Option<UniqueRef<T>>);
impl<T: ?Sized> UniquePtr<T> {
@ -100,6 +102,7 @@ impl<T> From<UniqueRef<T>> for UniquePtr<T> {
/// Pointer to object allocated on the C++ heap. The pointer may not be null.
#[repr(transparent)]
#[derive(Debug)]
pub struct UniqueRef<T: ?Sized>(NonNull<T>);
impl<T> UniqueRef<T> {
@ -194,7 +197,7 @@ where
/// Private base type which is shared by the `SharedPtr` and `SharedRef`
/// implementations.
#[repr(C)]
#[derive(Eq, PartialEq)]
#[derive(Eq, Debug, PartialEq)]
pub struct SharedPtrBase<T: Shared>([usize; 2], PhantomData<T>);
unsafe impl<T: Shared + Sync> Send for SharedPtrBase<T> {}
@ -214,6 +217,7 @@ impl<T: Shared> Drop for SharedPtrBase<T> {
/// Wrapper around a C++ shared_ptr. A shared_ptr may be be null.
#[repr(C)]
#[derive(Debug)]
pub struct SharedPtr<T: Shared>(SharedPtrBase<T>);
impl<T: Shared> SharedPtr<T> {
@ -280,6 +284,7 @@ impl<T: Shared> From<SharedRef<T>> for SharedPtr<T> {
/// Wrapper around a C++ shared_ptr. The shared_ptr is assumed to contain a
/// value and may not be null.
#[repr(C)]
#[derive(Debug)]
pub struct SharedRef<T: Shared>(SharedPtrBase<T>);
impl<T: Shared> SharedRef<T> {
@ -423,6 +428,19 @@ impl<T: ?Sized + 'static> Allocation<T> {
}
}
impl<T: Debug + ?Sized> Debug for Allocation<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Allocation::Arc(r) => f.debug_tuple("Arc").field(&r).finish(),
Allocation::Box(b) => f.debug_tuple("Box").field(&b).finish(),
Allocation::Other(_) => f.debug_tuple("Other").finish(),
Allocation::Rc(r) => f.debug_tuple("Rc").field(&r).finish(),
Allocation::Static(s) => f.debug_tuple("Static").field(&s).finish(),
Allocation::UniqueRef(u) => f.debug_tuple("UniqueRef").field(&u).finish(),
}
}
}
impl<T: ?Sized> Deref for Allocation<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
@ -477,13 +495,14 @@ impl From<Option<bool>> for MaybeBool {
}
}
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
#[repr(transparent)]
pub struct CxxVTable(pub *const Opaque);
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub struct RustVTable<DynT>(pub *const Opaque, pub PhantomData<DynT>);
#[derive(Debug)]
pub struct FieldOffset<F>(usize, PhantomData<F>);
unsafe impl<F> Send for FieldOffset<F> where F: Send {}
@ -560,7 +579,7 @@ impl BuildHasher for BuildTypeIdHasher {
}
#[repr(C)]
#[derive(Default)]
#[derive(Debug, Default)]
pub struct Maybe<T> {
has_value: bool,
value: T,
@ -588,7 +607,7 @@ where
impl<T> UnitType for T where T: Copy + Sized {}
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
struct UnitValue<T>(PhantomData<T>)
where
Self: Sized;
@ -622,7 +641,10 @@ where
}
}
#[derive(Debug)]
pub struct DefaultTag;
#[derive(Debug)]
pub struct IdenticalConversionTag;
pub trait MapFnFrom<F, Tag = DefaultTag>