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

AK: Add new failable JsonArray::{append/set} functions

Move all old usages to the more explicit `JsonArray:must_{append/set}`
This commit is contained in:
Cameron Youell 2023-04-17 15:38:27 +10:00 committed by Andreas Kling
parent 3b00636288
commit 8134dccdc7
14 changed files with 28 additions and 25 deletions

View file

@ -260,7 +260,7 @@ public:
for (auto& object : Object::all_objects()) {
JsonObject json_object;
object.save_to(json_object);
objects.append(move(json_object));
objects.must_append(move(json_object));
}
response.set("objects", move(objects));
send_response(response);

View file

@ -335,8 +335,8 @@ requires IsBaseOf<Object, T>
[this] { \
auto size = this->getter(); \
JsonArray size_array; \
size_array.append(size.width()); \
size_array.append(size.height()); \
size_array.must_append(size.width()); \
size_array.must_append(size.height()); \
return size_array; \
}, \
{});
@ -379,8 +379,8 @@ requires IsBaseOf<Object, T>
[this] { \
auto size = this->getter(); \
JsonArray size_array; \
size_array.append(size.width()); \
size_array.append(size.height()); \
size_array.must_append(size.width()); \
size_array.must_append(size.height()); \
return size_array; \
}, \
[this](auto& value) { \

View file

@ -67,7 +67,7 @@ bool JsonArrayModel::add(Vector<JsonValue> const&& values)
auto& field_spec = m_fields[i];
obj.set(field_spec.json_field_name, values.at(i));
}
m_array.append(move(obj));
m_array.must_append(move(obj));
did_update();
return true;
}
@ -85,7 +85,7 @@ bool JsonArrayModel::set(int row, Vector<JsonValue>&& values)
obj.set(field_spec.json_field_name, move(values.at(i)));
}
m_array.set(row, move(obj));
m_array.must_set(row, move(obj));
did_update();
return true;
@ -99,7 +99,7 @@ bool JsonArrayModel::remove(int row)
JsonArray new_array;
for (size_t i = 0; i < m_array.size(); ++i)
if (i != (size_t)row)
new_array.append(m_array.at(i));
new_array.must_append(m_array.at(i));
m_array = new_array;

View file

@ -34,7 +34,7 @@ Layout::Layout(Margins initial_margins, int spacing)
} else {
VERIFY_NOT_REACHED();
}
entries_array.append(move(entry_object));
entries_array.must_append(move(entry_object));
}
return entries_array;
});

View file

@ -347,7 +347,7 @@ Response process_capabilities(JsonValue const& parameters)
all_first_match_capabilities = capabilities->as_array();
} else {
// a. If all first match capabilities is undefined, set the value to a JSON List with a single entry of an empty JSON Object.
all_first_match_capabilities.append(JsonObject {});
all_first_match_capabilities.must_append(JsonObject {});
}
// 4. Let validated first match capabilities be an empty JSON List.
@ -360,7 +360,7 @@ Response process_capabilities(JsonValue const& parameters)
auto validated_capabilities = TRY(validate_capabilities(first_match_capabilities));
// b. Append validated capabilities to validated first match capabilities.
validated_first_match_capabilities.append(move(validated_capabilities));
validated_first_match_capabilities.must_append(move(validated_capabilities));
return {};
}));
@ -374,7 +374,7 @@ Response process_capabilities(JsonValue const& parameters)
auto merged = TRY(merge_capabilities(required_capabilities, first_match_capabilities.as_object()));
// b. Append merged to merged capabilities.
merged_capabilities.append(move(merged));
merged_capabilities.must_append(move(merged));
return {};
}));

View file

@ -170,7 +170,7 @@ static ErrorOr<JsonValue, ExecuteScriptResultType> clone_an_object(JS::Realm& re
return ExecuteScriptResultType::JavaScriptError;
auto array = JsonArray {};
for (size_t i = 0; i < length; ++i)
array.append(JsonValue {});
array.must_append(JsonValue {});
return array;
}
// -> Otherwise
@ -203,7 +203,7 @@ static ErrorOr<JsonValue, ExecuteScriptResultType> clone_an_object(JS::Realm& re
[&](JsonArray& array) {
// NOTE: If this was a JS array, only indexed properties would be serialized anyway.
if (name.is_number())
array.set(name.as_number(), cloned_property_result.value());
array.must_set(name.as_number(), cloned_property_result.value());
},
[&](JsonObject& object) {
object.set(name.to_string(), cloned_property_result.value());