summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/PixelPaint/Image.cpp30
-rw-r--r--Userland/Applications/PixelPaint/ImageEditor.cpp18
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp4
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.cpp33
-rw-r--r--Userland/Services/LaunchServer/Launcher.cpp14
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.cpp12
6 files changed, 58 insertions, 53 deletions
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp
index c4ada542a7..9a28b60d4c 100644
--- a/Userland/Applications/PixelPaint/Image.cpp
+++ b/Userland/Applications/PixelPaint/Image.cpp
@@ -111,22 +111,22 @@ ErrorOr<NonnullRefPtr<Image>> Image::try_create_from_pixel_paint_json(JsonObject
void Image::serialize_as_json(JsonObjectSerializer<StringBuilder>& json) const
{
- json.add("width", m_size.width());
- json.add("height", m_size.height());
+ MUST(json.add("width", m_size.width()));
+ MUST(json.add("height", m_size.height()));
{
- auto json_layers = json.add_array("layers");
+ auto json_layers = MUST(json.add_array("layers"));
for (const auto& layer : m_layers) {
Gfx::BMPWriter bmp_dumber;
- auto json_layer = json_layers.add_object();
- json_layer.add("width", layer.size().width());
- json_layer.add("height", layer.size().height());
- json_layer.add("name", layer.name());
- json_layer.add("locationx", layer.location().x());
- json_layer.add("locationy", layer.location().y());
- json_layer.add("opacity_percent", layer.opacity_percent());
- json_layer.add("visible", layer.is_visible());
- json_layer.add("selected", layer.is_selected());
- json_layer.add("bitmap", encode_base64(bmp_dumber.dump(layer.bitmap())));
+ auto json_layer = MUST(json_layers.add_object());
+ MUST(json_layer.add("width", layer.size().width()));
+ MUST(json_layer.add("height", layer.size().height()));
+ MUST(json_layer.add("name", layer.name()));
+ MUST(json_layer.add("locationx", layer.location().x()));
+ MUST(json_layer.add("locationy", layer.location().y()));
+ MUST(json_layer.add("opacity_percent", layer.opacity_percent()));
+ MUST(json_layer.add("visible", layer.is_visible()));
+ MUST(json_layer.add("selected", layer.is_selected()));
+ MUST(json_layer.add("bitmap", encode_base64(bmp_dumber.dump(layer.bitmap()))));
}
}
}
@@ -134,9 +134,9 @@ void Image::serialize_as_json(JsonObjectSerializer<StringBuilder>& json) const
ErrorOr<void> Image::write_to_file(const String& file_path) const
{
StringBuilder builder;
- JsonObjectSerializer json(builder);
+ auto json = MUST(JsonObjectSerializer<>::try_create(builder));
serialize_as_json(json);
- json.finish();
+ MUST(json.finish());
auto file = TRY(Core::File::open(file_path, (Core::OpenMode)(Core::OpenMode::WriteOnly | Core::OpenMode::Truncate)));
if (!file->write(builder.string_view()))
diff --git a/Userland/Applications/PixelPaint/ImageEditor.cpp b/Userland/Applications/PixelPaint/ImageEditor.cpp
index 5b2192ff52..3c3d87be17 100644
--- a/Userland/Applications/PixelPaint/ImageEditor.cpp
+++ b/Userland/Applications/PixelPaint/ImageEditor.cpp
@@ -602,20 +602,20 @@ void ImageEditor::save_project_as()
Result<void, String> ImageEditor::save_project_to_file(Core::File& file) const
{
StringBuilder builder;
- JsonObjectSerializer json(builder);
+ auto json = MUST(JsonObjectSerializer<>::try_create(builder));
m_image->serialize_as_json(json);
- auto json_guides = json.add_array("guides");
+ auto json_guides = MUST(json.add_array("guides"));
for (const auto& guide : m_guides) {
- auto json_guide = json_guides.add_object();
- json_guide.add("offset"sv, (double)guide.offset());
+ auto json_guide = MUST(json_guides.add_object());
+ MUST(json_guide.add("offset"sv, (double)guide.offset()));
if (guide.orientation() == Guide::Orientation::Vertical)
- json_guide.add("orientation", "vertical");
+ MUST(json_guide.add("orientation", "vertical"));
else if (guide.orientation() == Guide::Orientation::Horizontal)
- json_guide.add("orientation", "horizontal");
- json_guide.finish();
+ MUST(json_guide.add("orientation", "horizontal"));
+ MUST(json_guide.finish());
}
- json_guides.finish();
- json.finish();
+ MUST(json_guides.finish());
+ MUST(json.finish());
if (!file.write(builder.string_view()))
return String { file.error_string() };
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 95cc0ffe88..46ec48a9ac 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -1185,10 +1185,10 @@ void Document::set_cookie(String const& cookie_string, Cookie::Source source)
String Document::dump_dom_tree_as_json() const
{
StringBuilder builder;
- JsonObjectSerializer json(builder);
+ auto json = MUST(JsonObjectSerializer<>::try_create(builder));
serialize_tree_as_json(json);
- json.finish();
+ MUST(json.finish());
return builder.to_string();
}
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp
index a20c94011e..4676ef44b6 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Node.cpp
@@ -723,47 +723,52 @@ bool Node::is_uninteresting_whitespace_node() const
void Node::serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object) const
{
- object.add("name", node_name().view());
- object.add("id", id());
+ MUST(object.add("name", node_name().view()));
+ MUST(object.add("id", id()));
if (is_document()) {
- object.add("type", "document");
+ MUST(object.add("type", "document"));
} else if (is_element()) {
- object.add("type", "element");
+ MUST(object.add("type", "element"));
auto const* element = static_cast<DOM::Element const*>(this);
if (element->has_attributes()) {
- auto attributes = object.add_object("attributes");
+ auto attributes = MUST(object.add_object("attributes"));
element->for_each_attribute([&attributes](auto& name, auto& value) {
- attributes.add(name, value);
+ MUST(attributes.add(name, value));
});
+ MUST(attributes.finish());
}
if (element->is_browsing_context_container()) {
auto const* container = static_cast<HTML::BrowsingContextContainer const*>(element);
if (auto const* content_document = container->content_document()) {
- auto children = object.add_array("children");
- JsonObjectSerializer<StringBuilder> content_document_object = children.add_object();
+ auto children = MUST(object.add_array("children"));
+ JsonObjectSerializer<StringBuilder> content_document_object = MUST(children.add_object());
content_document->serialize_tree_as_json(content_document_object);
+ MUST(content_document_object.finish());
+ MUST(children.finish());
}
}
} else if (is_text()) {
- object.add("type", "text");
+ MUST(object.add("type", "text"));
auto text_node = static_cast<DOM::Text const*>(this);
- object.add("text", text_node->data());
+ MUST(object.add("text", text_node->data()));
} else if (is_comment()) {
- object.add("type"sv, "comment"sv);
- object.add("data"sv, static_cast<DOM::Comment const&>(*this).data());
+ MUST(object.add("type"sv, "comment"sv));
+ MUST(object.add("data"sv, static_cast<DOM::Comment const&>(*this).data()));
}
if (has_child_nodes()) {
- auto children = object.add_array("children");
+ auto children = MUST(object.add_array("children"));
for_each_child([&children](DOM::Node& child) {
if (child.is_uninteresting_whitespace_node())
return;
- JsonObjectSerializer<StringBuilder> child_object = children.add_object();
+ JsonObjectSerializer<StringBuilder> child_object = MUST(children.add_object());
child.serialize_tree_as_json(child_object);
+ MUST(child_object.finish());
});
+ MUST(children.finish());
}
}
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();
};