js: Print different type for each kind of ECMAScript function object

Instead of just printing 'ECMAScriptFunctionObject' (and leaking an
implementation detail in the process - this is not a public facing name)
let's instead print a different type string for each function kind, and
only keep the old class_name() printing for other JS::FunctionObject
subclasses.
This commit is contained in:
Linus Groh 2022-05-05 22:42:10 +02:00
parent 2ad9641315
commit 88f637a505

View file

@ -316,7 +316,27 @@ static void print_object(JS::Object& object, HashTable<JS::Object*>& seen_object
static void print_function(JS::Object const& object, HashTable<JS::Object*>&)
{
print_type(object.class_name());
if (is<JS::ECMAScriptFunctionObject>(object)) {
auto const& function = static_cast<JS::ECMAScriptFunctionObject const&>(object);
switch (function.kind()) {
case JS::FunctionKind::Normal:
print_type("Function");
break;
case JS::FunctionKind::Generator:
print_type("GeneratorFunction");
break;
case JS::FunctionKind::Async:
print_type("AsyncFunction");
break;
case JS::FunctionKind::AsyncGenerator:
print_type("AsyncGeneratorFunction");
break;
default:
VERIFY_NOT_REACHED();
}
} else {
print_type(object.class_name());
}
if (is<JS::ECMAScriptFunctionObject>(object))
js_out(" {}", static_cast<JS::ECMAScriptFunctionObject const&>(object).name());
else if (is<JS::NativeFunction>(object))