Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Improve debug output of JsNativeError and Realm #2894

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion boa_engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand All @@ -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 {
Expand Down
17 changes: 15 additions & 2 deletions boa_engine/src/realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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>,
Expand Down