mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +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:
parent
6682afb5d4
commit
feb00b7105
18 changed files with 837 additions and 592 deletions
|
@ -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();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue