Skip to content

Commit

Permalink
Merge d0e93a2 into 2c19c6a
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Feb 23, 2022
2 parents 2c19c6a + d0e93a2 commit 9cb7d91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit 9cb7d91

Please sign in to comment.