diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-12-21 20:56:50 +0000 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-01-27 08:07:24 -0500 |
commit | ba51e2dd3f4cbda3a3f446c4dd30c770dc088bb0 (patch) | |
tree | 83bb5f368b387f964dad37fecaef74fa2c963249 | |
parent | b592629fe5c7e2dd521ec435e667750dbfb6eb4a (diff) | |
download | serenity-ba51e2dd3f4cbda3a3f446c4dd30c770dc088bb0.zip |
Services: Replace uses of JsonObject::get_deprecated()/get_ptr()
-rw-r--r-- | Userland/Services/DHCPClient/DHCPv4Client.cpp | 10 | ||||
-rw-r--r-- | Userland/Services/LookupServer/MulticastDNS.cpp | 2 | ||||
-rw-r--r-- | Userland/Services/NetworkServer/main.cpp | 2 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebDriverConnection.cpp | 22 | ||||
-rw-r--r-- | Userland/Services/WebDriver/Client.cpp | 20 | ||||
-rw-r--r-- | Userland/Services/WindowServer/KeymapSwitcher.cpp | 4 |
6 files changed, 30 insertions, 30 deletions
diff --git a/Userland/Services/DHCPClient/DHCPv4Client.cpp b/Userland/Services/DHCPClient/DHCPv4Client.cpp index 6e352d1196..9ea10573b2 100644 --- a/Userland/Services/DHCPClient/DHCPv4Client.cpp +++ b/Userland/Services/DHCPClient/DHCPv4Client.cpp @@ -193,13 +193,13 @@ ErrorOr<DHCPv4Client::Interfaces> DHCPv4Client::get_discoverable_interfaces() json.value().as_array().for_each([&ifnames_to_immediately_discover, &ifnames_to_attempt_later](auto& value) { auto if_object = value.as_object(); - if (if_object.get_deprecated("class_name"sv).to_deprecated_string() == "LoopbackAdapter") + if (if_object.get_deprecated_string("class_name"sv).value_or({}) == "LoopbackAdapter") return; - auto name = if_object.get_deprecated("name"sv).to_deprecated_string(); - auto mac = if_object.get_deprecated("mac_address"sv).to_deprecated_string(); - auto is_up = if_object.get_deprecated("link_up"sv).to_bool(); - auto ipv4_addr_maybe = IPv4Address::from_string(if_object.get_deprecated("ipv4_address"sv).to_deprecated_string()); + auto name = if_object.get_deprecated_string("name"sv).value_or({}); + auto mac = if_object.get_deprecated_string("mac_address"sv).value_or({}); + auto is_up = if_object.get_bool("link_up"sv).value_or(false); + auto ipv4_addr_maybe = IPv4Address::from_string(if_object.get_deprecated_string("ipv4_address"sv).value_or({})); auto ipv4_addr = ipv4_addr_maybe.has_value() ? ipv4_addr_maybe.value() : IPv4Address { 0, 0, 0, 0 }; if (is_up) { dbgln_if(DHCPV4_DEBUG, "Found adapter '{}' with mac {}, and it was up!", name, mac); diff --git a/Userland/Services/LookupServer/MulticastDNS.cpp b/Userland/Services/LookupServer/MulticastDNS.cpp index e3699b70e7..15472b0310 100644 --- a/Userland/Services/LookupServer/MulticastDNS.cpp +++ b/Userland/Services/LookupServer/MulticastDNS.cpp @@ -132,7 +132,7 @@ Vector<IPv4Address> MulticastDNS::local_addresses() const json.as_array().for_each([&addresses](auto& value) { auto if_object = value.as_object(); - auto address = if_object.get_deprecated("ipv4_address"sv).to_deprecated_string(); + auto address = if_object.get_deprecated_string("ipv4_address"sv).value_or({}); auto ipv4_address = IPv4Address::from_string(address); // Skip unconfigured interfaces. if (!ipv4_address.has_value()) diff --git a/Userland/Services/NetworkServer/main.cpp b/Userland/Services/NetworkServer/main.cpp index 185f303577..6ede99f447 100644 --- a/Userland/Services/NetworkServer/main.cpp +++ b/Userland/Services/NetworkServer/main.cpp @@ -51,7 +51,7 @@ ErrorOr<int> serenity_main(Main::Arguments) Vector<DeprecatedString> interfaces_with_dhcp_enabled; proc_net_adapters_json.as_array().for_each([&](auto& value) { auto& if_object = value.as_object(); - auto ifname = if_object.get_deprecated("name"sv).to_deprecated_string(); + auto ifname = if_object.get_deprecated_string("name"sv).value_or({}); if (ifname == "loop"sv) return; diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 3edcbc5981..ef98229a55 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -222,9 +222,9 @@ static ErrorOr<PropertyType, Web::WebDriver::Error> get_property(JsonValue const if (!payload.is_object()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object"); - auto const* property = payload.as_object().get_ptr(key); + auto property = payload.as_object().get(key); - if (!property) + if (!property.has_value()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, DeprecatedString::formatted("No property called '{}' present", key)); if constexpr (IsSame<PropertyType, DeprecatedString>) { @@ -335,7 +335,7 @@ Messages::WebDriverClient::NavigateToResponse WebDriverConnection::navigate_to(J // 2. Let url be the result of getting the property url from the parameters argument. if (!payload.is_object() || !payload.as_object().has_string("url"sv)) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload doesn't have a string `url`"sv); - URL url(payload.as_object().get_ptr("url"sv)->as_string()); + URL url(payload.as_object().get_deprecated_string("url"sv).value()); // FIXME: 3. If url is not an absolute URL or is not an absolute URL with fragment or not a local scheme, return error with error code invalid argument. @@ -548,13 +548,13 @@ Messages::WebDriverClient::SetWindowRectResponse WebDriverConnection::set_window auto const& properties = payload.as_object(); - auto resolve_property = [](auto name, auto const* property, auto min, auto max) -> ErrorOr<Optional<i32>, Web::WebDriver::Error> { - if (!property) + auto resolve_property = [](auto name, auto const& property, auto min, auto max) -> ErrorOr<Optional<i32>, Web::WebDriver::Error> { + if (property.is_null()) return Optional<i32> {}; - if (!property->is_number()) + if (!property.is_number()) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, DeprecatedString::formatted("Property '{}' is not a Number", name)); - auto number = property->template to_number<i64>(); + auto number = property.template to_number<i64>(); if (number < min) return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, DeprecatedString::formatted("Property '{}' value {} exceeds the minimum allowed value {}", name, number, min)); @@ -565,16 +565,16 @@ Messages::WebDriverClient::SetWindowRectResponse WebDriverConnection::set_window }; // 1. Let width be the result of getting a property named width from the parameters argument, else let it be null. - auto const* width_property = properties.get_ptr("width"sv); + auto width_property = properties.get("width"sv).value_or(JsonValue()); // 2. Let height be the result of getting a property named height from the parameters argument, else let it be null. - auto const* height_property = properties.get_ptr("height"sv); + auto height_property = properties.get("height"sv).value_or(JsonValue()); // 3. Let x be the result of getting a property named x from the parameters argument, else let it be null. - auto const* x_property = properties.get_ptr("x"sv); + auto x_property = properties.get("x"sv).value_or(JsonValue()); // 4. Let y be the result of getting a property named y from the parameters argument, else let it be null. - auto const* y_property = properties.get_ptr("y"sv); + auto y_property = properties.get("y"sv).value_or(JsonValue()); // 5. If width or height is neither null nor a Number from 0 to 2^31 − 1, return error with error code invalid argument. auto width = TRY(resolve_property("width"sv, width_property, 0, NumericLimits<i32>::max())); diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index 2e4f7ba923..de491fded4 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -81,20 +81,20 @@ void Client::close_session(unsigned session_id) static void initialize_session_from_capabilities(WebContentConnection& web_content_connection, JsonObject& capabilities) { // 1. Let strategy be the result of getting property "pageLoadStrategy" from capabilities. - auto const* strategy = capabilities.get_ptr("pageLoadStrategy"sv); + auto strategy = capabilities.get_deprecated_string("pageLoadStrategy"sv); // 2. If strategy is a string, set the current session’s page loading strategy to strategy. Otherwise, set the page loading strategy to normal and set a property of capabilities with name "pageLoadStrategy" and value "normal". - if (strategy && strategy->is_string()) - web_content_connection.async_set_page_load_strategy(Web::WebDriver::page_load_strategy_from_string(strategy->as_string())); + if (strategy.has_value()) + web_content_connection.async_set_page_load_strategy(Web::WebDriver::page_load_strategy_from_string(*strategy)); else capabilities.set("pageLoadStrategy"sv, "normal"sv); // 3. Let strictFileInteractability be the result of getting property "strictFileInteractability" from capabilities. - auto const* strict_file_interactiblity = capabilities.get_ptr("strictFileInteractability"sv); + auto strict_file_interactiblity = capabilities.get_bool("strictFileInteractability"sv); // 4. If strictFileInteractability is a boolean, set the current session’s strict file interactability to strictFileInteractability. Otherwise set the current session’s strict file interactability to false. - if (strict_file_interactiblity && strict_file_interactiblity->is_bool()) - web_content_connection.async_set_strict_file_interactability(strict_file_interactiblity->as_bool()); + if (strict_file_interactiblity.has_value()) + web_content_connection.async_set_strict_file_interactability(*strict_file_interactiblity); else capabilities.set("strictFileInteractability"sv, false); @@ -105,7 +105,7 @@ static void initialize_session_from_capabilities(WebContentConnection& web_conte // FIXME: Set a property of capabilities with name "proxy" and a value that is a new JSON Object. // 6. If capabilities has a property with the key "timeouts": - if (auto const* timeouts = capabilities.get_ptr("timeouts"sv); timeouts && timeouts->is_object()) { + if (auto timeouts = capabilities.get_object("timeouts"sv); timeouts.has_value()) { // a. Let timeouts be the result of trying to JSON deserialize as a timeouts configuration the value of the "timeouts" property. // NOTE: This happens on the remote end. @@ -117,9 +117,9 @@ static void initialize_session_from_capabilities(WebContentConnection& web_conte } // 8. Apply changes to the user agent for any implementation-defined capabilities selected during the capabilities processing step. - auto const* behavior = capabilities.get_ptr("unhandledPromptBehavior"sv); - if (behavior && behavior->is_string()) - web_content_connection.async_set_unhandled_prompt_behavior(Web::WebDriver::unhandled_prompt_behavior_from_string(behavior->as_string())); + auto behavior = capabilities.get_deprecated_string("unhandledPromptBehavior"sv); + if (behavior.has_value()) + web_content_connection.async_set_unhandled_prompt_behavior(Web::WebDriver::unhandled_prompt_behavior_from_string(*behavior)); else capabilities.set("unhandledPromptBehavior"sv, "dismiss and notify"sv); } diff --git a/Userland/Services/WindowServer/KeymapSwitcher.cpp b/Userland/Services/WindowServer/KeymapSwitcher.cpp index 5a7cd98728..92adcb0adb 100644 --- a/Userland/Services/WindowServer/KeymapSwitcher.cpp +++ b/Userland/Services/WindowServer/KeymapSwitcher.cpp @@ -96,8 +96,8 @@ DeprecatedString KeymapSwitcher::get_current_keymap() const auto json = JsonValue::from_string(proc_keymap->read_all()).release_value_but_fixme_should_propagate_errors(); auto const& keymap_object = json.as_object(); - VERIFY(keymap_object.has("keymap"sv)); - return keymap_object.get_deprecated("keymap"sv).to_deprecated_string(); + VERIFY(keymap_object.has_string("keymap"sv)); + return keymap_object.get_deprecated_string("keymap"sv).value(); } void KeymapSwitcher::set_keymap(const AK::DeprecatedString& keymap) |