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] - Toggleable JsValue internals displaying #1865

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion boa_engine/src/value/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ use super::{fmt, Display, HashSet, JsValue, PropertyKey};
#[derive(Debug, Clone, Copy)]
pub struct ValueDisplay<'value> {
pub(super) value: &'value JsValue,
pub(super) internals: bool,
}

impl ValueDisplay<'_> {
/// Display internal information about value.
///
/// By default this is `false`.
#[inline]
pub fn internals(mut self, yes: bool) -> Self {
self.internals = yes;
self
}
}

/// A helper macro for printing objects
Expand Down Expand Up @@ -275,7 +287,9 @@ impl Display for ValueDisplay<'_> {
},
JsValue::String(ref v) => write!(f, "\"{v}\""),
JsValue::Rational(v) => format_rational(*v, f),
JsValue::Object(_) => write!(f, "{}", log_string_from(self.value, true, true)),
JsValue::Object(_) => {
write!(f, "{}", log_string_from(self.value, self.internals, true))
}
JsValue::Integer(v) => write!(f, "{v}"),
JsValue::BigInt(ref num) => write!(f, "{num}n"),
}
Expand Down
8 changes: 7 additions & 1 deletion boa_engine/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ impl JsValue {

/// Returns an object that implements `Display`.
///
/// By default the internals are not shown, but they can be toggled
/// with [`ValueDisplay::internals`] method.
///
/// # Examples
///
/// ```
Expand All @@ -505,7 +508,10 @@ impl JsValue {
/// ```
#[inline]
pub fn display(&self) -> ValueDisplay<'_> {
ValueDisplay { value: self }
ValueDisplay {
value: self,
internals: false,
}
}

/// Converts the value to a string.
Expand Down
7 changes: 5 additions & 2 deletions boa_tester/src/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ impl Test {
match context.eval(&self.content.as_ref()) {
Ok(res) => (false, res.display().to_string()),
Err(e) => {
let passed =
e.display().to_string().contains(error_type.as_ref());
let passed = e
.display()
.internals(true)
.to_string()
.contains(error_type.as_ref());

(passed, format!("Uncaught {}", e.display()))
}
Expand Down