Skip to content

Commit 63ca217

Browse files
authored
fixed show ArrayBuffer constructor as [Function: ArrayBuffer] (#4935)
## Summary Fixes how constructors are shown in console/debug output so that only real class constructors use `[class Name]`, while built-ins like ArrayBuffer use `[Function: Name]`. Solves #4934 ## Changes Modified `core/engine/src/value/display.rs` > only shows `[class Name]` when the value is an `OrdinaryFunction` with `is_class_constructor()`; otherwise shows callables as `[Function: Name]`. Replace `.map(...).unwrap_or(false)` with `.is_some_and(...)` to satisfy Clippy.
1 parent 1da865a commit 63ca217

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

core/engine/src/value/display.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use super::{Display, HashSet, JsValue, JsVariant, fmt};
22
use crate::{
33
JsError, JsObject, JsString,
44
builtins::{
5-
Array, Promise, error::Error, map::ordered_map::OrderedMap, promise::PromiseState,
6-
set::ordered_set::OrderedSet,
5+
Array, Promise, error::Error, function::OrdinaryFunction, map::ordered_map::OrderedMap,
6+
promise::PromiseState, set::ordered_set::OrderedSet,
77
},
88
js_string,
99
property::{DescriptorKind, PropertyDescriptor, PropertyKey},
@@ -284,25 +284,30 @@ pub(crate) fn log_value_to(
284284
}
285285
}
286286
f.write_str(" }")
287-
} else if v.is_constructor() {
288-
// FIXME: ArrayBuffer is not [class ArrayBuffer] but we cannot distinguish it.
289-
let name = v
290-
.get_property(&PropertyKey::from(js_string!("name")))
291-
.and_then(|d| Some(d.value()?.as_string()?.to_std_string_escaped()));
292-
match name {
293-
Some(name) => write!(f, "[class {name}]"),
294-
None => f.write_str("[class (anonymous)]"),
295-
}
296-
} else if v.is_callable() {
297-
let name = v
298-
.get_property(&PropertyKey::from(js_string!("name")))
299-
.and_then(|d| Some(d.value()?.as_string()?.to_std_string_escaped()));
300-
match name {
301-
Some(name) => write!(f, "[Function: {name}]"),
302-
None => f.write_str("[Function (anonymous)]"),
303-
}
304287
} else {
305-
Display::fmt(&x.display_obj(print_internals), f)
288+
let is_class_constructor = v
289+
.downcast_ref::<OrdinaryFunction>()
290+
.is_some_and(|f| f.codeblock().is_class_constructor());
291+
292+
if is_class_constructor {
293+
let name = v
294+
.get_property(&PropertyKey::from(js_string!("name")))
295+
.and_then(|d| Some(d.value()?.as_string()?.to_std_string_escaped()));
296+
match name {
297+
Some(name) => write!(f, "[class {name}]"),
298+
None => f.write_str("[class (anonymous)]"),
299+
}
300+
} else if v.is_callable() {
301+
let name = v
302+
.get_property(&PropertyKey::from(js_string!("name")))
303+
.and_then(|d| Some(d.value()?.as_string()?.to_std_string_escaped()));
304+
match name {
305+
Some(name) => write!(f, "[Function: {name}]"),
306+
None => f.write_str("[Function (anonymous)]"),
307+
}
308+
} else {
309+
Display::fmt(&x.display_obj(print_internals), f)
310+
}
306311
}
307312
}
308313
JsVariant::Null => write!(f, "null"),

0 commit comments

Comments
 (0)