summaryrefslogtreecommitdiff
path: root/Userland/Utilities/js.cpp
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-09-02 08:32:55 -0400
committerLinus Groh <mail@linusgroh.de>2021-09-02 17:56:42 +0100
commit128779938d8f705e6cd1a1e392d58e06733237bc (patch)
treeced965a19b826b41d33811102d02519339f61e2a /Userland/Utilities/js.cpp
parent2c10e9fdd304354bba3d133f82e89ec3d0e8b4eb (diff)
downloadserenity-128779938d8f705e6cd1a1e392d58e06733237bc.zip
js: Implement pretty-printing of Intl.Locale
Diffstat (limited to 'Userland/Utilities/js.cpp')
-rw-r--r--Userland/Utilities/js.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp
index 219b4f04eb..422ab5769a 100644
--- a/Userland/Utilities/js.cpp
+++ b/Userland/Utilities/js.cpp
@@ -30,6 +30,7 @@
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/DisplayNames.h>
+#include <LibJS/Runtime/Intl/Locale.h>
#include <LibJS/Runtime/Map.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/NumberObject.h>
@@ -518,6 +519,36 @@ static void print_intl_display_names(JS::Object const& object, HashTable<JS::Obj
print_value(js_string(object.vm(), display_names.fallback_string()), seen_objects);
}
+static void print_intl_locale(JS::Object const& object, HashTable<JS::Object*>& seen_objects)
+{
+ auto& locale = static_cast<JS::Intl::Locale const&>(object);
+ print_type("Intl.Locale");
+ out("\n locale: ");
+ print_value(js_string(object.vm(), locale.locale()), seen_objects);
+ if (locale.has_calendar()) {
+ out("\n calendar: ");
+ print_value(js_string(object.vm(), locale.calendar()), seen_objects);
+ }
+ if (locale.has_case_first()) {
+ out("\n caseFirst: ");
+ print_value(js_string(object.vm(), locale.case_first()), seen_objects);
+ }
+ if (locale.has_collation()) {
+ out("\n collation: ");
+ print_value(js_string(object.vm(), locale.collation()), seen_objects);
+ }
+ if (locale.has_hour_cycle()) {
+ out("\n hourCycle: ");
+ print_value(js_string(object.vm(), locale.hour_cycle()), seen_objects);
+ }
+ if (locale.has_numbering_system()) {
+ out("\n numberingSystem: ");
+ print_value(js_string(object.vm(), locale.numbering_system()), seen_objects);
+ }
+ out("\n numeric: ");
+ print_value(JS::Value(locale.numeric()), seen_objects);
+}
+
static void print_primitive_wrapper_object(FlyString const& name, JS::Object const& object, HashTable<JS::Object*>& seen_objects)
{
// BooleanObject, NumberObject, StringObject
@@ -593,6 +624,8 @@ static void print_value(JS::Value value, HashTable<JS::Object*>& seen_objects)
return print_temporal_zoned_date_time(object, seen_objects);
if (is<JS::Intl::DisplayNames>(object))
return print_intl_display_names(object, seen_objects);
+ if (is<JS::Intl::Locale>(object))
+ return print_intl_locale(object, seen_objects);
return print_object(object, seen_objects);
}