diff --git a/AK/JsonArray.h b/AK/JsonArray.h index c8f687928a..e292defa48 100644 --- a/AK/JsonArray.h +++ b/AK/JsonArray.h @@ -61,9 +61,12 @@ public: [[nodiscard]] JsonValue take(size_t index) { return m_values.take(index); } + void must_append(JsonValue value) { m_values.append(move(value)); } + void must_set(size_t index, JsonValue value) { m_values.insert(index, move(value)); } + void clear() { m_values.clear(); } - void append(JsonValue value) { m_values.append(move(value)); } - void set(size_t index, JsonValue value) { m_values[index] = move(value); } + ErrorOr append(JsonValue value) { return m_values.try_append(move(value)); } + ErrorOr set(size_t index, JsonValue value) { return m_values.try_insert(index, move(value)); } template typename Builder::OutputType serialized() const; diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index bde540a634..c45f15812c 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -164,7 +164,7 @@ ErrorOr JsonParser::parse_array() if (peek() == ']') break; auto element = TRY(parse_helper()); - array.append(move(element)); + array.must_append(move(element)); ignore_while(is_space); if (peek() == ']') break; diff --git a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp index a830081c26..947c6c6f55 100644 --- a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp +++ b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp @@ -177,7 +177,7 @@ ErrorOr KeyboardMapperWidget::save_to_file(StringView filename) sb.append_code_point(values[i]); JsonValue val(sb.to_deprecated_string()); - items.append(move(val)); + items.must_append(move(val)); } map_json.set(name, move(items)); }; diff --git a/Userland/Applications/Spreadsheet/ExportDialog.cpp b/Userland/Applications/Spreadsheet/ExportDialog.cpp index ed59cea6b2..41441f3e11 100644 --- a/Userland/Applications/Spreadsheet/ExportDialog.cpp +++ b/Userland/Applications/Spreadsheet/ExportDialog.cpp @@ -202,7 +202,7 @@ ErrorOr ExportDialog::make_and_run_for(StringView mime, Core::File& file, auto export_worksheet = [&]() -> ErrorOr { JsonArray array; for (auto& sheet : workbook.sheets()) - array.append(sheet->to_json()); + array.must_append(sheet->to_json()); auto file_content = array.to_deprecated_string(); return file.write_until_depleted(file_content.bytes()); diff --git a/Userland/Applications/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp index dc693570f8..3dd6258ca1 100644 --- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp @@ -542,7 +542,7 @@ JsonObject Sheet::to_json() const if (!columns_are_standard()) { auto columns = JsonArray(); for (auto& column : m_columns) - columns.append(column); + columns.must_append(column); object.set("columns", move(columns)); } object.set("rows", bottom_right.row + 1); @@ -587,7 +587,7 @@ JsonObject Sheet::to_json() const fmt_object.set("condition", fmt.condition); save_format(fmt, fmt_object); - conditional_formats.append(move(fmt_object)); + conditional_formats.must_append(move(fmt_object)); } data.set("conditional_formats", move(conditional_formats)); diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index 149360e181..e4e921cced 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -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); diff --git a/Userland/Libraries/LibCore/Object.h b/Userland/Libraries/LibCore/Object.h index 3bbf7f80b9..da518e2a31 100644 --- a/Userland/Libraries/LibCore/Object.h +++ b/Userland/Libraries/LibCore/Object.h @@ -335,8 +335,8 @@ requires IsBaseOf [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 [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) { \ diff --git a/Userland/Libraries/LibGUI/JsonArrayModel.cpp b/Userland/Libraries/LibGUI/JsonArrayModel.cpp index f92cb9e84a..90511abd94 100644 --- a/Userland/Libraries/LibGUI/JsonArrayModel.cpp +++ b/Userland/Libraries/LibGUI/JsonArrayModel.cpp @@ -67,7 +67,7 @@ bool JsonArrayModel::add(Vector 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&& 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; diff --git a/Userland/Libraries/LibGUI/Layout.cpp b/Userland/Libraries/LibGUI/Layout.cpp index ec1d32b48d..156d4653b6 100644 --- a/Userland/Libraries/LibGUI/Layout.cpp +++ b/Userland/Libraries/LibGUI/Layout.cpp @@ -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; }); diff --git a/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp b/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp index 8754daf6ba..caad3524a2 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Capabilities.cpp @@ -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 {}; })); diff --git a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp index f19dc11b7f..8a2819128a 100644 --- a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp @@ -170,7 +170,7 @@ static ErrorOr 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 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()); diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index f718189823..73968c0ca7 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -1521,7 +1521,7 @@ Messages::WebDriverClient::GetAllCookiesResponse WebDriverConnection::get_all_co auto serialized_cookie = serialize_cookie(cookie); // 2. Append serialized cookie to cookies - cookies.append(move(serialized_cookie)); + cookies.must_append(move(serialized_cookie)); } // 5. Return success with data cookies. @@ -1997,7 +1997,7 @@ ErrorOr WebDriverConnection::find(StartNodeGet // 8. For each element in elements returned, append the web element reference object for element, to result. for (size_t i = 0; i < elements->length(); ++i) - result.append(web_element_reference_object(*elements->item(i))); + result.must_append(web_element_reference_object(*elements->item(i))); // 9. Return success with data result. return result; diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index 20c16b51ac..3a029fcbbe 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -162,7 +162,7 @@ Web::WebDriver::Response Session::get_window_handles() const // 2. For each top-level browsing context in the remote end, push the associated window handle onto handles. for (auto const& window_handle : m_windows.keys()) { - handles.append(JsonValue(window_handle)); + handles.must_append(JsonValue(window_handle)); } // 3. Return success with data handles. diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index 638889564f..f5acf281be 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -2367,7 +2367,7 @@ void Shell::save_to(JsonObject& object) job_object.set("running_time", job_entry.value->timer().elapsed()); job_object.set("command", job_entry.value->cmd()); job_object.set("is_running_in_background", job_entry.value->is_running_in_background()); - job_objects.append(move(job_object)); + job_objects.must_append(move(job_object)); } object.set("jobs", move(job_objects)); }