diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-02-24 20:08:48 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-27 20:37:57 +0100 |
commit | feb00b7105bbb55ba28b3fe8b6c526695f77bc84 (patch) | |
tree | 4be5bcdf63171729618deff8194db8fbcdb5bc3f /Userland/Services | |
parent | 6682afb5d4d6b7455f85fa3a8f07dd14cae4211e (diff) | |
download | serenity-feb00b7105bbb55ba28b3fe8b6c526695f77bc84.zip |
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.
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/LaunchServer/Launcher.cpp | 14 | ||||
-rw-r--r-- | Userland/Services/WebContent/ConnectionFromClient.cpp | 12 |
2 files changed, 13 insertions, 13 deletions
diff --git a/Userland/Services/LaunchServer/Launcher.cpp b/Userland/Services/LaunchServer/Launcher.cpp index b413561c2a..09fa6d496b 100644 --- a/Userland/Services/LaunchServer/Launcher.cpp +++ b/Userland/Services/LaunchServer/Launcher.cpp @@ -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(); } diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 6e01c5e0a7..d9a52631b1 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -271,18 +271,18 @@ Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect auto serialize_json = [](Web::CSS::StyleProperties const& properties) -> String { StringBuilder builder; - JsonObjectSerializer serializer(builder); + auto serializer = MUST(JsonObjectSerializer<>::try_create(builder)); properties.for_each_property([&](auto property_id, auto& value) { - serializer.add(Web::CSS::string_from_property_id(property_id), value.to_string()); + MUST(serializer.add(Web::CSS::string_from_property_id(property_id), value.to_string())); }); - serializer.finish(); + MUST(serializer.finish()); return builder.to_string(); }; auto serialize_custom_properties_json = [](Web::DOM::Element const& element) -> String { StringBuilder builder; - JsonObjectSerializer serializer(builder); + auto serializer = MUST(JsonObjectSerializer<>::try_create(builder)); HashTable<String> seen_properties; auto const* element_to_check = &element; @@ -290,14 +290,14 @@ Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect for (auto const& property : element_to_check->custom_properties()) { if (!seen_properties.contains(property.key)) { seen_properties.set(property.key); - serializer.add(property.key, property.value.value->to_string()); + MUST(serializer.add(property.key, property.value.value->to_string())); } } element_to_check = element_to_check->parent_element(); } - serializer.finish(); + MUST(serializer.finish()); return builder.to_string(); }; |