From 777a93918fa17d337bb6224d0a5f325747382d7b Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 4 Jul 2021 17:59:07 +0100 Subject: [PATCH] LibJS: Handle invalid and symbol PropertyName in its AK::Formatter This would previously crash as we used to_string() without checking the type first. Circumvent that by handling invalid and numeric ones separately and then using to_string_or_symbol(). --- Userland/Libraries/LibJS/Runtime/PropertyName.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/PropertyName.h b/Userland/Libraries/LibJS/Runtime/PropertyName.h index 107b6098ea..8df48475ad 100644 --- a/Userland/Libraries/LibJS/Runtime/PropertyName.h +++ b/Userland/Libraries/LibJS/Runtime/PropertyName.h @@ -230,9 +230,14 @@ namespace AK { template<> struct Formatter : Formatter { - void format(FormatBuilder& builder, JS::PropertyName const& value) + void format(FormatBuilder& builder, JS::PropertyName const& property_name) { - Formatter::format(builder, value.to_string()); + if (!property_name.is_valid()) + Formatter::format(builder, ""); + else if (property_name.is_number()) + Formatter::format(builder, String::number(property_name.as_number())); + else + Formatter::format(builder, property_name.to_string_or_symbol().to_display_string()); } };