From b3fa79e64de4e08cf9c98857c65c51c7b311224a Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Tue, 29 Aug 2023 21:20:29 +0100 Subject: [PATCH] LibJS: Cover all property kinds when stringifying Put bytecode ops --- Userland/Libraries/LibJS/Bytecode/Op.cpp | 54 +++++++++++------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 1125ee7e9f..b3b312eccc 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -1593,36 +1593,40 @@ DeprecatedString SetLocal::to_deprecated_string_impl(Bytecode::Executable const& return DeprecatedString::formatted("SetLocal {}", m_index); } +static StringView property_kind_to_string(PropertyKind kind) +{ + switch (kind) { + case PropertyKind::Getter: + return "getter"sv; + case PropertyKind::Setter: + return "setter"sv; + case PropertyKind::KeyValue: + return "key-value"sv; + case PropertyKind::DirectKeyValue: + return "direct-key-value"sv; + case PropertyKind::Spread: + return "spread"sv; + case PropertyKind::ProtoSetter: + return "proto-setter"sv; + } + VERIFY_NOT_REACHED(); +} + DeprecatedString PutById::to_deprecated_string_impl(Bytecode::Executable const& executable) const { - auto kind = m_kind == PropertyKind::Getter - ? "getter" - : m_kind == PropertyKind::Setter - ? "setter" - : "property"; - + auto kind = property_kind_to_string(m_kind); return DeprecatedString::formatted("PutById kind:{} base:{}, property:{} ({})", kind, m_base, m_property, executable.identifier_table->get(m_property)); } DeprecatedString PutByIdWithThis::to_deprecated_string_impl(Bytecode::Executable const& executable) const { - auto kind = m_kind == PropertyKind::Getter - ? "getter" - : m_kind == PropertyKind::Setter - ? "setter" - : "property"; - + auto kind = property_kind_to_string(m_kind); return DeprecatedString::formatted("PutByIdWithThis kind:{} base:{}, property:{} ({}) this_value:{}", kind, m_base, m_property, executable.identifier_table->get(m_property), m_this_value); } DeprecatedString PutPrivateById::to_deprecated_string_impl(Bytecode::Executable const& executable) const { - auto kind = m_kind == PropertyKind::Getter - ? "getter" - : m_kind == PropertyKind::Setter - ? "setter" - : "property"; - + auto kind = property_kind_to_string(m_kind); return DeprecatedString::formatted("PutPrivateById kind:{} base:{}, property:{} ({})", kind, m_base, m_property, executable.identifier_table->get(m_property)); } @@ -1837,23 +1841,13 @@ DeprecatedString GetByValueWithThis::to_deprecated_string_impl(Bytecode::Executa DeprecatedString PutByValue::to_deprecated_string_impl(Bytecode::Executable const&) const { - auto kind = m_kind == PropertyKind::Getter - ? "getter" - : m_kind == PropertyKind::Setter - ? "setter" - : "property"; - + auto kind = property_kind_to_string(m_kind); return DeprecatedString::formatted("PutByValue kind:{} base:{}, property:{}", kind, m_base, m_property); } DeprecatedString PutByValueWithThis::to_deprecated_string_impl(Bytecode::Executable const&) const { - auto kind = m_kind == PropertyKind::Getter - ? "getter" - : m_kind == PropertyKind::Setter - ? "setter" - : "property"; - + auto kind = property_kind_to_string(m_kind); return DeprecatedString::formatted("PutByValueWithThis kind:{} base:{}, property:{} this_value:{}", kind, m_base, m_property, m_this_value); }