mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
AK: Allow destruction of JsonObjectSerializer objects after errors
Previously we'd VERIFY() that the user had called finish(). This makes the following code incorrect though: auto json = TRY(JsonObjectSerializer<>::try_create(builder)); TRY(json.add("total_time"sv, total_time_scheduled.total)); TRY(json.finish()); return ...; If the second TRY() returns early we'd fail at the VERIFY() call in the destructor. Calling finish() in the destructor - like we had done earlier - is also not helpful because we have no idea whether the builder is still valid. Plus we wouldn't be able to handle any errors for that call. Verifying that either finish() was called or an error occurred doesn't work either because the caller might have multiple Json*Serializer objects, e.g. when inserting a JSON array into a JSON object. Forcing the user to call finish() on their "main" object when a sub-object caused an error seems unnecessarily tedious.
This commit is contained in:
parent
92efa21727
commit
d1bc157e9f
Notes:
sideshowbarker
2024-07-17 04:55:29 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/d1bc157e9f Pull-request: https://github.com/SerenityOS/serenity/pull/15876
2 changed files with 0 additions and 10 deletions
|
@ -43,11 +43,6 @@ public:
|
|||
|
||||
JsonArraySerializer(JsonArraySerializer const&) = delete;
|
||||
|
||||
~JsonArraySerializer()
|
||||
{
|
||||
VERIFY(m_finished);
|
||||
}
|
||||
|
||||
#ifndef KERNEL
|
||||
ErrorOr<void> add(JsonValue const& value)
|
||||
{
|
||||
|
|
|
@ -38,11 +38,6 @@ public:
|
|||
|
||||
JsonObjectSerializer(JsonObjectSerializer const&) = delete;
|
||||
|
||||
~JsonObjectSerializer()
|
||||
{
|
||||
VERIFY(m_finished);
|
||||
}
|
||||
|
||||
#ifndef KERNEL
|
||||
ErrorOr<void> add(StringView key, JsonValue const& value)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue