summaryrefslogtreecommitdiff
path: root/Userland/Utilities/js.cpp
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-06-30 19:57:59 +0100
committerLinus Groh <mail@linusgroh.de>2022-07-01 00:13:21 +0100
commit18f27c2e6433a1342d76c6b6703441ee37fd2328 (patch)
treee5bbfcb30ea2a73e514d740f28dd723fbf3a5be5 /Userland/Utilities/js.cpp
parentc6cd784d4e6cb7cf6d907ee75d19760b563ae0e1 (diff)
downloadserenity-18f27c2e6433a1342d76c6b6703441ee37fd2328.zip
js: Fix pretty-printing of primitive wrapper objects
Currently, they print `[Type] <already printed Object 0x...>` as, for some reason, we were simply trying to print the object again.
Diffstat (limited to 'Userland/Utilities/js.cpp')
-rw-r--r--Userland/Utilities/js.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp
index 047410a543..1ceda2b5ef 100644
--- a/Userland/Utilities/js.cpp
+++ b/Userland/Utilities/js.cpp
@@ -923,12 +923,25 @@ static void print_intl_duration_format(JS::Intl::DurationFormat const& duration_
}
}
-static void print_primitive_wrapper_object(FlyString const& name, JS::Object const& object, HashTable<JS::Object*>& seen_objects)
+static void print_boolean_object(JS::BooleanObject const& boolean_object, HashTable<JS::Object*>& seen_objects)
{
- // BooleanObject, NumberObject, StringObject
- print_type(name);
+ print_type("Boolean");
js_out(" ");
- print_value(&object, seen_objects);
+ print_value(JS::Value(boolean_object.boolean()), seen_objects);
+}
+
+static void print_number_object(JS::NumberObject const& number_object, HashTable<JS::Object*>& seen_objects)
+{
+ print_type("Number");
+ js_out(" ");
+ print_value(JS::Value(number_object.number()), seen_objects);
+}
+
+static void print_string_object(JS::StringObject const& string_object, HashTable<JS::Object*>& seen_objects)
+{
+ print_type("String");
+ js_out(" ");
+ print_value(&string_object.primitive_string(), seen_objects);
}
static void print_value(JS::Value value, HashTable<JS::Object*>& seen_objects)
@@ -985,12 +998,12 @@ static void print_value(JS::Value value, HashTable<JS::Object*>& seen_objects)
return print_async_generator(static_cast<JS::AsyncGenerator&>(object), seen_objects);
if (object.is_typed_array())
return print_typed_array(static_cast<JS::TypedArrayBase&>(object), seen_objects);
- if (is<JS::StringObject>(object))
- return print_primitive_wrapper_object("String", object, seen_objects);
- if (is<JS::NumberObject>(object))
- return print_primitive_wrapper_object("Number", object, seen_objects);
if (is<JS::BooleanObject>(object))
- return print_primitive_wrapper_object("Boolean", object, seen_objects);
+ return print_boolean_object(static_cast<JS::BooleanObject&>(object), seen_objects);
+ if (is<JS::NumberObject>(object))
+ return print_number_object(static_cast<JS::NumberObject&>(object), seen_objects);
+ if (is<JS::StringObject>(object))
+ return print_string_object(static_cast<JS::StringObject&>(object), seen_objects);
if (is<JS::Temporal::Calendar>(object))
return print_temporal_calendar(static_cast<JS::Temporal::Calendar&>(object), seen_objects);
if (is<JS::Temporal::Duration>(object))