From dca9dfa40141ae56bf9d2d495a0cb65921a3acd2 Mon Sep 17 00:00:00 2001 From: jasonwilliams Date: Wed, 24 May 2023 23:33:29 +0100 Subject: [PATCH 1/4] show object kind, name and address when using dbg! --- boa_engine/src/object/jsobject.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/boa_engine/src/object/jsobject.rs b/boa_engine/src/object/jsobject.rs index 56eed871442..19445df343f 100644 --- a/boa_engine/src/object/jsobject.rs +++ b/boa_engine/src/object/jsobject.rs @@ -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; @@ -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. @@ -1102,10 +1101,29 @@ 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(); + let name_prop = self + .borrow() + .properties() + .get(&PropertyKey::String(JsString::from("name"))); + + if obj.is_function() { + let name = match name_prop { + None => JsString::default(), + Some(prop) => prop + .value() + .expect("no name property") + .as_string() + .expect("cannot convert to string") + .clone(), + }; + + 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("{ ... }") } From b9d0436131c18b81bdc849b2d6ec2d9befca4c03 Mon Sep 17 00:00:00 2001 From: Jason Williams <936006+jasonwilliams@users.noreply.github.com> Date: Sun, 28 May 2023 16:33:13 +0100 Subject: [PATCH 2/4] Update boa_engine/src/object/jsobject.rs Co-authored-by: Haled Odat <8566042+HalidOdat@users.noreply.github.com> --- boa_engine/src/object/jsobject.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/boa_engine/src/object/jsobject.rs b/boa_engine/src/object/jsobject.rs index 19445df343f..2a840ee3e1d 100644 --- a/boa_engine/src/object/jsobject.rs +++ b/boa_engine/src/object/jsobject.rs @@ -1114,10 +1114,9 @@ impl Debug for JsObject { None => JsString::default(), Some(prop) => prop .value() - .expect("no name property") - .as_string() - .expect("cannot convert to string") - .clone(), + .and_then(JsValue::as_string) + .cloned() + .unwrap_or_default() }; return f.write_fmt(format_args!("({:?}) {:?} 0x{:X}", kind, name, ptr as usize)); From 8b27bd64ea1f7c516e047266495468b91f311626 Mon Sep 17 00:00:00 2001 From: Jason Williams <936006+jasonwilliams@users.noreply.github.com> Date: Sun, 28 May 2023 16:33:45 +0100 Subject: [PATCH 3/4] Update boa_engine/src/object/jsobject.rs Co-authored-by: Haled Odat <8566042+HalidOdat@users.noreply.github.com> --- boa_engine/src/object/jsobject.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/boa_engine/src/object/jsobject.rs b/boa_engine/src/object/jsobject.rs index 2a840ee3e1d..ef5a2ff7a94 100644 --- a/boa_engine/src/object/jsobject.rs +++ b/boa_engine/src/object/jsobject.rs @@ -1104,12 +1104,10 @@ impl Debug for JsObject { let ptr: *const _ = self.as_ref(); let obj = self.borrow(); let kind = obj.kind(); - let name_prop = self - .borrow() - .properties() - .get(&PropertyKey::String(JsString::from("name"))); - - if obj.is_function() { + 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 From efbd36b7cd8852d67ec971bff05ec7d99882bf69 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Sat, 3 Jun 2023 12:08:48 +0200 Subject: [PATCH 4/4] Run `rust-fmt` --- boa_engine/src/object/jsobject.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boa_engine/src/object/jsobject.rs b/boa_engine/src/object/jsobject.rs index ef5a2ff7a94..6d48b7bdf4b 100644 --- a/boa_engine/src/object/jsobject.rs +++ b/boa_engine/src/object/jsobject.rs @@ -1104,7 +1104,7 @@ impl Debug for JsObject { let ptr: *const _ = self.as_ref(); let obj = self.borrow(); let kind = obj.kind(); - if obj.is_function() { + if obj.is_function() { let name_prop = obj .properties() .get(&PropertyKey::String(JsString::from("name"))); @@ -1114,7 +1114,7 @@ impl Debug for JsObject { .value() .and_then(JsValue::as_string) .cloned() - .unwrap_or_default() + .unwrap_or_default(), }; return f.write_fmt(format_args!("({:?}) {:?} 0x{:X}", kind, name, ptr as usize));