1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:47:34 +00:00

LibJS: Convert PropertyDescriptor's formatter to String

And generally propagate OOM.
This commit is contained in:
Timothy Flynn 2023-02-12 21:36:02 -05:00 committed by Linus Groh
parent a73b8292ed
commit 9a5a4302d9

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Optional.h>
#include <AK/String.h>
#include <LibJS/Forward.h>
#include <LibJS/Runtime/Value.h>
@ -49,20 +50,20 @@ template<>
struct Formatter<JS::PropertyDescriptor> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, JS::PropertyDescriptor const& property_descriptor)
{
Vector<DeprecatedString> parts;
Vector<String> parts;
if (property_descriptor.value.has_value())
parts.append(DeprecatedString::formatted("[[Value]]: {}", property_descriptor.value->to_deprecated_string_without_side_effects()));
TRY(parts.try_append(TRY(String::formatted("[[Value]]: {}", TRY(property_descriptor.value->to_string_without_side_effects())))));
if (property_descriptor.get.has_value())
parts.append(DeprecatedString::formatted("[[Get]]: JS::Function* @ {:p}", *property_descriptor.get));
TRY(parts.try_append(TRY(String::formatted("[[Get]]: JS::Function* @ {:p}", *property_descriptor.get))));
if (property_descriptor.set.has_value())
parts.append(DeprecatedString::formatted("[[Set]]: JS::Function* @ {:p}", *property_descriptor.set));
TRY(parts.try_append(TRY(String::formatted("[[Set]]: JS::Function* @ {:p}", *property_descriptor.set))));
if (property_descriptor.writable.has_value())
parts.append(DeprecatedString::formatted("[[Writable]]: {}", *property_descriptor.writable));
TRY(parts.try_append(TRY(String::formatted("[[Writable]]: {}", *property_descriptor.writable))));
if (property_descriptor.enumerable.has_value())
parts.append(DeprecatedString::formatted("[[Enumerable]]: {}", *property_descriptor.enumerable));
TRY(parts.try_append(TRY(String::formatted("[[Enumerable]]: {}", *property_descriptor.enumerable))));
if (property_descriptor.configurable.has_value())
parts.append(DeprecatedString::formatted("[[Configurable]]: {}", *property_descriptor.configurable));
return Formatter<StringView>::format(builder, DeprecatedString::formatted("PropertyDescriptor {{ {} }}", DeprecatedString::join(", "sv, parts)));
TRY(parts.try_append(TRY(String::formatted("[[Configurable]]: {}", *property_descriptor.configurable))));
return Formatter<StringView>::format(builder, TRY(String::formatted("PropertyDescriptor {{ {} }}", TRY(String::join(", "sv, parts)))));
}
};