Skip to content

Commit

Permalink
show object kind, name and address when using dbg! (#2960)
Browse files Browse the repository at this point in the history
* show object kind, name and address when using dbg!

* Update boa_engine/src/object/jsobject.rs

Co-authored-by: Haled Odat <[email protected]>

* Update boa_engine/src/object/jsobject.rs

Co-authored-by: Haled Odat <[email protected]>

* Run `rust-fmt`

---------

Co-authored-by: Haled Odat <[email protected]>
  • Loading branch information
2 people authored and Razican committed Jun 26, 2023
1 parent ab53109 commit 010de8b
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions boa_engine/src/object/jsobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
property::{PropertyDescriptor, PropertyKey},
string::utf16,
value::PreferredType,
Context, JsResult, JsValue,
Context, JsResult, JsString, JsValue,
};
use boa_gc::{self, Finalize, Gc, GcRefCell, Trace};
use boa_interner::Sym;
Expand Down Expand Up @@ -1092,7 +1092,6 @@ impl RecursionLimiter {

impl Debug for JsObject {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
let ptr: *const _ = self.vtable();
let limiter = RecursionLimiter::new(self.as_ref());

// Typically, using `!limiter.live` would be good enough here.
Expand All @@ -1102,10 +1101,26 @@ impl Debug for JsObject {
// Instead, we check if the object has appeared before in the entire graph. This means that objects will appear
// at most once, hopefully making things a bit clearer.
if !limiter.visited && !limiter.live {
f.debug_struct("JsObject")
.field("vtable", &ptr)
.field("object", &self.inner.object)
.finish()
let ptr: *const _ = self.as_ref();
let obj = self.borrow();
let kind = obj.kind();
if obj.is_function() {
let name_prop = obj
.properties()
.get(&PropertyKey::String(JsString::from("name")));
let name = match name_prop {
None => JsString::default(),
Some(prop) => prop
.value()
.and_then(JsValue::as_string)
.cloned()
.unwrap_or_default(),
};

return f.write_fmt(format_args!("({:?}) {:?} 0x{:X}", kind, name, ptr as usize));
}

f.write_fmt(format_args!("({:?}) 0x{:X}", kind, ptr as usize))
} else {
f.write_str("{ ... }")
}
Expand Down

0 comments on commit 010de8b

Please sign in to comment.