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

Everywhere: Make JSON serialization fallible

This allows us to eliminate a major source of infallible allocation in
the Kernel, as well as lay down the groundwork for OOM fallibility in
userland.
This commit is contained in:
Idan Horowitz 2022-02-24 20:08:48 +02:00 committed by Andreas Kling
parent 6682afb5d4
commit feb00b7105
18 changed files with 837 additions and 592 deletions

View file

@ -45,23 +45,23 @@ void Handler::from_executable(Type handler_type, const String& executable)
String Handler::to_details_str() const
{
StringBuilder builder;
JsonObjectSerializer obj { builder };
obj.add("executable", executable);
obj.add("name", name);
auto obj = MUST(JsonObjectSerializer<>::try_create(builder));
MUST(obj.add("executable", executable));
MUST(obj.add("name", name));
switch (handler_type) {
case Type::Application:
obj.add("type", "app");
MUST(obj.add("type", "app"));
break;
case Type::UserDefault:
obj.add("type", "userdefault");
MUST(obj.add("type", "userdefault"));
break;
case Type::UserPreferred:
obj.add("type", "userpreferred");
MUST(obj.add("type", "userpreferred"));
break;
default:
break;
}
obj.finish();
MUST(obj.finish());
return builder.build();
}