Browse Source

Improve debug output of `JsNativeError` and `Realm` (#2894)

It was reported that the `dbg!` output of native errors was too long. This PR skips printing the `Realm` of a `JsNativeError`. It also improves the `dbg!` output of `Realm` by skipping printing `Inner` and only printing the inner fields of `Inner`.
pull/2895/head
José Julián Espina 2 years ago
parent
commit
9795eba1c4
  1. 12
      boa_engine/src/error.rs
  2. 17
      boa_engine/src/realm.rs

12
boa_engine/src/error.rs

@ -417,7 +417,7 @@ impl std::fmt::Display for JsError {
///
/// assert_eq!(native_error.message(), "cannot decode uri");
/// ```
#[derive(Debug, Clone, Trace, Finalize, Error)]
#[derive(Clone, Trace, Finalize, Error)]
#[error("{kind}: {message}")]
pub struct JsNativeError {
/// The kind of native error (e.g. `TypeError`, `SyntaxError`, etc.)
@ -428,6 +428,16 @@ pub struct JsNativeError {
realm: Option<Realm>,
}
impl std::fmt::Debug for JsNativeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("JsNativeError")
.field("kind", &self.kind)
.field("message", &self.message)
.field("cause", &self.cause)
.finish_non_exhaustive()
}
}
impl JsNativeError {
/// Creates a new `JsNativeError` from its `kind`, `message` and (optionally) its `cause`.
fn new(kind: JsNativeErrorKind, message: Box<str>, cause: Option<Box<JsError>>) -> Self {

17
boa_engine/src/realm.rs

@ -6,6 +6,8 @@
//!
//! A realm is represented in this implementation as a Realm struct with the fields specified from the spec.
use std::fmt;
use crate::{
context::{intrinsics::Intrinsics, HostHooks},
environments::DeclarativeEnvironment,
@ -17,18 +19,29 @@ use boa_profiler::Profiler;
/// Representation of a Realm.
///
/// In the specification these are called Realm Records.
#[derive(Clone, Debug, Trace, Finalize)]
#[derive(Clone, Trace, Finalize)]
pub struct Realm {
inner: Gc<Inner>,
}
impl fmt::Debug for Realm {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Realm")
.field("intrinsics", &self.inner.intrinsics)
.field("environment", &self.inner.environment)
.field("global_object", &self.inner.global_object)
.field("global_this", &self.inner.global_this)
.finish()
}
}
impl PartialEq for Realm {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(&*self.inner, &*other.inner)
}
}
#[derive(Debug, Trace, Finalize)]
#[derive(Trace, Finalize)]
struct Inner {
intrinsics: Intrinsics,
environment: Gc<DeclarativeEnvironment>,

Loading…
Cancel
Save